use of io.spine.test.projection.ProjectId in project core-java by SpineEventEngine.
the class ProjectionRepositoryShould method perform_bulk_catch_up_if_required.
// Due to mockito matcher usage
@SuppressWarnings("unchecked")
@Test
public void perform_bulk_catch_up_if_required() {
final ProjectId projectId = ProjectId.newBuilder().setId("mock-project-id").build();
final Message eventMessage = ProjectCreated.newBuilder().setProjectId(projectId).build();
final Event event = createEvent(pack(projectId), eventMessage);
appendEvent(boundedContext.getEventBus().getEventStore(), event);
// Set up repository
final Duration duration = Durations2.seconds(10L);
final ProjectionRepository repository = spy(new ManualCatchupProjectionRepository(boundedContext, duration));
repository.initStorage(storageFactory());
repository.catchUp();
// Check bulk write
verify(repository).store(any(Collection.class));
verify(repository, never()).store(any(TestProjection.class));
}
use of io.spine.test.projection.ProjectId in project core-java by SpineEventEngine.
the class ProjectionRepositoryShould method use_id_set_function.
@Test
public void use_id_set_function() {
final IdSetEventFunction<ProjectId, ProjectCreated> delegateFn = new IdSetEventFunction<ProjectId, ProjectCreated>() {
@Override
public Set<ProjectId> apply(ProjectCreated message, EventContext context) {
return newHashSet();
}
};
final IdSetEventFunction<ProjectId, ProjectCreated> idSetFunction = spy(delegateFn);
repository().addIdSetFunction(ProjectCreated.class, idSetFunction);
final Event event = createEvent(PRODUCER_ID, projectCreated());
repository().dispatch(event);
final ProjectCreated expectedEventMessage = Events.getMessage(event);
final EventContext context = event.getContext();
verify(idSetFunction).apply(eq(expectedEventMessage), eq(context));
}
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(Identifiers.newUuid()).build();
final Given.StandTestAggregate entity = Given.aggregateRepo().create(enitityId);
stand.post(entity, requestFactory.createCommandContext());
threadInvocationRegistry.add(threadName);
}
};
for (int i = 0; i < threadsCount; i++) {
executor.execute(task);
}
executor.awaitTermination(threadExecutionMaxAwaitSeconds, TimeUnit.SECONDS);
Assert.assertEquals(threadInvocationRegistry.size(), threadsCount);
}
use of io.spine.test.projection.ProjectId in project core-java by SpineEventEngine.
the class AggregateStateIdStringifierShould method unpack_registered_message_ids.
@Test
public void unpack_registered_message_ids() {
final ProjectId messageId = Sample.messageOfType(ProjectId.class);
final String stringMessageId = Stringifiers.toString(messageId);
final String stringId = ANY_TYPE_URL.value() + '-' + TypeName.of(ProjectId.class) + '-' + stringMessageId;
final Stringifier<AggregateStateId> stringifier = stringifier();
final AggregateStateId id = stringifier.reverse().convert(stringId);
assertNotNull(id);
assertEquals(ANY_TYPE_URL, id.getStateType());
assertEquals(messageId, id.getAggregateId());
}
use of io.spine.test.projection.ProjectId in project core-java by SpineEventEngine.
the class StandShould method fillSampleProjects.
private static Map<ProjectId, Project> fillSampleProjects(int numberOfProjects) {
final Map<ProjectId, Project> sampleProjects = newHashMap();
@SuppressWarnings("UnsecureRandomNumberGeneration") final Random randomizer = new Random(Integer.MAX_VALUE);
for (int projectIndex = 0; projectIndex < numberOfProjects; projectIndex++) {
final int numericId = randomizer.nextInt();
final ProjectId customerId = projectIdFor(numericId);
final Project project = Project.newBuilder().setName(String.valueOf(numericId)).build();
sampleProjects.put(customerId, project);
}
return sampleProjects;
}
Aggregations