Search in sources :

Example 1 with Snapshot

use of akka.persistence.serialization.Snapshot 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 2 with Snapshot

use of akka.persistence.serialization.Snapshot in project controller by opendaylight.

the class LocalSnapshotStore method tryDeserializeAkkaSnapshot.

private Object tryDeserializeAkkaSnapshot(final File file) throws IOException {
    LOG.debug("tryDeserializeAkkaSnapshot {}", file);
    // The snapshot was probably previously stored via akka's LocalSnapshotStore which wraps the data
    // in a Snapshot instance and uses the SnapshotSerializer to serialize it to a byte[]. So we'll use
    // the SnapshotSerializer to try to de-serialize it.
    SnapshotSerializer snapshotSerializer = new SnapshotSerializer((ExtendedActorSystem) context().system());
    try (InputStream in = new BufferedInputStream(new FileInputStream(file))) {
        return ((Snapshot) snapshotSerializer.fromBinary(ByteStreams.toByteArray(in))).data();
    }
}
Also used : Snapshot(akka.persistence.serialization.Snapshot) SelectedSnapshot(akka.persistence.SelectedSnapshot) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) ObjectInputStream(java.io.ObjectInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) SnapshotSerializer(akka.persistence.serialization.SnapshotSerializer) FileInputStream(java.io.FileInputStream)

Aggregations

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