Search in sources :

Example 11 with Duration

use of com.google.protobuf.Duration 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 12 with Duration

use of com.google.protobuf.Duration 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)

Example 13 with Duration

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

the class CommandSchedulingShould method reschedule_commands_from_storage.

@Test
public void reschedule_commands_from_storage() {
    final Timestamp schedulingTime = minutesAgo(3);
    final Duration delayPrimary = Durations2.fromMinutes(5);
    // = 5 - 3
    final Duration newDelayExpected = Durations2.fromMinutes(2);
    final List<Command> commandsPrimary = newArrayList(createProject(), addTask(), startProject());
    storeAsScheduled(commandsPrimary, delayPrimary, schedulingTime);
    commandBus.rescheduleCommands();
    final ArgumentCaptor<Command> commandCaptor = ArgumentCaptor.forClass(Command.class);
    verify(scheduler, times(commandsPrimary.size())).schedule(commandCaptor.capture());
    final List<Command> commandsRescheduled = commandCaptor.getAllValues();
    for (Command cmd : commandsRescheduled) {
        final long actualDelay = getDelaySeconds(cmd);
        Tests.assertSecondsEqual(newDelayExpected.getSeconds(), actualDelay, /*maxDiffSec=*/
        1);
    }
}
Also used : Command(io.spine.core.Command) Duration(com.google.protobuf.Duration) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 14 with Duration

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

the class AggregateStorageShould method write_records_and_load_history_till_last_snapshot.

@Test
public void write_records_and_load_history_till_last_snapshot() {
    final Duration delta = seconds(10);
    final Timestamp time1 = getCurrentTime();
    final Timestamp time2 = add(time1, delta);
    final Timestamp time3 = add(time2, delta);
    storage.writeRecord(id, StorageRecord.create(time1));
    storage.writeSnapshot(id, newSnapshot(time2));
    testWriteRecordsAndLoadHistory(time3);
}
Also used : Duration(com.google.protobuf.Duration) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 15 with Duration

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

the class StorageRecords method sequenceFor.

/**
 * Returns several records sorted by timestamp ascending.
 *
 * @param start the timestamp of first record.
 */
public static List<AggregateEventRecord> sequenceFor(ProjectId id, Timestamp start) {
    final Duration delta = seconds(10);
    final Timestamp timestamp2 = add(start, delta);
    final Timestamp timestamp3 = add(timestamp2, delta);
    final TestEventFactory eventFactory = newInstance(Given.class);
    final Event e1 = eventFactory.createEvent(projectCreated(id, Given.projectName(id)), null, start);
    final AggregateEventRecord record1 = StorageRecord.create(start, e1);
    final Event e2 = eventFactory.createEvent(taskAdded(id), null, timestamp2);
    final AggregateEventRecord record2 = StorageRecord.create(timestamp2, e2);
    final Event e3 = eventFactory.createEvent(Given.EventMessage.projectStarted(id), null, timestamp3);
    final AggregateEventRecord record3 = StorageRecord.create(timestamp3, e3);
    return newArrayList(record1, record2, record3);
}
Also used : AggregateEventRecord(io.spine.server.aggregate.AggregateEventRecord) TestEventFactory(io.spine.server.command.TestEventFactory) Event(io.spine.core.Event) Duration(com.google.protobuf.Duration) Timestamp(com.google.protobuf.Timestamp)

Aggregations

Duration (com.google.protobuf.Duration)45 Test (org.junit.Test)31 Timestamp (com.google.protobuf.Timestamp)25 AbstractZonedTimeTest (io.spine.time.AbstractZonedTimeTest)8 LocalTime (io.spine.time.LocalTime)8 Command (io.spine.core.Command)5 BulkWriteOperation (io.spine.server.projection.BulkWriteOperation)4 Message (com.google.protobuf.Message)3 Schedule (io.spine.core.CommandContext.Schedule)3 Event (io.spine.core.Event)3 Interval (io.spine.time.Interval)3 Event (io.spine.base.Event)2 CommandContext (io.spine.core.CommandContext)2 ProjectId (io.spine.test.projection.ProjectId)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 ImmutableCollection (com.google.common.collect.ImmutableCollection)1 Schedule (io.spine.base.CommandContext.Schedule)1 Error (io.spine.base.Error)1 ThrowableMessage (io.spine.base.ThrowableMessage)1 CommandEnvelope (io.spine.core.CommandEnvelope)1