Search in sources :

Example 36 with TenantId

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

the class TenantRepositoryShould method clear_cache.

@Test
public void clear_cache() {
    final TenantId tenantId = newUuid();
    repository.keep(tenantId);
    repository.clearCache();
    assertFalse(repository.unCache(tenantId));
}
Also used : TenantId(io.spine.core.TenantId) Test(org.junit.Test)

Example 37 with TenantId

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

the class TenantRepositoryShould method un_cache_values.

@Test
public void un_cache_values() {
    final TenantId tenantId = newUuid();
    repository.keep(tenantId);
    assertTrue(repository.unCache(tenantId));
    assertFalse(repository.unCache(tenantId));
}
Also used : TenantId(io.spine.core.TenantId) Test(org.junit.Test)

Example 38 with TenantId

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

the class MultiTenantStandShould method not_allow_reading_aggregate_records_for_another_tenant.

@Test
public void not_allow_reading_aggregate_records_for_another_tenant() {
    final Stand stand = doCheckReadingCustomersById(15);
    final TenantId anotherTenant = newUuid();
    final ActorRequestFactory requestFactory = createRequestFactory(anotherTenant);
    final Query readAllCustomers = requestFactory.query().all(Customer.class);
    final MemoizeQueryResponseObserver responseObserver = new MemoizeQueryResponseObserver();
    stand.execute(readAllCustomers, responseObserver);
    final QueryResponse response = responseObserver.getResponseHandled();
    assertTrue(Responses.isOk(response.getResponse()));
    assertEquals(0, response.getMessagesCount());
}
Also used : TenantId(io.spine.core.TenantId) Query(io.spine.client.Query) QueryResponse(io.spine.client.QueryResponse) ActorRequestFactory(io.spine.client.ActorRequestFactory) Test(org.junit.Test)

Example 39 with TenantId

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

the class MultiTenantStandShould method not_trigger_updates_of_aggregate_records_for_another_tenant_subscriptions.

@Test
public void not_trigger_updates_of_aggregate_records_for_another_tenant_subscriptions() {
    final StandStorage standStorage = InMemoryStorageFactory.newInstance(newName(getClass().getSimpleName()), isMultitenant()).createStandStorage();
    final Stand stand = prepareStandWithAggregateRepo(standStorage);
    // --- Default Tenant
    final ActorRequestFactory requestFactory = getRequestFactory();
    final MemoizeEntityUpdateCallback defaultTenantCallback = subscribeToAllOf(stand, requestFactory, Customer.class);
    // --- Another Tenant
    final TenantId anotherTenant = newUuid();
    final ActorRequestFactory anotherFactory = createRequestFactory(anotherTenant);
    final MemoizeEntityUpdateCallback anotherCallback = subscribeToAllOf(stand, anotherFactory, Customer.class);
    // Trigger updates in Default Tenant.
    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);
    // Verify that Default Tenant callback has got the update.
    assertEquals(packedState, defaultTenantCallback.getNewEntityState());
    // And Another Tenant callback has not been called.
    assertEquals(null, anotherCallback.getNewEntityState());
}
Also used : TenantId(io.spine.core.TenantId) Customer(io.spine.test.commandservice.customer.Customer) GivenVersion(io.spine.core.given.GivenVersion) Version(io.spine.core.Version) ActorRequestFactory(io.spine.client.ActorRequestFactory) CustomerId(io.spine.test.commandservice.customer.CustomerId) Map(java.util.Map) Any(com.google.protobuf.Any) Test(org.junit.Test)

Example 40 with TenantId

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

the class EntityMessageEndpoint method handle.

/**
 * Handles the message processing.
 *
 * @return the result of the message processing
 */
public final R handle() {
    final TenantId tenantId = envelope().getTenantId();
    final TenantAwareFunction0<R> operation = new Operation(tenantId);
    final R result = operation.execute();
    return result;
}
Also used : TenantId(io.spine.core.TenantId)

Aggregations

TenantId (io.spine.core.TenantId)41 Test (org.junit.Test)27 Command (io.spine.core.Command)17 Ack (io.spine.core.Ack)11 Event (io.spine.core.Event)6 AggregateMessageDispatcher.dispatchCommand (io.spine.server.aggregate.AggregateMessageDispatcher.dispatchCommand)6 AggregateTestEnv.newTenantId (io.spine.server.aggregate.given.aggregate.AggregateTestEnv.newTenantId)6 CommandBus (io.spine.server.commandbus.CommandBus)6 Error (io.spine.base.Error)4 CommandId (io.spine.core.CommandId)4 IdempotencyGuardTestEnv.newProjectId (io.spine.server.aggregate.given.IdempotencyGuardTestEnv.newProjectId)4 IdempotencyGuardTestEnv.newTenantId (io.spine.server.aggregate.given.IdempotencyGuardTestEnv.newTenantId)4 IgTestAggregate (io.spine.server.aggregate.given.aggregate.IgTestAggregate)4 Nullable (javax.annotation.Nullable)4 ActorContext (io.spine.core.ActorContext)3 CommandContext (io.spine.core.CommandContext)3 Rejection (io.spine.core.Rejection)3 BoundedContext (io.spine.server.BoundedContext)3 AggregateMessageDispatcher.dispatchRejection (io.spine.server.aggregate.AggregateMessageDispatcher.dispatchRejection)3 AggregateTestEnv.newTaskBoundedContext (io.spine.server.aggregate.given.aggregate.AggregateTestEnv.newTaskBoundedContext)3