use of org.openstreetmap.osmosis.core.domain.v0_6.Entity in project beam by apache.
the class DatastoreV1Test method testAddEntitiesWithIncompleteKeys.
/**
* Test that entities with incomplete keys cannot be updated.
*/
@Test
public void testAddEntitiesWithIncompleteKeys() throws Exception {
Key key = makeKey("bird").build();
Entity entity = Entity.newBuilder().setKey(key).build();
UpsertFn upsertFn = new UpsertFn();
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Entities to be written to the Cloud Datastore must have complete keys");
upsertFn.apply(entity);
}
use of org.openstreetmap.osmosis.core.domain.v0_6.Entity in project beam by apache.
the class DatastoreV1Test method testDeleteEntities.
/**
* Test that entities with valid keys are transformed to delete mutations.
*/
@Test
public void testDeleteEntities() throws Exception {
Key key = makeKey("bird", "finch").build();
Entity entity = Entity.newBuilder().setKey(key).build();
DeleteEntityFn deleteEntityFn = new DeleteEntityFn();
Mutation exceptedMutation = makeDelete(entity.getKey()).build();
assertEquals(deleteEntityFn.apply(entity), exceptedMutation);
}
use of org.openstreetmap.osmosis.core.domain.v0_6.Entity in project beam by apache.
the class V1ReadIT method writeEntitiesToDatastore.
// Creates entities and write them to datastore
private static void writeEntitiesToDatastore(V1TestOptions options, String project, String ancestor, long numEntities) throws Exception {
Datastore datastore = getDatastore(options, project);
// Write test entities to datastore
V1TestWriter writer = new V1TestWriter(datastore, new UpsertMutationBuilder());
Key ancestorKey = makeAncestorKey(options.getNamespace(), options.getKind(), ancestor);
for (long i = 0; i < numEntities; i++) {
Entity entity = makeEntity(i, ancestorKey, options.getKind(), options.getNamespace(), 0);
writer.write(entity);
}
writer.close();
}
use of org.openstreetmap.osmosis.core.domain.v0_6.Entity in project beam by apache.
the class V1TestUtil method deleteAllEntities.
/**
* Delete all entities with the given ancestor.
*/
static void deleteAllEntities(V1TestOptions options, String project, String ancestor) throws Exception {
Datastore datastore = getDatastore(options, project);
Query query = V1TestUtil.makeAncestorKindQuery(options.getKind(), options.getNamespace(), ancestor);
V1TestReader reader = new V1TestReader(datastore, query, options.getNamespace());
V1TestWriter writer = new V1TestWriter(datastore, new DeleteMutationBuilder());
long numEntities = 0;
while (reader.advance()) {
Entity entity = reader.getCurrent();
numEntities++;
writer.write(entity);
}
writer.close();
LOG.info("Successfully deleted {} entities", numEntities);
}
use of org.openstreetmap.osmosis.core.domain.v0_6.Entity in project beam by apache.
the class DatastoreV1Test method makeLatestTimestampResponse.
/** Builds a response of the given timestamp. */
private static RunQueryResponse makeLatestTimestampResponse(long timestamp) {
RunQueryResponse.Builder timestampResponse = RunQueryResponse.newBuilder();
Entity.Builder entity = Entity.newBuilder();
entity.setKey(makeKey("dummyKind", "dummyId"));
entity.putProperties("timestamp", makeValue(new Date(timestamp * 1000)).build());
EntityResult.Builder entityResult = EntityResult.newBuilder();
entityResult.setEntity(entity);
QueryResultBatch.Builder batch = QueryResultBatch.newBuilder();
batch.addEntityResults(entityResult);
timestampResponse.setBatch(batch);
return timestampResponse.build();
}
Aggregations