Mercurial > hg4j
comparison test/org/tmatesoft/hg/test/TestAuxUtilities.java @ 313:c1e3c18fd2f2
Test manifest cancellation
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 27 Sep 2011 05:57:30 +0200 |
parents | f9f3e9b67ccc |
children | d68dcb3b5f49 |
comparison
equal
deleted
inserted
replaced
312:f9f3e9b67ccc | 313:c1e3c18fd2f2 |
---|---|
14 * the terms of a license other than GNU General Public License | 14 * the terms of a license other than GNU General Public License |
15 * contact TMate Software at support@hg4j.com | 15 * contact TMate Software at support@hg4j.com |
16 */ | 16 */ |
17 package org.tmatesoft.hg.test; | 17 package org.tmatesoft.hg.test; |
18 | 18 |
19 import static org.tmatesoft.hg.repo.HgRepository.TIP; | |
20 | |
19 import org.junit.Assert; | 21 import org.junit.Assert; |
20 import org.junit.Test; | 22 import org.junit.Test; |
21 import org.tmatesoft.hg.core.Nodeid; | 23 import org.tmatesoft.hg.core.Nodeid; |
22 import org.tmatesoft.hg.internal.ArrayHelper; | 24 import org.tmatesoft.hg.internal.ArrayHelper; |
23 import org.tmatesoft.hg.repo.HgChangelog; | 25 import org.tmatesoft.hg.repo.HgChangelog; |
24 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset; | 26 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset; |
27 import org.tmatesoft.hg.repo.HgManifest; | |
28 import org.tmatesoft.hg.repo.HgManifest.Flags; | |
25 import org.tmatesoft.hg.repo.HgRepository; | 29 import org.tmatesoft.hg.repo.HgRepository; |
26 import org.tmatesoft.hg.util.Adaptable; | 30 import org.tmatesoft.hg.util.Adaptable; |
27 import org.tmatesoft.hg.util.CancelSupport; | 31 import org.tmatesoft.hg.util.CancelSupport; |
28 import org.tmatesoft.hg.util.CancelledException; | 32 import org.tmatesoft.hg.util.CancelledException; |
33 import org.tmatesoft.hg.util.Path; | |
29 | 34 |
30 /** | 35 /** |
31 * | 36 * |
32 * @author Artem Tikhomirov | 37 * @author Artem Tikhomirov |
33 * @author TMate Software Ltd. | 38 * @author TMate Software Ltd. |
58 rebuilt[indexInOriginal-1] = sorted[i]; | 63 rebuilt[indexInOriginal-1] = sorted[i]; |
59 } | 64 } |
60 return rebuilt; | 65 return rebuilt; |
61 } | 66 } |
62 | 67 |
63 @Test | 68 static class CancelImpl implements CancelSupport { |
64 public void testCancelSupport() throws Exception { | 69 private boolean shallStop = false; |
65 HgRepository repository = Configuration.get().find("branches-1"); // any repo with more revisions | 70 public void stop() { |
66 class CancelImpl implements CancelSupport { | 71 shallStop = true; |
67 private boolean shallStop = false; | 72 } |
68 public void stop() { | 73 public void checkCancelled() throws CancelledException { |
69 shallStop = true; | 74 if (shallStop) { |
70 } | 75 throw new CancelledException(); |
71 public void checkCancelled() throws CancelledException { | |
72 if (shallStop) { | |
73 throw new CancelledException(); | |
74 } | |
75 } | 76 } |
76 } | 77 } |
78 } | |
79 | |
80 @Test | |
81 public void testChangelogCancelSupport() throws Exception { | |
82 HgRepository repository = Configuration.get().find("branches-1"); // any repo with more revisions | |
77 class InspectorImplementsCancel implements HgChangelog.Inspector, CancelSupport { | 83 class InspectorImplementsCancel implements HgChangelog.Inspector, CancelSupport { |
78 public final int when2stop; | 84 public final int when2stop; |
79 public int lastVisitet = 0; | 85 public int lastVisitet = 0; |
80 private final CancelImpl cancelImpl = new CancelImpl(); | 86 private final CancelImpl cancelImpl = new CancelImpl(); |
81 | 87 |
129 repository.getChangelog().all(insp2= new InspectorImplementsAdaptable(3)); | 135 repository.getChangelog().all(insp2= new InspectorImplementsAdaptable(3)); |
130 Assert.assertEquals(insp2.when2stop, insp2.lastVisitet); | 136 Assert.assertEquals(insp2.when2stop, insp2.lastVisitet); |
131 repository.getChangelog().all(insp2 = new InspectorImplementsAdaptable(10)); | 137 repository.getChangelog().all(insp2 = new InspectorImplementsAdaptable(10)); |
132 Assert.assertEquals(insp2.when2stop, insp2.lastVisitet); | 138 Assert.assertEquals(insp2.when2stop, insp2.lastVisitet); |
133 } | 139 } |
140 | |
141 @Test | |
142 public void testManifestCancelSupport() throws Exception { | |
143 HgRepository repository = Configuration.get().find("branches-1"); // any repo with as many revisions as possible | |
144 class InspectorImplementsAdaptable implements HgManifest.Inspector2, Adaptable { | |
145 public final int when2stop; | |
146 public int lastVisitet = 0; | |
147 private final CancelImpl cancelImpl = new CancelImpl(); | |
148 | |
149 public InspectorImplementsAdaptable(int limit) { | |
150 when2stop = limit; | |
151 } | |
152 | |
153 public boolean begin(int mainfestRevision, Nodeid nid, int changelogRevision) { | |
154 if (++lastVisitet == when2stop) { | |
155 cancelImpl.stop(); | |
156 } | |
157 return true; | |
158 } | |
159 | |
160 public boolean next(Nodeid nid, String fname, String flags) { | |
161 return true; | |
162 } | |
163 | |
164 public boolean end(int manifestRevision) { | |
165 return true; | |
166 } | |
167 | |
168 @SuppressWarnings("unchecked") | |
169 public <T> T getAdapter(Class<T> adapterClass) { | |
170 if (CancelSupport.class == adapterClass) { | |
171 return (T) cancelImpl; | |
172 } | |
173 return null; | |
174 } | |
175 | |
176 public boolean next(Nodeid nid, Path fname, Flags flags) { | |
177 return true; | |
178 } | |
179 } | |
180 InspectorImplementsAdaptable insp1; | |
181 repository.getManifest().walk(0, TIP, insp1= new InspectorImplementsAdaptable(3)); | |
182 Assert.assertEquals(insp1.when2stop, insp1.lastVisitet); | |
183 repository.getManifest().walk(0, TIP, insp1 = new InspectorImplementsAdaptable(10)); | |
184 Assert.assertEquals(insp1.when2stop, insp1.lastVisitet); | |
185 } | |
186 | |
134 } | 187 } |