/** * Creates a new {@link StoreAdapter} on top of a newly created transient {@link Backend}, using the default {@link * InMemoryBackendFactory} implementation. * * @return a new store */ @Nonnull private StoreAdapter createTransientStore() { Backend backend; ImmutableConfig config; if (factory.supportsTransient()) { config = new InMemoryConfig(); backend = new InMemoryBackendFactory().createBackend(uri, config); } else { config = new BaseConfig<>(); backend = new InvalidBackend("This back-end does not provide a transient layer: you must save/load the associated resource before using it"); } return createStore(backend, config); }
@Nonnull @Override public BackendFactory factory() { return new InMemoryBackendFactory(); }
/** * Check the creation of chaining between the default {@link Store}s and a {@link InMemoryBackend}. */ @Test public void testCreateTransientStore() throws IOException { try (Backend backend = new InMemoryBackendFactory().createBackend(new InMemoryUriFactory().createLocalUri(currentTempFile()), new InMemoryConfig())) { try (Store store = StoreFactory.getInstance().createStore(backend, context().config())) { assertThat(store).isInstanceOf(NoopStore.class); assertThat(store.backend()).isSameAs(backend); } } }
/** * Checks the copy of a {@link Backend} to another. */ @Test public void testCopyBackend() throws IOException { ImmutableConfig config = context().config(); File file = currentTempFile(); try (Backend transientBackend = new InMemoryBackendFactory().createBackend(new InMemoryUriFactory().createLocalUri(file), new InMemoryConfig())) { try (Backend persistentBackend = context().factory().createBackend(context().createUri(currentTempFile()), config)) { transientBackend.copyTo(persistentBackend); } } }