Search in sources :

Example 1 with Duration

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

the class IntervalsShould method calculate_duration_of_interval.

@Test
public void calculate_duration_of_interval() {
    final Timestamp start = newTimestamp(5, 6);
    final Timestamp end = newTimestamp(10, 10);
    final Duration expectedDuration = Duration.newBuilder().setSeconds(end.getSeconds() - start.getSeconds()).setNanos(end.getNanos() - start.getNanos()).build();
    final Interval interval = Intervals.between(start, end);
    final Duration actualDuration = Intervals.toDuration(interval);
    assertEquals(expectedDuration, actualDuration);
}
Also used : Duration(com.google.protobuf.Duration) Timestamp(com.google.protobuf.Timestamp) Interval(io.spine.time.Interval) Test(org.junit.Test)

Example 2 with Duration

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

the class Commands method isScheduled.

/**
     * Checks if the command is scheduled to be delivered later.
     *
     * @param command a command to check
     * @return {@code true} if the command context has a scheduling option set,
     * {@code false} otherwise
     */
public static boolean isScheduled(Command command) {
    checkNotNull(command);
    final Schedule schedule = command.getContext().getSchedule();
    final Duration delay = schedule.getDelay();
    if (isNotDefault(delay)) {
        checkArgument(delay.getSeconds() > 0, "Command delay seconds must be a positive value.");
        return true;
    }
    return false;
}
Also used : Schedule(io.spine.base.CommandContext.Schedule) Duration(com.google.protobuf.Duration)

Example 3 with Duration

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

the class OffsetTimesShould method subtract_minutes.

@Test
public void subtract_minutes() {
    final int minutesDelta = random(1, 1024);
    final Duration deltaDuration = Durations2.minutes(minutesDelta);
    final Timestamp gmtPast = Timestamps.subtract(gmtNow, deltaDuration);
    final LocalTime expectedPast = LocalTimes.timeAt(gmtPast, zoneOffset);
    final LocalTime actualPast = subtractMinutes(now, minutesDelta).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 4 with Duration

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

the class OffsetTimesShould method add_hours.

/*
     * Math with time
     */
@Test
public void add_hours() {
    final int hoursDelta = random(1, 100);
    final Duration deltaDuration = Durations2.hours(hoursDelta);
    final Timestamp gmtFuture = Timestamps.add(gmtNow, deltaDuration);
    final LocalTime expectedFuture = LocalTimes.timeAt(gmtFuture, zoneOffset);
    final LocalTime actualFuture = addHours(now, hoursDelta).getTime();
    assertEquals(expectedFuture, actualFuture);
}
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 5 with Duration

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

the class ZoneOffsetsShould method create_instance_by_hours_offset.

@Test
public void create_instance_by_hours_offset() {
    final Duration twoHours = hours(2);
    Assert.assertEquals(twoHours.getSeconds(), ZoneOffsets.ofHours(2).getAmountSeconds());
}
Also used : Duration(com.google.protobuf.Duration) Test(org.junit.Test)

Aggregations

Duration (com.google.protobuf.Duration)58 Test (org.junit.Test)37 Timestamp (com.google.protobuf.Timestamp)25 AbstractZonedTimeTest (io.spine.time.AbstractZonedTimeTest)8 LocalTime (io.spine.time.LocalTime)8 ByteString (com.google.protobuf.ByteString)7 Metadata (io.grpc.Metadata)7 InetSocketAddress (java.net.InetSocketAddress)7 SocketAddress (java.net.SocketAddress)6 Command (io.spine.core.Command)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 CallOptions (io.grpc.CallOptions)4 Channel (io.grpc.Channel)4 ClientCall (io.grpc.ClientCall)4 MethodDescriptor (io.grpc.MethodDescriptor)4 Status (io.grpc.Status)4 Message (com.google.protobuf.Message)3 ServerCall (io.grpc.ServerCall)3 DomainSocketAddress (io.netty.channel.unix.DomainSocketAddress)3 Schedule (io.spine.core.CommandContext.Schedule)3