Search in sources :

Example 36 with Any

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));
    }
}
Also used : Customer(io.spine.test.commandservice.customer.Customer) CustomerId(io.spine.test.commandservice.customer.CustomerId) Any(com.google.protobuf.Any) Target(io.spine.client.Target) GivenVersion(io.spine.core.given.GivenVersion) Version(io.spine.core.Version) EntityStateUpdate(io.spine.client.EntityStateUpdate) Map(java.util.Map) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) Test(org.junit.Test) TenantAwareTest(io.spine.server.tenant.TenantAwareTest)

Example 37 with Any

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());
}
Also used : EntityRecord(io.spine.server.entity.EntityRecord) Query(io.spine.client.Query) TypeUrl(io.spine.type.TypeUrl) Any(com.google.protobuf.Any) Test(org.junit.Test) TenantAwareTest(io.spine.server.tenant.TenantAwareTest)

Example 38 with Any

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;
        }
    };
}
Also used : EntityId(io.spine.client.EntityId) Message(com.google.protobuf.Message) ArgumentMatcher(org.mockito.ArgumentMatcher) EntityFilters(io.spine.client.EntityFilters) ProjectId(io.spine.test.projection.ProjectId) Any(com.google.protobuf.Any)

Example 39 with Any

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));
}
Also used : EntityRecord(io.spine.server.entity.EntityRecord) Project(io.spine.test.storage.Project) ProjectVBuilder(io.spine.test.storage.ProjectVBuilder) Any(com.google.protobuf.Any) Test(org.junit.Test)

Example 40 with Any

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;
}
Also used : EntityRecord(io.spine.server.entity.EntityRecord) Any(com.google.protobuf.Any)

Aggregations

Any (com.google.protobuf.Any)212 Test (org.junit.Test)88 Message (com.google.protobuf.Message)45 TypeConverter.toAny (io.spine.protobuf.TypeConverter.toAny)27 EntityRecord (io.spine.server.entity.EntityRecord)24 TypeUrl (io.spine.type.TypeUrl)15 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)11 Version (io.spine.core.Version)11 Customer (io.spine.test.commandservice.customer.Customer)11 Truth.assertWithMessage (com.google.common.truth.Truth.assertWithMessage)10 CdsUpdate (io.grpc.xds.XdsClient.CdsUpdate)9 GivenVersion (io.spine.core.given.GivenVersion)9 EntityRecordWithColumns (io.spine.server.entity.storage.EntityRecordWithColumns)8 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)8 CustomerId (io.spine.test.commandservice.customer.CustomerId)8 Query (io.spine.client.Query)7 Project (io.spine.test.storage.Project)7 FieldMask (com.google.protobuf.FieldMask)6 LbEndpoint (io.grpc.xds.Endpoints.LbEndpoint)6 EntityId (io.spine.client.EntityId)6