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());
}
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();
}
}
Aggregations