Search in sources :

Example 16 with Timestamp

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());
}
Also used : StringValue(com.google.protobuf.StringValue) Timestamp(com.google.protobuf.Timestamp) Interval(io.spine.time.Interval) Test(org.junit.Test)

Example 17 with Timestamp

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);
}
Also used : Timestamp(com.google.protobuf.Timestamp) Nullable(javax.annotation.Nullable)

Example 18 with Timestamp

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;
}
Also used : CommandContext(io.spine.base.CommandContext) Timestamp(com.google.protobuf.Timestamp)

Example 19 with Timestamp

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);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TaskAdded(io.spine.test.event.TaskAdded) EventStreamQuery(io.spine.server.event.EventStreamQuery) Event(io.spine.base.Event) Duration(com.google.protobuf.Duration) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 20 with Timestamp

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);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) EventStreamQuery(io.spine.server.event.EventStreamQuery) Event(io.spine.base.Event) Duration(com.google.protobuf.Duration) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Aggregations

Timestamp (com.google.protobuf.Timestamp)89 Test (org.junit.Test)66 Duration (com.google.protobuf.Duration)19 Interval (io.spine.time.Interval)11 Command (io.spine.base.Command)8 AbstractZonedTimeTest (io.spine.time.AbstractZonedTimeTest)8 LocalTime (io.spine.time.LocalTime)8 Message (com.google.protobuf.Message)4 StringValue (com.google.protobuf.StringValue)4 EventStreamQuery (io.spine.server.event.EventStreamQuery)4 TimeTests (io.spine.test.TimeTests)4 Nullable (javax.annotation.Nullable)4 Event (io.spine.base.Event)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 Predicate (com.google.common.base.Predicate)2 ByteString (com.google.protobuf.ByteString)2 PubsubMessage (com.google.pubsub.v1.PubsubMessage)2 PullRequest (com.google.pubsub.v1.PullRequest)2 PullResponse (com.google.pubsub.v1.PullResponse)2 ReceivedMessage (com.google.pubsub.v1.ReceivedMessage)2