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