DatastoreV1 { public DatastoreV1.Read read() { return new AutoValue_DatastoreV1_Read.Builder().setNumQuerySplits(0).build(); } DatastoreV1(); DatastoreV1.Read read(); Write write(); DeleteEntity deleteEntity(); DeleteKey deleteKey();  }
@Test public void testBuildRead() throws Exception { DatastoreV1.Read read = DatastoreIO.v1().read().withProjectId(PROJECT_ID).withQuery(QUERY).withNamespace(NAMESPACE); assertEquals(QUERY, read.getQuery()); assertEquals(PROJECT_ID, read.getProjectId().get()); assertEquals(NAMESPACE, read.getNamespace().get()); }
@Test public void testBuildReadWithGqlQuery() throws Exception { DatastoreV1.Read read = DatastoreIO.v1() .read() .withProjectId(PROJECT_ID) .withLiteralGqlQuery(GQL_QUERY) .withNamespace(NAMESPACE); assertEquals(GQL_QUERY, read.getLiteralGqlQuery().get()); assertEquals(PROJECT_ID, read.getProjectId().get()); assertEquals(NAMESPACE, read.getNamespace().get()); }
@Test public void testBuildReadAlt() throws Exception { DatastoreV1.Read read = DatastoreIO.v1() .read() .withQuery(QUERY) .withNamespace(NAMESPACE) .withProjectId(PROJECT_ID) .withLocalhost(LOCALHOST); assertEquals(QUERY, read.getQuery()); assertEquals(PROJECT_ID, read.getProjectId().get()); assertEquals(NAMESPACE, read.getNamespace().get()); assertEquals(LOCALHOST, read.getLocalhost()); }
@Test public void testReadValidationFailsQueryAndGqlQuery() throws Exception { DatastoreV1.Read read = DatastoreIO.v1() .read() .withProjectId(PROJECT_ID) .withLiteralGqlQuery(GQL_QUERY) .withQuery(QUERY); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("withQuery() and withLiteralGqlQuery() are exclusive"); read.expand(null); }
@Test public void testReadValidationFailsQueryLimitZero() throws Exception { Query invalidLimit = Query.newBuilder().setLimit(Int32Value.newBuilder().setValue(0)).build(); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Invalid query limit 0: must be positive"); DatastoreIO.v1().read().withQuery(invalidLimit); }
@Test public void testReadValidationFailsQueryLimitNegative() throws Exception { Query invalidLimit = Query.newBuilder().setLimit(Int32Value.newBuilder().setValue(-5)).build(); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Invalid query limit -5: must be positive"); DatastoreIO.v1().read().withQuery(invalidLimit); }
@Test public void testReadDisplayData() { DatastoreV1.Read read = DatastoreIO.v1().read().withProjectId(PROJECT_ID).withQuery(QUERY).withNamespace(NAMESPACE); DisplayData displayData = DisplayData.from(read); assertThat(displayData, hasDisplayItem("projectId", PROJECT_ID)); assertThat(displayData, hasDisplayItem("query", QUERY.toString())); assertThat(displayData, hasDisplayItem("namespace", NAMESPACE)); }
@Test public void testReadDisplayDataWithGqlQuery() { DatastoreV1.Read read = DatastoreIO.v1() .read() .withProjectId(PROJECT_ID) .withLiteralGqlQuery(GQL_QUERY) .withNamespace(NAMESPACE); DisplayData displayData = DisplayData.from(read); assertThat(displayData, hasDisplayItem("projectId", PROJECT_ID)); assertThat(displayData, hasDisplayItem("gqlQuery", GQL_QUERY)); assertThat(displayData, hasDisplayItem("namespace", NAMESPACE)); }
@Test public void testSourcePrimitiveDisplayData() { DisplayDataEvaluator evaluator = DisplayDataEvaluator.create(); int numSplits = 98; PTransform<PBegin, PCollection<Entity>> read = DatastoreIO.v1() .read() .withProjectId(PROJECT_ID) .withQuery(Query.newBuilder().build()) .withNumQuerySplits(numSplits); String assertMessage = "DatastoreIO read should include the '%s' in its primitive display data"; Set<DisplayData> displayData = evaluator.displayDataForPrimitiveSourceTransforms(read); assertThat( String.format(assertMessage, "project id"), displayData, hasItem(hasDisplayItem("projectId", PROJECT_ID))); assertThat( String.format(assertMessage, "number of query splits"), displayData, hasItem(hasDisplayItem("numQuerySplits", numSplits))); }