Search in sources :

Example 46 with Entity

use of net.minecraft.server.v1_16_R3.Entity in project entity-service by hypertrace.

the class EntityChangeEventGeneratorImplTest method sendDeleteNotification.

@Test
void sendDeleteNotification() {
    List<Entity> entities = createEntities(2);
    changeEventGenerator.sendDeleteNotification(requestContext, entities);
    InOrder inOrderVerifier = inOrder(eventProducer);
    inOrderVerifier.verify(eventProducer).send(KeyUtil.getKey(entities.get(0)), EntityChangeEventValue.newBuilder().setDeleteEvent(EntityDeleteEvent.newBuilder().setDeletedEntity(entities.get(0)).build()).setEventTimeMillis(CURRENT_TIME_MILLIS).build());
    inOrderVerifier.verify(eventProducer).send(KeyUtil.getKey(entities.get(1)), EntityChangeEventValue.newBuilder().setDeleteEvent(EntityDeleteEvent.newBuilder().setDeletedEntity(entities.get(1)).build()).setEventTimeMillis(CURRENT_TIME_MILLIS).build());
}
Also used : Entity(org.hypertrace.entity.data.service.v1.Entity) InOrder(org.mockito.InOrder) Test(org.junit.jupiter.api.Test)

Example 47 with Entity

use of net.minecraft.server.v1_16_R3.Entity in project entity-service by hypertrace.

the class EdsCacheClient method initCache.

private void initCache(EntityServiceClientCacheConfig cacheConfig, Executor executor) {
    this.enrichedEntityCache = CacheBuilder.newBuilder().refreshAfterWrite(cacheConfig.getEnrichedEntityCacheRefreshMs(), TimeUnit.MILLISECONDS).expireAfterWrite(cacheConfig.getEnrichedEntityCacheExpiryMs(), TimeUnit.MILLISECONDS).maximumSize(cacheConfig.getEnrichedEntityMaxCacheSize()).recordStats().build(CacheLoader.asyncReloading(new CacheLoader<>() {

        public EnrichedEntity load(@Nonnull EdsCacheKey key) throws Exception {
            EnrichedEntity enrichedEntity = client.getEnrichedEntityById(key.tenantId, key.entityId);
            if (enrichedEntity == null) {
                throw new NotFoundException("Enriched entity not found");
            }
            return enrichedEntity;
        }
    }, executor));
    this.entityCache = CacheBuilder.newBuilder().refreshAfterWrite(cacheConfig.getEntityCacheRefreshMs(), TimeUnit.MILLISECONDS).expireAfterWrite(cacheConfig.getEntityCacheExpiryMs(), TimeUnit.MILLISECONDS).maximumSize(cacheConfig.getEntityMaxCacheSize()).recordStats().build(CacheLoader.asyncReloading(new CacheLoader<>() {

        public Entity load(@Nonnull EdsCacheKey key) throws Exception {
            Entity entity = client.getById(key.tenantId, key.entityId);
            if (entity == null) {
                throw new NotFoundException("Entity not found");
            }
            return entity;
        }
    }, executor));
    this.entityIdsCache = CacheBuilder.newBuilder().refreshAfterWrite(cacheConfig.getEntityIdsCacheRefreshMs(), TimeUnit.MILLISECONDS).expireAfterWrite(cacheConfig.getEntityIdsCacheExpiryMs(), TimeUnit.MILLISECONDS).maximumSize(cacheConfig.getEntityIdsMaxCacheSize()).recordStats().build(CacheLoader.asyncReloading(new CacheLoader<>() {

        public String load(@Nonnull EdsTypeAndIdAttributesCacheKey key) throws Exception {
            Entity entity = client.getByTypeAndIdentifyingAttributes(key.tenantId, key.byTypeAndIdentifyingAttributes);
            if (entity == null) {
                throw new NotFoundException("Entity not found!!");
            }
            entityCache.put(new EdsCacheKey(entity.getTenantId(), entity.getEntityId()), entity);
            return entity.getEntityId();
        }
    }, executor));
    PlatformMetricsRegistry.registerCache(this.getClass().getName() + ".enrichedEntityCache", enrichedEntityCache, Collections.emptyMap());
    PlatformMetricsRegistry.registerCache(this.getClass().getName() + ".entityCache", entityCache, Collections.emptyMap());
    PlatformMetricsRegistry.registerCache(this.getClass().getName() + ".entityIdsCache", entityIdsCache, Collections.emptyMap());
}
Also used : Entity(org.hypertrace.entity.data.service.v1.Entity) EnrichedEntity(org.hypertrace.entity.data.service.v1.EnrichedEntity) NotFoundException(org.hypertrace.entity.data.service.client.exception.NotFoundException) NotFoundException(org.hypertrace.entity.data.service.client.exception.NotFoundException) ExecutionException(java.util.concurrent.ExecutionException) EnrichedEntity(org.hypertrace.entity.data.service.v1.EnrichedEntity)

Example 48 with Entity

use of net.minecraft.server.v1_16_R3.Entity in project entity-service by hypertrace.

the class EdsCacheClientTest method testGetByTypeAndIdentifyingAttributes.

@Test
public void testGetByTypeAndIdentifyingAttributes() {
    String tenantId = "tenant";
    String entityId = "entity-12345";
    Map<String, AttributeValue> identifyingAttributesMap = new HashMap<>();
    identifyingAttributesMap.put("entity_name", AttributeValue.newBuilder().setValue(Value.newBuilder().setString("GET /products").build()).build());
    identifyingAttributesMap.put("is_active", AttributeValue.newBuilder().setValue(Value.newBuilder().setBoolean(true).build()).build());
    Entity entity = Entity.newBuilder().setTenantId(tenantId).setEntityId(entityId).setEntityType("API").setEntityName("GET /products").putAllIdentifyingAttributes(identifyingAttributesMap).build();
    when(entityDataServiceClient.getById(anyString(), anyString())).thenReturn(entity);
    when(entityDataServiceClient.getByTypeAndIdentifyingAttributes(anyString(), any())).thenReturn(entity);
    ByTypeAndIdentifyingAttributes attributes = ByTypeAndIdentifyingAttributes.newBuilder().setEntityType("API").putAllIdentifyingAttributes(identifyingAttributesMap).build();
    edsCacheClient.getByTypeAndIdentifyingAttributes(tenantId, attributes);
    edsCacheClient.getByTypeAndIdentifyingAttributes(tenantId, attributes);
    verify(entityDataServiceClient, times(1)).getByTypeAndIdentifyingAttributes("tenant", attributes);
    verify(entityDataServiceClient, never()).getById("tenant", "entity-12345");
}
Also used : Entity(org.hypertrace.entity.data.service.v1.Entity) EnrichedEntity(org.hypertrace.entity.data.service.v1.EnrichedEntity) AttributeValue(org.hypertrace.entity.data.service.v1.AttributeValue) ByTypeAndIdentifyingAttributes(org.hypertrace.entity.data.service.v1.ByTypeAndIdentifyingAttributes) HashMap(java.util.HashMap) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 49 with Entity

use of net.minecraft.server.v1_16_R3.Entity in project entity-service by hypertrace.

the class EntityDataServiceClientRetriesTest method testRetryForInternalError.

@Test
public void testRetryForInternalError() {
    doAnswer(invocation -> {
        StreamObserver<Entity> observer = invocation.getArgument(1, StreamObserver.class);
        observer.onError(new RuntimeException(new StatusRuntimeException(Status.INTERNAL)));
        return null;
    }).when(this.mockDataService).getById(any(), any());
    StatusRuntimeException exception = assertThrows(StatusRuntimeException.class, () -> edsClient.getById("__default", "id1"));
    assertEquals(Status.INTERNAL, exception.getStatus());
    verify(this.mockDataService, times(3)).getById(any(), any());
}
Also used : Entity(org.hypertrace.entity.data.service.v1.Entity) StatusRuntimeException(io.grpc.StatusRuntimeException) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.jupiter.api.Test)

Example 50 with Entity

use of net.minecraft.server.v1_16_R3.Entity in project java-video-intelligence by googleapis.

the class TrackObjects method trackObjects.

// [START video_object_tracking_beta]
/**
 * Track objects in a video.
 *
 * @param filePath the path to the video file to analyze.
 */
public static VideoAnnotationResults trackObjects(String filePath) throws Exception {
    try (VideoIntelligenceServiceClient client = VideoIntelligenceServiceClient.create()) {
        // Read file
        Path path = Paths.get(filePath);
        byte[] data = Files.readAllBytes(path);
        // Create the request
        AnnotateVideoRequest request = AnnotateVideoRequest.newBuilder().setInputContent(ByteString.copyFrom(data)).addFeatures(Feature.OBJECT_TRACKING).setLocationId("us-east1").build();
        // asynchronously perform object tracking on videos
        OperationFuture<AnnotateVideoResponse, AnnotateVideoProgress> future = client.annotateVideoAsync(request);
        System.out.println("Waiting for operation to complete...");
        // The first result is retrieved because a single video was processed.
        AnnotateVideoResponse response = future.get(600, TimeUnit.SECONDS);
        VideoAnnotationResults results = response.getAnnotationResults(0);
        // Get only the first annotation for demo purposes.
        ObjectTrackingAnnotation annotation = results.getObjectAnnotations(0);
        System.out.println("Confidence: " + annotation.getConfidence());
        if (annotation.hasEntity()) {
            Entity entity = annotation.getEntity();
            System.out.println("Entity description: " + entity.getDescription());
            System.out.println("Entity id:: " + entity.getEntityId());
        }
        if (annotation.hasSegment()) {
            VideoSegment videoSegment = annotation.getSegment();
            Duration startTimeOffset = videoSegment.getStartTimeOffset();
            Duration endTimeOffset = videoSegment.getEndTimeOffset();
            // Display the segment time in seconds, 1e9 converts nanos to seconds
            System.out.println(String.format("Segment: %.2fs to %.2fs", startTimeOffset.getSeconds() + startTimeOffset.getNanos() / 1e9, endTimeOffset.getSeconds() + endTimeOffset.getNanos() / 1e9));
        }
        // Here we print only the bounding box of the first frame in this segment.
        ObjectTrackingFrame frame = annotation.getFrames(0);
        // Display the offset time in seconds, 1e9 converts nanos to seconds
        Duration timeOffset = frame.getTimeOffset();
        System.out.println(String.format("Time offset of the first frame: %.2fs", timeOffset.getSeconds() + timeOffset.getNanos() / 1e9));
        // Display the bounding box of the detected object
        NormalizedBoundingBox normalizedBoundingBox = frame.getNormalizedBoundingBox();
        System.out.println("Bounding box position:");
        System.out.println("\tleft: " + normalizedBoundingBox.getLeft());
        System.out.println("\ttop: " + normalizedBoundingBox.getTop());
        System.out.println("\tright: " + normalizedBoundingBox.getRight());
        System.out.println("\tbottom: " + normalizedBoundingBox.getBottom());
        return results;
    }
}
Also used : Path(java.nio.file.Path) Entity(com.google.cloud.videointelligence.v1p2beta1.Entity) ObjectTrackingAnnotation(com.google.cloud.videointelligence.v1p2beta1.ObjectTrackingAnnotation) AnnotateVideoRequest(com.google.cloud.videointelligence.v1p2beta1.AnnotateVideoRequest) Duration(com.google.protobuf.Duration) VideoIntelligenceServiceClient(com.google.cloud.videointelligence.v1p2beta1.VideoIntelligenceServiceClient) ObjectTrackingFrame(com.google.cloud.videointelligence.v1p2beta1.ObjectTrackingFrame) AnnotateVideoProgress(com.google.cloud.videointelligence.v1p2beta1.AnnotateVideoProgress) NormalizedBoundingBox(com.google.cloud.videointelligence.v1p2beta1.NormalizedBoundingBox) VideoSegment(com.google.cloud.videointelligence.v1p2beta1.VideoSegment) VideoAnnotationResults(com.google.cloud.videointelligence.v1p2beta1.VideoAnnotationResults) AnnotateVideoResponse(com.google.cloud.videointelligence.v1p2beta1.AnnotateVideoResponse)

Aggregations

Entity (org.hypertrace.entity.data.service.v1.Entity)110 LivingEntity (org.bukkit.entity.LivingEntity)96 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 ArrayList (java.util.ArrayList)36 Location (org.bukkit.Location)36 Entity (com.google.datastore.v1.Entity)33 EnrichedEntity (org.hypertrace.entity.data.service.v1.EnrichedEntity)32 Event (org.hypertrace.core.datamodel.Event)27 Player (org.bukkit.entity.Player)23 AttributeValue (org.hypertrace.core.datamodel.AttributeValue)22 CraftEntity (org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity)21 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 CraftPlayer (org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer)18 AnnotateVideoProgress (com.google.cloud.videointelligence.v1.AnnotateVideoProgress)17