private final FreenetInterface freenetInterface;
private final SoneModificationDetector soneModificationDetector;
+ private final long delay;
/** The Sone to insert. */
private volatile Sone sone;
* 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;
}
//
while (!shouldStop()) {
try {
/* check every second. */
- sleep(1000);
+ sleep(delay);
if (soneModificationDetector.isEligibleForInsert()) {
InsertInformation insertInformation = new InsertInformation(sone);
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));
}
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));
}
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<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
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<FreenetURI>() {
@Override
public FreenetURI answer(InvocationOnMock invocation) throws Throwable {
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() {
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<FreenetURI>() {
@Override