Mercurial > hg4j
changeset 313:c1e3c18fd2f2
Test manifest cancellation
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 27 Sep 2011 05:57:30 +0200 |
parents | f9f3e9b67ccc |
children | fb74133d2025 |
files | src/org/tmatesoft/hg/repo/HgManifest.java test/org/tmatesoft/hg/test/TestAuxUtilities.java |
diffstat | 2 files changed, 66 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/repo/HgManifest.java Tue Sep 27 05:29:12 2011 +0200 +++ b/src/org/tmatesoft/hg/repo/HgManifest.java Tue Sep 27 05:57:30 2011 +0200 @@ -370,6 +370,7 @@ Pool2<Nodeid> t = nodeidPool; nodeidPool = thisRevPool; thisRevPool = t; + iterateControl.checkCancelled(); progressHelper.worked(1); } catch (IOException ex) { throw new HgBadStateException(ex);
--- a/test/org/tmatesoft/hg/test/TestAuxUtilities.java Tue Sep 27 05:29:12 2011 +0200 +++ b/test/org/tmatesoft/hg/test/TestAuxUtilities.java Tue Sep 27 05:57:30 2011 +0200 @@ -16,16 +16,21 @@ */ package org.tmatesoft.hg.test; +import static org.tmatesoft.hg.repo.HgRepository.TIP; + import org.junit.Assert; import org.junit.Test; import org.tmatesoft.hg.core.Nodeid; import org.tmatesoft.hg.internal.ArrayHelper; import org.tmatesoft.hg.repo.HgChangelog; import org.tmatesoft.hg.repo.HgChangelog.RawChangeset; +import org.tmatesoft.hg.repo.HgManifest; +import org.tmatesoft.hg.repo.HgManifest.Flags; import org.tmatesoft.hg.repo.HgRepository; import org.tmatesoft.hg.util.Adaptable; import org.tmatesoft.hg.util.CancelSupport; import org.tmatesoft.hg.util.CancelledException; +import org.tmatesoft.hg.util.Path; /** * @@ -60,20 +65,21 @@ return rebuilt; } - @Test - public void testCancelSupport() throws Exception { - HgRepository repository = Configuration.get().find("branches-1"); // any repo with more revisions - class CancelImpl implements CancelSupport { - private boolean shallStop = false; - public void stop() { - shallStop = true; - } - public void checkCancelled() throws CancelledException { - if (shallStop) { - throw new CancelledException(); - } + static class CancelImpl implements CancelSupport { + private boolean shallStop = false; + public void stop() { + shallStop = true; + } + public void checkCancelled() throws CancelledException { + if (shallStop) { + throw new CancelledException(); } } + } + + @Test + public void testChangelogCancelSupport() throws Exception { + HgRepository repository = Configuration.get().find("branches-1"); // any repo with more revisions class InspectorImplementsCancel implements HgChangelog.Inspector, CancelSupport { public final int when2stop; public int lastVisitet = 0; @@ -131,4 +137,51 @@ repository.getChangelog().all(insp2 = new InspectorImplementsAdaptable(10)); Assert.assertEquals(insp2.when2stop, insp2.lastVisitet); } + + @Test + public void testManifestCancelSupport() throws Exception { + HgRepository repository = Configuration.get().find("branches-1"); // any repo with as many revisions as possible + class InspectorImplementsAdaptable implements HgManifest.Inspector2, Adaptable { + public final int when2stop; + public int lastVisitet = 0; + private final CancelImpl cancelImpl = new CancelImpl(); + + public InspectorImplementsAdaptable(int limit) { + when2stop = limit; + } + + public boolean begin(int mainfestRevision, Nodeid nid, int changelogRevision) { + if (++lastVisitet == when2stop) { + cancelImpl.stop(); + } + return true; + } + + public boolean next(Nodeid nid, String fname, String flags) { + return true; + } + + public boolean end(int manifestRevision) { + return true; + } + + @SuppressWarnings("unchecked") + public <T> T getAdapter(Class<T> adapterClass) { + if (CancelSupport.class == adapterClass) { + return (T) cancelImpl; + } + return null; + } + + public boolean next(Nodeid nid, Path fname, Flags flags) { + return true; + } + } + InspectorImplementsAdaptable insp1; + repository.getManifest().walk(0, TIP, insp1= new InspectorImplementsAdaptable(3)); + Assert.assertEquals(insp1.when2stop, insp1.lastVisitet); + repository.getManifest().walk(0, TIP, insp1 = new InspectorImplementsAdaptable(10)); + Assert.assertEquals(insp1.when2stop, insp1.lastVisitet); + } + }