Search in sources :

Example 1 with SelectedSnapshot

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());
}
Also used : LoadSnapshot(akka.persistence.SnapshotProtocol.LoadSnapshot) LoadSnapshotResult(akka.persistence.SnapshotProtocol.LoadSnapshotResult) SelectedSnapshot(akka.persistence.SelectedSnapshot) SnapshotMetadata(akka.persistence.SnapshotMetadata) TestKit(akka.testkit.javadsl.TestKit) File(java.io.File) Test(org.junit.Test)

Example 2 with SelectedSnapshot

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());
}
Also used : LoadSnapshot(akka.persistence.SnapshotProtocol.LoadSnapshot) LoadSnapshotResult(akka.persistence.SnapshotProtocol.LoadSnapshotResult) SelectedSnapshot(akka.persistence.SelectedSnapshot) SnapshotMetadata(akka.persistence.SnapshotMetadata) TestKit(akka.testkit.javadsl.TestKit) Test(org.junit.Test)

Example 3 with SelectedSnapshot

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);
}
Also used : ClientIdentifier(org.opendaylight.controller.cluster.access.concepts.ClientIdentifier) SelectedSnapshot(akka.persistence.SelectedSnapshot) SnapshotMetadata(akka.persistence.SnapshotMetadata) FrontendIdentifier(org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier) Test(org.junit.Test)

Example 4 with SelectedSnapshot

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);
    }
}
Also used : SelectedSnapshot(akka.persistence.SelectedSnapshot) SnapshotMetadata(akka.persistence.SnapshotMetadata) IOException(java.io.IOException) File(java.io.File)

Example 5 with SelectedSnapshot

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());
}
Also used : SelectedSnapshot(akka.persistence.SelectedSnapshot) Test(org.junit.Test)

Aggregations

SelectedSnapshot (akka.persistence.SelectedSnapshot)7 Test (org.junit.Test)6 SnapshotMetadata (akka.persistence.SnapshotMetadata)5 LoadSnapshot (akka.persistence.SnapshotProtocol.LoadSnapshot)4 LoadSnapshotResult (akka.persistence.SnapshotProtocol.LoadSnapshotResult)4 TestKit (akka.testkit.javadsl.TestKit)4 File (java.io.File)3 Snapshot (akka.persistence.serialization.Snapshot)1 SnapshotSerializer (akka.persistence.serialization.SnapshotSerializer)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 ClientIdentifier (org.opendaylight.controller.cluster.access.concepts.ClientIdentifier)1 FrontendIdentifier (org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier)1