Search in sources :

Example 36 with Duration

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

the class Intervals method toDuration.

/**
     * Returns a duration of the interval.
     *
     * @param interval the interval to calculate its duration
     * @return the duration between the start and the end of the interval
     */
public static Duration toDuration(Interval interval) {
    final Timestamp start = interval.getStart();
    final Timestamp end = interval.getEnd();
    if (start.equals(end)) {
        return Durations2.ZERO;
    }
    final long secondsBetween = end.getSeconds() - start.getSeconds();
    final int nanosBetween = end.getNanos() - start.getNanos();
    final Duration.Builder duration = Duration.newBuilder().setSeconds(abs(secondsBetween)).setNanos(abs(nanosBetween));
    return duration.build();
}
Also used : Duration(com.google.protobuf.Duration) Timestamp(com.google.protobuf.Timestamp)

Example 37 with Duration

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

the class ProjectionRepositoryShould method skip_all_the_events_after_catch_up_outdated.

// Due to mockito matcher usage
@SuppressWarnings("unchecked")
@Test
public void skip_all_the_events_after_catch_up_outdated() throws InterruptedException {
    // Set up bounded context
    final BoundedContext boundedContext = TestBoundedContextFactory.MultiTenant.newBoundedContext();
    final int eventsCount = 10;
    final EventStore eventStore = boundedContext.getEventBus().getEventStore();
    for (int i = 0; i < eventsCount; i++) {
        final ProjectId projectId = ProjectId.newBuilder().setId(valueOf(i)).build();
        final Message eventMessage = ProjectCreated.newBuilder().setProjectId(projectId).build();
        final Event event = createEvent(pack(projectId), eventMessage);
        appendEvent(eventStore, event);
    }
    // Set up repository
    final Duration duration = Durations2.nanos(1L);
    final ProjectionRepository repository = spy(new ManualCatchupProjectionRepository(boundedContext, duration));
    repository.initStorage(storageFactory());
    repository.catchUp();
    // Check bulk write
    verify(repository, never()).store(any(Projection.class));
}
Also used : EventStore(io.spine.server.event.EventStore) Message(com.google.protobuf.Message) ProjectId(io.spine.test.projection.ProjectId) Event(io.spine.base.Event) MultiTenant.newBoundedContext(io.spine.testdata.TestBoundedContextFactory.MultiTenant.newBoundedContext) BoundedContext(io.spine.server.BoundedContext) Duration(com.google.protobuf.Duration) Test(org.junit.Test)

Example 38 with Duration

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

the class BulkWriteOperationShould method initialize_with_proper_delay_and_callback.

@Test
public void initialize_with_proper_delay_and_callback() {
    final Duration duration = Durations2.seconds(60);
    final BulkWriteOperation operation = new BulkWriteOperation<>(duration, new EmptyCallback());
    assertNotNull(operation);
}
Also used : BulkWriteOperation(io.spine.server.projection.BulkWriteOperation) Duration(com.google.protobuf.Duration) Test(org.junit.Test)

Aggregations

Duration (com.google.protobuf.Duration)38 Test (org.junit.Test)26 Timestamp (com.google.protobuf.Timestamp)20 AbstractZonedTimeTest (io.spine.time.AbstractZonedTimeTest)8 LocalTime (io.spine.time.LocalTime)8 Command (io.spine.base.Command)5 Event (io.spine.base.Event)4 BulkWriteOperation (io.spine.server.projection.BulkWriteOperation)4 Message (com.google.protobuf.Message)3 Interval (io.spine.time.Interval)3 Schedule (io.spine.base.CommandContext.Schedule)2 EventStreamQuery (io.spine.server.event.EventStreamQuery)2 ProjectId (io.spine.test.projection.ProjectId)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 ImmutableCollection (com.google.common.collect.ImmutableCollection)1 CommandContext (io.spine.base.CommandContext)1 CommandId (io.spine.base.CommandId)1 Commands.getMessage (io.spine.base.Commands.getMessage)1 Error (io.spine.base.Error)1 CommandEnvelope (io.spine.envelope.CommandEnvelope)1