Search in sources :

Example 16 with Datastore

use of com.google.datastore.v1.client.Datastore 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);
}
Also used : Entity(com.google.datastore.v1.Entity) DeleteEntity(org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.DeleteEntity) UpsertFn(org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.UpsertFn) DeleteKey(org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.DeleteKey) Key(com.google.datastore.v1.Key) DatastoreHelper.makeKey(com.google.datastore.v1.client.DatastoreHelper.makeKey) DatastoreV1.isValidKey(org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.isValidKey) Test(org.junit.Test)

Example 17 with Datastore

use of com.google.datastore.v1.client.Datastore 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();
}
Also used : Entity(com.google.datastore.v1.Entity) V1TestUtil.makeEntity(org.apache.beam.sdk.io.gcp.datastore.V1TestUtil.makeEntity) UpsertMutationBuilder(org.apache.beam.sdk.io.gcp.datastore.V1TestUtil.UpsertMutationBuilder) V1TestUtil.getDatastore(org.apache.beam.sdk.io.gcp.datastore.V1TestUtil.getDatastore) Datastore(com.google.datastore.v1.client.Datastore) V1TestWriter(org.apache.beam.sdk.io.gcp.datastore.V1TestUtil.V1TestWriter) V1TestUtil.makeAncestorKey(org.apache.beam.sdk.io.gcp.datastore.V1TestUtil.makeAncestorKey) Key(com.google.datastore.v1.Key)

Example 18 with Datastore

use of com.google.datastore.v1.client.Datastore in project beam by apache.

the class V1TestUtil method countEntities.

/**
   * Returns the total number of entities for the given datastore.
   */
static long countEntities(V1TestOptions options, String project, String ancestor) throws Exception {
    // Read from datastore.
    Datastore datastore = V1TestUtil.getDatastore(options, project);
    Query query = V1TestUtil.makeAncestorKindQuery(options.getKind(), options.getNamespace(), ancestor);
    V1TestReader reader = new V1TestReader(datastore, query, options.getNamespace());
    long numEntitiesRead = 0;
    while (reader.advance()) {
        reader.getCurrent();
        numEntitiesRead++;
    }
    return numEntitiesRead;
}
Also used : Datastore(com.google.datastore.v1.client.Datastore) Query(com.google.datastore.v1.Query)

Example 19 with Datastore

use of com.google.datastore.v1.client.Datastore 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);
}
Also used : Entity(com.google.datastore.v1.Entity) Datastore(com.google.datastore.v1.client.Datastore) Query(com.google.datastore.v1.Query)

Example 20 with Datastore

use of com.google.datastore.v1.client.Datastore in project beam by apache.

the class DatastoreV1Test method testDeleteIncompleteKeys.

/**
   * Test that incomplete keys cannot be deleted.
   */
@Test
public void testDeleteIncompleteKeys() throws Exception {
    Key key = makeKey("bird").build();
    DeleteKeyFn deleteKeyFn = new DeleteKeyFn();
    thrown.expect(IllegalArgumentException.class);
    thrown.expectMessage("Keys to be deleted from the Cloud Datastore must be complete");
    deleteKeyFn.apply(key);
}
Also used : DeleteKeyFn(org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.DeleteKeyFn) DeleteKey(org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.DeleteKey) Key(com.google.datastore.v1.Key) DatastoreHelper.makeKey(com.google.datastore.v1.client.DatastoreHelper.makeKey) DatastoreV1.isValidKey(org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.isValidKey) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)11 Entity (com.google.datastore.v1.Entity)5 Query (com.google.datastore.v1.Query)5 Key (com.google.datastore.v1.Key)4 LookupRequest (com.google.datastore.v1.LookupRequest)4 RunQueryRequest (com.google.datastore.v1.RunQueryRequest)4 Datastore (com.google.datastore.v1.client.Datastore)4 RunQueryResponse (com.google.datastore.v1.RunQueryResponse)3 DatastoreHelper.makeKey (com.google.datastore.v1.client.DatastoreHelper.makeKey)3 DeleteEntity (org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.DeleteEntity)3 DeleteKey (org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.DeleteKey)3 DatastoreV1.isValidKey (org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.isValidKey)3 GqlQuery (com.google.datastore.v1.GqlQuery)2 ReadOptions (com.google.datastore.v1.ReadOptions)2 DatastoreException (com.google.datastore.v1.client.DatastoreException)2 DatastoreOptions (com.google.datastore.v1.client.DatastoreOptions)2 ByteString (com.google.protobuf.ByteString)2 Status (com.yahoo.ycsb.Status)2 StringByteIterator (com.yahoo.ycsb.StringByteIterator)2 Credential (com.google.api.client.auth.oauth2.Credential)1