final KijiMetaTable metaTable = kiji.getMetaTable();
final KijiSchemaTable schemaTable = kiji.getSchemaTable();
final KijiSystemTable systemTable = kiji.getSystemTable();
final TableLayoutDesc layout = KijiTableLayouts.getLayout(KijiTableLayouts.FOO_TEST);
final KijiTableLayout updatedLayout = metaTable.updateTableLayout("foo", layout);
metaTable.putValue("foo", "key", BYTES_VALUE);
systemTable.putValue("testKey", Bytes.toBytes("testValue"));
assertEquals(1, metaTable.listTables().size());
assertEquals(1, metaTable.tableSet().size());
assertEquals(1, metaTable.keySet("foo").size());
assertArrayEquals(BYTES_VALUE, metaTable.getValue("foo", "key"));
// write to backupBuilder
final MetadataBackup.Builder backupBuilder = MetadataBackup.newBuilder()
.setLayoutVersion(kiji.getSystemTable().getDataVersion().toString())
.setMetaTable(
MetaTableBackup.newBuilder()
.setTables(new HashMap<String, TableBackup>())
.build())
.setSchemaTable(
SchemaTableBackup.newBuilder()
.setEntries(new ArrayList<SchemaTableEntry>())
.build())
.setSystemTable(
SystemTableBackup.newBuilder()
.setEntries(new ArrayList<SystemTableEntry>())
.build());
backupBuilder.setMetaTable(metaTable.toBackup());
backupBuilder.setSchemaTable(schemaTable.toBackup());
backupBuilder.setSystemTable(systemTable.toBackup());
final MetadataBackup backup = backupBuilder.build();
// make sure metadata key-value pairs are what we expect.
List<KeyValueBackupEntry> keyValues =
backup.getMetaTable().getTables().get("foo").getKeyValueBackup().getKeyValues();
assertEquals(1, keyValues.size());
assertEquals("key", keyValues.get(0).getKey());
assertArrayEquals(BYTES_VALUE, keyValues.get(0).getValue().array());
// make sure layouts are what we expect.
List<TableLayoutBackupEntry> layoutBackups =
backup.getMetaTable().getTables().get("foo").getTableLayoutsBackup().getLayouts();
assertEquals(1, layoutBackups.size());
assertEquals(updatedLayout.getDesc(), layoutBackups.get(0).getLayout());
metaTable.deleteTable("foo");
assertTrue(!metaTable.tableSet().contains("foo"));
assertEquals(0, metaTable.listTables().size());
assertEquals(0, metaTable.tableSet().size());