BigtableIO { public static Read read() { return Read.create(); } private  BigtableIO(); static Read read(); static Write write();  }
@Test public void testReadBuildsCorrectly() { BigtableIO.Read read = BigtableIO.read() .withBigtableOptions(BIGTABLE_OPTIONS) .withTableId("table") .withInstanceId("instance") .withProjectId("project") .withBigtableOptionsConfigurator(PORT_CONFIGURATOR); assertEquals("options_project", read.getBigtableOptions().getProjectId()); assertEquals("options_instance", read.getBigtableOptions().getInstanceId()); assertEquals("instance", read.getBigtableConfig().getInstanceId().get()); assertEquals("project", read.getBigtableConfig().getProjectId().get()); assertEquals("table", read.getTableId()); assertEquals(PORT_CONFIGURATOR, read.getBigtableConfig().getBigtableOptionsConfigurator()); }
@Test public void testReadValidationFailsMissingTable() { BigtableIO.Read read = BigtableIO.read().withBigtableOptions(BIGTABLE_OPTIONS); thrown.expect(IllegalArgumentException.class); read.expand(null); }
@Test public void testReadValidationFailsMissingInstanceId() { BigtableIO.Read read = BigtableIO.read() .withTableId("table") .withProjectId("project") .withBigtableOptions(new BigtableOptions.Builder().build()); thrown.expect(IllegalArgumentException.class); read.expand(null); }
@Test public void testReadValidationFailsMissingProjectId() { BigtableIO.Read read = BigtableIO.read() .withTableId("table") .withInstanceId("instance") .withBigtableOptions(new BigtableOptions.Builder().build()); thrown.expect(IllegalArgumentException.class); read.expand(null); }
@Test public void testReadValidationFailsMissingInstanceIdAndProjectId() { BigtableIO.Read read = BigtableIO.read() .withTableId("table") .withBigtableOptions(new BigtableOptions.Builder().build()); thrown.expect(IllegalArgumentException.class); read.expand(null); }
@Test public void testReadWithRuntimeParametersValidationFailed() { ReadOptions options = PipelineOptionsFactory.fromArgs().withValidation().as(ReadOptions.class); BigtableIO.Read read = BigtableIO.read() .withProjectId(options.getBigtableProject()) .withInstanceId(options.getBigtableInstanceId()) .withTableId(options.getBigtableTableId()); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("tableId was not supplied"); p.apply(read); }
@Test public void testReadWithRuntimeParametersValidationDisabled() { ReadOptions options = PipelineOptionsFactory.fromArgs().withValidation().as(ReadOptions.class); BigtableIO.Read read = BigtableIO.read() .withoutValidation() .withProjectId(options.getBigtableProject()) .withInstanceId(options.getBigtableInstanceId()) .withTableId(options.getBigtableTableId()); thrown.expect(PipelineRunMissingException.class); p.apply(read); }
@Test public void testReadingFailsTableDoesNotExist() throws Exception { final String table = "TEST-TABLE"; BigtableIO.Read read = BigtableIO.read() .withBigtableOptions(BIGTABLE_OPTIONS) .withTableId(table) .withBigtableService(service); thrown.expect(IllegalArgumentException.class); thrown.expectMessage(String.format("Table %s does not exist", table)); p.apply(read); p.run(); }
@Test public void testReadingDisplayData() { RowFilter rowFilter = RowFilter.newBuilder().setRowKeyRegexFilter(ByteString.copyFromUtf8("foo.*")).build(); ByteKeyRange keyRange = ByteKeyRange.ALL_KEYS.withEndKey(ByteKey.of(0xab, 0xcd)); BigtableIO.Read read = BigtableIO.read() .withBigtableOptions(BIGTABLE_OPTIONS) .withTableId("fooTable") .withRowFilter(rowFilter) .withKeyRange(keyRange); DisplayData displayData = DisplayData.from(read); assertThat( displayData, hasDisplayItem( allOf(hasKey("tableId"), hasLabel("Bigtable Table Id"), hasValue("fooTable")))); assertThat(displayData, hasDisplayItem("rowFilter", rowFilter.toString())); assertThat( displayData, hasDisplayItem("keyRanges", "[ByteKeyRange{startKey=[], endKey=[abcd]}]")); assertThat(displayData, hasDisplayItem("bigtableOptions")); }
@Test public void testReadingDisplayDataFromRuntimeParameters() { ReadOptions options = PipelineOptionsFactory.fromArgs().withValidation().as(ReadOptions.class); BigtableIO.Read read = BigtableIO.read() .withBigtableOptions(BIGTABLE_OPTIONS) .withProjectId(options.getBigtableProject()) .withInstanceId(options.getBigtableInstanceId()) .withTableId(options.getBigtableTableId()); DisplayData displayData = DisplayData.from(read); assertThat( displayData, hasDisplayItem( allOf( hasKey("projectId"), hasLabel("Bigtable Project Id"), hasValue("RuntimeValueProvider{propertyName=bigtableProject, default=null}")))); assertThat( displayData, hasDisplayItem( allOf( hasKey("instanceId"), hasLabel("Bigtable Instance Id"), hasValue("RuntimeValueProvider{propertyName=bigtableInstanceId, default=null}")))); assertThat( displayData, hasDisplayItem( allOf( hasKey("tableId"), hasLabel("Bigtable Table Id"), hasValue("RuntimeValueProvider{propertyName=bigtableTableId, default=null}")))); }
@Test public void testReadWithoutValidate() { final String table = "fooTable"; BigtableIO.Read read = BigtableIO.read() .withBigtableOptions(BIGTABLE_OPTIONS) .withTableId(table) .withBigtableService(service) .withoutValidation(); read.validate(TestPipeline.testingPipelineOptions()); }
@Test public void testReadWithBigTableOptionsSetsRetryOptions() { final int initialBackoffMillis = -1; BigtableOptions.Builder optionsBuilder = BIGTABLE_OPTIONS.toBuilder(); RetryOptions.Builder retryOptionsBuilder = new RetryOptions.Builder(); retryOptionsBuilder.setInitialBackoffMillis(initialBackoffMillis); optionsBuilder.setRetryOptions(retryOptionsBuilder.build()); BigtableIO.Read read = BigtableIO.read().withBigtableOptions(optionsBuilder.build()); BigtableOptions options = read.getBigtableOptions(); assertEquals(initialBackoffMillis, options.getRetryOptions().getInitialBackoffMillis()); assertThat(options.getRetryOptions(), Matchers.equalTo(retryOptionsBuilder.build())); }