Search in sources :

Example 36 with Timestamp

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

the class ChangesShould method create_TimestampChange_instance.

@Test
public void create_TimestampChange_instance() {
    final Timestamp fiveMinutesAgo = TimeTests.Past.minutesAgo(5);
    final Timestamp now = getCurrentTime();
    final TimestampChange result = Changes.of(fiveMinutesAgo, now);
    assertEquals(fiveMinutesAgo, result.getPreviousValue());
    assertEquals(now, result.getNewValue());
}
Also used : Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 37 with Timestamp

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

the class ChangesShould method create_IntervalChange_instance.

@Test
public void create_IntervalChange_instance() {
    final Timestamp fiveMinutesAgo = TimeTests.Past.minutesAgo(5);
    final Timestamp fourMinutesAgo = TimeTests.Past.minutesAgo(4);
    final Timestamp now = getCurrentTime();
    final Interval fourMinutes = Intervals.between(fourMinutesAgo, now);
    final Interval fiveMinutes = Intervals.between(fiveMinutesAgo, now);
    final IntervalChange result = Changes.of(fourMinutes, fiveMinutes);
    assertEquals(fourMinutes, result.getPreviousValue());
    assertEquals(fiveMinutes, result.getNewValue());
}
Also used : Timestamp(com.google.protobuf.Timestamp) Interval(io.spine.time.Interval) Test(org.junit.Test)

Example 38 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));
    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)

Example 39 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));
    assertDone(done);
    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) Event(io.spine.core.Event) Duration(com.google.protobuf.Duration) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 40 with Timestamp

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

the class CommandSchedulingShould method update_schedule_options.

@Test
public void update_schedule_options() {
    final Command cmd = requestFactory.command().create(toMessage(newUuid()));
    final Timestamp schedulingTime = getCurrentTime();
    final Duration delay = Durations2.minutes(5);
    final Command cmdUpdated = setSchedule(cmd, delay, schedulingTime);
    final CommandContext.Schedule schedule = cmdUpdated.getContext().getSchedule();
    assertEquals(delay, schedule.getDelay());
    assertEquals(schedulingTime, cmdUpdated.getSystemProperties().getSchedulingTime());
}
Also used : CommandContext(io.spine.core.CommandContext) Command(io.spine.core.Command) Duration(com.google.protobuf.Duration) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Aggregations

Timestamp (com.google.protobuf.Timestamp)120 Test (org.junit.Test)84 Duration (com.google.protobuf.Duration)24 Interval (io.spine.time.Interval)16 Command (io.spine.core.Command)9 AbstractZonedTimeTest (io.spine.time.AbstractZonedTimeTest)8 LocalTime (io.spine.time.LocalTime)8 Nullable (javax.annotation.Nullable)7 StringValue (com.google.protobuf.StringValue)6 Event (io.spine.core.Event)6 Message (com.google.protobuf.Message)5 Predicate (com.google.common.base.Predicate)4 TimeTests (io.spine.test.TimeTests)4 CommandContext (io.spine.core.CommandContext)3 EventContext (io.spine.core.EventContext)3 Version (io.spine.core.Version)3 Any (com.google.protobuf.Any)2 ByteString (com.google.protobuf.ByteString)2 PubsubMessage (com.google.pubsub.v1.PubsubMessage)2 PullRequest (com.google.pubsub.v1.PullRequest)2