LocalSnapshotStore extends SnapshotStore { @Override public Future<Optional<SelectedSnapshot>> doLoadAsync(final String persistenceId, final SnapshotSelectionCriteria criteria) { LOG.debug("In doLoadAsync - persistenceId: {}, criteria: {}", persistenceId, criteria); Deque<SnapshotMetadata> metadatas = getSnapshotMetadatas(persistenceId, criteria).stream() .sorted(LocalSnapshotStore::compare).collect(reverse()).stream().limit(maxLoadAttempts) .collect(Collectors.toCollection(ArrayDeque::new)); if (metadatas.isEmpty()) { return Futures.successful(Optional.empty()); } LOG.debug("doLoadAsync - found: {}", metadatas); return Futures.future(() -> doLoad(metadatas), executionContext); } LocalSnapshotStore(final Config config); @Override void preStart(); @Override Future<Optional<SelectedSnapshot>> doLoadAsync(final String persistenceId,
                                                          final SnapshotSelectionCriteria criteria); @Override Future<Void> doSaveAsync(final SnapshotMetadata metadata, final Object snapshot); @Override Future<Void> doDeleteAsync(final SnapshotMetadata metadata); @Override Future<Void> doDeleteAsync(final String persistenceId, final SnapshotSelectionCriteria criteria);  }
@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()); }