Mercurial > hg4j
annotate test/org/tmatesoft/hg/test/TestAuxUtilities.java @ 320:678e326fd27c
Issue 15: Exception accessing oddly named file from history
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 30 Sep 2011 06:22:11 +0200 |
parents | c1e3c18fd2f2 |
children | d68dcb3b5f49 |
rev | line source |
---|---|
311
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
1 /* |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2011 TMate Software Ltd |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
3 * |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
6 * the Free Software Foundation; version 2 of the License. |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
7 * |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
8 * This program is distributed in the hope that it will be useful, |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
11 * GNU General Public License for more details. |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
12 * |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
13 * For information on how to redistribute this software under |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
14 * the terms of a license other than GNU General Public License |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
15 * contact TMate Software at support@hg4j.com |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
16 */ |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
17 package org.tmatesoft.hg.test; |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 |
313
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
19 import static org.tmatesoft.hg.repo.HgRepository.TIP; |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
20 |
311
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
21 import org.junit.Assert; |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
22 import org.junit.Test; |
312
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
23 import org.tmatesoft.hg.core.Nodeid; |
311
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
24 import org.tmatesoft.hg.internal.ArrayHelper; |
312
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
25 import org.tmatesoft.hg.repo.HgChangelog; |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
26 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset; |
313
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
27 import org.tmatesoft.hg.repo.HgManifest; |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
28 import org.tmatesoft.hg.repo.HgManifest.Flags; |
312
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
29 import org.tmatesoft.hg.repo.HgRepository; |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
30 import org.tmatesoft.hg.util.Adaptable; |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
31 import org.tmatesoft.hg.util.CancelSupport; |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
32 import org.tmatesoft.hg.util.CancelledException; |
313
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
33 import org.tmatesoft.hg.util.Path; |
311
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
34 |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
35 /** |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
36 * |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
37 * @author Artem Tikhomirov |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
38 * @author TMate Software Ltd. |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
39 */ |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
40 public class TestAuxUtilities { |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
41 |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
42 @Test |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
43 public void testArrayHelper() { |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
44 String[] initial = {"d", "w", "k", "b", "c", "i", "a", "r", "e", "h" }; |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
45 ArrayHelper ah = new ArrayHelper(); |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
46 String[] result = initial.clone(); |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
47 ah.sort(result); |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
48 String[] restored = restore(result, ah.getReverse()); |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
49 Assert.assertArrayEquals(initial, restored); |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
50 // |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
51 // few elements are on the right place from the very start and do not shift during sort. |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
52 // make sure for them we've got correct reversed indexes as well |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
53 initial = new String[] {"d", "h", "c", "b", "k", "i", "a", "r", "e", "w" }; |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
54 ah.sort(result = initial.clone()); |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
55 restored = restore(result, ah.getReverse()); |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
56 Assert.assertArrayEquals(initial, restored); |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
57 } |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
58 |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
59 private static String[] restore(String[] sorted, int[] sortReverse) { |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
60 String[] rebuilt = new String[sorted.length]; |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
61 for (int i = 0; i < sorted.length; i++) { |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
62 int indexInOriginal = sortReverse[i]; |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
63 rebuilt[indexInOriginal-1] = sorted[i]; |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
64 } |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
65 return rebuilt; |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
66 } |
312
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
67 |
313
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
68 static class CancelImpl implements CancelSupport { |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
69 private boolean shallStop = false; |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
70 public void stop() { |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
71 shallStop = true; |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
72 } |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
73 public void checkCancelled() throws CancelledException { |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
74 if (shallStop) { |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
75 throw new CancelledException(); |
312
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
76 } |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
77 } |
313
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
78 } |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
79 |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
80 @Test |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
81 public void testChangelogCancelSupport() throws Exception { |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
82 HgRepository repository = Configuration.get().find("branches-1"); // any repo with more revisions |
312
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
83 class InspectorImplementsCancel implements HgChangelog.Inspector, CancelSupport { |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
84 public final int when2stop; |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
85 public int lastVisitet = 0; |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
86 private final CancelImpl cancelImpl = new CancelImpl(); |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
87 |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
88 public InspectorImplementsCancel(int limit) { |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
89 when2stop = limit; |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
90 } |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
91 |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
92 public void next(int revisionNumber, Nodeid nodeid, RawChangeset cset) { |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
93 lastVisitet = revisionNumber; |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
94 if (revisionNumber == when2stop) { |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
95 cancelImpl.stop(); |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
96 } |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
97 } |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
98 |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
99 public void checkCancelled() throws CancelledException { |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
100 cancelImpl.checkCancelled(); |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
101 } |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
102 }; |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
103 class InspectorImplementsAdaptable implements HgChangelog.Inspector, Adaptable { |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
104 public final int when2stop; |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
105 public int lastVisitet = 0; |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
106 private final CancelImpl cancelImpl = new CancelImpl(); |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
107 |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
108 public InspectorImplementsAdaptable(int limit) { |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
109 when2stop = limit; |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
110 } |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
111 |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
112 public void next(int revisionNumber, Nodeid nodeid, RawChangeset cset) { |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
113 lastVisitet = revisionNumber; |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
114 if (revisionNumber == when2stop) { |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
115 cancelImpl.stop(); |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
116 } |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
117 } |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
118 @SuppressWarnings("unchecked") |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
119 public <T> T getAdapter(Class<T> adapterClass) { |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
120 if (CancelSupport.class == adapterClass) { |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
121 return (T) cancelImpl; |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
122 } |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
123 return null; |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
124 } |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
125 |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
126 } |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
127 // |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
128 InspectorImplementsCancel insp1; |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
129 repository.getChangelog().all(insp1= new InspectorImplementsCancel(2)); |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
130 Assert.assertEquals(insp1.when2stop, insp1.lastVisitet); |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
131 repository.getChangelog().all(insp1 = new InspectorImplementsCancel(12)); |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
132 Assert.assertEquals(insp1.when2stop, insp1.lastVisitet); |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
133 // |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
134 InspectorImplementsAdaptable insp2; |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
135 repository.getChangelog().all(insp2= new InspectorImplementsAdaptable(3)); |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
136 Assert.assertEquals(insp2.when2stop, insp2.lastVisitet); |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
137 repository.getChangelog().all(insp2 = new InspectorImplementsAdaptable(10)); |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
138 Assert.assertEquals(insp2.when2stop, insp2.lastVisitet); |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
139 } |
313
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
140 |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
141 @Test |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
142 public void testManifestCancelSupport() throws Exception { |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
143 HgRepository repository = Configuration.get().find("branches-1"); // any repo with as many revisions as possible |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
144 class InspectorImplementsAdaptable implements HgManifest.Inspector2, Adaptable { |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
145 public final int when2stop; |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
146 public int lastVisitet = 0; |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
147 private final CancelImpl cancelImpl = new CancelImpl(); |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
148 |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
149 public InspectorImplementsAdaptable(int limit) { |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
150 when2stop = limit; |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
151 } |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
152 |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
153 public boolean begin(int mainfestRevision, Nodeid nid, int changelogRevision) { |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
154 if (++lastVisitet == when2stop) { |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
155 cancelImpl.stop(); |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
156 } |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
157 return true; |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
158 } |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
159 |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
160 public boolean next(Nodeid nid, String fname, String flags) { |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
161 return true; |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
162 } |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
163 |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
164 public boolean end(int manifestRevision) { |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
165 return true; |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
166 } |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
167 |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
168 @SuppressWarnings("unchecked") |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
169 public <T> T getAdapter(Class<T> adapterClass) { |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
170 if (CancelSupport.class == adapterClass) { |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
171 return (T) cancelImpl; |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
172 } |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
173 return null; |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
174 } |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
175 |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
176 public boolean next(Nodeid nid, Path fname, Flags flags) { |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
177 return true; |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
178 } |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
179 } |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
180 InspectorImplementsAdaptable insp1; |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
181 repository.getManifest().walk(0, TIP, insp1= new InspectorImplementsAdaptable(3)); |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
182 Assert.assertEquals(insp1.when2stop, insp1.lastVisitet); |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
183 repository.getManifest().walk(0, TIP, insp1 = new InspectorImplementsAdaptable(10)); |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
184 Assert.assertEquals(insp1.when2stop, insp1.lastVisitet); |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
185 } |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
186 |
311
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
187 } |