Search in sources :

Example 6 with EventContext

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

the class AggregateStorageShould method not_store_enrichment_for_EventContext.

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

Example 7 with EventContext

use of io.spine.core.EventContext 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 8 with EventContext

use of io.spine.core.EventContext 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)

Example 9 with EventContext

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

the class EventStoreShould method fail_to_store_events_of_different_tenants_in_a_single_operation.

@Test(expected = IllegalArgumentException.class)
public void fail_to_store_events_of_different_tenants_in_a_single_operation() {
    final TenantId firstTenantId = TenantId.newBuilder().setValue("abc").build();
    final TenantId secondTenantId = TenantId.newBuilder().setValue("xyz").build();
    final ActorContext firstTenantActor = ActorContext.newBuilder().setTenantId(firstTenantId).build();
    final ActorContext secondTenantActor = ActorContext.newBuilder().setTenantId(secondTenantId).build();
    final CommandContext firstTenantCommand = CommandContext.newBuilder().setActorContext(firstTenantActor).build();
    final CommandContext secondTenantCommand = CommandContext.newBuilder().setActorContext(secondTenantActor).build();
    final EventContext firstTenantContext = EventContext.newBuilder().setCommandContext(firstTenantCommand).build();
    final EventContext secondTenantContext = EventContext.newBuilder().setCommandContext(secondTenantCommand).build();
    final Event firstTenantEvent = Event.newBuilder().setContext(firstTenantContext).build();
    final Event secondTenantEvent = Event.newBuilder().setContext(secondTenantContext).build();
    final Collection<Event> event = ImmutableSet.of(firstTenantEvent, secondTenantEvent);
    eventStore.appendAll(event);
}
Also used : EventContext(io.spine.core.EventContext) TenantId(io.spine.core.TenantId) CommandContext(io.spine.core.CommandContext) Event(io.spine.core.Event) ActorContext(io.spine.core.ActorContext) Test(org.junit.Test)

Example 10 with EventContext

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

the class ProjectionEndpoint method onModified.

@Override
protected void onModified(P projection) {
    final ProjectionRepository<I, P, ?> repository = repository();
    repository.store(projection);
    final EventContext eventContext = envelope().getEventContext();
    final Timestamp eventTime = eventContext.getTimestamp();
    repository.projectionStorage().writeLastHandledEventTime(eventTime);
    repository.getStand().post(eventContext.getCommandContext().getActorContext().getTenantId(), projection);
}
Also used : EventContext(io.spine.core.EventContext) Timestamp(com.google.protobuf.Timestamp)

Aggregations

EventContext (io.spine.core.EventContext)16 Event (io.spine.core.Event)12 Test (org.junit.Test)6 Timestamp (com.google.protobuf.Timestamp)3 IntegrationEventContext (io.spine.server.integration.IntegrationEventContext)3 CommandContext (io.spine.core.CommandContext)2 IntegrationEvent (io.spine.server.integration.IntegrationEvent)2 Any (com.google.protobuf.Any)1 Message (com.google.protobuf.Message)1 TextFormat.shortDebugString (com.google.protobuf.TextFormat.shortDebugString)1 ActorContext (io.spine.core.ActorContext)1 EventId (io.spine.core.EventId)1 RejectionContext (io.spine.core.RejectionContext)1 TenantId (io.spine.core.TenantId)1 GivenEvent (io.spine.core.given.GivenEvent)1