FileBasedSnapshotStoreFactory implements SnapshotStoreSupplier, ReceivableSnapshotStoreFactory { @Override public ReceivableSnapshotStore createReceivableSnapshotStore( final Path root, final String partitionName) { final var snapshotDirectory = root.resolve(SNAPSHOTS_DIRECTORY); final var pendingDirectory = root.resolve(PENDING_DIRECTORY); IoUtil.ensureDirectoryExists(snapshotDirectory.toFile(), "Snapshot directory"); IoUtil.ensureDirectoryExists(pendingDirectory.toFile(), "Pending snapshot directory"); return partitionSnapshotStores.computeIfAbsent( partitionName, p -> new FileBasedSnapshotStore( new SnapshotMetrics(partitionName), snapshotDirectory, pendingDirectory)); }  @Override ReceivableSnapshotStore createReceivableSnapshotStore(
      final Path root, final String partitionName); @Override ConstructableSnapshotStore getConstructableSnapshotStore(final String partitionName); @Override ReceivableSnapshotStore getReceivableSnapshotStore(final String partitionName); @Override PersistedSnapshotStore getPersistedSnapshotStore(final String partitionName); static final String SNAPSHOTS_DIRECTORY; static final String PENDING_DIRECTORY; }
@Test public void shouldCreateDirectoriesIfNotExist() { final var root = temporaryFolder.getRoot().toPath(); final var factory = new FileBasedSnapshotStoreFactory(); final var store = factory.createReceivableSnapshotStore(root, "ignored"); assertThat(root.resolve(FileBasedSnapshotStoreFactory.SNAPSHOTS_DIRECTORY)) .exists() .isDirectory(); assertThat(root.resolve(FileBasedSnapshotStoreFactory.PENDING_DIRECTORY)) .exists() .isDirectory(); assertThat(store.getLatestSnapshot()).isEmpty(); }