Search in sources :

Example 1 with ProjectId

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));
}
Also used : Message(com.google.protobuf.Message) ProjectId(io.spine.test.projection.ProjectId) Event(io.spine.base.Event) ImmutableCollection(com.google.common.collect.ImmutableCollection) Collection(java.util.Collection) Duration(com.google.protobuf.Duration) Test(org.junit.Test)

Example 2 with ProjectId

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));
}
Also used : EventContext(io.spine.base.EventContext) ProjectId(io.spine.test.projection.ProjectId) Event(io.spine.base.Event) IdSetEventFunction(io.spine.server.entity.idfunc.IdSetEventFunction) ProjectCreated(io.spine.test.projection.event.ProjectCreated) Test(org.junit.Test)

Example 3 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(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);
}
Also used : ConcurrentSet(io.netty.util.internal.ConcurrentSet) ExecutorService(java.util.concurrent.ExecutorService) ProjectId(io.spine.test.projection.ProjectId) Test(org.junit.Test)

Example 4 with ProjectId

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());
}
Also used : ProjectId(io.spine.test.projection.ProjectId) Test(org.junit.Test)

Example 5 with ProjectId

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;
}
Also used : Project(io.spine.test.projection.Project) Random(java.util.Random) ProjectId(io.spine.test.projection.ProjectId)

Aggregations

ProjectId (io.spine.test.projection.ProjectId)15 Test (org.junit.Test)8 Project (io.spine.test.projection.Project)5 Any (com.google.protobuf.Any)4 Message (com.google.protobuf.Message)3 Event (io.spine.base.Event)3 Version (io.spine.base.Version)3 Duration (com.google.protobuf.Duration)2 EntityFilters (io.spine.client.EntityFilters)2 Topic (io.spine.client.Topic)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 ArgumentMatcher (org.mockito.ArgumentMatcher)2 ImmutableCollection (com.google.common.collect.ImmutableCollection)1 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)1 FieldMask (com.google.protobuf.FieldMask)1 StringValue (com.google.protobuf.StringValue)1 ConcurrentSet (io.netty.util.internal.ConcurrentSet)1