use of io.spine.core.Version in project core-java by SpineEventEngine.
the class AggregateStorageShould method continue_history_reading_if_snapshot_was_not_found_in_first_batch.
@Test
public void continue_history_reading_if_snapshot_was_not_found_in_first_batch() {
Version currentVersion = zero();
final Snapshot snapshot = Snapshot.newBuilder().setVersion(currentVersion).build();
storage.writeSnapshot(id, snapshot);
final int eventCountAfterSnapshot = 10;
for (int i = 0; i < eventCountAfterSnapshot; i++) {
currentVersion = increment(currentVersion);
final Project state = Project.getDefaultInstance();
final Event event = eventFactory.createEvent(state, currentVersion);
storage.writeEvent(id, event);
}
final int batchSize = 1;
final AggregateReadRequest<ProjectId> request = new AggregateReadRequest<>(id, batchSize);
final Optional<AggregateStateRecord> optionalStateRecord = storage.read(request);
assertTrue(optionalStateRecord.isPresent());
final AggregateStateRecord stateRecord = optionalStateRecord.get();
assertEquals(snapshot, stateRecord.getSnapshot());
assertEquals(eventCountAfterSnapshot, stateRecord.getEventCount());
}
use of io.spine.core.Version 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 io.spine.core.Version 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 io.spine.core.Version in project core-java by SpineEventEngine.
the class ProjectionShould method expose_playing_events_to_the_package.
@Test
public void expose_playing_events_to_the_package() {
final TestEventFactory eventFactory = TestEventFactory.newInstance(getClass());
final StringValue strValue = StringValue.newBuilder().setValue("eins zwei drei").build();
final Int32Value intValue = Int32Value.newBuilder().setValue(123).build();
final Version nextVersion = Versions.increment(projection.getVersion());
final Event e1 = eventFactory.createEvent(strValue, nextVersion);
final Event e2 = eventFactory.createEvent(intValue, Versions.increment(nextVersion));
final boolean projectionChanged = Projection.play(projection, ImmutableList.of(e1, e2));
final String projectionState = projection.getState().getValue();
assertTrue(projectionChanged);
assertTrue(projectionState.contains(strValue.getValue()));
assertTrue(projectionState.contains(String.valueOf(intValue.getValue())));
}
use of io.spine.core.Version in project core-java by SpineEventEngine.
the class ProjectionTransactionShould method increment_version_on_event.
/**
* Tests the version advancement strategy for the {@link Projection}s.
*
* <p>The versioning strategy is for {@link Projection} is
* {@link io.spine.server.entity.EntityVersioning#AUTO_INCREMENT AUTO_INCREMENT}. This test
* case substitutes {@link #advance_version_from_event()}, which tested the behavior of
* {@link io.spine.server.entity.EntityVersioning#FROM_EVENT FROM_EVENT} strategy.
*/
@Test
public void increment_version_on_event() {
final Projection<ProjectId, Project, PatchedProjectBuilder> entity = createEntity();
final Version oldVersion = entity.getVersion();
final Event event = createEvent(createEventMessage());
Projection.play(entity, Collections.singleton(event));
final Version expected = Versions.increment(oldVersion);
assertEquals(expected.getNumber(), entity.getVersion().getNumber());
assertNotEquals(event.getContext().getVersion(), entity.getVersion());
}
Aggregations