Search in sources :

Example 6 with ProjectId

use of io.spine.test.projection.ProjectId in project core-java by SpineEventEngine.

the class ProjectionEventDeliveryShould method postpone_events_dispatched_to_subscriber_method.

@Test
public void postpone_events_dispatched_to_subscriber_method() {
    assertNull(ProjectDetails.getEventReceived());
    final Event event = projectCreated();
    boundedContext.getEventBus().post(event);
    assertNull(ProjectDetails.getEventReceived());
    final EventEnvelope expectedEnvelope = EventEnvelope.of(event);
    final PostponingEventDelivery delivery = repository.getEndpointDelivery();
    final Map<ProjectId, EventEnvelope> postponedEvents = delivery.getPostponedEvents();
    assertTrue(postponedEvents.size() == 1 && postponedEvents.containsValue(expectedEnvelope));
    final ProjectId projectId = postponedEvents.keySet().iterator().next();
    delivery.deliverNow(projectId, postponedEvents.get(projectId));
    final PrjProjectCreated deliveredEventMsg = ProjectDetails.getEventReceived();
    assertNotNull(deliveredEventMsg);
    assertEquals(Events.getMessage(event), deliveredEventMsg);
}
Also used : EventEnvelope(io.spine.core.EventEnvelope) PrjProjectCreated(io.spine.test.projection.event.PrjProjectCreated) ProjectId(io.spine.test.projection.ProjectId) Event(io.spine.core.Event) PostponingEventDelivery(io.spine.server.projection.given.ProjectionEventDeliveryTestEnv.PostponingEventDelivery) Test(org.junit.Test)

Example 7 with ProjectId

use of io.spine.test.projection.ProjectId in project core-java by SpineEventEngine.

the class ProjectionRepositoryShould method dispatch_event_to_archived_projection.

@Test
public void dispatch_event_to_archived_projection() {
    final PrjProjectArchived projectArchived = GivenEventMessage.projectArchived();
    checkDispatchesEvent(projectArchived);
    final ProjectId projectId = projectArchived.getProjectId();
    TestProjection projection = repository().findOrCreate(projectId);
    assertTrue(projection.isArchived());
    // Dispatch an event to the archived projection.
    checkDispatchesEvent(GivenEventMessage.taskAdded());
    projection = repository().findOrCreate(projectId);
    final List<Task> addedTasks = projection.getState().getTaskList();
    assertFalse(addedTasks.isEmpty());
    // Check that the projection was not re-created before dispatching.
    assertTrue(projection.isArchived());
}
Also used : Task(io.spine.test.projection.Task) PrjProjectArchived(io.spine.test.projection.event.PrjProjectArchived) ProjectId(io.spine.test.projection.ProjectId) TestProjection(io.spine.server.projection.given.ProjectionRepositoryTestEnv.TestProjection) Test(org.junit.Test)

Example 8 with ProjectId

use of io.spine.test.projection.ProjectId in project core-java by SpineEventEngine.

the class ProjectionRepositoryShould method dispatch_event_to_deleted_projection.

@Test
public void dispatch_event_to_deleted_projection() {
    final PrjProjectDeleted projectDeleted = GivenEventMessage.projectDeleted();
    checkDispatchesEvent(projectDeleted);
    final ProjectId projectId = projectDeleted.getProjectId();
    TestProjection projection = repository().findOrCreate(projectId);
    assertTrue(projection.isDeleted());
    // Dispatch an event to the deleted projection.
    checkDispatchesEvent(GivenEventMessage.taskAdded());
    projection = repository().findOrCreate(projectId);
    final List<Task> addedTasks = projection.getState().getTaskList();
    assertTrue(projection.isDeleted());
    // Check that the projection was not re-created before dispatching.
    assertFalse(addedTasks.isEmpty());
}
Also used : Task(io.spine.test.projection.Task) PrjProjectDeleted(io.spine.test.projection.event.PrjProjectDeleted) ProjectId(io.spine.test.projection.ProjectId) TestProjection(io.spine.server.projection.given.ProjectionRepositoryTestEnv.TestProjection) Test(org.junit.Test)

Example 9 with ProjectId

use of io.spine.test.projection.ProjectId in project core-java by SpineEventEngine.

the class ProjectionEventDeliveryTestEnv method projectCreated.

public static Event projectCreated() {
    final ProjectId projectId = projectId();
    final TestEventFactory eventFactory = TestEventFactory.newInstance(pack(projectId), ProjectionEventDeliveryTestEnv.class);
    final PrjProjectCreated msg = PrjProjectCreated.newBuilder().setProjectId(projectId).build();
    final Event result = eventFactory.createEvent(msg);
    return result;
}
Also used : PrjProjectCreated(io.spine.test.projection.event.PrjProjectCreated) TestEventFactory(io.spine.server.command.TestEventFactory) ProjectId(io.spine.test.projection.ProjectId) Event(io.spine.core.Event)

Example 10 with ProjectId

use of io.spine.test.projection.ProjectId in project core-java by SpineEventEngine.

the class StandPostShould method deliver_updates_through_several_threads.

@SuppressWarnings("MethodWithMultipleLoops")
@Test
public void deliver_updates_through_several_threads() throws InterruptedException {
    final int threadsCount = Given.THREADS_COUNT_IN_POOL_EXECUTOR;
    // Too long variable name
    @SuppressWarnings("LocalVariableNamingConvention") final int threadExecutionMaxAwaitSeconds = Given.AWAIT_SECONDS;
    final Set<String> threadInvocationRegistry = new ConcurrentSet<>();
    final Stand stand = Stand.newBuilder().build();
    final ExecutorService executor = Executors.newFixedThreadPool(threadsCount);
    final Runnable task = new Runnable() {

        @Override
        public void run() {
            final String threadName = Thread.currentThread().getName();
            Assert.assertFalse(threadInvocationRegistry.contains(threadName));
            final ProjectId enitityId = ProjectId.newBuilder().setId(Identifier.newUuid()).build();
            final Given.StandTestAggregate entity = Given.aggregateRepo().create(enitityId);
            stand.post(requestFactory.createCommandContext().getActorContext().getTenantId(), entity);
            threadInvocationRegistry.add(threadName);
        }
    };
    for (int i = 0; i < threadsCount; i++) {
        executor.execute(task);
    }
    executor.awaitTermination(threadExecutionMaxAwaitSeconds, TimeUnit.SECONDS);
    Assert.assertEquals(threadInvocationRegistry.size(), threadsCount);
}
Also used : ConcurrentSet(io.netty.util.internal.ConcurrentSet) ExecutorService(java.util.concurrent.ExecutorService) ProjectId(io.spine.test.projection.ProjectId) Test(org.junit.Test)

Aggregations

ProjectId (io.spine.test.projection.ProjectId)21 Test (org.junit.Test)13 Project (io.spine.test.projection.Project)6 Any (com.google.protobuf.Any)4 Version (io.spine.core.Version)4 Message (com.google.protobuf.Message)3 Event (io.spine.base.Event)3 Event (io.spine.core.Event)3 TestProjection (io.spine.server.projection.given.ProjectionRepositoryTestEnv.TestProjection)3 Duration (com.google.protobuf.Duration)2 EntityFilters (io.spine.client.EntityFilters)2 Topic (io.spine.client.Topic)2 GivenVersion (io.spine.core.given.GivenVersion)2 BoundedContext (io.spine.server.BoundedContext)2 StandTestProjection (io.spine.server.stand.Given.StandTestProjection)2 StandTestProjectionRepository (io.spine.server.stand.Given.StandTestProjectionRepository)2 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)2 Task (io.spine.test.projection.Task)2 PrjProjectCreated (io.spine.test.projection.event.PrjProjectCreated)2 ArgumentMatcher (org.mockito.ArgumentMatcher)2