@Test public void testE2EBigtableWrite() throws Exception { final String tableName = bigtableOptions.getInstanceName().toTableNameStr(tableId); final String instanceName = bigtableOptions.getInstanceName().toString(); final int numRows = 1000; final List<KV<ByteString, ByteString>> testData = generateTableData(numRows); createEmptyTable(instanceName, tableId); Pipeline p = Pipeline.create(options); p.apply(CountingInput.upTo(numRows)) .apply( ParDo.of( new DoFn<Long, KV<ByteString, Iterable<Mutation>>>() { @ProcessElement public void processElement(ProcessContext c) { int index = c.element().intValue(); Iterable<Mutation> mutations = ImmutableList.of( Mutation.newBuilder() .setSetCell( Mutation.SetCell.newBuilder() .setValue(testData.get(index).getValue()) .setFamilyName(COLUMN_FAMILY_NAME)) .build()); c.output(KV.of(testData.get(index).getKey(), mutations)); } })) .apply(BigtableIO.write().withBigtableOptions(bigtableOptions).withTableId(tableId)); p.run(); // Test number of column families and column family name equality Table table = getTable(tableName); assertThat(table.getColumnFamilies().keySet(), Matchers.hasSize(1)); assertThat(table.getColumnFamilies(), Matchers.hasKey(COLUMN_FAMILY_NAME)); // Test table data equality List<KV<ByteString, ByteString>> tableData = getTableData(tableName); assertThat(tableData, Matchers.containsInAnyOrder(testData.toArray())); }
@After public void tearDown() throws Exception { final String tableName = bigtableOptions.getInstanceName().toTableNameStr(tableId); deleteTable(tableName); session.close(); }