Search in sources :

Example 16 with Version

use of io.spine.core.Version 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 17 with Version

use of io.spine.core.Version in project core-java by SpineEventEngine.

the class StandShould method do_not_trigger_subscription_callbacks_in_case_of_another_type_criterion_mismatch.

@Test
public void do_not_trigger_subscription_callbacks_in_case_of_another_type_criterion_mismatch() {
    final Stand stand = prepareStandWithAggregateRepo(mock(StandStorage.class));
    final Target allProjects = Targets.allOf(Project.class);
    final MemoizeEntityUpdateCallback callback = subscribeWithCallback(stand, allProjects);
    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));
    verify(callback, never()).onStateChanged(any(EntityStateUpdate.class));
}
Also used : Target(io.spine.client.Target) Customer(io.spine.test.commandservice.customer.Customer) GivenVersion(io.spine.core.given.GivenVersion) Version(io.spine.core.Version) EntityStateUpdate(io.spine.client.EntityStateUpdate) CustomerId(io.spine.test.commandservice.customer.CustomerId) Map(java.util.Map) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) Test(org.junit.Test) TenantAwareTest(io.spine.server.tenant.TenantAwareTest)

Example 18 with Version

use of io.spine.core.Version in project core-java by SpineEventEngine.

the class RecordStorageShould method filter_records_by_columns.

// Complex test case (still tests a single operation)
@SuppressWarnings("OverlyLongMethod")
@Test
public void filter_records_by_columns() {
    final Project.Status requiredValue = DONE;
    final Int32Value wrappedValue = Int32Value.newBuilder().setValue(requiredValue.getNumber()).build();
    final Version versionValue = Version.newBuilder().setNumber(// Value of the counter after one columns
    2).build();
    final ColumnFilter status = eq("projectStatusValue", wrappedValue);
    final ColumnFilter version = eq("counterVersion", versionValue);
    final CompositeColumnFilter aggregatingFilter = CompositeColumnFilter.newBuilder().setOperator(ALL).addFilter(status).addFilter(version).build();
    final EntityFilters filters = EntityFilters.newBuilder().addFilter(aggregatingFilter).build();
    final RecordStorage<I> storage = getStorage();
    final EntityQuery<I> query = EntityQueries.from(filters, storage);
    final I idMatching = newId();
    final I idWrong1 = newId();
    final I idWrong2 = newId();
    final TestCounterEntity<I> matchingEntity = new TestCounterEntity<>(idMatching);
    final TestCounterEntity<I> wrongEntity1 = new TestCounterEntity<>(idWrong1);
    final TestCounterEntity<I> wrongEntity2 = new TestCounterEntity<>(idWrong2);
    // 2 of 3 have required values
    matchingEntity.setStatus(requiredValue);
    wrongEntity1.setStatus(requiredValue);
    wrongEntity2.setStatus(CANCELLED);
    // Change internal Entity state
    wrongEntity1.getCounter();
    // After the mutation above the single matching record is the one under the `idMatching` ID
    final EntityRecord fineRecord = newStorageRecord(idMatching, newState(idMatching));
    final EntityRecord notFineRecord1 = newStorageRecord(idWrong1, newState(idWrong1));
    final EntityRecord notFineRecord2 = newStorageRecord(idWrong2, newState(idWrong2));
    final EntityRecordWithColumns recordRight = create(fineRecord, matchingEntity, storage);
    final EntityRecordWithColumns recordWrong1 = create(notFineRecord1, wrongEntity1, storage);
    final EntityRecordWithColumns recordWrong2 = create(notFineRecord2, wrongEntity2, storage);
    storage.write(idMatching, recordRight);
    storage.write(idWrong1, recordWrong1);
    storage.write(idWrong2, recordWrong2);
    final Iterator<EntityRecord> readRecords = storage.readAll(query, FieldMask.getDefaultInstance());
    assertSingleRecord(fineRecord, readRecords);
}
Also used : CompositeColumnFilter(io.spine.client.CompositeColumnFilter) EntityFilters(io.spine.client.EntityFilters) CompositeColumnFilter(io.spine.client.CompositeColumnFilter) ColumnFilter(io.spine.client.ColumnFilter) EntityRecordWithColumns(io.spine.server.entity.storage.EntityRecordWithColumns) EntityRecord(io.spine.server.entity.EntityRecord) Project(io.spine.test.storage.Project) GivenVersion(io.spine.core.given.GivenVersion) Version(io.spine.core.Version) Int32Value(com.google.protobuf.Int32Value) Test(org.junit.Test)

Example 19 with Version

use of io.spine.core.Version in project core-java by SpineEventEngine.

the class GivenVersionShould method generate_version_by_number.

@Test
public void generate_version_by_number() {
    final int number = random(100);
    final Version version = GivenVersion.withNumber(number);
    assertEquals(number, version.getNumber());
}
Also used : Version(io.spine.core.Version) Test(org.junit.Test)

Example 20 with Version

use of io.spine.core.Version in project core-java by SpineEventEngine.

the class EntityShould method have_state.

@Test
public void have_state() {
    final Version ver = Versions.newVersion(3, getCurrentTime());
    entityNew.updateState(state, ver);
    assertEquals(state, entityNew.getState());
    assertEquals(ver, entityNew.getVersion());
}
Also used : Version(io.spine.core.Version) Test(org.junit.Test)

Aggregations

Version (io.spine.core.Version)41 Test (org.junit.Test)33 GivenVersion (io.spine.core.given.GivenVersion)16 Customer (io.spine.test.commandservice.customer.Customer)13 Any (com.google.protobuf.Any)11 Versions.newVersion (io.spine.core.Versions.newVersion)11 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)11 Event (io.spine.core.Event)10 CustomerId (io.spine.test.commandservice.customer.CustomerId)10 Map (java.util.Map)7 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)6 Query (io.spine.client.Query)5 Topic (io.spine.client.Topic)5 QueryResponse (io.spine.client.QueryResponse)4 ProjectId (io.spine.test.projection.ProjectId)4 Message (com.google.protobuf.Message)3 Timestamp (com.google.protobuf.Timestamp)3 EntityStateUpdate (io.spine.client.EntityStateUpdate)3 EntityRecord (io.spine.server.entity.EntityRecord)3 Project (io.spine.test.aggregate.Project)3