use of io.spine.core.Version in project core-java by SpineEventEngine.
the class StandShould method use_provided_executor_upon_update_of_watched_type.
@Test
public void use_provided_executor_upon_update_of_watched_type() {
final Executor executor = mock(Executor.class);
final BoundedContext boundedContext = BoundedContext.newBuilder().setStand(Stand.newBuilder().setCallbackExecutor(executor)).build();
final Stand stand = boundedContext.getStand();
final StandTestProjectionRepository standTestProjectionRepo = new StandTestProjectionRepository();
stand.registerTypeSupplier(standTestProjectionRepo);
final Topic projectProjections = requestFactory.topic().allOf(Project.class);
final MemoizingObserver<Subscription> observer = memoizingObserver();
stand.subscribe(projectProjections, observer);
final Subscription subscription = observer.firstResponse();
final StreamObserver<Response> noopObserver = noOpObserver();
stand.activate(subscription, emptyUpdateCallback(), noopObserver);
assertNotNull(subscription);
verify(executor, never()).execute(any(Runnable.class));
final ProjectId someId = ProjectId.getDefaultInstance();
final Version stateVersion = GivenVersion.withNumber(1);
stand.update(asEnvelope(someId, Project.getDefaultInstance(), stateVersion));
verify(executor, times(1)).execute(any(Runnable.class));
}
use of io.spine.core.Version in project core-java by SpineEventEngine.
the class StandShould method triggerMultipleUpdates.
private void triggerMultipleUpdates(Map<CustomerId, Customer> sampleCustomers, Stand stand) {
// Trigger the aggregate state updates.
for (CustomerId id : sampleCustomers.keySet()) {
final Customer sampleCustomer = sampleCustomers.get(id);
final Version stateVersion = GivenVersion.withNumber(1);
stand.update(asEnvelope(id, sampleCustomer, stateVersion));
}
}
use of io.spine.core.Version in project core-java by SpineEventEngine.
the class StandShould method operate_with_storage_provided_through_builder.
@SuppressWarnings("OverlyCoupledMethod")
@Test
public void operate_with_storage_provided_through_builder() {
final StandStorage standStorageMock = mock(StandStorage.class);
final BoundedContext boundedContext = BoundedContext.newBuilder().setStand(Stand.newBuilder().setStorage(standStorageMock)).build();
final Stand stand = boundedContext.getStand();
assertNotNull(stand);
final CustomerAggregateRepository customerAggregateRepo = new CustomerAggregateRepository();
stand.registerTypeSupplier(customerAggregateRepo);
final int numericIdValue = 17;
final CustomerId customerId = customerIdFor(numericIdValue);
final CustomerAggregate customerAggregate = customerAggregateRepo.create(customerId);
final Customer customerState = customerAggregate.getState();
final TypeUrl customerType = TypeUrl.of(Customer.class);
final Version stateVersion = GivenVersion.withNumber(1);
verify(standStorageMock, never()).write(any(AggregateStateId.class), any(EntityRecordWithColumns.class));
stand.update(asEnvelope(customerId, customerState, stateVersion));
final AggregateStateId expectedAggregateStateId = AggregateStateId.of(customerId, customerType);
final Any packedState = AnyPacker.pack(customerState);
final EntityRecord expectedRecord = EntityRecord.newBuilder().setState(packedState).build();
verify(standStorageMock, times(1)).write(eq(expectedAggregateStateId), recordStateMatcher(expectedRecord));
}
use of io.spine.core.Version in project core-java by SpineEventEngine.
the class StandShould method allow_cancelling_subscriptions.
@Test
public void allow_cancelling_subscriptions() {
final Stand stand = prepareStandWithAggregateRepo(mock(StandStorage.class));
final Topic allCustomers = requestFactory.topic().allOf(Customer.class);
final MemoizeEntityUpdateCallback memoizeCallback = new MemoizeEntityUpdateCallback();
final Subscription subscription = subscribeAndActivate(stand, allCustomers, memoizeCallback);
stand.cancel(subscription, StreamObservers.<Response>noOpObserver());
final Map.Entry<CustomerId, Customer> sampleData = fillSampleCustomers(1).entrySet().iterator().next();
final CustomerId customerId = sampleData.getKey();
final Customer customer = sampleData.getValue();
final Version stateVersion = GivenVersion.withNumber(1);
stand.update(asEnvelope(customerId, customer, stateVersion));
assertNull(memoizeCallback.newEntityState);
}
use of io.spine.core.Version in project core-java by SpineEventEngine.
the class StandShould method trigger_subscription_callbacks_matching_by_id.
@Test
public void trigger_subscription_callbacks_matching_by_id() {
final Stand stand = prepareStandWithAggregateRepo(mock(StandStorage.class));
final Map<CustomerId, Customer> sampleCustomers = fillSampleCustomers(10);
final Topic someCustomers = requestFactory.topic().someOf(Customer.class, sampleCustomers.keySet());
final Map<CustomerId, Customer> callbackStates = newHashMap();
final MemoizeEntityUpdateCallback callback = new MemoizeEntityUpdateCallback() {
@Override
public void onStateChanged(EntityStateUpdate update) {
super.onStateChanged(update);
final Customer customerInCallback = unpack(update.getState());
final CustomerId customerIdInCallback = unpack(update.getId());
callbackStates.put(customerIdInCallback, customerInCallback);
}
};
subscribeAndActivate(stand, someCustomers, callback);
for (Map.Entry<CustomerId, Customer> sampleEntry : sampleCustomers.entrySet()) {
final CustomerId customerId = sampleEntry.getKey();
final Customer customer = sampleEntry.getValue();
final Version stateVersion = GivenVersion.withNumber(1);
stand.update(asEnvelope(customerId, customer, stateVersion));
}
assertEquals(newHashMap(sampleCustomers), callbackStates);
}
Aggregations