use of com.google.protobuf.Any in project core-java by SpineEventEngine.
the class StandShould method trigger_each_subscription_callback_once_for_multiple_subscriptions.
@SuppressWarnings("MethodWithMultipleLoops")
@Test
public void trigger_each_subscription_callback_once_for_multiple_subscriptions() {
final Stand stand = prepareStandWithAggregateRepo(mock(StandStorage.class));
final Target allCustomers = Targets.allOf(Customer.class);
final Set<MemoizeEntityUpdateCallback> callbacks = newHashSet();
final int totalCallbacks = 100;
for (int callbackIndex = 0; callbackIndex < totalCallbacks; callbackIndex++) {
final MemoizeEntityUpdateCallback callback = subscribeWithCallback(stand, allCustomers);
callbacks.add(callback);
}
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));
final Any packedState = AnyPacker.pack(customer);
for (MemoizeEntityUpdateCallback callback : callbacks) {
assertEquals(packedState, callback.newEntityState);
verify(callback, times(1)).onStateChanged(any(EntityStateUpdate.class));
}
}
use of com.google.protobuf.Any in project core-java by SpineEventEngine.
the class StandShould method return_empty_list_for_aggregate_reads_with_filters_not_set.
@Test
public void return_empty_list_for_aggregate_reads_with_filters_not_set() {
final StandStorage standStorageMock = mock(StandStorage.class);
// Return non-empty results on any storage read call.
final EntityRecord someRecord = EntityRecord.getDefaultInstance();
final ImmutableList<EntityRecord> nonEmptyList = ImmutableList.<EntityRecord>builder().add(someRecord).build();
when(standStorageMock.readAllByType(any(TypeUrl.class))).thenReturn(nonEmptyList.iterator());
when(standStorageMock.readAll()).thenReturn(Collections.<EntityRecord>emptyIterator());
when(standStorageMock.readMultiple(ArgumentMatchers.<AggregateStateId>anyIterable())).thenReturn(nonEmptyList.iterator());
when(standStorageMock.readMultiple(ArgumentMatchers.<AggregateStateId>anyIterable())).thenReturn(nonEmptyList.iterator());
final Stand stand = prepareStandWithAggregateRepo(standStorageMock);
final Query noneOfCustomersQuery = requestFactory.query().byIds(Customer.class, Collections.<Message>emptySet());
final MemoizeQueryResponseObserver responseObserver = new MemoizeQueryResponseObserver();
stand.execute(noneOfCustomersQuery, responseObserver);
verifyObserver(responseObserver);
final List<Any> messageList = checkAndGetMessageList(responseObserver);
assertTrue("Query returned a non-empty response message list " + "though the filter was not set", messageList.isEmpty());
}
use of com.google.protobuf.Any in project core-java by SpineEventEngine.
the class StandShould method entityFilterMatcher.
@SuppressWarnings("OverlyComplexAnonymousInnerClass")
private static ArgumentMatcher<EntityFilters> entityFilterMatcher(final Collection<ProjectId> projectIds) {
// ALL the expected IDs.
return new ArgumentMatcher<EntityFilters>() {
@Override
public boolean matches(EntityFilters argument) {
boolean everyElementPresent = true;
for (EntityId entityId : argument.getIdFilter().getIdsList()) {
final Any idAsAny = entityId.getId();
final Message rawId = unpack(idAsAny);
if (rawId instanceof ProjectId) {
final ProjectId convertedProjectId = (ProjectId) rawId;
everyElementPresent = everyElementPresent && projectIds.contains(convertedProjectId);
} else {
everyElementPresent = false;
}
}
return everyElementPresent;
}
};
}
use of com.google.protobuf.Any in project core-java by SpineEventEngine.
the class RecordStorageShould method write_none_storage_fields_is_none_passed.
@Test
public void write_none_storage_fields_is_none_passed() {
final RecordStorage<I> storage = spy(getStorage());
final I id = newId();
final Any state = pack(Sample.messageOfType(Project.class));
final EntityRecord record = Sample.<EntityRecord, EntityRecord.Builder>builderForType(EntityRecord.class).setState(state).build();
storage.write(id, record);
verify(storage).write(eq(id), withRecordAndNoFields(record));
}
use of com.google.protobuf.Any in project core-java by SpineEventEngine.
the class RecordStorageShould method newStorageRecord.
private EntityRecord newStorageRecord(I id, Message state) {
final Any wrappedState = pack(state);
final EntityRecord record = EntityRecord.newBuilder().setEntityId(pack(id)).setState(wrappedState).setVersion(GivenVersion.withNumber(0)).build();
return record;
}
Aggregations