Search in sources :

Example 56 with Timestamp

use of com.google.protobuf.Timestamp in project core-java by SpineEventEngine.

the class ProjectionRepository method catchUp.

/**
     * Updates projections from the event stream obtained from {@code EventStore}.
     */
public void catchUp() {
    setStatus(Status.CATCHING_UP);
    final AllTenantOperation op = new AllTenantOperation(boundedContext.getTenantIndex()) {

        private final EventStore eventStore = getBoundedContext().getEventBus().getEventStore();

        private final Set<EventFilter> eventFilters = getEventFilters();

        @Override
        public void run() {
            // Get the timestamp of the last event. This also ensures we have the storage.
            final Timestamp timestamp = nullToDefault(projectionStorage().readLastHandledEventTime());
            final EventStreamQuery query = EventStreamQuery.newBuilder().setAfter(timestamp).addAllFilter(eventFilters).build();
            eventStore.read(query, new EventStreamObserver(ProjectionRepository.this));
        }
    };
    op.execute();
    completeCatchUp();
    logCatchUpComplete();
}
Also used : EventStore(io.spine.server.event.EventStore) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) EventStreamQuery(io.spine.server.event.EventStreamQuery) Timestamp(com.google.protobuf.Timestamp) AllTenantOperation(io.spine.server.tenant.AllTenantOperation)

Example 57 with Timestamp

use of com.google.protobuf.Timestamp in project core-java by SpineEventEngine.

the class ProjectionRepository method dispatchToEntity.

@Override
protected void dispatchToEntity(I id, Message eventMessage, EventContext context) {
    final P projection = findOrCreate(id);
    final ProjectionTransaction<I, ?, ?> tx = ProjectionTransaction.start((Projection<I, ?, ?>) projection);
    projection.handle(eventMessage, context);
    tx.commit();
    if (projection.isChanged()) {
        final Timestamp eventTime = context.getTimestamp();
        if (isBulkWriteInProgress()) {
            storePostponed(projection, eventTime);
        } else {
            storeNow(projection, eventTime);
        }
        stand.post(projection, context.getCommandContext());
    }
}
Also used : Timestamp(com.google.protobuf.Timestamp)

Example 58 with Timestamp

use of com.google.protobuf.Timestamp in project core-java by SpineEventEngine.

the class BulkWriteOperationShould method store_given_projections_in_memory.

@SuppressWarnings("MethodWithMultipleLoops")
@Test
public void store_given_projections_in_memory() {
    final int projectionsCount = 5;
    final Set<TestProjection> projections = new HashSet<>(projectionsCount);
    for (int i = 0; i < projectionsCount; i++) {
        projections.add(new TestProjection(i));
    }
    final Timestamp whenHandled = Timestamp.getDefaultInstance();
    final BulkWriteOperation<Object, TestProjection> operation = newOperation(projections, whenHandled);
    assertTrue(operation.isInProgress());
    for (TestProjection projection : projections) {
        operation.storeProjection(projection);
    }
    operation.complete();
    assertFalse(operation.isInProgress());
}
Also used : Timestamp(com.google.protobuf.Timestamp) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 59 with Timestamp

use of com.google.protobuf.Timestamp in project core-java by SpineEventEngine.

the class BulkWriteOperationShould method store_the_very_last_timestamp_only.

@Test
public void store_the_very_last_timestamp_only() {
    final Set<TestProjection> projections = emptySet();
    final Timestamp firstEvent = TimeTests.Past.secondsAgo(5L);
    final Timestamp secondEvent = TimeTests.Past.secondsAgo(5L);
    final Timestamp lastEvent = TimeTests.Past.secondsAgo(5L);
    final BulkWriteOperation<Object, TestProjection> operation = newOperation(projections, lastEvent);
    assertTrue(operation.isInProgress());
    operation.storeLastHandledEventTime(firstEvent);
    operation.storeLastHandledEventTime(secondEvent);
    operation.storeLastHandledEventTime(lastEvent);
    operation.complete();
    assertFalse(operation.isInProgress());
}
Also used : Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 60 with Timestamp

use of com.google.protobuf.Timestamp in project core-java by SpineEventEngine.

the class MessageFieldValidator method validateTimestamps.

private void validateTimestamps() {
    final Time when = timeOption.getIn();
    if (when == TIME_UNDEFINED) {
        return;
    }
    final Timestamp now = getCurrentTime();
    for (Message value : getValues()) {
        final Timestamp time = (Timestamp) value;
        if (isTimeInvalid(time, when, now)) {
            addViolation(newTimeViolation(time));
            // return because one error message is enough for the "time" option
            return;
        }
    }
}
Also used : Message(com.google.protobuf.Message) Time(io.spine.option.Time) Time.getCurrentTime(io.spine.time.Time.getCurrentTime) Timestamp(com.google.protobuf.Timestamp)

Aggregations

Timestamp (com.google.protobuf.Timestamp)120 Test (org.junit.Test)84 Duration (com.google.protobuf.Duration)24 Interval (io.spine.time.Interval)16 Command (io.spine.core.Command)9 AbstractZonedTimeTest (io.spine.time.AbstractZonedTimeTest)8 LocalTime (io.spine.time.LocalTime)8 Nullable (javax.annotation.Nullable)7 StringValue (com.google.protobuf.StringValue)6 Event (io.spine.core.Event)6 Message (com.google.protobuf.Message)5 Predicate (com.google.common.base.Predicate)4 TimeTests (io.spine.test.TimeTests)4 CommandContext (io.spine.core.CommandContext)3 EventContext (io.spine.core.EventContext)3 Version (io.spine.core.Version)3 Any (com.google.protobuf.Any)2 ByteString (com.google.protobuf.ByteString)2 PubsubMessage (com.google.pubsub.v1.PubsubMessage)2 PullRequest (com.google.pubsub.v1.PullRequest)2