import net.pterodactylus.sone.data.Reply;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.data.Sone.SoneStatus;
+import net.pterodactylus.sone.database.Database;
import net.pterodactylus.sone.freenet.StringBucket;
import net.pterodactylus.sone.main.SonePlugin;
import net.pterodactylus.util.io.Closer;
/** The Freenet interface. */
private final FreenetInterface freenetInterface;
-
+ private final Database database;
private final SoneModificationDetector soneModificationDetector;
private final long delay;
private final String soneId;
* @param soneId
* The ID of the Sone to insert
*/
- public SoneInserter(final Core core, EventBus eventBus, FreenetInterface freenetInterface, final String soneId) {
- this(core, eventBus, freenetInterface, soneId, new SoneModificationDetector(new LockableFingerprintProvider() {
+ public SoneInserter(final Core core, EventBus eventBus, FreenetInterface freenetInterface, Database database, final String soneId) {
+ this(core, eventBus, freenetInterface, database, soneId, new SoneModificationDetector(new LockableFingerprintProvider() {
@Override
public boolean isLocked() {
final Optional<LocalSone> sone = core.getLocalSone(soneId);
}
@VisibleForTesting
- SoneInserter(Core core, EventBus eventBus, FreenetInterface freenetInterface, String soneId, SoneModificationDetector soneModificationDetector, long delay) {
+ SoneInserter(Core core, EventBus eventBus, FreenetInterface freenetInterface, Database database, String soneId, SoneModificationDetector soneModificationDetector, long delay) {
super("Sone Inserter for “" + soneId + "”", false);
this.core = core;
this.eventBus = eventBus;
this.freenetInterface = freenetInterface;
+ this.database = database;
this.soneId = soneId;
this.soneModificationDetector = soneModificationDetector;
this.delay = delay;
/* if so, bail out, don’t change anything. */
break;
}
- sone.setTime(insertTime);
+ database.updateSoneTime(sone, insertTime);
sone.setLatestEdition(finalUri.getEdition());
core.touchConfiguration();
success = true;
import java.util.HashMap;
import java.util.Map;
-import net.pterodactylus.sone.core.SoneInserter.InsertInformation;
import net.pterodactylus.sone.core.SoneInserter.ManifestCreator;
import net.pterodactylus.sone.core.event.InsertionDelayChangedEvent;
import net.pterodactylus.sone.core.event.SoneEvent;
import net.pterodactylus.sone.data.Album;
import net.pterodactylus.sone.data.LocalSone;
import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.database.Database;
import net.pterodactylus.sone.main.SonePlugin;
import freenet.client.async.ManifestElement;
private final Core core = mock(Core.class);
private final EventBus eventBus = mock(EventBus.class);
private final FreenetInterface freenetInterface = mock(FreenetInterface.class);
+ private final Database database = mock(Database.class);
@Before
public void setupCore() {
@Test
public void insertionDelayIsForwardedToSoneInserter() {
EventBus eventBus = new AsyncEventBus(sameThreadExecutor());
- eventBus.register(new SoneInserter(core, eventBus, freenetInterface, "SoneId"));
+ eventBus.register(new SoneInserter(core, eventBus, freenetInterface, database, "SoneId"));
eventBus.post(new InsertionDelayChangedEvent(15));
assertThat(SoneInserter.getInsertionDelay().get(), is(15));
}
public void isModifiedIsTrueIfModificationDetectorSaysSo() {
SoneModificationDetector soneModificationDetector = mock(SoneModificationDetector.class);
when(soneModificationDetector.isModified()).thenReturn(true);
- SoneInserter soneInserter = new SoneInserter(core, eventBus, freenetInterface, "SoneId", soneModificationDetector, 1);
+ SoneInserter soneInserter = new SoneInserter(core, eventBus, freenetInterface, database, "SoneId", soneModificationDetector, 1);
assertThat(soneInserter.isModified(), is(true));
}
@Test
public void isModifiedIsFalseIfModificationDetectorSaysSo() {
SoneModificationDetector soneModificationDetector = mock(SoneModificationDetector.class);
- SoneInserter soneInserter = new SoneInserter(core, eventBus, freenetInterface, "SoneId", soneModificationDetector, 1);
+ SoneInserter soneInserter = new SoneInserter(core, eventBus, freenetInterface, database, "SoneId", soneModificationDetector, 1);
assertThat(soneInserter.isModified(), is(false));
}
@Test
public void lastFingerprintIsStoredCorrectly() {
- SoneInserter soneInserter = new SoneInserter(core, eventBus, freenetInterface, "SoneId");
+ SoneInserter soneInserter = new SoneInserter(core, eventBus, freenetInterface, database, "SoneId");
soneInserter.setLastInsertFingerprint("last-fingerprint");
assertThat(soneInserter.getLastInsertFingerprint(), is("last-fingerprint"));
}
@Test
public void soneInserterStopsWhenItShould() {
- SoneInserter soneInserter = new SoneInserter(core, eventBus, freenetInterface, "SoneId");
+ SoneInserter soneInserter = new SoneInserter(core, eventBus, freenetInterface, database, "SoneId");
soneInserter.stop();
soneInserter.serviceRun();
}
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, "SoneId", soneModificationDetector, 1);
+ final SoneInserter soneInserter = new SoneInserter(core, eventBus, freenetInterface, database, "SoneId", 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, "SoneId", soneModificationDetector, 1);
+ final SoneInserter soneInserter = new SoneInserter(core, eventBus, freenetInterface, database, "SoneId", 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, "SoneId", soneModificationDetector, 1);
+ final SoneInserter soneInserter = new SoneInserter(core, eventBus, freenetInterface, database, "SoneId", 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, "SoneId", soneModificationDetector, 1);
+ final SoneInserter soneInserter = new SoneInserter(core, eventBus, freenetInterface, database, "SoneId", 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
SoneModificationDetector soneModificationDetector =
mock(SoneModificationDetector.class);
SoneInserter soneInserter =
- new SoneInserter(core, eventBus, freenetInterface, "SoneId",
+ new SoneInserter(core, eventBus, freenetInterface, database, "SoneId",
soneModificationDetector, 1);
when(soneModificationDetector.isEligibleForInsert()).thenReturn(true);
when(core.getSone("SoneId")).thenReturn(Optional.<Sone>absent());
SoneModificationDetector soneModificationDetector =
mock(SoneModificationDetector.class);
final SoneInserter soneInserter =
- new SoneInserter(core, eventBus, freenetInterface, "SoneId",
+ new SoneInserter(core, eventBus, freenetInterface, database, "SoneId",
soneModificationDetector, 1);
Answer<Optional<Sone>> stopInserterAndThrowException =
new Answer<Optional<Sone>>() {