Search in sources :

Example 46 with Duration

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

the class OperatorEvaluatorShould method compare_timestamps_by_GE.

@Test
public void compare_timestamps_by_GE() {
    final Duration delta = seconds(5);
    final Timestamp small = getCurrentTime();
    final Timestamp medium = add(small, delta);
    final Timestamp big = add(medium, delta);
    assertTrue(eval(medium, GREATER_OR_EQUAL, small));
    assertTrue(eval(big, GREATER_OR_EQUAL, medium));
    assertTrue(eval(big, GREATER_OR_EQUAL, small));
    assertTrue(eval(small, GREATER_OR_EQUAL, small));
    assertFalse(eval(small, GREATER_OR_EQUAL, big));
    assertFalse(eval(nullRef(), GREATER_OR_EQUAL, small));
}
Also used : Duration(com.google.protobuf.Duration) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 47 with Duration

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

the class OperatorEvaluatorShould method compare_timestamps_by_GT.

@Test
public void compare_timestamps_by_GT() {
    final Duration delta = seconds(5);
    final Timestamp small = getCurrentTime();
    final Timestamp medium = add(small, delta);
    final Timestamp big = add(medium, delta);
    assertTrue(eval(medium, GREATER_THAN, small));
    assertTrue(eval(big, GREATER_THAN, medium));
    assertTrue(eval(big, GREATER_THAN, small));
    assertFalse(eval(small, GREATER_THAN, small));
    assertFalse(eval(small, GREATER_THAN, big));
    assertFalse(eval(nullRef(), GREATER_THAN, small));
}
Also used : Duration(com.google.protobuf.Duration) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 48 with Duration

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

the class CommandScheduler method setSchedulingTime.

/**
 * Sets a new scheduling time in the {@linkplain CommandContext.Schedule context}
 * of the passed command.
 *
 * @param command        a command to update
 * @param schedulingTime the time when the command was scheduled by the {@code CommandScheduler}
 * @return an updated command
 */
static Command setSchedulingTime(Command command, Timestamp schedulingTime) {
    checkNotNull(command);
    checkNotNull(schedulingTime);
    final Duration delay = command.getContext().getSchedule().getDelay();
    final Command result = setSchedule(command, delay, schedulingTime);
    return result;
}
Also used : Command(io.spine.core.Command) Duration(com.google.protobuf.Duration)

Example 49 with Duration

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

the class ExecutorCommandScheduler method getDelayMilliseconds.

private static long getDelayMilliseconds(Command command) {
    final Schedule schedule = command.getContext().getSchedule();
    final Duration delay = schedule.getDelay();
    final long delaySec = delay.getSeconds();
    final long delayMillisFraction = delay.getNanos() / NANOS_IN_MILLISECOND;
    /**
     * Maximum value of {@link Duration#getSeconds()} is
     * <a href="https://github.com/google/protobuf/blob/master/src/google/protobuf/duration.proto"+315,576,000,000.</a>.
     *
     * {@link Long.MAX_VALUE} is +9,223,372,036,854,775,807. That's why it is safe to multiply
     * {@code delaySec * MILLIS_IN_SECOND}.
     */
    final long absoluteMillis = delaySec * MILLIS_IN_SECOND + delayMillisFraction;
    return absoluteMillis;
}
Also used : Schedule(io.spine.core.CommandContext.Schedule) Duration(com.google.protobuf.Duration)

Example 50 with Duration

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

the class Rescheduler method reschedule.

private void reschedule(Command command) {
    final Timestamp now = getCurrentTime();
    final Timestamp timeToPost = getTimeToPost(command);
    if (isLaterThan(now, /*than*/
    timeToPost)) {
        onScheduledCommandExpired(command);
    } else {
        final Interval interval = Intervals.between(now, timeToPost);
        final Duration newDelay = Intervals.toDuration(interval);
        final Command updatedCommand = CommandScheduler.setSchedule(command, newDelay, now);
        scheduler().schedule(updatedCommand);
    }
}
Also used : Command(io.spine.core.Command) Duration(com.google.protobuf.Duration) Timestamp(com.google.protobuf.Timestamp) Interval(io.spine.time.Interval)

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