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);
}
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());
}
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());
}
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;
}
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);
}
Aggregations