Search in sources :

Example 1 with StorageFactory

use of io.spine.server.storage.StorageFactory in project core-java by SpineEventEngine.

the class ProcessManagerShould method setUp.

@Before
public void setUp() {
    final StorageFactory storageFactory = StorageFactorySwitch.get(true);
    final TenantIndex tenantIndex = TenantAwareTest.createTenantIndex(false, storageFactory);
    final CommandStore commandStore = spy(new CommandStore(storageFactory, tenantIndex));
    commandBus = spy(CommandBus.newBuilder().setCommandStore(commandStore).build());
    processManager = Given.processManagerOfClass(TestProcessManager.class).withId(ID).withVersion(2).withState(Any.getDefaultInstance()).build();
}
Also used : StorageFactory(io.spine.server.storage.StorageFactory) CommandStore(io.spine.server.commandstore.CommandStore) TenantIndex(io.spine.server.tenant.TenantIndex) Before(org.junit.Before)

Example 2 with StorageFactory

use of io.spine.server.storage.StorageFactory in project core-java by SpineEventEngine.

the class StorageFactorySwitchShould method return_InMemoryStorageFactory_in_tests_if_tests_supplier_was_not_set.

@Test
public void return_InMemoryStorageFactory_in_tests_if_tests_supplier_was_not_set() {
    final StorageFactory storageFactory = storageFactorySwitch.get();
    assertNotNull(storageFactory);
    assertTrue(storageFactory instanceof InMemoryStorageFactory);
}
Also used : StorageFactory(io.spine.server.storage.StorageFactory) InMemoryStorageFactory(io.spine.server.storage.memory.InMemoryStorageFactory) InMemoryStorageFactory(io.spine.server.storage.memory.InMemoryStorageFactory) Test(org.junit.Test)

Example 3 with StorageFactory

use of io.spine.server.storage.StorageFactory in project core-java by SpineEventEngine.

the class StorageFactorySwitchShould method return_custom_test_StorageFactory_if_supplier_for_tests_was_set.

@Test
public void return_custom_test_StorageFactory_if_supplier_for_tests_was_set() {
    // This call avoids the racing conditions anomaly when running
    // the Gradle build from the console.
    // Despite the fact that we reset the switch state in `cleanUp()`, we still
    // get the cached value of the StorageFactory remembered by the switch in a previous test.
    // Having this call avoids the problem.
    storageFactorySwitch.reset();
    final StorageFactory custom = mock(StorageFactory.class);
    storageFactorySwitch.init(testsSupplier, new Supplier<StorageFactory>() {

        @Override
        public StorageFactory get() {
            return custom;
        }
    });
    // These calls ensure that we're under the testing mode and we get the supplier for tests.
    assertTrue(Environment.getInstance().isTests());
    assertTrue(storageFactorySwitch.testsSupplier().isPresent());
    // Get the StorageFactory from the switch.
    final StorageFactory obtained = storageFactorySwitch.get();
    assertEquals(custom, obtained);
}
Also used : StorageFactory(io.spine.server.storage.StorageFactory) InMemoryStorageFactory(io.spine.server.storage.memory.InMemoryStorageFactory) Test(org.junit.Test)

Example 4 with StorageFactory

use of io.spine.server.storage.StorageFactory in project core-java by SpineEventEngine.

the class BoundedContextShould method not_change_storage_during_registration_if_a_repository_has_one.

@Test
public void not_change_storage_during_registration_if_a_repository_has_one() {
    final ProjectAggregateRepository repository = new ProjectAggregateRepository(boundedContext);
    repository.initStorage(storageFactory);
    final Repository spy = spy(repository);
    boundedContext.register(repository);
    verify(spy, never()).initStorage(any(StorageFactory.class));
}
Also used : AggregateRepository(io.spine.server.aggregate.AggregateRepository) Repository(io.spine.server.entity.Repository) ProcessManagerRepository(io.spine.server.procman.ProcessManagerRepository) ProjectionRepository(io.spine.server.projection.ProjectionRepository) StorageFactory(io.spine.server.storage.StorageFactory) Test(org.junit.Test)

Aggregations

StorageFactory (io.spine.server.storage.StorageFactory)4 Test (org.junit.Test)3 InMemoryStorageFactory (io.spine.server.storage.memory.InMemoryStorageFactory)2 AggregateRepository (io.spine.server.aggregate.AggregateRepository)1 CommandStore (io.spine.server.commandstore.CommandStore)1 Repository (io.spine.server.entity.Repository)1 ProcessManagerRepository (io.spine.server.procman.ProcessManagerRepository)1 ProjectionRepository (io.spine.server.projection.ProjectionRepository)1 TenantIndex (io.spine.server.tenant.TenantIndex)1 Before (org.junit.Before)1