use of com.google.protobuf.Timestamp in project core-java by SpineEventEngine.
the class EntityShould method create_and_initialize_entity_instance.
@Test
public void create_and_initialize_entity_instance() {
final Long id = 100L;
final Timestamp before = TimeTests.Past.secondsAgo(1);
// Create and init the entity.
final Constructor<BareBonesEntity> ctor = getConstructor(BareBonesEntity.class, Long.class);
final AbstractVersionableEntity<Long, StringValue> entity = createEntity(ctor, id);
final Timestamp after = Time.getCurrentTime();
// The interval with a much earlier start to allow non-zero interval on faster computers.
final Interval whileWeCreate = Intervals.between(before, after);
assertEquals(id, entity.getId());
assertEquals(0, entity.getVersion().getNumber());
assertTrue(Intervals.contains(whileWeCreate, entity.whenModified()));
assertEquals(StringValue.getDefaultInstance(), entity.getState());
assertFalse(entity.isArchived());
assertFalse(entity.isDeleted());
}
use of com.google.protobuf.Timestamp in project core-java by SpineEventEngine.
the class ZoneConverter method toZoneOffset.
/**
* Obtains the {@code ZoneOffset} instance using {@code TimeZone}.
*
* @param timeZone target time zone
* @return zone offset instance of specified timezone
*/
private static ZoneOffset toZoneOffset(TimeZone timeZone) {
final Timestamp now = getCurrentTime();
final long date = Timestamps.toMillis(now);
final int offsetInSeconds = getOffsetInSeconds(timeZone, date);
@Nullable final String zoneId = timeZone.getID();
return ZoneOffsets.create(offsetInSeconds, zoneId);
}
use of com.google.protobuf.Timestamp in project core-java by SpineEventEngine.
the class Rescheduler method getTimeToPost.
private static Timestamp getTimeToPost(Command command) {
final CommandContext.Schedule schedule = command.getContext().getSchedule();
final Timestamp timeToPost = add(command.getSystemProperties().getSchedulingTime(), schedule.getDelay());
return timeToPost;
}
use of com.google.protobuf.Timestamp in project core-java by SpineEventEngine.
the class EventStoreShould method read_events_by_time_and_type.
@Test
public void read_events_by_time_and_type() {
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 = taskAdded(past);
final Event eventInPresent = projectCreated(present);
final Event eventInFuture = taskAdded(future);
eventStore.append(eventInPast);
eventStore.append(eventInPresent);
eventStore.append(eventInFuture);
final EventFilter taskAddedType = EventFilter.newBuilder().setEventType(of(TaskAdded.class).value()).build();
final EventStreamQuery query = EventStreamQuery.newBuilder().setAfter(past).addFilter(taskAddedType).build();
final AtomicBoolean done = new AtomicBoolean(false);
final Collection<Event> resultEvents = newConcurrentHashSet();
eventStore.read(query, new ResponseObserver(resultEvents, done));
if (!done.get()) {
fail("Please use the MoreExecutors.directExecutor in EventStore for tests.");
}
assertSize(1, resultEvents);
final Event event = resultEvents.iterator().next();
assertEquals(eventInFuture, event);
}
use of com.google.protobuf.Timestamp 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));
if (!done.get()) {
fail("Please use the MoreExecutors.directExecutor in EventStore for tests.");
}
assertSize(1, resultEvents);
final Event event = resultEvents.iterator().next();
assertEquals(eventInPresent, event);
}
Aggregations