TableAdapter { protected static void adapt(HTableDescriptor desc, CreateTableRequest request) { if (request != null) { for (HColumnDescriptor column : desc.getColumnFamilies()) { String columnName = column.getNameAsString(); request.addFamily(columnName, buildGarbageCollectionRule(column)); } } } private  TableAdapter(); static CreateTableRequest adapt(HTableDescriptor desc, byte[][] splitKeys); static void addSplitKeys(byte[][] splitKeys, CreateTableRequest request); static HTableDescriptor adapt(Table table);  }
@Test public void testAdaptWithHTableDescriptorWhenSplitIsEmpty() { byte[][] splits = new byte[0][0]; CreateTableRequest actualRequest = TableAdapter.adapt(new HTableDescriptor(TableName.valueOf(TABLE_ID)), splits); CreateTableRequest expectedRequest = CreateTableRequest.of(TABLE_ID); Assert.assertEquals( expectedRequest.toProto(PROJECT_ID, INSTANCE_ID), actualRequest.toProto(PROJECT_ID, INSTANCE_ID)); }
@Test public void testAdaptWithColumnDesc() { HColumnDescriptor columnDesc = new HColumnDescriptor(COLUMN_FAMILY); HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(TABLE_ID)); CreateTableRequest request = CreateTableRequest.of(TABLE_ID); desc.addFamily(columnDesc); TableAdapter.adapt(desc, request); GCRule gcRule = ColumnDescriptorAdapter.buildGarbageCollectionRule(columnDesc); CreateTableRequest expected = CreateTableRequest.of(TABLE_ID).addFamily(COLUMN_FAMILY, gcRule); Assert.assertEquals( request.toProto(PROJECT_ID, INSTANCE_ID), expected.toProto(PROJECT_ID, INSTANCE_ID)); }
@Test public void testAdaptForTable() { GCRule gcRule = GCRULES.maxVersions(1); ColumnFamily columnFamily = ColumnFamily.newBuilder().setGcRule(gcRule.toProto()).build(); Table table = Table.newBuilder() .setName(TABLE_NAME) .putColumnFamilies(COLUMN_FAMILY, columnFamily) .build(); HTableDescriptor actualTableDesc = TableAdapter.adapt(com.google.cloud.bigtable.admin.v2.models.Table.fromProto(table)); HTableDescriptor expected = new HTableDescriptor(TableName.valueOf(TABLE_ID)); expected.addFamily(new HColumnDescriptor(COLUMN_FAMILY)); Assert.assertEquals(expected, actualTableDesc); }