From bbdc7a081a8829e1f6483e3da549d1bd85c01537 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 2 Aug 2014 16:54:04 +0200 Subject: [PATCH] Make delay configurable in test constructor to allow faster testing. --- src/main/java/net/pterodactylus/sone/core/SoneInserter.java | 8 +++++--- .../java/net/pterodactylus/sone/core/SoneInserterTest.java | 12 ++++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/core/SoneInserter.java b/src/main/java/net/pterodactylus/sone/core/SoneInserter.java index 1e93aa6..843e9c4 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneInserter.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneInserter.java @@ -99,6 +99,7 @@ public class SoneInserter extends AbstractService { private final FreenetInterface freenetInterface; private final SoneModificationDetector soneModificationDetector; + private final long delay; /** The Sone to insert. */ private volatile Sone sone; @@ -116,17 +117,18 @@ public class SoneInserter extends AbstractService { * The Sone to insert */ public SoneInserter(Core core, EventBus eventBus, FreenetInterface freenetInterface, Sone sone) { - this(core, eventBus, freenetInterface, sone, new SoneModificationDetector(core, sone, insertionDelay)); + this(core, eventBus, freenetInterface, sone, new SoneModificationDetector(core, sone, insertionDelay), 1000); } @VisibleForTesting - SoneInserter(Core core, EventBus eventBus, FreenetInterface freenetInterface, Sone sone, SoneModificationDetector soneModificationDetector) { + SoneInserter(Core core, EventBus eventBus, FreenetInterface freenetInterface, Sone sone, SoneModificationDetector soneModificationDetector, long delay) { super("Sone Inserter for “" + sone.getName() + "”", false); this.core = core; this.eventBus = eventBus; this.freenetInterface = freenetInterface; this.sone = sone; this.soneModificationDetector = soneModificationDetector; + this.delay = delay; } // @@ -204,7 +206,7 @@ public class SoneInserter extends AbstractService { while (!shouldStop()) { try { /* check every second. */ - sleep(1000); + sleep(delay); if (soneModificationDetector.isEligibleForInsert()) { InsertInformation insertInformation = new InsertInformation(sone); diff --git a/src/test/java/net/pterodactylus/sone/core/SoneInserterTest.java b/src/test/java/net/pterodactylus/sone/core/SoneInserterTest.java index b303a1c..c5c74dc 100644 --- a/src/test/java/net/pterodactylus/sone/core/SoneInserterTest.java +++ b/src/test/java/net/pterodactylus/sone/core/SoneInserterTest.java @@ -99,7 +99,7 @@ public class SoneInserterTest { Sone sone = mock(Sone.class); SoneModificationDetector soneModificationDetector = mock(SoneModificationDetector.class); when(soneModificationDetector.isModified()).thenReturn(true); - SoneInserter soneInserter = new SoneInserter(core, eventBus, freenetInterface, sone, soneModificationDetector); + SoneInserter soneInserter = new SoneInserter(core, eventBus, freenetInterface, sone, soneModificationDetector, 1); assertThat(soneInserter.isModified(), is(true)); } @@ -107,7 +107,7 @@ public class SoneInserterTest { public void isModifiedIsFalseIfModificationDetectorSaysSo() { Sone sone = mock(Sone.class); SoneModificationDetector soneModificationDetector = mock(SoneModificationDetector.class); - SoneInserter soneInserter = new SoneInserter(core, eventBus, freenetInterface, sone, soneModificationDetector); + SoneInserter soneInserter = new SoneInserter(core, eventBus, freenetInterface, sone, soneModificationDetector, 1); assertThat(soneInserter.isModified(), is(false)); } @@ -136,7 +136,7 @@ public class SoneInserterTest { SoneModificationDetector soneModificationDetector = mock(SoneModificationDetector.class); when(soneModificationDetector.isEligibleForInsert()).thenReturn(true); when(freenetInterface.insertDirectory(eq(insertUri), any(HashMap.class), eq("index.html"))).thenReturn(finalUri); - final SoneInserter soneInserter = new SoneInserter(core, eventBus, freenetInterface, sone, soneModificationDetector); + final SoneInserter soneInserter = new SoneInserter(core, eventBus, freenetInterface, sone, soneModificationDetector, 1); doAnswer(new Answer() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { @@ -162,7 +162,7 @@ public class SoneInserterTest { Sone sone = createSone(insertUri, fingerprint); SoneModificationDetector soneModificationDetector = mock(SoneModificationDetector.class); when(soneModificationDetector.isEligibleForInsert()).thenReturn(true); - final SoneInserter soneInserter = new SoneInserter(core, eventBus, freenetInterface, sone, soneModificationDetector); + final SoneInserter soneInserter = new SoneInserter(core, eventBus, freenetInterface, sone, soneModificationDetector, 1); when(freenetInterface.insertDirectory(eq(insertUri), any(HashMap.class), eq("index.html"))).thenAnswer(new Answer() { @Override public FreenetURI answer(InvocationOnMock invocation) throws Throwable { @@ -187,7 +187,7 @@ public class SoneInserterTest { String fingerprint = "fingerprint"; Sone sone = createSone(insertUri, fingerprint); SoneModificationDetector soneModificationDetector = mock(SoneModificationDetector.class); - final SoneInserter soneInserter = new SoneInserter(core, eventBus, freenetInterface, sone, soneModificationDetector); + final SoneInserter soneInserter = new SoneInserter(core, eventBus, freenetInterface, sone, soneModificationDetector, 1); new Thread(new Runnable() { @Override public void run() { @@ -211,7 +211,7 @@ public class SoneInserterTest { Sone sone = createSone(insertUri, fingerprint); SoneModificationDetector soneModificationDetector = mock(SoneModificationDetector.class); when(soneModificationDetector.isEligibleForInsert()).thenReturn(true); - final SoneInserter soneInserter = new SoneInserter(core, eventBus, freenetInterface, sone, soneModificationDetector); + final SoneInserter soneInserter = new SoneInserter(core, eventBus, freenetInterface, sone, soneModificationDetector, 1); final SoneException soneException = new SoneException(new Exception()); when(freenetInterface.insertDirectory(eq(insertUri), any(HashMap.class), eq("index.html"))).thenAnswer(new Answer() { @Override -- 2.7.4