From b1bd4772b9c6bf30775678ac021336524d6aaf65 Mon Sep 17 00:00:00 2001 From: "dmytro.grankin" Date: Thu, 12 Oct 2017 19:07:46 +0300 Subject: [PATCH 01/17] Move event compacting method from `EEntity` to `Events` --- core/src/main/java/io/spine/core/Events.java | 47 ++++++++++++++++++ .../java/io/spine/server/event/EEntity.java | 48 +------------------ 2 files changed, 48 insertions(+), 47 deletions(-) diff --git a/core/src/main/java/io/spine/core/Events.java b/core/src/main/java/io/spine/core/Events.java index 3ec4533c488..1fdadb68573 100644 --- a/core/src/main/java/io/spine/core/Events.java +++ b/core/src/main/java/io/spine/core/Events.java @@ -36,6 +36,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import static io.spine.protobuf.AnyPacker.unpack; +import static io.spine.util.Exceptions.newIllegalStateException; import static io.spine.validate.Validate.checkNotEmptyOrBlank; /** @@ -217,6 +218,52 @@ public static boolean isExternal(EventContext context) { return context.getExternal(); } + /** + * Obtains the compacted version of the event, which should be used for storing. + * + *

A compacted version doesn't contain: + *

+ * + * @param event the event to compact + * @return the compacted event + */ + @Internal + public static Event compact(Event event) { + final EventContext context = event.getContext(); + final EventContext.Builder resultContext = context.toBuilder() + .clearEnrichment(); + final EventContext.OriginCase originCase = resultContext.getOriginCase(); + switch (originCase) { + case EVENT_CONTEXT: + resultContext.setEventContext(context.getEventContext() + .toBuilder() + .clearOrigin() + .clearEnrichment()); + break; + case REJECTION_CONTEXT: + resultContext.setRejectionContext(context.getRejectionContext() + .toBuilder() + .clearEnrichment()); + break; + case COMMAND_CONTEXT: + // Nothing to remove. + break; + case ORIGIN_NOT_SET: + // Does nothing because there is no origin for this event. + break; + default: + throw newIllegalStateException("Unsupported origin case encountered: %s", + originCase); + } + return event.toBuilder() + .setContext(resultContext) + .build(); + } + /** * The stringifier of event IDs. */ diff --git a/server/src/main/java/io/spine/server/event/EEntity.java b/server/src/main/java/io/spine/server/event/EEntity.java index ff285dd2145..35cdcfb13dc 100644 --- a/server/src/main/java/io/spine/server/event/EEntity.java +++ b/server/src/main/java/io/spine/server/event/EEntity.java @@ -23,7 +23,6 @@ import com.google.protobuf.Timestamp; import io.spine.annotation.Internal; import io.spine.core.Event; -import io.spine.core.EventContext; import io.spine.core.EventEnvelope; import io.spine.core.EventId; import io.spine.core.Events; @@ -34,7 +33,7 @@ import javax.annotation.Nullable; import java.util.Comparator; -import static io.spine.util.Exceptions.newIllegalStateException; +import static io.spine.core.Events.compact; /** * Stores an event. @@ -128,49 +127,4 @@ public String getType() { } return typeName.value(); } - - /** - * Obtains the compacted version of the event. - * - *

A compacted version doesn't contain: - *

- * - * @param event the event to compact - * @return the compacted event - */ - private static Event compact(Event event) { - final EventContext context = event.getContext(); - final EventContext.Builder resultContext = context.toBuilder() - .clearEnrichment(); - final EventContext.OriginCase originCase = resultContext.getOriginCase(); - switch (originCase) { - case EVENT_CONTEXT: - resultContext.setEventContext(context.getEventContext() - .toBuilder() - .clearOrigin() - .clearEnrichment()); - break; - case REJECTION_CONTEXT: - resultContext.setRejectionContext(context.getRejectionContext() - .toBuilder() - .clearEnrichment()); - break; - case COMMAND_CONTEXT: - // Does nothing. - break; - case ORIGIN_NOT_SET: - // Does nothing because there is no origin for this event. - break; - default: - throw newIllegalStateException("Unsupported origin case encountered: %s", - originCase); - } - return event.toBuilder() - .setContext(resultContext) - .build(); - } } From b5aa07bd9e0524d19aa08a012025549804383c1c Mon Sep 17 00:00:00 2001 From: "dmytro.grankin" Date: Thu, 12 Oct 2017 19:08:32 +0300 Subject: [PATCH 02/17] Add event compacting to `AggregateStorage.writeEvent(...)` --- .../java/io/spine/server/aggregate/AggregateStorage.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/io/spine/server/aggregate/AggregateStorage.java b/server/src/main/java/io/spine/server/aggregate/AggregateStorage.java index ebaa7c74546..f982c85db97 100644 --- a/server/src/main/java/io/spine/server/aggregate/AggregateStorage.java +++ b/server/src/main/java/io/spine/server/aggregate/AggregateStorage.java @@ -38,6 +38,7 @@ import static com.google.common.collect.Lists.newLinkedList; import static com.google.protobuf.TextFormat.shortDebugString; import static com.google.protobuf.util.Timestamps.checkValid; +import static io.spine.core.Events.compact; import static io.spine.util.Exceptions.newIllegalStateException; import static io.spine.validate.Validate.checkNotEmptyOrBlank; @@ -156,13 +157,17 @@ public void write(I id, AggregateStateRecord events) { /** * Writes an event to the storage by an aggregate ID. * + *

Before the storing, an event will be + * {@linkplain io.spine.core.Events#compact(Event) compacted}. + * * @param id the aggregate ID * @param event the event to write */ void writeEvent(I id, Event event) { checkNotClosedAndArguments(id, event); - final AggregateEventRecord record = toStorageRecord(event); + final Event compacted = compact(event); + final AggregateEventRecord record = toStorageRecord(compacted); writeRecord(id, record); } From b6c1e3beead744497a35c350231fddec74b9e612 Mon Sep 17 00:00:00 2001 From: "dmytro.grankin" Date: Fri, 13 Oct 2017 14:11:55 +0300 Subject: [PATCH 03/17] Introduce `GivenEnrichment` utility --- core/src/main/java/io/spine/core/Events.java | 2 +- .../spine/server/event/EventStoreShould.java | 30 +++------- .../io/spine/core/given/GivenEnrichment.java | 60 +++++++++++++++++++ .../core/given/GivenEnrichmentShould.java | 52 ++++++++++++++++ 4 files changed, 121 insertions(+), 23 deletions(-) create mode 100644 testutil-core/src/main/java/io/spine/core/given/GivenEnrichment.java create mode 100644 testutil-core/src/test/java/io/spine/core/given/GivenEnrichmentShould.java diff --git a/core/src/main/java/io/spine/core/Events.java b/core/src/main/java/io/spine/core/Events.java index 1fdadb68573..ddfb187ec95 100644 --- a/core/src/main/java/io/spine/core/Events.java +++ b/core/src/main/java/io/spine/core/Events.java @@ -256,7 +256,7 @@ public static Event compact(Event event) { // Does nothing because there is no origin for this event. break; default: - throw newIllegalStateException("Unsupported origin case encountered: %s", + throw newIllegalStateException("Unsupported origin case is encountered: %s", originCase); } return event.toBuilder() diff --git a/server/src/test/java/io/spine/server/event/EventStoreShould.java b/server/src/test/java/io/spine/server/event/EventStoreShould.java index 031a4d43d58..cfa473b8d1d 100644 --- a/server/src/test/java/io/spine/server/event/EventStoreShould.java +++ b/server/src/test/java/io/spine/server/event/EventStoreShould.java @@ -22,14 +22,11 @@ import com.google.common.collect.ImmutableSet; import com.google.common.util.concurrent.MoreExecutors; -import com.google.protobuf.Any; import com.google.protobuf.Duration; import com.google.protobuf.Timestamp; import io.grpc.stub.StreamObserver; import io.spine.core.ActorContext; import io.spine.core.CommandContext; -import io.spine.core.Enrichment; -import io.spine.core.Enrichment.Container; import io.spine.core.Event; import io.spine.core.EventContext; import io.spine.core.RejectionContext; @@ -51,11 +48,10 @@ import java.util.concurrent.atomic.AtomicBoolean; import static com.google.common.collect.Sets.newConcurrentHashSet; -import static com.google.protobuf.Any.pack; import static com.google.protobuf.util.Timestamps.add; import static com.google.protobuf.util.Timestamps.subtract; +import static io.spine.core.given.GivenEnrichment.enabledEnrichment; import static io.spine.grpc.StreamObservers.memoizingObserver; -import static io.spine.protobuf.TypeConverter.toMessage; import static io.spine.test.Verify.assertContainsAll; import static io.spine.test.Verify.assertSize; import static io.spine.time.Time.getCurrentTime; @@ -242,7 +238,7 @@ public void not_store_enrichment_for_EventContext() { final Event enriched = event.toBuilder() .setContext(event.getContext() .toBuilder() - .setEnrichment(newEnrichment())) + .setEnrichment(enabledEnrichment())) .build(); eventStore.append(enriched); final MemoizingObserver observer = memoizingObserver(); @@ -256,7 +252,7 @@ public void not_store_enrichment_for_EventContext() { @Test public void not_store_enrichment_for_origin_of_RejectionContext_type() { final RejectionContext originContext = RejectionContext.newBuilder() - .setEnrichment(newEnrichment()) + .setEnrichment(enabledEnrichment()) .build(); final Event event = projectCreated(Time.getCurrentTime()); final Event enriched = event.toBuilder() @@ -277,7 +273,7 @@ public void not_store_enrichment_for_origin_of_RejectionContext_type() { @Test public void not_store_enrichment_for_origin_of_EventContext_type() { final EventContext.Builder originContext = EventContext.newBuilder() - .setEnrichment(newEnrichment()); + .setEnrichment(enabledEnrichment()); final Event event = projectCreated(Time.getCurrentTime()); final Event enriched = event.toBuilder() .setContext(event.getContext() @@ -297,7 +293,7 @@ public void not_store_enrichment_for_origin_of_EventContext_type() { @Test public void not_store_nested_origins_for_EventContext_origin() { final EventContext.Builder context = EventContext.newBuilder() - .setEnrichment(newEnrichment()); + .setEnrichment(enabledEnrichment()); final EventContext originContext = EventContext.newBuilder() .setEventContext(context) .build(); @@ -311,9 +307,9 @@ public void not_store_nested_origins_for_EventContext_origin() { final MemoizingObserver observer = memoizingObserver(); eventStore.read(EventStreamQuery.getDefaultInstance(), observer); final EventContext loadedOriginContext = observer.responses() - .get(0) - .getContext() - .getEventContext(); + .get(0) + .getContext() + .getEventContext(); assertTrue(isDefault(loadedOriginContext.getEventContext())); } @@ -337,16 +333,6 @@ private static void assertDone(AtomicBoolean done) { } } - private static Enrichment newEnrichment() { - final String key = "enrichment key"; - final Any value = pack(toMessage("enrichment value")); - return Enrichment.newBuilder() - .setContainer(Container.newBuilder() - .putItems(key, value) - .build()) - .build(); - } - private static class ResponseObserver implements StreamObserver { private final Collection resultStorage; diff --git a/testutil-core/src/main/java/io/spine/core/given/GivenEnrichment.java b/testutil-core/src/main/java/io/spine/core/given/GivenEnrichment.java new file mode 100644 index 00000000000..81c938b02b2 --- /dev/null +++ b/testutil-core/src/main/java/io/spine/core/given/GivenEnrichment.java @@ -0,0 +1,60 @@ +/* + * Copyright 2017, TeamDev Ltd. All rights reserved. + * + * Redistribution and use in source and/or binary forms, with or without + * modification, must retain the above copyright notice and the following + * disclaimer. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package io.spine.core.given; + +import com.google.protobuf.Any; +import io.spine.core.Enrichment; + +import static com.google.protobuf.Any.pack; +import static io.spine.Identifier.newUuid; +import static io.spine.protobuf.TypeConverter.toMessage; + +/** + * Factory methods to create {@code Enrichment} instances for test purposes. + * + * @author Dmytro Grankin + */ +public class GivenEnrichment { + + private GivenEnrichment() { + // Prevent instantiation of this utility class. + } + + /** + * Creates a new enabled {@link Enrichment}. + * + *

A result will contain an enrichment {@linkplain Enrichment#getContainer() instruction}. + * + *

An enrichment instruction is invalid and has random values. + * + * @return an enabled enrichment + * @see Enrichment.ModeCase#getDoNotEnrich() + */ + public static Enrichment enabledEnrichment() { + final String key = newUuid(); + final Any value = pack(toMessage(newUuid())); + return Enrichment.newBuilder() + .setContainer(Enrichment.Container.newBuilder() + .putItems(key, value) + .build()) + .build(); + } +} diff --git a/testutil-core/src/test/java/io/spine/core/given/GivenEnrichmentShould.java b/testutil-core/src/test/java/io/spine/core/given/GivenEnrichmentShould.java new file mode 100644 index 00000000000..6a969b1f324 --- /dev/null +++ b/testutil-core/src/test/java/io/spine/core/given/GivenEnrichmentShould.java @@ -0,0 +1,52 @@ +/* + * Copyright 2017, TeamDev Ltd. All rights reserved. + * + * Redistribution and use in source and/or binary forms, with or without + * modification, must retain the above copyright notice and the following + * disclaimer. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package io.spine.core.given; + +import com.google.protobuf.Any; +import io.spine.core.Enrichment; +import org.junit.Test; + +import java.util.Map; + +import static io.spine.core.given.GivenEnrichment.enabledEnrichment; +import static io.spine.test.Tests.assertHasPrivateParameterlessCtor; +import static io.spine.test.Verify.assertNotEmpty; +import static org.junit.Assert.assertFalse; + +/** + * @author Dmytro Grankin + */ +public class GivenEnrichmentShould { + + @Test + public void have_private_utility_ctor() { + assertHasPrivateParameterlessCtor(GivenEnrichment.class); + } + + @Test + public void create_enabled_enrichment() { + final Enrichment enrichment = enabledEnrichment(); + assertFalse(enrichment.getDoNotEnrich()); + final Map enrichmentInstructions = enrichment.getContainer() + .getItems(); + assertNotEmpty(enrichmentInstructions); + } +} From ccc359df551c796f3fa6e8a3efe1626e712cbbb5 Mon Sep 17 00:00:00 2001 From: "dmytro.grankin" Date: Fri, 13 Oct 2017 14:54:41 +0300 Subject: [PATCH 04/17] Add tests for event compacting in `AggregateStorage` --- .../aggregate/AggregateStorageShould.java | 101 ++++++++++++++++-- 1 file changed, 94 insertions(+), 7 deletions(-) diff --git a/server/src/test/java/io/spine/server/aggregate/AggregateStorageShould.java b/server/src/test/java/io/spine/server/aggregate/AggregateStorageShould.java index 28e5c4dbde5..6a0826a3291 100644 --- a/server/src/test/java/io/spine/server/aggregate/AggregateStorageShould.java +++ b/server/src/test/java/io/spine/server/aggregate/AggregateStorageShould.java @@ -27,6 +27,8 @@ import com.google.protobuf.Timestamp; import com.google.protobuf.util.Timestamps; import io.spine.core.Event; +import io.spine.core.EventContext; +import io.spine.core.RejectionContext; import io.spine.core.Version; import io.spine.server.aggregate.given.Given.StorageRecord; import io.spine.server.command.TestEventFactory; @@ -52,10 +54,12 @@ import static io.spine.Identifier.newUuid; import static io.spine.core.Versions.increment; import static io.spine.core.Versions.zero; +import static io.spine.core.given.GivenEnrichment.enabledEnrichment; import static io.spine.server.aggregate.given.Given.StorageRecords.sequenceFor; import static io.spine.server.command.TestEventFactory.newInstance; import static io.spine.time.Durations2.seconds; import static io.spine.time.Time.getCurrentTime; +import static io.spine.validate.Validate.isDefault; import static java.lang.Integer.MAX_VALUE; import static java.util.Collections.reverse; import static org.junit.Assert.assertEquals; @@ -345,6 +349,89 @@ public void continue_history_reading_if_snapshot_was_not_found_in_first_batch() assertEquals(eventCountAfterSnapshot, stateRecord.getEventCount()); } + @Test + public void not_store_enrichment_for_EventContext() { + final EventContext enrichedContext = EventContext.newBuilder() + .setEnrichment(enabledEnrichment()) + .build(); + final Event event = Event.newBuilder() + .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())); + } + + @Test + public void not_store_enrichment_for_origin_of_RejectionContext_type() { + final RejectionContext origin = RejectionContext.newBuilder() + .setEnrichment(enabledEnrichment()) + .build(); + final EventContext context = EventContext.newBuilder() + .setRejectionContext(origin) + .build(); + final Event event = Event.newBuilder() + .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())); + } + + @Test + public void not_store_enrichment_for_origin_of_EventContext_type() { + final EventContext origin = EventContext.newBuilder() + .setEnrichment(enabledEnrichment()) + .build(); + final EventContext context = EventContext.newBuilder() + .setEventContext(origin) + .build(); + final Event event = Event.newBuilder() + .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())); + } + + @Test + public void not_store_nested_origin_for_EventContext_origin() { + final EventContext nestedOrigin = EventContext.newBuilder() + .setEnrichment(enabledEnrichment()) + .build(); + final EventContext origin = EventContext.newBuilder() + .setEventContext(nestedOrigin) + .build(); + final EventContext context = EventContext.newBuilder() + .setEventContext(origin) + .build(); + final Event event = Event.newBuilder() + .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.getEventContext())); + } + @Test(expected = IllegalStateException.class) public void throw_exception_if_try_to_write_event_count_to_closed_storage() { close(storage); @@ -402,18 +489,18 @@ protected void writeAll(ProjectId id, Iterable records) { } private Iterator historyBackward() { - final AggregateReadRequest readRequest = new AggregateReadRequest<>(id, MAX_VALUE); + final AggregateReadRequest readRequest = newReadRequest(id); return storage.historyBackward(readRequest); } protected static final Function TO_EVENT = new Function() { - @Nullable // return null because an exception won't be propagated in this case - @Override - public Event apply(@Nullable AggregateEventRecord input) { - return (input == null) ? null : input.getEvent(); - } - }; + @Nullable // return null because an exception won't be propagated in this case + @Override + public Event apply(@Nullable AggregateEventRecord input) { + return (input == null) ? null : input.getEvent(); + } + }; private static Snapshot newSnapshot(Timestamp time) { return Snapshot.newBuilder() From bbe426304d82667726aba6ccd2b451edab053fec Mon Sep 17 00:00:00 2001 From: "dmytro.grankin" Date: Fri, 13 Oct 2017 15:27:15 +0300 Subject: [PATCH 05/17] Improve Javadoc for `EEntity` --- server/src/main/java/io/spine/server/event/EEntity.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/io/spine/server/event/EEntity.java b/server/src/main/java/io/spine/server/event/EEntity.java index 35cdcfb13dc..dedb0d260bf 100644 --- a/server/src/main/java/io/spine/server/event/EEntity.java +++ b/server/src/main/java/io/spine/server/event/EEntity.java @@ -36,7 +36,9 @@ import static io.spine.core.Events.compact; /** - * Stores an event. + * An entity for storing an event. + * + *

The entity {@linkplain Events#compact(Event) compacts} an underlying event. * * @author Alexander Yevsyukov * @author Dmytro Dashenkov From 5abce6b8f0aa3907842a71c20ab0f88689bd56b7 Mon Sep 17 00:00:00 2001 From: "dmytro.grankin" Date: Fri, 13 Oct 2017 15:33:23 +0300 Subject: [PATCH 06/17] Bump Spine version to `0.9.78-SNAPSHOT` --- ext.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext.gradle b/ext.gradle index fd53ed27c1b..ce21c93cf63 100644 --- a/ext.gradle +++ b/ext.gradle @@ -25,7 +25,7 @@ * as we want to manage the versions in a single source. */ -def final SPINE_VERSION = '0.9.77-SNAPSHOT' +def final SPINE_VERSION = '0.9.78-SNAPSHOT' ext { // The version of the modules in this project. From 05af44ae89170f9a2c34ae64714153eb2b01e5ac Mon Sep 17 00:00:00 2001 From: "dmytro.grankin" Date: Fri, 13 Oct 2017 16:12:31 +0300 Subject: [PATCH 07/17] Remove clearing of nested origins during event compacting --- core/src/main/java/io/spine/core/Events.java | 7 +++--- .../aggregate/AggregateStorageShould.java | 24 ------------------- .../spine/server/event/EventStoreShould.java | 23 ------------------ 3 files changed, 4 insertions(+), 50 deletions(-) diff --git a/core/src/main/java/io/spine/core/Events.java b/core/src/main/java/io/spine/core/Events.java index ddfb187ec95..700b125df8b 100644 --- a/core/src/main/java/io/spine/core/Events.java +++ b/core/src/main/java/io/spine/core/Events.java @@ -224,10 +224,12 @@ public static boolean isExternal(EventContext context) { *

A compacted version doesn't contain: *

* + *

Enrichments will not be removed from second-level and more deeper origins, + * because it's a heavy performance operation. + * * @param event the event to compact * @return the compacted event */ @@ -241,7 +243,6 @@ public static Event compact(Event event) { case EVENT_CONTEXT: resultContext.setEventContext(context.getEventContext() .toBuilder() - .clearOrigin() .clearEnrichment()); break; case REJECTION_CONTEXT: diff --git a/server/src/test/java/io/spine/server/aggregate/AggregateStorageShould.java b/server/src/test/java/io/spine/server/aggregate/AggregateStorageShould.java index 6a0826a3291..de3009f22ae 100644 --- a/server/src/test/java/io/spine/server/aggregate/AggregateStorageShould.java +++ b/server/src/test/java/io/spine/server/aggregate/AggregateStorageShould.java @@ -408,30 +408,6 @@ public void not_store_enrichment_for_origin_of_EventContext_type() { assertTrue(isDefault(loadedOrigin.getEnrichment())); } - @Test - public void not_store_nested_origin_for_EventContext_origin() { - final EventContext nestedOrigin = EventContext.newBuilder() - .setEnrichment(enabledEnrichment()) - .build(); - final EventContext origin = EventContext.newBuilder() - .setEventContext(nestedOrigin) - .build(); - final EventContext context = EventContext.newBuilder() - .setEventContext(origin) - .build(); - final Event event = Event.newBuilder() - .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.getEventContext())); - } - @Test(expected = IllegalStateException.class) public void throw_exception_if_try_to_write_event_count_to_closed_storage() { close(storage); diff --git a/server/src/test/java/io/spine/server/event/EventStoreShould.java b/server/src/test/java/io/spine/server/event/EventStoreShould.java index cfa473b8d1d..a22cd8fdec1 100644 --- a/server/src/test/java/io/spine/server/event/EventStoreShould.java +++ b/server/src/test/java/io/spine/server/event/EventStoreShould.java @@ -290,29 +290,6 @@ public void not_store_enrichment_for_origin_of_EventContext_type() { assertTrue(isDefault(loadedOriginContext.getEnrichment())); } - @Test - public void not_store_nested_origins_for_EventContext_origin() { - final EventContext.Builder context = EventContext.newBuilder() - .setEnrichment(enabledEnrichment()); - final EventContext originContext = EventContext.newBuilder() - .setEventContext(context) - .build(); - final Event event = projectCreated(Time.getCurrentTime()); - final Event enriched = event.toBuilder() - .setContext(event.getContext() - .toBuilder() - .setEventContext(originContext)) - .build(); - eventStore.append(enriched); - final MemoizingObserver observer = memoizingObserver(); - eventStore.read(EventStreamQuery.getDefaultInstance(), observer); - final EventContext loadedOriginContext = observer.responses() - .get(0) - .getContext() - .getEventContext(); - assertTrue(isDefault(loadedOriginContext.getEventContext())); - } - /* * Test environment *********************/ From f0ab6b0de380ff3b9e4d187cbcbf1ea7970cd1ab Mon Sep 17 00:00:00 2001 From: "dmytro.grankin" Date: Fri, 13 Oct 2017 16:28:42 +0300 Subject: [PATCH 08/17] Fix code style in `GivenEnrichment` --- .../java/io/spine/core/given/GivenEnrichment.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/testutil-core/src/main/java/io/spine/core/given/GivenEnrichment.java b/testutil-core/src/main/java/io/spine/core/given/GivenEnrichment.java index 81c938b02b2..4c7450ca34f 100644 --- a/testutil-core/src/main/java/io/spine/core/given/GivenEnrichment.java +++ b/testutil-core/src/main/java/io/spine/core/given/GivenEnrichment.java @@ -51,10 +51,11 @@ private GivenEnrichment() { public static Enrichment enabledEnrichment() { final String key = newUuid(); final Any value = pack(toMessage(newUuid())); - return Enrichment.newBuilder() - .setContainer(Enrichment.Container.newBuilder() - .putItems(key, value) - .build()) - .build(); + final Enrichment result = Enrichment.newBuilder() + .setContainer(Enrichment.Container.newBuilder() + .putItems(key, value) + .build()) + .build(); + return result; } } From f169cb0340b37eeea4ce61edd3cbe16f2821eb2f Mon Sep 17 00:00:00 2001 From: "dmytro.grankin" Date: Fri, 13 Oct 2017 17:25:06 +0300 Subject: [PATCH 09/17] Fix a typo in `enrichment.proto` --- core/src/main/proto/spine/core/enrichment.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/proto/spine/core/enrichment.proto b/core/src/main/proto/spine/core/enrichment.proto index 016c67ffc67..78064114aae 100644 --- a/core/src/main/proto/spine/core/enrichment.proto +++ b/core/src/main/proto/spine/core/enrichment.proto @@ -34,7 +34,7 @@ import "google/protobuf/any.proto"; // Attributes with additional information (enrichment) for an outer message. // // A message can be enriched with one or more messages. For example, an `Event` can be enriched with -// information for easier building of user interface projections. A `Rejection` can be eriched with +// information for easier building of user interface projections. A `Rejection` can be enriched with // additional information on why the command was rejected. // // If message enrichment should not be performed (e.g. because of performance or security From 329536cdc31b05a74bab31005e08740ba359ff50 Mon Sep 17 00:00:00 2001 From: "dmytro.grankin" Date: Fri, 13 Oct 2017 17:32:20 +0300 Subject: [PATCH 10/17] Rename `GivenEnrichment.enabledEnrichment()` to `GivenEnrichment.newEnrichment()` --- .../server/aggregate/AggregateStorageShould.java | 8 ++++---- .../io/spine/server/event/EventStoreShould.java | 8 ++++---- .../java/io/spine/core/given/GivenEnrichment.java | 13 +++++-------- .../spine/core/given/GivenEnrichmentShould.java | 15 ++++----------- 4 files changed, 17 insertions(+), 27 deletions(-) diff --git a/server/src/test/java/io/spine/server/aggregate/AggregateStorageShould.java b/server/src/test/java/io/spine/server/aggregate/AggregateStorageShould.java index de3009f22ae..52d74a12237 100644 --- a/server/src/test/java/io/spine/server/aggregate/AggregateStorageShould.java +++ b/server/src/test/java/io/spine/server/aggregate/AggregateStorageShould.java @@ -54,7 +54,7 @@ import static io.spine.Identifier.newUuid; import static io.spine.core.Versions.increment; import static io.spine.core.Versions.zero; -import static io.spine.core.given.GivenEnrichment.enabledEnrichment; +import static io.spine.core.given.GivenEnrichment.newEnrichment; import static io.spine.server.aggregate.given.Given.StorageRecords.sequenceFor; import static io.spine.server.command.TestEventFactory.newInstance; import static io.spine.time.Durations2.seconds; @@ -352,7 +352,7 @@ public void continue_history_reading_if_snapshot_was_not_found_in_first_batch() @Test public void not_store_enrichment_for_EventContext() { final EventContext enrichedContext = EventContext.newBuilder() - .setEnrichment(enabledEnrichment()) + .setEnrichment(newEnrichment()) .build(); final Event event = Event.newBuilder() .setContext(enrichedContext) @@ -369,7 +369,7 @@ public void not_store_enrichment_for_EventContext() { @Test public void not_store_enrichment_for_origin_of_RejectionContext_type() { final RejectionContext origin = RejectionContext.newBuilder() - .setEnrichment(enabledEnrichment()) + .setEnrichment(newEnrichment()) .build(); final EventContext context = EventContext.newBuilder() .setRejectionContext(origin) @@ -390,7 +390,7 @@ public void not_store_enrichment_for_origin_of_RejectionContext_type() { @Test public void not_store_enrichment_for_origin_of_EventContext_type() { final EventContext origin = EventContext.newBuilder() - .setEnrichment(enabledEnrichment()) + .setEnrichment(newEnrichment()) .build(); final EventContext context = EventContext.newBuilder() .setEventContext(origin) diff --git a/server/src/test/java/io/spine/server/event/EventStoreShould.java b/server/src/test/java/io/spine/server/event/EventStoreShould.java index a22cd8fdec1..3bda02b6b9f 100644 --- a/server/src/test/java/io/spine/server/event/EventStoreShould.java +++ b/server/src/test/java/io/spine/server/event/EventStoreShould.java @@ -50,7 +50,7 @@ import static com.google.common.collect.Sets.newConcurrentHashSet; import static com.google.protobuf.util.Timestamps.add; import static com.google.protobuf.util.Timestamps.subtract; -import static io.spine.core.given.GivenEnrichment.enabledEnrichment; +import static io.spine.core.given.GivenEnrichment.newEnrichment; import static io.spine.grpc.StreamObservers.memoizingObserver; import static io.spine.test.Verify.assertContainsAll; import static io.spine.test.Verify.assertSize; @@ -238,7 +238,7 @@ public void not_store_enrichment_for_EventContext() { final Event enriched = event.toBuilder() .setContext(event.getContext() .toBuilder() - .setEnrichment(enabledEnrichment())) + .setEnrichment(newEnrichment())) .build(); eventStore.append(enriched); final MemoizingObserver observer = memoizingObserver(); @@ -252,7 +252,7 @@ public void not_store_enrichment_for_EventContext() { @Test public void not_store_enrichment_for_origin_of_RejectionContext_type() { final RejectionContext originContext = RejectionContext.newBuilder() - .setEnrichment(enabledEnrichment()) + .setEnrichment(newEnrichment()) .build(); final Event event = projectCreated(Time.getCurrentTime()); final Event enriched = event.toBuilder() @@ -273,7 +273,7 @@ public void not_store_enrichment_for_origin_of_RejectionContext_type() { @Test public void not_store_enrichment_for_origin_of_EventContext_type() { final EventContext.Builder originContext = EventContext.newBuilder() - .setEnrichment(enabledEnrichment()); + .setEnrichment(newEnrichment()); final Event event = projectCreated(Time.getCurrentTime()); final Event enriched = event.toBuilder() .setContext(event.getContext() diff --git a/testutil-core/src/main/java/io/spine/core/given/GivenEnrichment.java b/testutil-core/src/main/java/io/spine/core/given/GivenEnrichment.java index 4c7450ca34f..11b805d85a6 100644 --- a/testutil-core/src/main/java/io/spine/core/given/GivenEnrichment.java +++ b/testutil-core/src/main/java/io/spine/core/given/GivenEnrichment.java @@ -21,6 +21,7 @@ package io.spine.core.given; import com.google.protobuf.Any; +import com.google.protobuf.Message; import io.spine.core.Enrichment; import static com.google.protobuf.Any.pack; @@ -39,16 +40,12 @@ private GivenEnrichment() { } /** - * Creates a new enabled {@link Enrichment}. + * Creates a non-{@linkplain io.spine.validate.Validate#isDefault(Message) default} + * {@link Enrichment}. * - *

A result will contain an enrichment {@linkplain Enrichment#getContainer() instruction}. - * - *

An enrichment instruction is invalid and has random values. - * - * @return an enabled enrichment - * @see Enrichment.ModeCase#getDoNotEnrich() + * @return a new enrichment instance */ - public static Enrichment enabledEnrichment() { + public static Enrichment newEnrichment() { final String key = newUuid(); final Any value = pack(toMessage(newUuid())); final Enrichment result = Enrichment.newBuilder() diff --git a/testutil-core/src/test/java/io/spine/core/given/GivenEnrichmentShould.java b/testutil-core/src/test/java/io/spine/core/given/GivenEnrichmentShould.java index 6a969b1f324..692297d640b 100644 --- a/testutil-core/src/test/java/io/spine/core/given/GivenEnrichmentShould.java +++ b/testutil-core/src/test/java/io/spine/core/given/GivenEnrichmentShould.java @@ -20,15 +20,11 @@ package io.spine.core.given; -import com.google.protobuf.Any; import io.spine.core.Enrichment; import org.junit.Test; -import java.util.Map; - -import static io.spine.core.given.GivenEnrichment.enabledEnrichment; import static io.spine.test.Tests.assertHasPrivateParameterlessCtor; -import static io.spine.test.Verify.assertNotEmpty; +import static io.spine.validate.Validate.isDefault; import static org.junit.Assert.assertFalse; /** @@ -42,11 +38,8 @@ public void have_private_utility_ctor() { } @Test - public void create_enabled_enrichment() { - final Enrichment enrichment = enabledEnrichment(); - assertFalse(enrichment.getDoNotEnrich()); - final Map enrichmentInstructions = enrichment.getContainer() - .getItems(); - assertNotEmpty(enrichmentInstructions); + public void create_non_default_enrichment() { + final Enrichment enrichment = enrichment(); + assertFalse(isDefault(enrichment)); } } From 6626ac3246769f36dc5729ba6af9a005d6d5dca0 Mon Sep 17 00:00:00 2001 From: "dmytro.grankin" Date: Fri, 13 Oct 2017 17:34:57 +0300 Subject: [PATCH 11/17] Update the method name in the test --- .../test/java/io/spine/core/given/GivenEnrichmentShould.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/testutil-core/src/test/java/io/spine/core/given/GivenEnrichmentShould.java b/testutil-core/src/test/java/io/spine/core/given/GivenEnrichmentShould.java index 692297d640b..2a3c80d7656 100644 --- a/testutil-core/src/test/java/io/spine/core/given/GivenEnrichmentShould.java +++ b/testutil-core/src/test/java/io/spine/core/given/GivenEnrichmentShould.java @@ -23,6 +23,7 @@ import io.spine.core.Enrichment; import org.junit.Test; +import static io.spine.core.given.GivenEnrichment.newEnrichment; import static io.spine.test.Tests.assertHasPrivateParameterlessCtor; import static io.spine.validate.Validate.isDefault; import static org.junit.Assert.assertFalse; @@ -39,7 +40,7 @@ public void have_private_utility_ctor() { @Test public void create_non_default_enrichment() { - final Enrichment enrichment = enrichment(); + final Enrichment enrichment = newEnrichment(); assertFalse(isDefault(enrichment)); } } From 131f6f993932866ca950f1d7e834f65c75300931 Mon Sep 17 00:00:00 2001 From: "dmytro.grankin" Date: Fri, 13 Oct 2017 17:41:16 +0300 Subject: [PATCH 12/17] Remove an unused import --- .../src/main/java/io/spine/core/given/GivenEnrichment.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/testutil-core/src/main/java/io/spine/core/given/GivenEnrichment.java b/testutil-core/src/main/java/io/spine/core/given/GivenEnrichment.java index 11b805d85a6..6a427d0ab3c 100644 --- a/testutil-core/src/main/java/io/spine/core/given/GivenEnrichment.java +++ b/testutil-core/src/main/java/io/spine/core/given/GivenEnrichment.java @@ -21,7 +21,6 @@ package io.spine.core.given; import com.google.protobuf.Any; -import com.google.protobuf.Message; import io.spine.core.Enrichment; import static com.google.protobuf.Any.pack; @@ -40,8 +39,8 @@ private GivenEnrichment() { } /** - * Creates a non-{@linkplain io.spine.validate.Validate#isDefault(Message) default} - * {@link Enrichment}. + * Creates a non-{@linkplain io.spine.validate.Validate#isDefault(com.google.protobuf.Message) + * default} {@link Enrichment}. * * @return a new enrichment instance */ From 42696e9bb22f34f1e712b9c3be123bacc08ba12e Mon Sep 17 00:00:00 2001 From: "dmytro.grankin" Date: Mon, 16 Oct 2017 11:59:06 +0300 Subject: [PATCH 13/17] Rename `GivenEnrichment.newEnrichment()` to `withOneAttribute()` --- .../server/aggregate/AggregateStorageShould.java | 8 ++++---- .../io/spine/server/event/EventStoreShould.java | 8 ++++---- .../io/spine/core/given/GivenEnrichment.java | 9 +++++---- .../spine/core/given/GivenEnrichmentShould.java | 16 ++++++++++------ 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/server/src/test/java/io/spine/server/aggregate/AggregateStorageShould.java b/server/src/test/java/io/spine/server/aggregate/AggregateStorageShould.java index 52d74a12237..0ffaa90b372 100644 --- a/server/src/test/java/io/spine/server/aggregate/AggregateStorageShould.java +++ b/server/src/test/java/io/spine/server/aggregate/AggregateStorageShould.java @@ -54,7 +54,7 @@ import static io.spine.Identifier.newUuid; import static io.spine.core.Versions.increment; import static io.spine.core.Versions.zero; -import static io.spine.core.given.GivenEnrichment.newEnrichment; +import static io.spine.core.given.GivenEnrichment.withOneAttribute; import static io.spine.server.aggregate.given.Given.StorageRecords.sequenceFor; import static io.spine.server.command.TestEventFactory.newInstance; import static io.spine.time.Durations2.seconds; @@ -352,7 +352,7 @@ public void continue_history_reading_if_snapshot_was_not_found_in_first_batch() @Test public void not_store_enrichment_for_EventContext() { final EventContext enrichedContext = EventContext.newBuilder() - .setEnrichment(newEnrichment()) + .setEnrichment(withOneAttribute()) .build(); final Event event = Event.newBuilder() .setContext(enrichedContext) @@ -369,7 +369,7 @@ public void not_store_enrichment_for_EventContext() { @Test public void not_store_enrichment_for_origin_of_RejectionContext_type() { final RejectionContext origin = RejectionContext.newBuilder() - .setEnrichment(newEnrichment()) + .setEnrichment(withOneAttribute()) .build(); final EventContext context = EventContext.newBuilder() .setRejectionContext(origin) @@ -390,7 +390,7 @@ public void not_store_enrichment_for_origin_of_RejectionContext_type() { @Test public void not_store_enrichment_for_origin_of_EventContext_type() { final EventContext origin = EventContext.newBuilder() - .setEnrichment(newEnrichment()) + .setEnrichment(withOneAttribute()) .build(); final EventContext context = EventContext.newBuilder() .setEventContext(origin) diff --git a/server/src/test/java/io/spine/server/event/EventStoreShould.java b/server/src/test/java/io/spine/server/event/EventStoreShould.java index 3bda02b6b9f..3a019624556 100644 --- a/server/src/test/java/io/spine/server/event/EventStoreShould.java +++ b/server/src/test/java/io/spine/server/event/EventStoreShould.java @@ -50,7 +50,7 @@ import static com.google.common.collect.Sets.newConcurrentHashSet; import static com.google.protobuf.util.Timestamps.add; import static com.google.protobuf.util.Timestamps.subtract; -import static io.spine.core.given.GivenEnrichment.newEnrichment; +import static io.spine.core.given.GivenEnrichment.withOneAttribute; import static io.spine.grpc.StreamObservers.memoizingObserver; import static io.spine.test.Verify.assertContainsAll; import static io.spine.test.Verify.assertSize; @@ -238,7 +238,7 @@ public void not_store_enrichment_for_EventContext() { final Event enriched = event.toBuilder() .setContext(event.getContext() .toBuilder() - .setEnrichment(newEnrichment())) + .setEnrichment(withOneAttribute())) .build(); eventStore.append(enriched); final MemoizingObserver observer = memoizingObserver(); @@ -252,7 +252,7 @@ public void not_store_enrichment_for_EventContext() { @Test public void not_store_enrichment_for_origin_of_RejectionContext_type() { final RejectionContext originContext = RejectionContext.newBuilder() - .setEnrichment(newEnrichment()) + .setEnrichment(withOneAttribute()) .build(); final Event event = projectCreated(Time.getCurrentTime()); final Event enriched = event.toBuilder() @@ -273,7 +273,7 @@ public void not_store_enrichment_for_origin_of_RejectionContext_type() { @Test public void not_store_enrichment_for_origin_of_EventContext_type() { final EventContext.Builder originContext = EventContext.newBuilder() - .setEnrichment(newEnrichment()); + .setEnrichment(withOneAttribute()); final Event event = projectCreated(Time.getCurrentTime()); final Event enriched = event.toBuilder() .setContext(event.getContext() diff --git a/testutil-core/src/main/java/io/spine/core/given/GivenEnrichment.java b/testutil-core/src/main/java/io/spine/core/given/GivenEnrichment.java index 6a427d0ab3c..dae92573763 100644 --- a/testutil-core/src/main/java/io/spine/core/given/GivenEnrichment.java +++ b/testutil-core/src/main/java/io/spine/core/given/GivenEnrichment.java @@ -28,7 +28,7 @@ import static io.spine.protobuf.TypeConverter.toMessage; /** - * Factory methods to create {@code Enrichment} instances for test purposes. + * Factory methods to create {@code Enrichment} instances in test purposes. * * @author Dmytro Grankin */ @@ -39,12 +39,13 @@ private GivenEnrichment() { } /** - * Creates a non-{@linkplain io.spine.validate.Validate#isDefault(com.google.protobuf.Message) - * default} {@link Enrichment}. + * Creates a new {@link Enrichment} with one {@linkplain Enrichment#getContainer() attribute}. + * + *

An enrichment attribute is invalid and has random values. * * @return a new enrichment instance */ - public static Enrichment newEnrichment() { + public static Enrichment withOneAttribute() { final String key = newUuid(); final Any value = pack(toMessage(newUuid())); final Enrichment result = Enrichment.newBuilder() diff --git a/testutil-core/src/test/java/io/spine/core/given/GivenEnrichmentShould.java b/testutil-core/src/test/java/io/spine/core/given/GivenEnrichmentShould.java index 2a3c80d7656..ac7bba8a12d 100644 --- a/testutil-core/src/test/java/io/spine/core/given/GivenEnrichmentShould.java +++ b/testutil-core/src/test/java/io/spine/core/given/GivenEnrichmentShould.java @@ -20,13 +20,15 @@ package io.spine.core.given; +import com.google.protobuf.Any; import io.spine.core.Enrichment; import org.junit.Test; -import static io.spine.core.given.GivenEnrichment.newEnrichment; +import java.util.Map; + +import static io.spine.core.given.GivenEnrichment.withOneAttribute; import static io.spine.test.Tests.assertHasPrivateParameterlessCtor; -import static io.spine.validate.Validate.isDefault; -import static org.junit.Assert.assertFalse; +import static io.spine.test.Verify.assertSize; /** * @author Dmytro Grankin @@ -39,8 +41,10 @@ public void have_private_utility_ctor() { } @Test - public void create_non_default_enrichment() { - final Enrichment enrichment = newEnrichment(); - assertFalse(isDefault(enrichment)); + public void create_enrichment_with_one_attribute() { + final Enrichment enrichment = withOneAttribute(); + final Map enrichmentAttributes = enrichment.getContainer() + .getItems(); + assertSize(1, enrichmentAttributes); } } From 0c1d663fa7b609c0cb0aaf6913f4fd2f72be1857 Mon Sep 17 00:00:00 2001 From: "dmytro.grankin" Date: Mon, 16 Oct 2017 13:09:52 +0300 Subject: [PATCH 14/17] Rename `Events.compact(Event)` to `clearEnrichments(Event)` --- core/src/main/java/io/spine/core/Events.java | 15 +++++++++------ .../spine/server/aggregate/AggregateStorage.java | 10 +++++----- .../main/java/io/spine/server/event/EEntity.java | 8 ++++---- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/core/src/main/java/io/spine/core/Events.java b/core/src/main/java/io/spine/core/Events.java index 700b125df8b..00f34c68dfa 100644 --- a/core/src/main/java/io/spine/core/Events.java +++ b/core/src/main/java/io/spine/core/Events.java @@ -219,22 +219,25 @@ public static boolean isExternal(EventContext context) { } /** - * Obtains the compacted version of the event, which should be used for storing. + * Clears enrichments of the specified event. * - *

A compacted version doesn't contain: + *

This method may be helpful to decrease a size of an event, + * when enrichments aren't important. + * + *

A result won't contain: *

* - *

Enrichments will not be removed from second-level and more deeper origins, + *

Enrichments will not be removed from second-level and deeper origins, * because it's a heavy performance operation. * - * @param event the event to compact - * @return the compacted event + * @param event the event to clear enrichments + * @return the event without enrichments */ @Internal - public static Event compact(Event event) { + public static Event clearEnrichments(Event event) { final EventContext context = event.getContext(); final EventContext.Builder resultContext = context.toBuilder() .clearEnrichment(); diff --git a/server/src/main/java/io/spine/server/aggregate/AggregateStorage.java b/server/src/main/java/io/spine/server/aggregate/AggregateStorage.java index f982c85db97..165547112e9 100644 --- a/server/src/main/java/io/spine/server/aggregate/AggregateStorage.java +++ b/server/src/main/java/io/spine/server/aggregate/AggregateStorage.java @@ -38,7 +38,7 @@ import static com.google.common.collect.Lists.newLinkedList; import static com.google.protobuf.TextFormat.shortDebugString; import static com.google.protobuf.util.Timestamps.checkValid; -import static io.spine.core.Events.compact; +import static io.spine.core.Events.clearEnrichments; import static io.spine.util.Exceptions.newIllegalStateException; import static io.spine.validate.Validate.checkNotEmptyOrBlank; @@ -157,8 +157,8 @@ public void write(I id, AggregateStateRecord events) { /** * Writes an event to the storage by an aggregate ID. * - *

Before the storing, an event will be - * {@linkplain io.spine.core.Events#compact(Event) compacted}. + *

Before the storing, {@linkplain io.spine.core.Events#clearEnrichments(Event) enrichments} + * will be removed from the event. * * @param id the aggregate ID * @param event the event to write @@ -166,8 +166,8 @@ public void write(I id, AggregateStateRecord events) { void writeEvent(I id, Event event) { checkNotClosedAndArguments(id, event); - final Event compacted = compact(event); - final AggregateEventRecord record = toStorageRecord(compacted); + final Event eventWithoutEnrichments = clearEnrichments(event); + final AggregateEventRecord record = toStorageRecord(eventWithoutEnrichments); writeRecord(id, record); } diff --git a/server/src/main/java/io/spine/server/event/EEntity.java b/server/src/main/java/io/spine/server/event/EEntity.java index dedb0d260bf..a94a5a01046 100644 --- a/server/src/main/java/io/spine/server/event/EEntity.java +++ b/server/src/main/java/io/spine/server/event/EEntity.java @@ -33,12 +33,12 @@ import javax.annotation.Nullable; import java.util.Comparator; -import static io.spine.core.Events.compact; +import static io.spine.core.Events.clearEnrichments; /** * An entity for storing an event. * - *

The entity {@linkplain Events#compact(Event) compacts} an underlying event. + *

An underlying event doesn't contain {@linkplain Events#clearEnrichments(Event) enrichments}. * * @author Alexander Yevsyukov * @author Dmytro Dashenkov @@ -88,8 +88,8 @@ public int compare(EEntity e1, EEntity e2) { EEntity(Event event) { this(event.getId()); - final Event compactedEvent = compact(event); - updateState(compactedEvent); + final Event eventWithoutEnrichments = clearEnrichments(event); + updateState(eventWithoutEnrichments); } /** From dc085c3dd063fb7e9cbc48505b6f7a466957604b Mon Sep 17 00:00:00 2001 From: "dmytro.grankin" Date: Mon, 16 Oct 2017 19:36:14 +0300 Subject: [PATCH 15/17] Clarify Javadoc for `Events.clearEnrichments(...)` --- core/src/main/java/io/spine/core/Events.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/src/main/java/io/spine/core/Events.java b/core/src/main/java/io/spine/core/Events.java index 00f34c68dfa..1bc173460ea 100644 --- a/core/src/main/java/io/spine/core/Events.java +++ b/core/src/main/java/io/spine/core/Events.java @@ -221,8 +221,7 @@ public static boolean isExternal(EventContext context) { /** * Clears enrichments of the specified event. * - *

This method may be helpful to decrease a size of an event, - * when enrichments aren't important. + *

Use this method to decrease a size of an event, if enrichments aren't important. * *

A result won't contain: *