Search in sources :

Example 76 with Event

use of io.spine.core.Event 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());
}
Also used : Project(io.spine.test.aggregate.Project) Version(io.spine.core.Version) ProjectId(io.spine.test.aggregate.ProjectId) Event(io.spine.core.Event) Test(org.junit.Test)

Example 77 with Event

use of io.spine.core.Event 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));
}
Also used : Project(io.spine.test.aggregate.Project) Version(io.spine.core.Version) Event(io.spine.core.Event) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 78 with Event

use of io.spine.core.Event 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);
}
Also used : Project(io.spine.test.aggregate.Project) Version(io.spine.core.Version) Event(io.spine.core.Event) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 79 with Event

use of io.spine.core.Event in project core-java by SpineEventEngine.

the class AggregateStorageShould method not_store_enrichment_for_origin_of_RejectionContext_type.

@Test
public void not_store_enrichment_for_origin_of_RejectionContext_type() {
    final RejectionContext origin = RejectionContext.newBuilder().setEnrichment(withOneAttribute()).build();
    final EventContext context = EventContext.newBuilder().setRejectionContext(origin).build();
    final Event event = Event.newBuilder().setId(newEventId()).setContext(context).setMessage(Any.getDefaultInstance()).build();
    storage.writeEvent(id, event);
    final RejectionContext loadedOrigin = storage.read(newReadRequest(id)).get().getEvent(0).getContext().getRejectionContext();
    assertTrue(isDefault(loadedOrigin.getEnrichment()));
}
Also used : EventContext(io.spine.core.EventContext) RejectionContext(io.spine.core.RejectionContext) Event(io.spine.core.Event) Test(org.junit.Test)

Example 80 with Event

use of io.spine.core.Event in project core-java by SpineEventEngine.

the class AggregateStorageShould method not_store_enrichment_for_origin_of_EventContext_type.

@Test
public void not_store_enrichment_for_origin_of_EventContext_type() {
    final EventContext origin = EventContext.newBuilder().setEnrichment(withOneAttribute()).build();
    final EventContext context = EventContext.newBuilder().setEventContext(origin).build();
    final Event event = Event.newBuilder().setId(newEventId()).setContext(context).setMessage(Any.getDefaultInstance()).build();
    storage.writeEvent(id, event);
    final EventContext loadedOrigin = storage.read(newReadRequest(id)).get().getEvent(0).getContext().getEventContext();
    assertTrue(isDefault(loadedOrigin.getEnrichment()));
}
Also used : EventContext(io.spine.core.EventContext) Event(io.spine.core.Event) Test(org.junit.Test)

Aggregations

Event (io.spine.core.Event)115 Test (org.junit.Test)75 Command (io.spine.core.Command)19 EventContext (io.spine.core.EventContext)12 BoundedContext (io.spine.server.BoundedContext)12 GivenEvent (io.spine.server.event.given.EventBusTestEnv.GivenEvent)12 Version (io.spine.core.Version)10 TestEventFactory (io.spine.server.command.TestEventFactory)10 Message (com.google.protobuf.Message)9 EventEnvelope (io.spine.core.EventEnvelope)9 InMemoryTransportFactory (io.spine.server.integration.memory.InMemoryTransportFactory)9 Timestamp (com.google.protobuf.Timestamp)6 Ack (io.spine.core.Ack)6 TenantId (io.spine.core.TenantId)6 Error (io.spine.base.Error)5 AggregateMessageDispatcher.dispatchCommand (io.spine.server.aggregate.AggregateMessageDispatcher.dispatchCommand)5 AggregateTestEnv.newTenantId (io.spine.server.aggregate.given.aggregate.AggregateTestEnv.newTenantId)5 StringValue (com.google.protobuf.StringValue)4 GivenEvent (io.spine.core.given.GivenEvent)4 Duration (com.google.protobuf.Duration)3