use of akka.persistence.SelectedSnapshot in project controller by opendaylight.
the class LocalSnapshotStoreTest method testDoLoadAsync.
@Test
public void testDoLoadAsync() throws IOException {
createSnapshotFile(PERSISTENCE_ID, "one", 0, 1000);
createSnapshotFile(PERSISTENCE_ID, "two", 1, 2000);
createSnapshotFile(PERSISTENCE_ID, "three", 1, 3000);
createSnapshotFile(PREFIX_BASED_SHARD_PERSISTENCE_ID, "foo", 0, 1000);
createSnapshotFile(PREFIX_BASED_SHARD_PERSISTENCE_ID, "bar", 1, 2000);
createSnapshotFile(PREFIX_BASED_SHARD_PERSISTENCE_ID, "foobar", 1, 3000);
createSnapshotFile("member-1-shard-default-oper", "foo", 0, 1000);
createSnapshotFile("member-1-shard-toaster-oper", "foo", 0, 1000);
new File(SNAPSHOT_DIR, "other").createNewFile();
new File(SNAPSHOT_DIR, "other-1485349217290").createNewFile();
SnapshotMetadata metadata3 = new SnapshotMetadata(PERSISTENCE_ID, 1, 3000);
TestKit probe = new TestKit(system);
snapshotStore.tell(new LoadSnapshot(PERSISTENCE_ID, SnapshotSelectionCriteria.latest(), Long.MAX_VALUE), probe.getRef());
LoadSnapshotResult result = probe.expectMsgClass(LoadSnapshotResult.class);
Option<SelectedSnapshot> possibleSnapshot = result.snapshot();
assertEquals("SelectedSnapshot present", TRUE, possibleSnapshot.nonEmpty());
assertEquals("SelectedSnapshot metadata", metadata3, possibleSnapshot.get().metadata());
assertEquals("SelectedSnapshot snapshot", "three", possibleSnapshot.get().snapshot());
snapshotStore.tell(new LoadSnapshot(PREFIX_BASED_SHARD_PERSISTENCE_ID, SnapshotSelectionCriteria.latest(), Long.MAX_VALUE), probe.getRef());
result = probe.expectMsgClass(LoadSnapshotResult.class);
possibleSnapshot = result.snapshot();
SnapshotMetadata prefixBasedShardMetada3 = new SnapshotMetadata(PREFIX_BASED_SHARD_PERSISTENCE_ID, 1, 3000);
assertEquals("SelectedSnapshot present", TRUE, possibleSnapshot.nonEmpty());
assertEquals("SelectedSnapshot metadata", prefixBasedShardMetada3, possibleSnapshot.get().metadata());
assertEquals("SelectedSnapshot snapshot", "foobar", possibleSnapshot.get().snapshot());
}
use of akka.persistence.SelectedSnapshot in project controller by opendaylight.
the class LocalSnapshotStoreTest method testDoLoadAsyncWithRetry.
@Test
public void testDoLoadAsyncWithRetry() throws IOException {
createSnapshotFile(PERSISTENCE_ID, "one", 0, 1000);
createSnapshotFile(PERSISTENCE_ID, null, 1, 2000);
SnapshotMetadata metadata = new SnapshotMetadata(PERSISTENCE_ID, 0, 1000);
TestKit probe = new TestKit(system);
snapshotStore.tell(new LoadSnapshot(PERSISTENCE_ID, SnapshotSelectionCriteria.latest(), Long.MAX_VALUE), probe.getRef());
LoadSnapshotResult result = probe.expectMsgClass(LoadSnapshotResult.class);
Option<SelectedSnapshot> possibleSnapshot = result.snapshot();
assertEquals("SelectedSnapshot present", TRUE, possibleSnapshot.nonEmpty());
assertEquals("SelectedSnapshot metadata", metadata, possibleSnapshot.get().metadata());
assertEquals("SelectedSnapshot snapshot", "one", possibleSnapshot.get().snapshot());
}
use of akka.persistence.SelectedSnapshot in project controller by opendaylight.
the class ActorBehaviorTest method testRecoveryAfterRestartFrontendIdMismatch.
@Test
public void testRecoveryAfterRestartFrontendIdMismatch() throws Exception {
system.stop(mockedActor);
// start actor again
mockedActor = system.actorOf(MockedActor.props(id, initialBehavior));
probe.expectMsgClass(MockedSnapshotStore.LoadRequest.class);
// offer snapshot with incorrect client id
final SnapshotMetadata metadata = saveRequest.getMetadata();
final FrontendIdentifier anotherFrontend = FrontendIdentifier.create(MemberName.forName("another"), FrontendType.forName("type-2"));
final ClientIdentifier incorrectClientId = ClientIdentifier.create(anotherFrontend, 0);
probe.watch(mockedActor);
probe.reply(Optional.of(new SelectedSnapshot(metadata, incorrectClientId)));
// actor should be stopped
probe.expectTerminated(mockedActor, TIMEOUT);
}
use of akka.persistence.SelectedSnapshot in project controller by opendaylight.
the class LocalSnapshotStore method doLoad.
private Optional<SelectedSnapshot> doLoad(final Deque<SnapshotMetadata> metadatas) throws IOException {
SnapshotMetadata metadata = metadatas.removeFirst();
File file = toSnapshotFile(metadata);
LOG.debug("doLoad {}", file);
try {
Object data = deserialize(file);
LOG.debug("deserialized data: {}", data);
return Optional.of(new SelectedSnapshot(metadata, data));
} catch (IOException e) {
LOG.error("Error loading snapshot file {}, remaining attempts: {}", file, metadatas.size(), e);
if (metadatas.isEmpty()) {
throw e;
}
return doLoad(metadatas);
}
}
use of akka.persistence.SelectedSnapshot in project controller by opendaylight.
the class ActorBehaviorTest method testRecoveryAfterRestart.
@Test
public void testRecoveryAfterRestart() throws Exception {
system.stop(mockedActor);
mockedActor = system.actorOf(MockedActor.props(id, initialBehavior));
final MockedSnapshotStore.SaveRequest newSaveRequest = handleRecovery(new SelectedSnapshot(saveRequest.getMetadata(), saveRequest.getSnapshot()));
Assert.assertEquals(MEMBER_1_FRONTEND_TYPE_1, newSaveRequest.getMetadata().persistenceId());
}
Aggregations