Search in sources :

Example 1 with LoadSnapshot

use of akka.persistence.SnapshotProtocol.LoadSnapshot 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 LoadSnapshot

use of akka.persistence.SnapshotProtocol.LoadSnapshot 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 LoadSnapshot

use of akka.persistence.SnapshotProtocol.LoadSnapshot in project controller by opendaylight.

the class LocalSnapshotStoreTest method testDoLoadAsyncWithAkkaSerializedSnapshot.

@Test
public void testDoLoadAsyncWithAkkaSerializedSnapshot() throws IOException {
    SnapshotSerializer snapshotSerializer = new SnapshotSerializer((ExtendedActorSystem) system);
    String name = toSnapshotName(PERSISTENCE_ID, 1, 1000);
    try (FileOutputStream fos = new FileOutputStream(new File(SNAPSHOT_DIR, name))) {
        fos.write(snapshotSerializer.toBinary(new Snapshot("one")));
    }
    SnapshotMetadata metadata = new SnapshotMetadata(PERSISTENCE_ID, 1, 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 : Snapshot(akka.persistence.serialization.Snapshot) LoadSnapshot(akka.persistence.SnapshotProtocol.LoadSnapshot) SelectedSnapshot(akka.persistence.SelectedSnapshot) LoadSnapshot(akka.persistence.SnapshotProtocol.LoadSnapshot) LoadSnapshotResult(akka.persistence.SnapshotProtocol.LoadSnapshotResult) SelectedSnapshot(akka.persistence.SelectedSnapshot) SnapshotMetadata(akka.persistence.SnapshotMetadata) FileOutputStream(java.io.FileOutputStream) SnapshotSerializer(akka.persistence.serialization.SnapshotSerializer) TestKit(akka.testkit.javadsl.TestKit) File(java.io.File) Test(org.junit.Test)

Example 4 with LoadSnapshot

use of akka.persistence.SnapshotProtocol.LoadSnapshot in project controller by opendaylight.

the class LocalSnapshotStoreTest method testDoLoadAsyncWithNoSnapshots.

@Test
public void testDoLoadAsyncWithNoSnapshots() throws IOException {
    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", FALSE, possibleSnapshot.nonEmpty());
}
Also used : LoadSnapshot(akka.persistence.SnapshotProtocol.LoadSnapshot) LoadSnapshotResult(akka.persistence.SnapshotProtocol.LoadSnapshotResult) SelectedSnapshot(akka.persistence.SelectedSnapshot) TestKit(akka.testkit.javadsl.TestKit) Test(org.junit.Test)

Aggregations

SelectedSnapshot (akka.persistence.SelectedSnapshot)4 LoadSnapshot (akka.persistence.SnapshotProtocol.LoadSnapshot)4 LoadSnapshotResult (akka.persistence.SnapshotProtocol.LoadSnapshotResult)4 TestKit (akka.testkit.javadsl.TestKit)4 Test (org.junit.Test)4 SnapshotMetadata (akka.persistence.SnapshotMetadata)3 File (java.io.File)2 Snapshot (akka.persistence.serialization.Snapshot)1 SnapshotSerializer (akka.persistence.serialization.SnapshotSerializer)1 FileOutputStream (java.io.FileOutputStream)1