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);
}
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());
}
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);
}
}
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);
}
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);
}
Aggregations