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());
}
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());
}
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");
}
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());
}
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;
}
}
Aggregations