Search in sources :

Example 1 with DatastoreV1.isValidKey

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

the class DatastoreV1Test method testSplitQueryFnWithQueryLimit.

/**
   * Tests {@link DatastoreV1.Read.SplitQueryFn} when the query has a user specified limit.
   */
@Test
public void testSplitQueryFnWithQueryLimit() throws Exception {
    Query queryWithLimit = QUERY.toBuilder().clone().setLimit(Int32Value.newBuilder().setValue(1)).build();
    SplitQueryFn splitQueryFn = new SplitQueryFn(V_1_OPTIONS, 10, mockDatastoreFactory);
    DoFnTester<Query, KV<Integer, Query>> doFnTester = DoFnTester.of(splitQueryFn);
    doFnTester.setCloningBehavior(CloningBehavior.DO_NOT_CLONE);
    List<KV<Integer, Query>> queries = doFnTester.processBundle(queryWithLimit);
    assertEquals(queries.size(), 1);
    verifyUniqueKeys(queries);
    verifyNoMoreInteractions(mockDatastore);
    verifyNoMoreInteractions(mockQuerySplitter);
}
Also used : GqlQuery(com.google.datastore.v1.GqlQuery) Query(com.google.datastore.v1.Query) SplitQueryFn(org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.Read.SplitQueryFn) KV(org.apache.beam.sdk.values.KV) Test(org.junit.Test)

Example 2 with DatastoreV1.isValidKey

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

the class DatastoreV1Test method testHasNameOrId.

/**
   * Test the detection of complete and incomplete keys.
   */
@Test
public void testHasNameOrId() {
    Key key;
    // Complete with name, no ancestor
    key = makeKey("bird", "finch").build();
    assertTrue(isValidKey(key));
    // Complete with id, no ancestor
    key = makeKey("bird", 123).build();
    assertTrue(isValidKey(key));
    // Incomplete, no ancestor
    key = makeKey("bird").build();
    assertFalse(isValidKey(key));
    // Complete with name and ancestor
    key = makeKey("bird", "owl").build();
    key = makeKey(key, "bird", "horned").build();
    assertTrue(isValidKey(key));
    // Complete with id and ancestor
    key = makeKey("bird", "owl").build();
    key = makeKey(key, "bird", 123).build();
    assertTrue(isValidKey(key));
    // Incomplete with ancestor
    key = makeKey("bird", "owl").build();
    key = makeKey(key, "bird").build();
    assertFalse(isValidKey(key));
    key = makeKey().build();
    assertFalse(isValidKey(key));
}
Also used : 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 3 with DatastoreV1.isValidKey

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

the class DatastoreV1Test method testBuildWrite.

/**
   * Test building a Write using builder methods.
   */
@Test
public void testBuildWrite() throws Exception {
    DatastoreV1.Write write = DatastoreIO.v1().write().withProjectId(PROJECT_ID);
    assertEquals(PROJECT_ID, write.getProjectId());
}
Also used : Write(org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.Write) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 GqlQuery (com.google.datastore.v1.GqlQuery)1 Key (com.google.datastore.v1.Key)1 Query (com.google.datastore.v1.Query)1 DatastoreHelper.makeKey (com.google.datastore.v1.client.DatastoreHelper.makeKey)1 DeleteKey (org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.DeleteKey)1 SplitQueryFn (org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.Read.SplitQueryFn)1 Write (org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.Write)1 DatastoreV1.isValidKey (org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.isValidKey)1 KV (org.apache.beam.sdk.values.KV)1