* @SnapshotDelete
*/
public void testSnapshotSave() throws Exception {
System.out.println("Starting testSnapshotSave");
Client client = getClient();
int num_replicated_items_per_chunk = 100;
int num_replicated_chunks = 10;
int num_partitioned_items_per_chunk = 120;
int num_partitioned_chunks = 10;
loadLargeReplicatedTable(client, "REPLICATED_TESTER", num_replicated_items_per_chunk, num_replicated_chunks);
loadLargePartitionedTable(client, "PARTITION_TESTER", num_partitioned_items_per_chunk, num_partitioned_chunks);
VoltTable[] results = null;
results = client.callProcedure("@SnapshotSave", TMPDIR, TESTNONCE, (byte) 1).getResults();
validateSnapshot(true);
// MORE SNAPSHOT SAVE TESTS
FilenameFilter cleaner = new FilenameFilter() {
public boolean accept(File dir, String file) {
return file.startsWith(TESTNONCE) && file.endsWith("vpt");
}
};
File tmp_dir = new File(TMPDIR);
File[] tmp_files = tmp_dir.listFiles(cleaner);
tmp_files[0].delete();
// Instead of something exhaustive, let's just make sure that we get
// the number of result rows corresponding to the number of
// ExecutionSites
// that did save work
Cluster cluster = CatalogUtil.getCluster(this.getCatalog());
Database database = cluster.getDatabases().get("database");
CatalogMap<Table> tables = database.getTables();
CatalogMap<Site> sites = cluster.getSites();
int num_hosts = cluster.getHosts().size();
int replicated = 0;
int total_tables = 0;
int expected_entries = 0;
for (Table table : tables) {
total_tables++;
if (table.getIsreplicated()) {
replicated++;
}
}
for (Site s : sites) {
for(Partition p : s.getPartitions())
expected_entries++;
}
assertEquals(expected_entries, results[0].getRowCount());
// Now, try the save again and verify that we fail (since all the save
// files will still exist. This will return one entry per table
// per host
expected_entries = ((total_tables - replicated) * num_hosts) + replicated;
try {
results = client.callProcedure("@SnapshotSave", TMPDIR, TESTNONCE, (byte) 1).getResults();
} catch (Exception ex) {
ex.printStackTrace();
fail("SnapshotSave exception: " + ex.getMessage());
}
System.out.println(results[0]);
while (results[0].advanceRow()) {
if (!tmp_files[0].getName().contains(results[0].getString("TABLE"))) {
assertEquals(results[0].getString("RESULT"), "FAILURE");
// can also fail due to "SNAPSHOT IN PROGRESS"
// assertTrue(results[0].getString("ERR_MSG").contains("SAVE FILE ALREADY EXISTS"));
}
}
VoltTable deleteResults[] = client.callProcedure("@SnapshotDelete", new String[] { TMPDIR }, new String[] { TESTNONCE }).getResults();
assertNotNull(deleteResults);
assertEquals(1, deleteResults.length);
System.out.println(deleteResults[0]);
assertEquals(9, deleteResults[0].getColumnCount());