Search in sources :

Example 16 with RequestContext

use of org.hypertrace.core.grpcutils.context.RequestContext in project entity-service by hypertrace.

the class EntityTypeCachingClientTest method supportsMultipleConcurrentCacheKeys.

@Test
void supportsMultipleConcurrentCacheKeys() throws Exception {
    EntityType defaultRetrieved = this.grpcTestContext.call(() -> this.typeClient.get("first").blockingGet());
    assertSame(this.type1, defaultRetrieved);
    verify(this.mockTypeService, times(1)).queryEntityTypes(any(), any());
    RequestContext otherMockContext = mock(RequestContext.class);
    when(otherMockContext.getTenantId()).thenReturn(Optional.of("other tenant"));
    Context otherGrpcContext = Context.current().withValue(RequestContext.CURRENT, otherMockContext);
    EntityType otherContextType = EntityType.newBuilder(this.type1).build();
    this.responseTypes = List.of(otherContextType);
    EntityType otherRetrieved = otherGrpcContext.call(() -> this.typeClient.get("first").blockingGet());
    assertSame(otherContextType, otherRetrieved);
    assertNotSame(defaultRetrieved, otherRetrieved);
    verify(this.mockTypeService, times(2)).queryEntityTypes(any(), any());
    verifyNoMoreInteractions(this.mockTypeService);
    assertSame(defaultRetrieved, this.grpcTestContext.call(() -> this.typeClient.get("first").blockingGet()));
    assertSame(otherRetrieved, otherGrpcContext.call(() -> this.typeClient.get("first").blockingGet()));
}
Also used : EntityType(org.hypertrace.entity.type.service.v2.EntityType) RequestContext(org.hypertrace.core.grpcutils.context.RequestContext) Context(io.grpc.Context) RequestContext(org.hypertrace.core.grpcutils.context.RequestContext) Test(org.junit.jupiter.api.Test)

Example 17 with RequestContext

use of org.hypertrace.core.grpcutils.context.RequestContext in project entity-service by hypertrace.

the class EntityTypeCachingClientTest method hasConfigurableCacheSize.

@Test
void hasConfigurableCacheSize() throws Exception {
    this.typeClient = EntityTypeClient.builder(this.grpcChannel).withMaximumCacheContexts(1).build();
    RequestContext otherMockContext = mock(RequestContext.class);
    when(otherMockContext.getTenantId()).thenReturn(Optional.of("other tenant"));
    this.grpcTestContext.call(() -> this.typeClient.get("first").blockingGet());
    // This call should evict the original call
    Context.current().withValue(RequestContext.CURRENT, otherMockContext).call(() -> this.typeClient.get("first").blockingGet());
    // Rerunning this call now fire again, a third server call
    this.grpcTestContext.call(() -> this.typeClient.get("first").blockingGet());
    verify(this.mockTypeService, times(3)).queryEntityTypes(any(), any());
}
Also used : RequestContext(org.hypertrace.core.grpcutils.context.RequestContext) Test(org.junit.jupiter.api.Test)

Aggregations

RequestContext (org.hypertrace.core.grpcutils.context.RequestContext)17 Test (org.junit.jupiter.api.Test)9 Entity (org.hypertrace.entity.data.service.v1.Entity)8 ServiceException (com.google.protobuf.ServiceException)6 Document (org.hypertrace.core.documentstore.Document)5 JSONDocument (org.hypertrace.core.documentstore.JSONDocument)5 Optional (java.util.Optional)4 Query (org.hypertrace.entity.data.service.v1.Query)4 ConversionException (org.hypertrace.entity.query.service.converter.ConversionException)4 ColumnIdentifier (org.hypertrace.entity.query.service.v1.ColumnIdentifier)4 EntityQueryRequest (org.hypertrace.entity.query.service.v1.EntityQueryRequest)4 StreamObserver (io.grpc.stub.StreamObserver)3 List (java.util.List)3 Map (java.util.Map)3 Objects.isNull (java.util.Objects.isNull)3 Collectors (java.util.stream.Collectors)3 Collection (org.hypertrace.core.documentstore.Collection)3 IdentifierExpression (org.hypertrace.core.documentstore.expression.impl.IdentifierExpression)3 EntityUpdateInfo (org.hypertrace.entity.query.service.v1.BulkEntityUpdateRequest.EntityUpdateInfo)3 Expression (org.hypertrace.entity.query.service.v1.Expression)3