Mercurial > hg4j
annotate test/org/tmatesoft/hg/test/TestAuxUtilities.java @ 325:f05c8b1f08c4
Explicit dependency for cmdline build
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Mon, 03 Oct 2011 06:54:43 +0200 |
parents | d68dcb3b5f49 |
children | 3f09b8c19142 |
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 |
322
d68dcb3b5f49
Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
313
diff
changeset
|
21 import java.io.IOException; |
d68dcb3b5f49
Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
313
diff
changeset
|
22 import java.nio.ByteBuffer; |
d68dcb3b5f49
Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
313
diff
changeset
|
23 |
311
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
24 import org.junit.Assert; |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
25 import org.junit.Test; |
322
d68dcb3b5f49
Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
313
diff
changeset
|
26 import org.tmatesoft.hg.core.HgCatCommand; |
312
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
27 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
|
28 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
|
29 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
|
30 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset; |
313
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
31 import org.tmatesoft.hg.repo.HgManifest; |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
32 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
|
33 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
|
34 import org.tmatesoft.hg.util.Adaptable; |
322
d68dcb3b5f49
Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
313
diff
changeset
|
35 import org.tmatesoft.hg.util.ByteChannel; |
312
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
36 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
|
37 import org.tmatesoft.hg.util.CancelledException; |
313
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
38 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
|
39 |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
40 /** |
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 * @author Artem Tikhomirov |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
43 * @author TMate Software Ltd. |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
44 */ |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
45 public class TestAuxUtilities { |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
46 |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
47 @Test |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
48 public void testArrayHelper() { |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
49 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
|
50 ArrayHelper ah = new ArrayHelper(); |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
51 String[] result = initial.clone(); |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
52 ah.sort(result); |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
53 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
|
54 Assert.assertArrayEquals(initial, restored); |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
55 // |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
56 // 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
|
57 // 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
|
58 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
|
59 ah.sort(result = initial.clone()); |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
60 restored = restore(result, ah.getReverse()); |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
61 Assert.assertArrayEquals(initial, restored); |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
62 } |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
63 |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
64 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
|
65 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
|
66 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
|
67 int indexInOriginal = sortReverse[i]; |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
68 rebuilt[indexInOriginal-1] = sorted[i]; |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
69 } |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
70 return rebuilt; |
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
71 } |
312
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
72 |
313
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
73 static class CancelImpl implements CancelSupport { |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
74 private boolean shallStop = false; |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
75 public void stop() { |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
76 shallStop = true; |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
77 } |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
78 public void checkCancelled() throws CancelledException { |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
79 if (shallStop) { |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
80 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
|
81 } |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
82 } |
313
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
83 } |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
84 |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
85 @Test |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
86 public void testChangelogCancelSupport() throws Exception { |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
87 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
|
88 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
|
89 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
|
90 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
|
91 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
|
92 |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
93 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
|
94 when2stop = limit; |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
95 } |
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 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
|
98 lastVisitet = revisionNumber; |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
99 if (revisionNumber == when2stop) { |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
100 cancelImpl.stop(); |
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 |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
104 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
|
105 cancelImpl.checkCancelled(); |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
106 } |
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 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
|
109 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
|
110 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
|
111 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
|
112 |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
113 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
|
114 when2stop = limit; |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
115 } |
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 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
|
118 lastVisitet = revisionNumber; |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
119 if (revisionNumber == when2stop) { |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
120 cancelImpl.stop(); |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
121 } |
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 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
|
124 if (CancelSupport.class == adapterClass) { |
322
d68dcb3b5f49
Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
313
diff
changeset
|
125 return adapterClass.cast(cancelImpl); |
312
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 return null; |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
128 } |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
129 |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
130 } |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
131 // |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
132 InspectorImplementsCancel insp1; |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
133 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
|
134 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
|
135 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
|
136 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
|
137 // |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
138 InspectorImplementsAdaptable insp2; |
f9f3e9b67ccc
Facilitate cancellation and progress reporting in changelog and manifest iterations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
311
diff
changeset
|
139 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
|
140 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
|
141 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
|
142 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
|
143 } |
313
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
144 |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
145 @Test |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
146 public void testManifestCancelSupport() throws Exception { |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
147 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
|
148 class InspectorImplementsAdaptable implements HgManifest.Inspector2, Adaptable { |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
149 public final int when2stop; |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
150 public int lastVisitet = 0; |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
151 private final CancelImpl cancelImpl = new CancelImpl(); |
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 InspectorImplementsAdaptable(int limit) { |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
154 when2stop = limit; |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
155 } |
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 public boolean begin(int mainfestRevision, Nodeid nid, int changelogRevision) { |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
158 if (++lastVisitet == when2stop) { |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
159 cancelImpl.stop(); |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
160 } |
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 next(Nodeid nid, String fname, String flags) { |
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 public boolean end(int manifestRevision) { |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
169 return true; |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
170 } |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
171 |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
172 public <T> T getAdapter(Class<T> adapterClass) { |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
173 if (CancelSupport.class == adapterClass) { |
322
d68dcb3b5f49
Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
313
diff
changeset
|
174 return adapterClass.cast(cancelImpl); |
313
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 return null; |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
177 } |
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 public boolean next(Nodeid nid, Path fname, Flags flags) { |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
180 return true; |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
181 } |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
182 } |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
183 InspectorImplementsAdaptable insp1; |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
184 repository.getManifest().walk(0, TIP, insp1= new InspectorImplementsAdaptable(3)); |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
185 Assert.assertEquals(insp1.when2stop, insp1.lastVisitet); |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
186 repository.getManifest().walk(0, TIP, insp1 = new InspectorImplementsAdaptable(10)); |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
187 Assert.assertEquals(insp1.when2stop, insp1.lastVisitet); |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
188 } |
c1e3c18fd2f2
Test manifest cancellation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
312
diff
changeset
|
189 |
322
d68dcb3b5f49
Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
313
diff
changeset
|
190 @Test |
d68dcb3b5f49
Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
313
diff
changeset
|
191 public void testCatCommandCancelSupport() throws Exception { |
d68dcb3b5f49
Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
313
diff
changeset
|
192 HgRepository repository = Configuration.get().find("branches-1"); // any repo |
d68dcb3b5f49
Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
313
diff
changeset
|
193 final HgCatCommand cmd = new HgCatCommand(repository); |
d68dcb3b5f49
Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
313
diff
changeset
|
194 cmd.file(Path.create("file1")); |
d68dcb3b5f49
Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
313
diff
changeset
|
195 cmd.set(new CancelSupport() { |
d68dcb3b5f49
Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
313
diff
changeset
|
196 int i = 0; |
d68dcb3b5f49
Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
313
diff
changeset
|
197 public void checkCancelled() throws CancelledException { |
d68dcb3b5f49
Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
313
diff
changeset
|
198 if (i++ == 2) { |
d68dcb3b5f49
Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
313
diff
changeset
|
199 throw new CancelledException(); |
d68dcb3b5f49
Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
313
diff
changeset
|
200 } |
d68dcb3b5f49
Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
313
diff
changeset
|
201 } |
d68dcb3b5f49
Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
313
diff
changeset
|
202 }); |
d68dcb3b5f49
Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
313
diff
changeset
|
203 try { |
d68dcb3b5f49
Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
313
diff
changeset
|
204 cmd.execute(new ByteChannel() { |
d68dcb3b5f49
Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
313
diff
changeset
|
205 |
d68dcb3b5f49
Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
313
diff
changeset
|
206 public int write(ByteBuffer buffer) throws IOException, CancelledException { |
d68dcb3b5f49
Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
313
diff
changeset
|
207 Assert.fail("Shall not get that far provided cancellation from command's CancelSupport is functional"); |
d68dcb3b5f49
Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
313
diff
changeset
|
208 return 0; |
d68dcb3b5f49
Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
313
diff
changeset
|
209 } |
d68dcb3b5f49
Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
313
diff
changeset
|
210 }); |
d68dcb3b5f49
Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
313
diff
changeset
|
211 Assert.fail("Command execution shall not fail silently, exception shall propagate"); |
d68dcb3b5f49
Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
313
diff
changeset
|
212 } catch (CancelledException ex) { |
d68dcb3b5f49
Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
313
diff
changeset
|
213 // good! |
d68dcb3b5f49
Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
313
diff
changeset
|
214 } |
d68dcb3b5f49
Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
313
diff
changeset
|
215 } |
311
b9592e21176a
Tests for array sort and reverse index building helper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
216 } |