Skip to content

Commit

Permalink
Merge pull request #1146 from SpineEventEngine/bbbc-improvements
Browse files Browse the repository at this point in the history
BlackBoxBoundedContext improvements
  • Loading branch information
dmdashenkov committed Aug 29, 2019
2 parents 8c73614 + b080ff6 commit 2a73509
Show file tree
Hide file tree
Showing 52 changed files with 741 additions and 663 deletions.
2 changes: 1 addition & 1 deletion config
Expand Up @@ -89,7 +89,7 @@ void expectedWithWrongType() {
}

@Test
@DisplayName("actual")
@DisplayName("actual boolean")
void actualWithWrongType() {
ValueMismatch mismatch = IntMismatch.of(1, 2, 3, VERSION);
assertThrows(RuntimeException.class, () -> BooleanMismatch.unpackActual(mismatch));
Expand Down
2 changes: 1 addition & 1 deletion core/src/test/java/io/spine/change/DoubleMismatchTest.java
Expand Up @@ -120,7 +120,7 @@ void expectedWithWrongType() {
}

@Test
@DisplayName("actual")
@DisplayName("actual double")
void actualWithWrongType() {
ValueMismatch mismatch = expectedTrue(VERSION);
assertThrows(RuntimeException.class, () -> unpackActual(mismatch));
Expand Down
2 changes: 1 addition & 1 deletion core/src/test/java/io/spine/change/FloatMismatchTest.java
Expand Up @@ -119,7 +119,7 @@ void expectedWithWrongType() {
}

@Test
@DisplayName("actual")
@DisplayName("actual float")
void actualWithWrongType() {
ValueMismatch mismatch = expectedTrue(VERSION);
assertThrows(RuntimeException.class, () -> unpackActual(mismatch));
Expand Down
2 changes: 1 addition & 1 deletion core/src/test/java/io/spine/change/IntMismatchTest.java
Expand Up @@ -136,7 +136,7 @@ void expectedWithWrongType() {
}

@Test
@DisplayName("actual")
@DisplayName("actual int")
void actualWithWrongType() {
ValueMismatch mismatch = expectedTrue(VERSION);
assertThrows(RuntimeException.class, () -> unpackActual(mismatch));
Expand Down
2 changes: 1 addition & 1 deletion core/src/test/java/io/spine/change/LongMismatchTest.java
Expand Up @@ -118,7 +118,7 @@ void expectedWithWrongType() {
}

@Test
@DisplayName("actual")
@DisplayName("actual long")
void actualWithWrongType() {
ValueMismatch mismatch = expectedTrue(VERSION);
assertThrows(RuntimeException.class, () -> unpackActual(mismatch));
Expand Down
2 changes: 1 addition & 1 deletion core/src/test/java/io/spine/change/StringMismatchTest.java
Expand Up @@ -111,7 +111,7 @@ void expectedWithWrongType() {
}

@Test
@DisplayName("actual")
@DisplayName("actual String")
void actualWithWrongType() {
ValueMismatch mismatch = expectedTrue(VERSION);
assertThrows(RuntimeException.class, () -> unpackActual(mismatch));
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
4 changes: 2 additions & 2 deletions gradlew
Expand Up @@ -125,8 +125,8 @@ if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi

# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
Expand Down
120 changes: 60 additions & 60 deletions license-report.md

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions pom.xml
Expand Up @@ -12,7 +12,7 @@ all modules and does not describe the project structure per-subproject.

<groupId>io.spine</groupId>
<artifactId>spine-core-java</artifactId>
<version>1.0.3-SNAPSHOT</version>
<version>1.0.4-SNAPSHOT</version>

<inceptionYear>2015</inceptionYear>

Expand Down Expand Up @@ -70,25 +70,25 @@ all modules and does not describe the project structure per-subproject.
<dependency>
<groupId>io.spine</groupId>
<artifactId>spine-base</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.spine</groupId>
<artifactId>spine-time</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.spine.tools</groupId>
<artifactId>spine-model-compiler</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.spine.tools</groupId>
<artifactId>spine-plugin-base</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -124,25 +124,25 @@ all modules and does not describe the project structure per-subproject.
<dependency>
<groupId>io.spine</groupId>
<artifactId>spine-testlib</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.spine</groupId>
<artifactId>spine-testutil-time</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.spine.tools</groupId>
<artifactId>spine-mute-logging</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.spine.tools</groupId>
<artifactId>spine-plugin-testlib</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -210,12 +210,12 @@ all modules and does not describe the project structure per-subproject.
<dependency>
<groupId>io.spine.tools</groupId>
<artifactId>spine-javadoc-filter</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>io.spine.tools</groupId>
<artifactId>spine-protoc-plugin</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
Expand Down
Expand Up @@ -319,7 +319,7 @@ public BoundedContextBuilder addEventDispatcher(EventDispatcher eventDispatcher)
*
* @param filter the filter to add
*/
public BoundedContextBuilder addEventFiler(BusFilter<EventEnvelope> filter) {
public BoundedContextBuilder addEventFilter(BusFilter<EventEnvelope> filter) {
checkNotNull(filter);
eventBus.appendFilter(filter);
return this;
Expand Down
Expand Up @@ -366,7 +366,7 @@ void forCommands() {
void forEvents() {
BusFilter<EventEnvelope> filter = event -> Optional.empty();

builder.addEventFiler(filter);
builder.addEventFilter(filter);

assertTrue(builder.build()
.eventBus()
Expand Down
Expand Up @@ -193,7 +193,7 @@ private void checkSubscribesTo(Class<? extends Message> aClass) {
subscriptionService.subscribe(topic, observer);

Subscription response = observer.firstResponse();
ProtoSubject<?, Message> assertResponse = ProtoTruth.assertThat(response);
ProtoSubject assertResponse = ProtoTruth.assertThat(response);
assertResponse
.isNotNull();
assertResponse
Expand Down
Expand Up @@ -68,6 +68,7 @@
import io.spine.testing.logging.MuteLogging;
import io.spine.testing.server.TestEventFactory;
import io.spine.testing.server.blackbox.BlackBoxBoundedContext;
import io.spine.testing.server.blackbox.SingleTenantBlackBoxContext;
import io.spine.testing.server.model.ModelTests;
import io.spine.type.TypeUrl;
import org.junit.jupiter.api.AfterEach;
Expand Down Expand Up @@ -96,12 +97,7 @@
import static io.spine.server.aggregate.given.repo.AggregateRepositoryTestEnv.resetRepository;
import static io.spine.server.aggregate.model.AggregateClass.asAggregateClass;
import static io.spine.system.server.SystemBoundedContexts.systemOf;
import static io.spine.testing.client.blackbox.Count.none;
import static io.spine.testing.client.blackbox.Count.thrice;
import static io.spine.testing.client.blackbox.VerifyAcknowledgements.acked;
import static io.spine.testing.core.given.GivenTenantId.generate;
import static io.spine.testing.server.blackbox.VerifyEvents.emittedEvent;
import static io.spine.testing.server.blackbox.VerifyEvents.emittedEventsHadVersions;
import static io.spine.validate.Validate.isNotDefault;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
Expand Down Expand Up @@ -499,7 +495,6 @@ void onRejections() {
// 1. got Rejections.AggCannotStartArchivedProject;
// 2. produced the state the event;
// 3. applied the event.
@SuppressWarnings("OptionalGetWithoutIsPresent") // checked above.
String value = optional.get()
.state()
.getValue();
Expand All @@ -514,7 +509,7 @@ void onRejections() {
@DisplayName("post produced events to EventBus")
class PostEventsToBus {

private AggregateRepository<?, ?> repository;
private BlackBoxBoundedContext<?> context;

/**
* Create a fresh instance of the repository since this nested class uses
Expand All @@ -525,7 +520,10 @@ class PostEventsToBus {
@BeforeEach
void createAnotherRepository() {
resetRepository();
repository = repository();
AggregateRepository<?, ?> repository = repository();
context = BlackBoxBoundedContext
.singleTenant()
.with(repository);
}

@Test
Expand All @@ -551,12 +549,8 @@ void afterCommand() {
.newBuilder()
.setProjectId(id)
.build();
BlackBoxBoundedContext
.singleTenant()
.with(repository)
.receivesCommands(create, addTask, start)
.assertThat(emittedEventsHadVersions(1, 2, 3))
.close();
context.receivesCommands(create, addTask, start);
assertEventVersions(1, 2, 3);
}

@Test
Expand All @@ -578,16 +572,12 @@ void afterEvent() {
.setProjectId(parent)
.addChildProjectId(id)
.build();
BlackBoxBoundedContext
.singleTenant()
.with(repository)
.receivesCommands(create, start)
.receivesEvent(archived)
.assertThat(emittedEventsHadVersions(
1, 2, // Product creation
3 // Event produced in response to `archived` event
))
.close();
context.receivesCommands(create, start)
.receivesEvent(archived);
assertEventVersions(
1, 2, // Results of commands.
3 // The result of the `archived` event.
);
}

@Test
Expand All @@ -609,14 +599,24 @@ void throughEventFilter() {
.setProjectId(parent)
.addChildProjectId(id)
.build();
BlackBoxBoundedContext
SingleTenantBlackBoxContext context = BlackBoxBoundedContext
.singleTenant()
.with(new EventDiscardingAggregateRepository())
.receivesCommands(create, start)
.receivesEvent(archived)
.assertThat(emittedEvent(none()))
.assertThat(acked(thrice()).withoutErrorsOrRejections())
.close();
.receivesEvent(archived);
context.assertEvents().isEmpty();
context.close();
}

private void assertEventVersions(int... expectedVersions) {
List<Event> events = context.assertEvents().actual();
assertThat(events).hasSize(expectedVersions.length);
for (int i = 0; i < events.size(); i++) {
Event event = events.get(i);
int expectedVersion = expectedVersions[i];
assertThat(event.context().getVersion().getNumber())
.isEqualTo(expectedVersion);
}
}
}

Expand Down
Expand Up @@ -38,8 +38,6 @@
import static io.spine.base.Identifier.newUuid;
import static io.spine.server.aggregate.given.fibonacci.FibonacciAggregate.lastNumberOne;
import static io.spine.server.aggregate.given.fibonacci.FibonacciAggregate.lastNumberTwo;
import static io.spine.testing.client.blackbox.Count.once;
import static io.spine.testing.server.blackbox.VerifyEvents.emittedEvent;

/**
* Verifies the integrity of the aggregate history after the storage truncation happens.
Expand Down Expand Up @@ -72,8 +70,9 @@ void restoreAggregateState() {
.setNumberTwo(1)
.vBuild();
context.receivesCommand(setStartingNumbers)
.assertThat(emittedEvent(StartingNumbersSet.class, once()));

.assertEvents()
.withType(StartingNumbersSet.class)
.hasSize(1);
// Send a lot of `MoveSequence` events, so several snapshots are created.
MoveSequence moveSequence = MoveSequence
.newBuilder()
Expand Down

0 comments on commit 2a73509

Please sign in to comment.