@Test
public void testBackupAndRestore() throws InterruptedException, IOException {
final Kiji kiji = getKiji();
final KijiMetaTable metaTable = kiji.getMetaTable();
final KijiSchemaTable schemaTable = kiji.getSchemaTable();
final KijiSystemTable systemTable = kiji.getSystemTable();
// Update the layout for table foo.
final TableLayoutDesc layout =
KijiTableLayouts.getLayout(KijiTableLayouts.FOO_TEST_FORMATTED_EID);
final KijiTableLayout updatedLayout = metaTable.updateTableLayout("foo", layout);
// Insert a user-level key-value pair for table foo.
metaTable.putValue("foo", "key", BYTES_VALUE);
// Insert a key-value pair in the system table
systemTable.putValue("testKey", Bytes.toBytes("testValue"));
// The meta table should have a single table, foo, in it.
assertEquals(1, metaTable.listTables().size());
assertEquals(1, metaTable.tableSet().size());
// The meta table should have a single key-value pair, "key"/"value", for table foo.
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 =