use of com.google.cloud.videointelligence.v1p2beta1.Entity in project entity-service by hypertrace.
the class EntityQueryServiceTest method testBulkUpdateWithLabels.
@Test
public void testBulkUpdateWithLabels() {
Entity.Builder apiEntityBuilder2 = Entity.newBuilder().setTenantId(TENANT_ID).setEntityType(EntityType.API.name()).setEntityName("api2").putIdentifyingAttributes(EntityConstants.getValue(ServiceAttribute.SERVICE_ATTRIBUTE_ID), createAttribute(SERVICE_ID)).putIdentifyingAttributes(EntityConstants.getValue(ApiAttribute.API_ATTRIBUTE_NAME), createAttribute("api2")).putIdentifyingAttributes(EntityConstants.getValue(ApiAttribute.API_ATTRIBUTE_API_TYPE), createAttribute(API_TYPE));
apiEntityBuilder2.putAttributes(apiAttributesMap.get(API_LABELS_ATTR), createStringArrayAttribute(List.of("Label1")));
Entity entity2 = entityDataServiceClient.upsert(apiEntityBuilder2.build());
UpdateOperation update = UpdateOperation.newBuilder().setSetAttribute(SetAttribute.newBuilder().setAttribute(ColumnIdentifier.newBuilder().setColumnName(API_LABELS_ATTR)).setValue(LiteralConstant.newBuilder().setValue(org.hypertrace.entity.query.service.v1.Value.newBuilder().addAllStringArray(Collections.emptyList()).setValueType(STRING_ARRAY)))).build();
EntityUpdateInfo updateInfo = EntityUpdateInfo.newBuilder().addUpdateOperation(update).build();
BulkEntityUpdateRequest bulkUpdateRequest = BulkEntityUpdateRequest.newBuilder().setEntityType(EntityType.API.name()).putEntities(entity2.getEntityId(), updateInfo).build();
assertDoesNotThrow(() -> GrpcClientRequestContextUtil.executeWithHeadersContext(HEADERS, () -> entityQueryServiceClient.bulkUpdate(bulkUpdateRequest)));
}
use of com.google.cloud.videointelligence.v1p2beta1.Entity in project entity-service by hypertrace.
the class UpsertConditionMatcherTest method handlesMissingValues.
@Test
void handlesMissingValues() {
Entity entity = entity(Map.of());
assertFalse(matcher.matches(entity, condition("key1", PREDICATE_OPERATOR_EQUALS, string("foo"))));
assertTrue(matcher.matches(entity, condition("key1", PREDICATE_OPERATOR_NOT_EQUALS, string("foo"))));
// Throws for comparisons
assertThrows(IllegalArgumentException.class, () -> matcher.matches(entity, condition("key1", PREDICATE_OPERATOR_LESS_THAN, integerValue(10))));
assertThrows(IllegalArgumentException.class, () -> matcher.matches(entity, condition("key1", PREDICATE_OPERATOR_GREATER_THAN, integerValue(10))));
}
use of com.google.cloud.videointelligence.v1p2beta1.Entity in project entity-service by hypertrace.
the class UpsertConditionMatcherTest method throwsIfUnknownOperator.
@Test
void throwsIfUnknownOperator() {
Entity entity = entity(Map.of("key1", string("foo")));
assertThrows(IllegalArgumentException.class, () -> matcher.matches(entity, condition("key1", PREDICATE_OPERATOR_UNSPECIFIED, string("foo"))));
}
use of com.google.cloud.videointelligence.v1p2beta1.Entity in project entity-service by hypertrace.
the class EntityQueryServiceImplTest method testExecute_success_chunksize_2.
@Test
public void testExecute_success_chunksize_2() throws Exception {
Collection mockEntitiesCollection = mock(Collection.class);
Entity entity1 = Entity.newBuilder().setTenantId("tenant-1").setEntityType(TEST_ENTITY_TYPE).setEntityId(UUID.randomUUID().toString()).setEntityName("Test entity 1").putAttributes(EDS_COLUMN_NAME1, AttributeValue.newBuilder().setValue(org.hypertrace.entity.data.service.v1.Value.newBuilder().setString("foo1")).build()).build();
Entity entity2 = Entity.newBuilder().setTenantId("tenant-1").setEntityType(TEST_ENTITY_TYPE).setEntityId(UUID.randomUUID().toString()).setEntityName("Test entity 2").putAttributes(EDS_COLUMN_NAME1, AttributeValue.newBuilder().setValue(org.hypertrace.entity.data.service.v1.Value.newBuilder().setString("foo2")).build()).build();
Entity entity3 = Entity.newBuilder().setTenantId("tenant-1").setEntityType(TEST_ENTITY_TYPE).setEntityId(UUID.randomUUID().toString()).setEntityName("Test entity 3").putAttributes(EDS_COLUMN_NAME1, AttributeValue.newBuilder().setValue(org.hypertrace.entity.data.service.v1.Value.newBuilder().setString("foo2")).build()).build();
List<Document> docs = List.of(new JSONDocument(JsonFormat.printer().print(entity1)), new JSONDocument(JsonFormat.printer().print(entity2)), new JSONDocument(JsonFormat.printer().print(entity3)), // this doc will result in parsing error
new JSONDocument("{\"entityId\": [1, 2]}"));
when(mockEntitiesCollection.aggregate(any())).thenReturn(convertToCloseableIterator(docs.iterator()));
when(mockEntitiesCollection.search(any())).thenReturn(convertToCloseableIterator(docs.iterator()));
EntityQueryRequest request = EntityQueryRequest.newBuilder().setEntityType(TEST_ENTITY_TYPE).addOrderBy(OrderByExpression.newBuilder().setExpression(Expression.newBuilder().setColumnIdentifier(ColumnIdentifier.newBuilder().setColumnName(ATTRIBUTE_ID1).build()))).build();
StreamObserver<ResultSetChunk> mockResponseObserver = mock(StreamObserver.class);
Context.current().withValue(RequestContext.CURRENT, mockRequestContextWithTenantId()).call(() -> {
EntityQueryServiceImpl eqs = new EntityQueryServiceImpl(mockEntitiesCollection, mockMappingForAttributes1And2(), 2, false);
eqs.execute(request, mockResponseObserver);
return null;
});
verify(mockEntitiesCollection, times(0)).aggregate(any());
verify(mockEntitiesCollection, times(1)).search(any());
verify(mockResponseObserver, times(2)).onNext(any());
verify(mockResponseObserver, times(1)).onCompleted();
}
use of com.google.cloud.videointelligence.v1p2beta1.Entity in project entity-service by hypertrace.
the class EntityQueryServiceImplTest method testExecute_success.
@Test
public void testExecute_success() throws Exception {
Collection mockEntitiesCollection = mock(Collection.class);
Entity entity1 = Entity.newBuilder().setTenantId("tenant-1").setEntityType(TEST_ENTITY_TYPE).setEntityId(UUID.randomUUID().toString()).setEntityName("Test entity 1").putAttributes(EDS_COLUMN_NAME1, AttributeValue.newBuilder().setValue(org.hypertrace.entity.data.service.v1.Value.newBuilder().setString("foo1")).build()).build();
Entity entity2 = Entity.newBuilder().setTenantId("tenant-1").setEntityType(TEST_ENTITY_TYPE).setEntityId(UUID.randomUUID().toString()).setEntityName("Test entity 2").putAttributes(EDS_COLUMN_NAME1, AttributeValue.newBuilder().setValue(org.hypertrace.entity.data.service.v1.Value.newBuilder().setString("foo2")).build()).build();
List<Document> docs = List.of(new JSONDocument(JsonFormat.printer().print(entity1)), new JSONDocument(JsonFormat.printer().print(entity2)), // this doc will result in parsing error
new JSONDocument("{\"entityId\": [1, 2]}"));
when(mockEntitiesCollection.aggregate(any())).thenReturn(convertToCloseableIterator(docs.iterator()));
when(mockEntitiesCollection.search(any())).thenReturn(convertToCloseableIterator(docs.iterator()));
EntityQueryRequest request = EntityQueryRequest.newBuilder().setEntityType(TEST_ENTITY_TYPE).addOrderBy(OrderByExpression.newBuilder().setExpression(Expression.newBuilder().setColumnIdentifier(ColumnIdentifier.newBuilder().setColumnName(ATTRIBUTE_ID1).build()))).build();
StreamObserver<ResultSetChunk> mockResponseObserver = mock(StreamObserver.class);
Context.current().withValue(RequestContext.CURRENT, mockRequestContextWithTenantId()).call(() -> {
EntityQueryServiceImpl eqs = new EntityQueryServiceImpl(mockEntitiesCollection, mockMappingForAttributes1And2(), 1, false);
eqs.execute(request, mockResponseObserver);
return null;
});
verify(mockEntitiesCollection, times(0)).aggregate(any());
verify(mockEntitiesCollection, times(1)).search(any());
verify(mockResponseObserver, times(3)).onNext(any());
verify(mockResponseObserver, times(1)).onCompleted();
}
Aggregations