Search in sources :

Example 21 with BoundedContext

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

the class BoundedContextShould method propagate_registered_repositories_to_stand.

@Test
public void propagate_registered_repositories_to_stand() {
    final BoundedContext boundedContext = BoundedContext.newBuilder().build();
    final Stand stand = Spy.ofClass(Stand.class).on(boundedContext);
    verify(stand, never()).registerTypeSupplier(any(Repository.class));
    final ProjectAggregateRepository repository = new ProjectAggregateRepository(boundedContext);
    boundedContext.register(repository);
    verify(stand).registerTypeSupplier(eq(repository));
}
Also used : Stand(io.spine.server.stand.Stand) AggregateRepository(io.spine.server.aggregate.AggregateRepository) Repository(io.spine.server.entity.Repository) ProcessManagerRepository(io.spine.server.procman.ProcessManagerRepository) ProjectionRepository(io.spine.server.projection.ProjectionRepository) BoundedContext(io.spine.server.BoundedContext) Test(org.junit.Test)

Example 22 with BoundedContext

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

the class BoundedContextShould method set_multi_tenancy_in_CommandBus.

@Test
public void set_multi_tenancy_in_CommandBus() {
    BoundedContext bc = BoundedContext.newBuilder().setMultitenant(true).build();
    assertEquals(bc.isMultitenant(), bc.getCommandBus().isMultitenant());
    bc = BoundedContext.newBuilder().setMultitenant(false).build();
    assertEquals(bc.isMultitenant(), bc.getCommandBus().isMultitenant());
}
Also used : BoundedContext(io.spine.server.BoundedContext) Test(org.junit.Test)

Example 23 with BoundedContext

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

the class StandPostShould method projectionRepositoryDispatch.

private static BoundedContextAction projectionRepositoryDispatch() {
    return new BoundedContextAction() {

        @Override
        public void perform(BoundedContext context) {
            // Init repository
            final ProjectionRepository repository = Given.projectionRepo(context);
            repository.initStorage(storageFactory(context.isMultitenant()));
            // Dispatch an update from projection repo
            repository.dispatch(EventEnvelope.of(Given.validEvent()));
        }
    };
}
Also used : ProjectionRepository(io.spine.server.projection.ProjectionRepository) BoundedContext(io.spine.server.BoundedContext)

Example 24 with BoundedContext

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

the class StandPostShould method checkUpdatesDelivery.

private static void checkUpdatesDelivery(boolean isConcurrent, BoundedContextAction... dispatchActions) {
    checkNotNull(dispatchActions);
    final Executor executor = isConcurrent ? Executors.newFixedThreadPool(Given.THREADS_COUNT_IN_POOL_EXECUTOR) : MoreExecutors.directExecutor();
    final StandUpdateDelivery delivery = spy(new SpyableStandUpdateDelivery(executor));
    final BoundedContext boundedContext = BoundedContext.newBuilder().setStand(Stand.newBuilder().setDelivery(delivery)).build();
    final Stand stand = boundedContext.getStand();
    for (BoundedContextAction dispatchAction : dispatchActions) {
        dispatchAction.perform(boundedContext);
    }
    // Was called as many times as there are dispatch actions.
    verify(delivery, times(dispatchActions.length)).deliver(any(EntityStateEnvelope.class));
    if (isConcurrent) {
        try {
            ((ExecutorService) executor).awaitTermination(Given.SEVERAL, TimeUnit.SECONDS);
        } catch (InterruptedException ignored) {
        }
    }
    verify(stand, times(dispatchActions.length)).update(any(EntityStateEnvelope.class));
}
Also used : Executor(java.util.concurrent.Executor) EntityStateEnvelope(io.spine.server.entity.EntityStateEnvelope) ExecutorService(java.util.concurrent.ExecutorService) BoundedContext(io.spine.server.BoundedContext)

Example 25 with BoundedContext

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

the class StandShould method register_projection_repositories.

@Test
public void register_projection_repositories() {
    final boolean multitenant = isMultitenant();
    final BoundedContext boundedContext = BoundedContext.newBuilder().setMultitenant(multitenant).build();
    final Stand stand = boundedContext.getStand();
    checkTypesEmpty(stand);
    final StandTestProjectionRepository standTestProjectionRepo = new StandTestProjectionRepository(boundedContext);
    stand.registerTypeSupplier(standTestProjectionRepo);
    checkHasExactlyOne(stand.getExposedTypes(), Project.getDescriptor());
    final ImmutableSet<TypeUrl> knownAggregateTypes = stand.getExposedAggregateTypes();
    // As we registered a projection repo, known aggregate types should be still empty.
    assertTrue("For some reason an aggregate type was registered", knownAggregateTypes.isEmpty());
    final StandTestProjectionRepository anotherTestProjectionRepo = new StandTestProjectionRepository(boundedContext);
    stand.registerTypeSupplier(anotherTestProjectionRepo);
    checkHasExactlyOne(stand.getExposedTypes(), Project.getDescriptor());
}
Also used : BoundedContext(io.spine.server.BoundedContext) TypeUrl(io.spine.type.TypeUrl) StandTestProjectionRepository(io.spine.server.stand.Given.StandTestProjectionRepository) Test(org.junit.Test) TenantAwareTest(io.spine.server.tenant.TenantAwareTest)

Aggregations

BoundedContext (io.spine.server.BoundedContext)26 Test (org.junit.Test)16 Before (org.junit.Before)5 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)4 StreamObserver (io.grpc.stub.StreamObserver)3 MemoizingObserver (io.spine.io.StreamObservers.MemoizingObserver)3 StreamObservers.memoizingObserver (io.spine.io.StreamObservers.memoizingObserver)3 StreamObservers.noOpObserver (io.spine.io.StreamObservers.noOpObserver)3 StandTestProjectionRepository (io.spine.server.stand.Given.StandTestProjectionRepository)3 NullPointerTester (com.google.common.testing.NullPointerTester)2 Any (com.google.protobuf.Any)2 Version (io.spine.base.Version)2 CommandEnvelope (io.spine.envelope.CommandEnvelope)2 CommandBus (io.spine.server.commandbus.CommandBus)2 EventStore (io.spine.server.event.EventStore)2 ProjectionRepository (io.spine.server.projection.ProjectionRepository)2 ProjectId (io.spine.test.projection.ProjectId)2 MultiTenant.newBoundedContext (io.spine.testdata.TestBoundedContextFactory.MultiTenant.newBoundedContext)2 TypeUrl (io.spine.type.TypeUrl)2 Executor (java.util.concurrent.Executor)2