use of com.google.cloud.videointelligence.v1p3beta1.Entity in project osmosis by openstreetmap.
the class ChangeDeriverTest method rightEmpty.
/**
* Deriving change with an empty right input should yield
* a change with creates only.
*
* @throws Exception if something goes wrong.
*/
@Test
public void rightEmpty() throws Exception {
// Cannot be tested with file comparison as the derived
// change contains deletes which have a current timestamp
// that cannot be reliably predicted.
// Therefore, check all relevant attributes manually.
ChangeDeriver deriver = new ChangeDeriver(1);
RunnableSource left = new XmlReader(dataUtils.createDataFile("v0_6/derive_change/simple.osm"), true, CompressionMethod.None);
RunnableSource right = new EmptyReader();
SinkChangeInspector result = RunTaskUtilities.run(deriver, left, right);
List<ChangeContainer> changes = result.getProcessedChanges();
Assert.assertEquals(3, changes.size());
for (ChangeContainer changeContainer : changes) {
Assert.assertEquals(ChangeAction.Delete, changeContainer.getAction());
}
Entity e;
e = changes.get(0).getEntityContainer().getEntity();
Assert.assertEquals(EntityType.Node, e.getType());
Assert.assertEquals(10, e.getId());
Assert.assertEquals(34, e.getVersion());
e = changes.get(1).getEntityContainer().getEntity();
Assert.assertEquals(EntityType.Way, e.getType());
Assert.assertEquals(100, e.getId());
Assert.assertEquals(56, e.getVersion());
e = changes.get(2).getEntityContainer().getEntity();
Assert.assertEquals(EntityType.Relation, e.getType());
Assert.assertEquals(1000, e.getId());
Assert.assertEquals(78, e.getVersion());
}
use of com.google.cloud.videointelligence.v1p3beta1.Entity in project osmosis by openstreetmap.
the class EntityHistoryListReader method next.
/**
* {@inheritDoc}
*/
@Override
public List<ChangeContainer> next() {
List<ChangeContainer> changeList;
Entity peekEntity;
long currentId;
EntityType currentEntityType;
// Get the next change from the underlying stream.
peekEntity = sourceIterator.peekNext().getEntityContainer().getEntity();
currentId = peekEntity.getId();
currentEntityType = peekEntity.getType();
// Loop until all history values for the current element are exhausted.
changeList = new ArrayList<ChangeContainer>();
while (sourceIterator.hasNext()) {
ChangeContainer tmpChangeContainer = sourceIterator.peekNext();
// Break out of the loop when we reach the next entity in the stream.
if (currentId != tmpChangeContainer.getEntityContainer().getEntity().getId() || !currentEntityType.equals(tmpChangeContainer.getEntityContainer().getEntity().getType())) {
break;
}
// We want the value that we have already peeked from the iterator, so remove it from the iterator.
sourceIterator.next();
// Add the change to the result list.
changeList.add(tmpChangeContainer);
}
return changeList;
}
use of com.google.cloud.videointelligence.v1p3beta1.Entity in project osmosis by openstreetmap.
the class PostgreSqlChangeWriter method process.
/**
* {@inheritDoc}
*/
public void process(ChangeContainer change) {
ChangeAction action;
initialize();
// Verify that the schema version is supported.
schemaVersionValidator.validateVersion(PostgreSqlVersionConstants.SCHEMA_VERSION);
action = change.getAction();
if (!actionWriterMap.containsKey(action)) {
throw new OsmosisRuntimeException("The action " + action + " is unrecognized.");
}
final Entity entity = change.getEntityContainer().getEntity();
this.appliedChangeSets.add(entity.getChangesetId());
this.earliestTimestamp = Math.min(this.earliestTimestamp, entity.getTimestamp().getTime());
this.latestTimestamp = Math.max(this.latestTimestamp, entity.getTimestamp().getTime());
final String name = entity.getType().name() + "-" + action.name();
final int count = modifications.getOrDefault(name, 0) + 1;
modifications.put(name, count);
// Process the entity using the action writer appropriate for the change
// action.
change.getEntityContainer().process(actionWriterMap.get(action));
}
use of com.google.cloud.videointelligence.v1p3beta1.Entity in project entity-service by hypertrace.
the class EntityDataCachingClientTest method createOrUpdateEventuallyThrottlesAndMergesTheUpdateRequests.
@Test
void createOrUpdateEventuallyThrottlesAndMergesTheUpdateRequests() {
// Just reflect entities in this test
this.possibleResponseEntities = Collections.emptyList();
Entity firstEntity = this.defaultResponseEntity.toBuilder().setEntityName("first name").putAttributes("key1", createAttribute("value1-1")).putAttributes("key2", createAttribute("value2-1")).build();
Entity secondEntity = this.defaultResponseEntity.toBuilder().setEntityName("second name").putAttributes("key2", createAttribute("value2-2")).build();
Entity thirdEntity = this.defaultResponseEntity.toBuilder().setEntityName("third name").putAttributes("key3", createAttribute("value3-3")).build();
this.dataClient.createOrUpdateEntityEventually(REQUEST_CONTEXT, firstEntity, UpsertCondition.getDefaultInstance(), Duration.ofMillis(1000));
testScheduler.advanceTimeBy(300, TimeUnit.MILLISECONDS);
this.dataClient.createOrUpdateEntityEventually(REQUEST_CONTEXT, secondEntity, UpsertCondition.getDefaultInstance(), Duration.ofMillis(200));
testScheduler.advanceTimeBy(150, TimeUnit.MILLISECONDS);
this.dataClient.createOrUpdateEntityEventually(REQUEST_CONTEXT, thirdEntity, UpsertCondition.getDefaultInstance(), Duration.ofMillis(5000));
testScheduler.advanceTimeBy(49, TimeUnit.MILLISECONDS);
// All 3 should complete at 500ms (we're currently at 499ms)
verifyNoInteractions(this.mockDataService);
testScheduler.advanceTimeBy(1, TimeUnit.MILLISECONDS);
verify(this.mockDataService, times(1)).mergeAndUpsertEntity(eq(MergeAndUpsertEntityRequest.newBuilder().setEntity(Entity.newBuilder().setEntityId(thirdEntity.getEntityId()).setEntityType(thirdEntity.getEntityType()).setEntityName(thirdEntity.getEntityName()).putAttributes("key1", createAttribute("value1-1")).putAttributes("key2", createAttribute("value2-2")).putAttributes("key3", createAttribute("value3-3")).build()).setUpsertCondition(UpsertCondition.getDefaultInstance()).build()), any());
}
use of com.google.cloud.videointelligence.v1p3beta1.Entity in project entity-service by hypertrace.
the class EntityKeyTest method matchesSameEntityIdSameRequestContext.
@Test
void matchesSameEntityIdSameRequestContext() {
RequestContext matchingContext = RequestContext.forTenantId(TENANT_ID_1);
// Change some attributes to make sure it's not a deep compare
Entity matchingEntity = this.entityV2.toBuilder().clearAttributes().build();
assertEquals(new EntityKey(REQUEST_CONTEXT_1, this.entityV2), new EntityKey(matchingContext, matchingEntity));
}
Aggregations