Search in sources :

Example 91 with Timestamp

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

the class OffsetTimesShould method subtract_millis.

@Test
public void subtract_millis() {
    final int millisDelta = random(1, 999_999);
    final Duration deltaDuration = Durations.fromMillis(millisDelta);
    final Timestamp gmtPast = Timestamps.subtract(gmtNow, deltaDuration);
    final LocalTime expectedPast = LocalTimes.timeAt(gmtPast, zoneOffset);
    final LocalTime actualPast = subtractMillis(now, millisDelta).getTime();
    assertEquals(expectedPast, actualPast);
}
Also used : LocalTime(io.spine.time.LocalTime) Duration(com.google.protobuf.Duration) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test) AbstractZonedTimeTest(io.spine.time.AbstractZonedTimeTest)

Example 92 with Timestamp

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

the class TimeChangesShould method do_not_accept_equal_Interval_values.

@Test(expected = IllegalArgumentException.class)
public void do_not_accept_equal_Interval_values() {
    final Timestamp fourMinutesAgo = TimeTests.Past.minutesAgo(4);
    final Timestamp now = getCurrentTime();
    final Interval fourMinutes = Intervals.between(now, fourMinutesAgo);
    TimeChanges.of(fourMinutes, fourMinutes);
}
Also used : Timestamp(com.google.protobuf.Timestamp) Interval(io.spine.time.Interval) Test(org.junit.Test)

Example 93 with Timestamp

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

the class CommandSchedulingShould method update_scheduling_time.

@Test
public void update_scheduling_time() {
    final Command cmd = requestFactory.command().create(toMessage(newUuid()));
    final Timestamp schedulingTime = getCurrentTime();
    final Command cmdUpdated = CommandScheduler.setSchedulingTime(cmd, schedulingTime);
    assertEquals(schedulingTime, cmdUpdated.getSystemProperties().getSchedulingTime());
}
Also used : Command(io.spine.core.Command) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 94 with Timestamp

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

the class CommandStoreShould method set_expired_scheduled_command_status_to_error_if_time_to_post_them_passed.

@Test
public void set_expired_scheduled_command_status_to_error_if_time_to_post_them_passed() {
    final List<Command> commands = newArrayList(createProject(), addTask(), startProject());
    final Duration delay = fromMinutes(5);
    // time to post passed
    final Timestamp schedulingTime = TimeTests.Past.minutesAgo(10);
    storeAsScheduled(commands, delay, schedulingTime);
    commandBus.rescheduleCommands();
    for (Command cmd : commands) {
        final CommandEnvelope envelope = CommandEnvelope.of(cmd);
        final Message msg = envelope.getMessage();
        final CommandId id = envelope.getId();
        // Check the expired status error was set.
        final ProcessingStatus status = getProcessingStatus(envelope);
        // Check that the logging was called.
        verify(log).errorExpiredCommand(msg, id);
        final Error expected = CommandExpiredException.commandExpired(cmd);
        assertEquals(expected, status.getError());
    }
}
Also used : Commands.getMessage(io.spine.core.Commands.getMessage) ThrowableMessage(io.spine.base.ThrowableMessage) CommandMessage.createProjectMessage(io.spine.server.commandbus.Given.CommandMessage.createProjectMessage) Message(com.google.protobuf.Message) Command(io.spine.core.Command) CommandEnvelope(io.spine.core.CommandEnvelope) Error(io.spine.base.Error) Duration(com.google.protobuf.Duration) CommandId(io.spine.core.CommandId) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 95 with Timestamp

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

the class AggregateShould method record_modification_timestamp.

@Test
public void record_modification_timestamp() {
    try {
        final TimeTests.BackToTheFuture provider = new TimeTests.BackToTheFuture();
        Time.setProvider(provider);
        Timestamp currentTime = Time.getCurrentTime();
        aggregate.dispatchCommands(command(createProject));
        assertEquals(currentTime, aggregate.whenModified());
        currentTime = provider.forward(10);
        aggregate.dispatchCommands(command(startProject));
        assertEquals(currentTime, aggregate.whenModified());
    } finally {
        Time.resetProvider();
    }
}
Also used : TimeTests(io.spine.test.TimeTests) 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