Search in sources :

Example 1 with UpsertFn

use of org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.UpsertFn in project beam by apache.

the class DatastoreV1Test method testAddEntities.

@Test
public /**
 * Test that entities with valid keys are transformed to upsert mutations.
 */
void testAddEntities() throws Exception {
    Key key = makeKey("bird", "finch").build();
    Entity entity = Entity.newBuilder().setKey(key).build();
    UpsertFn upsertFn = new UpsertFn();
    Mutation expectedMutation = makeUpsert(entity).build();
    assertEquals(expectedMutation, 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) Mutation(com.google.datastore.v1.Mutation) 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 2 with UpsertFn

use of org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.UpsertFn 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)

Aggregations

Entity (com.google.datastore.v1.Entity)2 Key (com.google.datastore.v1.Key)2 DatastoreHelper.makeKey (com.google.datastore.v1.client.DatastoreHelper.makeKey)2 DeleteEntity (org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.DeleteEntity)2 DeleteKey (org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.DeleteKey)2 UpsertFn (org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.UpsertFn)2 DatastoreV1.isValidKey (org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.isValidKey)2 Test (org.junit.Test)2 Mutation (com.google.datastore.v1.Mutation)1