BigtableIO { public static Write write() { return Write.create(); } private  BigtableIO(); static Read read(); static Write write();  }
@Test public void testWriteBuildsCorrectly() { BigtableIO.Write write = BigtableIO.write() .withBigtableOptions(BIGTABLE_OPTIONS) .withTableId("table") .withInstanceId("instance") .withProjectId("project"); assertEquals("table", write.getBigtableConfig().getTableId().get()); assertEquals("options_project", write.getBigtableOptions().getProjectId()); assertEquals("options_instance", write.getBigtableOptions().getInstanceId()); assertEquals("instance", write.getBigtableConfig().getInstanceId().get()); assertEquals("project", write.getBigtableConfig().getProjectId().get()); }
@Test public void testWriteValidationFailsMissingInstanceId() { BigtableIO.WriteWithResults write = BigtableIO.write() .withTableId("table") .withProjectId("project") .withBigtableOptions(new BigtableOptions.Builder().build()) .withWriteResults(); thrown.expect(IllegalArgumentException.class); write.expand(null); }
@Test public void testWriteValidationFailsMissingProjectId() { BigtableIO.WriteWithResults write = BigtableIO.write() .withTableId("table") .withInstanceId("instance") .withBigtableOptions(new BigtableOptions.Builder().build()) .withWriteResults(); thrown.expect(IllegalArgumentException.class); write.expand(null); }
@Test public void testWriteValidationFailsMissingInstanceIdAndProjectId() { BigtableIO.WriteWithResults write = BigtableIO.write() .withTableId("table") .withBigtableOptions(new BigtableOptions.Builder().build()) .withWriteResults(); thrown.expect(IllegalArgumentException.class); write.expand(null); }
@Test public void testWriteValidationFailsMissingOptionsAndInstanceAndProject() { BigtableIO.WriteWithResults write = BigtableIO.write().withTableId("table").withWriteResults(); thrown.expect(IllegalArgumentException.class); write.expand(null); }
@Test public void testWriteWithoutValidate() { final String table = "fooTable"; BigtableIO.Write write = BigtableIO.write() .withBigtableOptions(BIGTABLE_OPTIONS) .withTableId(table) .withBigtableService(service) .withoutValidation(); write.validate(TestPipeline.testingPipelineOptions()); }
@Test public void testWritingDisplayData() { BigtableIO.Write write = BigtableIO.write().withTableId("fooTable").withBigtableOptions(BIGTABLE_OPTIONS); DisplayData displayData = DisplayData.from(write); assertThat(displayData, hasDisplayItem("tableId", "fooTable")); }
@Test public void testWriteWithBigTableOptionsSetsBulkOptionsAndRetryOptions() { final int maxInflightRpcs = 1; final int initialBackoffMillis = -1; BigtableOptions.Builder optionsBuilder = BIGTABLE_OPTIONS.toBuilder(); BulkOptions.Builder bulkOptionsBuilder = new BulkOptions.Builder(); bulkOptionsBuilder.setMaxInflightRpcs(maxInflightRpcs); RetryOptions.Builder retryOptionsBuilder = new RetryOptions.Builder(); retryOptionsBuilder.setInitialBackoffMillis(initialBackoffMillis); optionsBuilder .setBulkOptions(bulkOptionsBuilder.build()) .setRetryOptions(retryOptionsBuilder.build()); BigtableIO.Write write = BigtableIO.write().withBigtableOptions(optionsBuilder.build()); BigtableOptions options = write.getBigtableOptions(); assertTrue(options.getBulkOptions().useBulkApi()); assertEquals(maxInflightRpcs, options.getBulkOptions().getMaxInflightRpcs()); assertEquals(initialBackoffMillis, options.getRetryOptions().getInitialBackoffMillis()); assertThat( options.getBulkOptions(), Matchers.equalTo(bulkOptionsBuilder.setUseBulkApi(true).build())); assertThat(options.getRetryOptions(), Matchers.equalTo(retryOptionsBuilder.build())); }