Search in sources :

Example 6 with Entity

use of com.google.cloud.videointelligence.v1p2beta1.Entity in project entity-service by hypertrace.

the class EntityDataServiceTest method testUpdateEntityWithPredicateViaUpsertAndMerge.

@Test
public void testUpdateEntityWithPredicateViaUpsertAndMerge() {
    // Scope this test to its own tenant for isolation
    String TENANT_ID = EntityDataServiceTest.TENANT_ID + "testUpdateEntityWithPredicateViaUpsertAndMerge";
    EntityDataServiceBlockingStub entityDataServiceStub = buildStubForTenant(TENANT_ID);
    setupEntityTypes(channel, TENANT_ID);
    Map<String, AttributeValue> createAttributes = Map.of("some-attr", stringValue("v1"));
    Map<String, AttributeValue> updateAttributes = Map.of("some-attr", stringValue("v2"));
    // Expect create and the first update to succeed, the second to fail
    UpsertCondition condition = UpsertCondition.newBuilder().setPropertyPredicate(Predicate.newBuilder().setAttributeKey("some-attr").setOperator(PredicateOperator.PREDICATE_OPERATOR_EQUALS).setValue(stringValue("v1"))).build();
    // V1 entity
    Entity entityToCreate = Entity.newBuilder().setTenantId(TENANT_ID).setEntityType(EntityType.K8S_POD.name()).setEntityName("V1 UPDATE PREDICATE POD").putIdentifyingAttributes(EntityConstants.getValue(CommonAttribute.COMMON_ATTRIBUTE_EXTERNAL_ID), generateRandomUUIDAttrValue()).putAllAttributes(createAttributes).build();
    // Successful create
    Entity createdEntity = entityDataServiceStub.mergeAndUpsertEntity(MergeAndUpsertEntityRequest.newBuilder().setEntity(entityToCreate).setUpsertCondition(condition).build()).getEntity();
    assertEquals(stringValue("v1"), createdEntity.getAttributesMap().get("some-attr"));
    Entity entityUpdate = entityToCreate.toBuilder().putAllAttributes(updateAttributes).build();
    Entity updatedEntity = entityDataServiceStub.mergeAndUpsertEntity(MergeAndUpsertEntityRequest.newBuilder().setEntity(entityUpdate).setUpsertCondition(condition).build()).getEntity();
    // Successful update
    assertEquals(stringValue("v2"), updatedEntity.getAttributesMap().get("some-attr"));
    Entity secondEntityUpdate = entityToCreate.toBuilder().putAttributes("some-new-attr", stringValue("foo")).build();
    Entity secondUpdatedEntity = entityDataServiceStub.mergeAndUpsertEntity(MergeAndUpsertEntityRequest.newBuilder().setEntity(secondEntityUpdate).setUpsertCondition(condition).build()).getEntity();
    // No change, update rejected
    assertFalse(secondUpdatedEntity.getAttributesMap().containsKey("some-new-attr"));
    assertEquals(stringValue("v2"), secondUpdatedEntity.getAttributesMap().get("some-attr"));
    // V2 Entity
    entityToCreate = Entity.newBuilder().setTenantId(TENANT_ID).setEntityId(UUID.randomUUID().toString()).setEntityType(TEST_ENTITY_TYPE_V2).setEntityName("V2 entity predicate update").putAllAttributes(createAttributes).build();
    // Successful create
    createdEntity = entityDataServiceStub.mergeAndUpsertEntity(MergeAndUpsertEntityRequest.newBuilder().setEntity(entityToCreate).setUpsertCondition(condition).build()).getEntity();
    assertEquals(stringValue("v1"), createdEntity.getAttributesMap().get("some-attr"));
    entityUpdate = entityToCreate.toBuilder().putAllAttributes(updateAttributes).build();
    updatedEntity = entityDataServiceStub.mergeAndUpsertEntity(MergeAndUpsertEntityRequest.newBuilder().setEntity(entityUpdate).setUpsertCondition(condition).build()).getEntity();
    // Successful update
    assertEquals(stringValue("v2"), updatedEntity.getAttributesMap().get("some-attr"));
    secondEntityUpdate = entityToCreate.toBuilder().putAttributes("some-new-attr", stringValue("foo")).build();
    secondUpdatedEntity = entityDataServiceStub.mergeAndUpsertEntity(MergeAndUpsertEntityRequest.newBuilder().setEntity(secondEntityUpdate).setUpsertCondition(condition).build()).getEntity();
    // No change, update rejected
    assertFalse(secondUpdatedEntity.getAttributesMap().containsKey("some-new-attr"));
    assertEquals(stringValue("v2"), secondUpdatedEntity.getAttributesMap().get("some-attr"));
}
Also used : EnrichedEntity(org.hypertrace.entity.data.service.v1.EnrichedEntity) Entity(org.hypertrace.entity.data.service.v1.Entity) AttributeValue(org.hypertrace.entity.data.service.v1.AttributeValue) UpsertCondition(org.hypertrace.entity.data.service.v1.MergeAndUpsertEntityRequest.UpsertCondition) EntityDataServiceBlockingStub(org.hypertrace.entity.data.service.v1.EntityDataServiceGrpc.EntityDataServiceBlockingStub) Test(org.junit.jupiter.api.Test)

Example 7 with Entity

use of com.google.cloud.videointelligence.v1p2beta1.Entity in project entity-service by hypertrace.

the class EntityDataServiceTest method testEntityQueryOrderBy.

@Test
public void testEntityQueryOrderBy() {
    Entity entity1 = Entity.newBuilder().setTenantId(TENANT_ID).setEntityType(EntityType.K8S_POD.name()).setEntityName("Some Service 1").putIdentifyingAttributes(EntityConstants.getValue(CommonAttribute.COMMON_ATTRIBUTE_EXTERNAL_ID), generateRandomUUIDAttrValue()).putAttributes("foo", AttributeValue.newBuilder().setValue(Value.newBuilder().setInt(5).build()).build()).build();
    Entity createdEntity1 = entityDataServiceClient.upsert(entity1);
    assertNotNull(createdEntity1);
    assertNotNull(createdEntity1.getEntityId().trim());
    Entity entity2 = Entity.newBuilder().setTenantId(TENANT_ID).setEntityType(EntityType.K8S_POD.name()).setEntityName("Some Service 2").putIdentifyingAttributes(EntityConstants.getValue(CommonAttribute.COMMON_ATTRIBUTE_EXTERNAL_ID), generateRandomUUIDAttrValue()).putAttributes("foo", AttributeValue.newBuilder().setValue(Value.newBuilder().setInt(10).build()).build()).build();
    Entity createdEntity2 = entityDataServiceClient.upsert(entity2);
    assertNotNull(createdEntity2);
    assertNotNull(createdEntity2.getEntityId().trim());
    // Query by field name
    Query entityNameQuery = Query.newBuilder().setEntityType(EntityType.K8S_POD.name()).addOrderBy(OrderByExpression.newBuilder().setOrder(SortOrder.DESC).setName("entityName").build()).build();
    List<Entity> entitiesList = entityDataServiceClient.query(TENANT_ID, entityNameQuery);
    assertTrue(entitiesList.size() > 1);
    assertTrue(entitiesList.contains(createdEntity1) && entitiesList.contains(createdEntity2));
    // ordered such that entity with "larger" entity name value is listed earlier
    assertTrue(entitiesList.indexOf(createdEntity2) < entitiesList.indexOf(createdEntity1));
    // Query by attribute
    Query attributeQuery = Query.newBuilder().setEntityType(EntityType.K8S_POD.name()).addOrderBy(OrderByExpression.newBuilder().setOrder(SortOrder.DESC).setName("attributes.foo").build()).build();
    entitiesList = entityDataServiceClient.query(TENANT_ID, attributeQuery);
    assertTrue(entitiesList.size() > 1);
    assertTrue(entitiesList.contains(createdEntity1) && entitiesList.contains(createdEntity2));
    // ordered such that entity with "larger" attributes value is listed earlier
    assertTrue(entitiesList.indexOf(createdEntity2) < entitiesList.indexOf(createdEntity1));
}
Also used : EnrichedEntity(org.hypertrace.entity.data.service.v1.EnrichedEntity) Entity(org.hypertrace.entity.data.service.v1.Entity) Query(org.hypertrace.entity.data.service.v1.Query) Test(org.junit.jupiter.api.Test)

Example 8 with Entity

use of com.google.cloud.videointelligence.v1p2beta1.Entity in project entity-service by hypertrace.

the class EntityDataServiceTest method testEntityNonAttributeQuery.

@Test
public void testEntityNonAttributeQuery() {
    Entity entity1 = Entity.newBuilder().setTenantId(TENANT_ID).setEntityType(EntityType.K8S_POD.name()).setEntityName("Some Service 1").putIdentifyingAttributes(EntityConstants.getValue(CommonAttribute.COMMON_ATTRIBUTE_EXTERNAL_ID), generateRandomUUIDAttrValue()).build();
    Entity createdEntity1 = entityDataServiceClient.upsert(entity1);
    assertNotNull(createdEntity1);
    assertFalse(createdEntity1.getEntityId().trim().isEmpty());
    Entity entity2 = Entity.newBuilder().setTenantId(TENANT_ID).setEntityType(EntityType.K8S_POD.name()).setEntityName("Some Service 2").putIdentifyingAttributes(EntityConstants.getValue(CommonAttribute.COMMON_ATTRIBUTE_EXTERNAL_ID), generateRandomUUIDAttrValue()).build();
    Entity createdEntity2 = entityDataServiceClient.upsert(entity2);
    assertNotNull(createdEntity2);
    assertFalse(createdEntity2.getEntityId().trim().isEmpty());
    long afterCreatedTime = Instant.now().toEpochMilli();
    Query createTimeQuery = Query.newBuilder().setEntityType(EntityType.K8S_POD.name()).setFilter(AttributeFilter.newBuilder().setOperator(Operator.LT).setName("createdTime").setAttributeValue(AttributeValue.newBuilder().setValue(Value.newBuilder().setLong(afterCreatedTime).build())).build()).build();
    // Query all entities that created time is less than now
    List<Entity> entitiesList = entityDataServiceClient.query(TENANT_ID, createTimeQuery);
    assertTrue(entitiesList.size() > 1);
}
Also used : EnrichedEntity(org.hypertrace.entity.data.service.v1.EnrichedEntity) Entity(org.hypertrace.entity.data.service.v1.Entity) Query(org.hypertrace.entity.data.service.v1.Query) Test(org.junit.jupiter.api.Test)

Example 9 with Entity

use of com.google.cloud.videointelligence.v1p2beta1.Entity in project entity-service by hypertrace.

the class EntityDataServiceTest method testCreateEntityViaUpsertAndMerge.

@Test
public void testCreateEntityViaUpsertAndMerge() {
    // Scope this test to its own tenant for isolation
    String tenantId = EntityDataServiceTest.TENANT_ID + "_testCreateEntityViaUpsertAndMerge";
    EntityDataServiceBlockingStub entityDataServiceStub = buildStubForTenant(tenantId);
    setupEntityTypes(channel, tenantId);
    // V1 entity
    Entity entityToCreate = Entity.newBuilder().setTenantId(tenantId).setEntityType(EntityType.K8S_POD.name()).setEntityName("V1 POD").putIdentifyingAttributes(EntityConstants.getValue(CommonAttribute.COMMON_ATTRIBUTE_EXTERNAL_ID), generateRandomUUIDAttrValue()).build();
    Entity createdEntity = entityDataServiceStub.mergeAndUpsertEntity(MergeAndUpsertEntityRequest.newBuilder().setEntity(entityToCreate).build()).getEntity();
    Entity fetchedEntity = entityDataServiceStub.getById(ByIdRequest.newBuilder().setEntityId(createdEntity.getEntityId()).setEntityType(createdEntity.getEntityType()).build());
    assertEntityEquals(createdEntity, fetchedEntity);
    // V2 Entity
    entityToCreate = Entity.newBuilder().setTenantId(tenantId).setEntityId(UUID.randomUUID().toString()).setEntityType(TEST_ENTITY_TYPE_V2).setEntityName("V2 entity").build();
    createdEntity = entityDataServiceStub.mergeAndUpsertEntity(MergeAndUpsertEntityRequest.newBuilder().setEntity(entityToCreate).build()).getEntity();
    assertEntityEquals(entityToCreate, createdEntity);
    fetchedEntity = entityDataServiceStub.getById(ByIdRequest.newBuilder().setEntityId(createdEntity.getEntityId()).setEntityType(createdEntity.getEntityType()).build());
    assertEquals(createdEntity, fetchedEntity);
}
Also used : EnrichedEntity(org.hypertrace.entity.data.service.v1.EnrichedEntity) Entity(org.hypertrace.entity.data.service.v1.Entity) EntityDataServiceBlockingStub(org.hypertrace.entity.data.service.v1.EntityDataServiceGrpc.EntityDataServiceBlockingStub) Test(org.junit.jupiter.api.Test)

Example 10 with Entity

use of com.google.cloud.videointelligence.v1p2beta1.Entity in project entity-service by hypertrace.

the class EntityDataServiceTest method upsertAndVerify.

private void upsertAndVerify(Entity entityToCreate) {
    Entity createdEntity = entityDataServiceClient.upsert(entityToCreate);
    assertNotNull(entityToCreate);
    assertNotNull(createdEntity.getEntityId().trim());
    Entity actualBackendEntity = entityDataServiceClient.getById(TENANT_ID, createdEntity.getEntityId());
    assertEquals(createdEntity, actualBackendEntity);
}
Also used : EnrichedEntity(org.hypertrace.entity.data.service.v1.EnrichedEntity) Entity(org.hypertrace.entity.data.service.v1.Entity)

Aggregations

Entity (org.hypertrace.entity.data.service.v1.Entity)110 LivingEntity (org.bukkit.entity.LivingEntity)95 Test (org.junit.jupiter.api.Test)95 SkinnableEntity (net.citizensnpcs.npc.skin.SkinnableEntity)88 net.minecraft.world.entity (net.minecraft.world.entity)40 org.bukkit.entity (org.bukkit.entity)40 Entity (com.google.datastore.v1.Entity)33 ArrayList (java.util.ArrayList)33 Location (org.bukkit.Location)33 EnrichedEntity (org.hypertrace.entity.data.service.v1.EnrichedEntity)32 Event (org.hypertrace.core.datamodel.Event)27 AttributeValue (org.hypertrace.core.datamodel.AttributeValue)22 BackendInfo (org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo)21 Mob (net.minecraft.world.entity.Mob)20 NPCHolder (net.citizensnpcs.npc.ai.NPCHolder)18 Entity (net.minecraft.server.v1_8_R3.Entity)18 AnnotateVideoProgress (com.google.cloud.videointelligence.v1.AnnotateVideoProgress)17 AnnotateVideoRequest (com.google.cloud.videointelligence.v1.AnnotateVideoRequest)17 AnnotateVideoResponse (com.google.cloud.videointelligence.v1.AnnotateVideoResponse)17 Entity (com.google.cloud.videointelligence.v1.Entity)17