Search in sources :

Example 6 with Duration

use of com.google.protobuf.Duration 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 7 with Duration

use of com.google.protobuf.Duration in project core-java by SpineEventEngine.

the class BulkWriteOperationShould method complete_on_timeout.

@SuppressWarnings("MagicNumber")
@Test
public void complete_on_timeout() throws InterruptedException {
    final Duration duration = Durations2.nanos(1L);
    final FlushCallback callback = spy(new EmptyCallback());
    // Due to `spy` usage
    @SuppressWarnings("unchecked") final BulkWriteOperation operation = spy(new BulkWriteOperation(duration, callback));
    assertTrue(operation.isInProgress());
    Thread.sleep(10L);
    operation.checkExpiration();
    assertFalse(operation.isInProgress());
    verify(operation).complete();
    verify(callback).onFlushResults(any(Set.class), any(Timestamp.class));
}
Also used : BulkWriteOperation(io.spine.server.projection.BulkWriteOperation) Collections.emptySet(java.util.Collections.emptySet) Set(java.util.Set) HashSet(java.util.HashSet) FlushCallback(io.spine.server.projection.BulkWriteOperation.FlushCallback) Duration(com.google.protobuf.Duration) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 8 with Duration

use of com.google.protobuf.Duration in project core-java by SpineEventEngine.

the class BulkWriteOperationShould method newOperation.

private static BulkWriteOperation<Object, TestProjection> newOperation() {
    final Duration duration = Durations2.seconds(100);
    final BulkWriteOperation<Object, TestProjection> operation = new BulkWriteOperation<>(duration, new EmptyCallback());
    return operation;
}
Also used : BulkWriteOperation(io.spine.server.projection.BulkWriteOperation) Duration(com.google.protobuf.Duration)

Example 9 with Duration

use of com.google.protobuf.Duration in project core-java by SpineEventEngine.

the class BulkWriteOperationShould method newOperation.

private static BulkWriteOperation<Object, TestProjection> newOperation(Set<TestProjection> projections, Timestamp lastHandldEventTime) {
    final Duration duration = Durations2.seconds(100);
    final BulkWriteOperation<Object, TestProjection> operation = new BulkWriteOperation<>(duration, new AssertResults(projections, lastHandldEventTime));
    return operation;
}
Also used : BulkWriteOperation(io.spine.server.projection.BulkWriteOperation) Duration(com.google.protobuf.Duration)

Example 10 with Duration

use of com.google.protobuf.Duration in project core-java by SpineEventEngine.

the class EventStoreShould method read_events_by_time_bounds.

@Test
public void read_events_by_time_bounds() {
    final Duration delta = Durations2.seconds(111);
    final Timestamp present = getCurrentTime();
    final Timestamp past = subtract(present, delta);
    final Timestamp future = add(present, delta);
    final Event eventInPast = projectCreated(past);
    final Event eventInPresent = projectCreated(present);
    final Event eventInFuture = projectCreated(future);
    eventStore.append(eventInPast);
    eventStore.append(eventInPresent);
    eventStore.append(eventInFuture);
    final EventStreamQuery query = EventStreamQuery.newBuilder().setAfter(past).setBefore(future).build();
    final AtomicBoolean done = new AtomicBoolean(false);
    final Collection<Event> resultEvents = newConcurrentHashSet();
    eventStore.read(query, new ResponseObserver(resultEvents, done));
    assertDone(done);
    assertSize(1, resultEvents);
    final Event event = resultEvents.iterator().next();
    assertEquals(eventInPresent, event);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Event(io.spine.core.Event) Duration(com.google.protobuf.Duration) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Aggregations

Duration (com.google.protobuf.Duration)45 Test (org.junit.Test)31 Timestamp (com.google.protobuf.Timestamp)25 AbstractZonedTimeTest (io.spine.time.AbstractZonedTimeTest)8 LocalTime (io.spine.time.LocalTime)8 Command (io.spine.core.Command)5 BulkWriteOperation (io.spine.server.projection.BulkWriteOperation)4 Message (com.google.protobuf.Message)3 Schedule (io.spine.core.CommandContext.Schedule)3 Event (io.spine.core.Event)3 Interval (io.spine.time.Interval)3 Event (io.spine.base.Event)2 CommandContext (io.spine.core.CommandContext)2 ProjectId (io.spine.test.projection.ProjectId)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 ImmutableCollection (com.google.common.collect.ImmutableCollection)1 Schedule (io.spine.base.CommandContext.Schedule)1 Error (io.spine.base.Error)1 ThrowableMessage (io.spine.base.ThrowableMessage)1 CommandEnvelope (io.spine.core.CommandEnvelope)1