use of com.google.protobuf.Timestamp in project core-java by SpineEventEngine.
the class AggregateStorageShould method sort_by_version_rather_then_by_timestamp.
@Test
public void sort_by_version_rather_then_by_timestamp() {
final Project state = Project.getDefaultInstance();
final Version minVersion = zero();
final Version maxVersion = increment(minVersion);
final Timestamp minTimestamp = Timestamps.MIN_VALUE;
final Timestamp maxTimestamp = Timestamps.MAX_VALUE;
// The first event is an event, which is the oldest, i.e. with the minimal version.
final Event expectedFirst = eventFactory.createEvent(state, minVersion, maxTimestamp);
final Event expectedSecond = eventFactory.createEvent(state, maxVersion, minTimestamp);
storage.writeEvent(id, expectedSecond);
storage.writeEvent(id, expectedFirst);
final List<Event> events = storage.read(newReadRequest(id)).get().getEventList();
assertTrue(events.indexOf(expectedFirst) < events.indexOf(expectedSecond));
}
use of com.google.protobuf.Timestamp in project core-java by SpineEventEngine.
the class AggregateStorageShould method write_records_and_return_sorted_by_version_descending.
@Test
public void write_records_and_return_sorted_by_version_descending() {
final int eventsNumber = 5;
final List<AggregateEventRecord> records = newLinkedList();
final Timestamp timestamp = getCurrentTime();
Version currentVersion = zero();
for (int i = 0; i < eventsNumber; i++) {
final Project state = Project.getDefaultInstance();
final Event event = eventFactory.createEvent(state, currentVersion, timestamp);
final AggregateEventRecord record = StorageRecord.create(timestamp, event);
records.add(record);
currentVersion = increment(currentVersion);
}
writeAll(id, records);
final Iterator<AggregateEventRecord> iterator = historyBackward();
final List<AggregateEventRecord> actual = newArrayList(iterator);
// expected records should be in a reverse order
reverse(records);
assertEquals(records, actual);
}
use of com.google.protobuf.Timestamp in project core-java by SpineEventEngine.
the class EventStoreShould method read_events_by_type.
@Test
public void read_events_by_type() {
final Timestamp now = getCurrentTime();
final Event taskAdded1 = taskAdded(now);
final Event projectCreated = projectCreated(now);
final Event teasAdded2 = taskAdded(now);
eventStore.append(taskAdded1);
eventStore.append(projectCreated);
eventStore.append(teasAdded2);
final EventFilter taskAddedType = EventFilter.newBuilder().setEventType(of(TaskAdded.class).value()).build();
final EventStreamQuery query = EventStreamQuery.newBuilder().addFilter(taskAddedType).build();
final AtomicBoolean done = new AtomicBoolean(false);
final Collection<Event> resultEvents = newConcurrentHashSet();
eventStore.read(query, new ResponseObserver(resultEvents, done));
assertDone(done);
assertSize(2, resultEvents);
assertContainsAll(resultEvents, taskAdded1, teasAdded2);
}
use of com.google.protobuf.Timestamp in project core-java by SpineEventEngine.
the class IteratingCommandRouterShould method produce_a_command_on_routeNext.
@Test
public void produce_a_command_on_routeNext() throws Exception {
/*
This is a hack, aimed to resolve the wall-clock inaccuracy issue, that is randomly
causing the test failure due to a fast execution.
<p>The idea is to add some randomization to {@code nanoseconds} value of the
current Timestamp obtained from the wall-clock provider.
*/
Time.setProvider(new Time.Provider() {
@Override
public Timestamp getCurrentTime() {
final Timestamp millis = Timestamps.fromMillis(System.currentTimeMillis());
final Timestamp nanos = Timestamps.fromNanos(System.nanoTime());
final Timestamp result = millis.toBuilder().setNanos(nanos.toBuilder().getNanos()).build();
return result;
}
});
final CommandRouted firstRouted = router().routeFirst();
assertTrue(router().hasNext());
final Command command = router().routeNext();
// Test that 2nd command message is in the next routed command.
assertEquals(messages().get(1), Commands.getMessage(command));
// Verify that the context for the next routed command has been created, not just copied.
final Command firstCommand = firstRouted.getSource();
assertNotEquals(firstCommand.getContext().getActorContext().getTimestamp(), command.getContext().getActorContext().getTimestamp());
// Revert the hack.
Time.resetProvider();
}
use of com.google.protobuf.Timestamp in project core-java by SpineEventEngine.
the class ProjectionRepositoryShould method convert_null_timestamp_to_default.
@Test
public void convert_null_timestamp_to_default() {
final Timestamp timestamp = getCurrentTime();
assertEquals(timestamp, ProjectionRepository.nullToDefault(timestamp));
assertEquals(Timestamp.getDefaultInstance(), ProjectionRepository.nullToDefault(null));
}
Aggregations