use of com.instaclustr.esop.impl.DatabaseEntities in project esop by instaclustr.
the class ManifestComponentsTest method testManifestFilterNoRestoreSystemKeyspaceYesNewCluster.
@Test
public void testManifestFilterNoRestoreSystemKeyspaceYesNewCluster() throws Exception {
Manifest manifest = parseManifest();
manifest.enrichManifestEntries();
List<ManifestEntry> manifestFiles = manifest.getManifestFiles(new DatabaseEntities(), // restoreSystemKeyspace
false, // restoreSystemAuth
false, // newCluster
true, // withSchemas
false);
Assert.assertTrue(manifestFiles.stream().allMatch(entry -> {
if (entry.keyspaceTable.keyspace.equals("system")) {
return entry.keyspaceTable.table.startsWith("schema_");
} else if (entry.keyspaceTable.keyspace.equals("system_schema")) {
return true;
} else
return !KeyspaceTable.isSystemKeyspace(entry.keyspaceTable.keyspace);
}));
}
use of com.instaclustr.esop.impl.DatabaseEntities in project esop by instaclustr.
the class ManifestComponentsTest method testManifestFilterYesRestoreSystemKeyspaceYesNewCluster.
@Test
public void testManifestFilterYesRestoreSystemKeyspaceYesNewCluster() throws Exception {
Manifest manifest = parseManifest();
manifest.enrichManifestEntries();
List<ManifestEntry> manifestFiles = manifest.getManifestFiles(new DatabaseEntities(), // restoreSystemKeyspace
true, // restoreSystemAuth
false, // newCluster
true, // withSchemas
false);
Assert.assertEquals(manifestFiles.size(), 304);
}
use of com.instaclustr.esop.impl.DatabaseEntities in project esop by instaclustr.
the class CassandraDataTest method testCassandraData.
@Test
public void testCassandraData() {
CassandraData parsed = new CassandraData(tableIdsMap, paths);
assertTrue(parsed.getTableId("system_schema", "tables").isPresent());
assertFalse(parsed.getTableId("system_schema", "asdadsad").isPresent());
assertFalse(parsed.getTableId("sdadasd", "types").isPresent());
Optional<List<String>> systemSchemaTablesNames = parsed.getTablesNames("system_schema");
assertTrue(systemSchemaTablesNames.isPresent());
Optional<List<Path>> systemSchemaTablesPaths = parsed.getTablesPaths("system_schema");
assertTrue(systemSchemaTablesPaths.isPresent());
assertEquals(2, systemSchemaTablesPaths.get().size());
assertTrue(parsed.containsKeyspace("ks1"));
assertFalse(parsed.containsKeyspace("asdsad"));
assertTrue(parsed.containsTable("ks1", "tb1"));
assertTrue(parsed.containsTable("ks1", "tb2"));
assertFalse(parsed.containsTable("ks1", "sdada"));
assertEquals("11111111111111111111111111111111", parsed.getTableId("ks1", "tb1").get());
assertEquals("88888888888888888888888888888888", parsed.getTableId("ks2", "tb4").get());
assertFalse(parsed.getTableId("ks2", "sdadsad").isPresent());
assertTrue(parsed.getTablesNames("ks1").get().containsAll(Arrays.asList("tb1", "tb2", "tb3", "tb4")));
assertTrue(parsed.getTablesNames("ks2").get().containsAll(Arrays.asList("tb1", "tb2", "tb3", "tb4")));
assertTrue(parsed.getTablesPaths("ks1").get().containsAll(Arrays.asList(Paths.get("/var/lib/cassandra/data/data/ks1/tb1-11111111111111111111111111111111"), Paths.get("/var/lib/cassandra/data/data/ks1/tb2-22222222222222222222222222222222"), Paths.get("/var/lib/cassandra/data/data/ks1/tb3-33333333333333333333333333333333"), Paths.get("/var/lib/cassandra/data/data/ks1/tb4-44444444444444444444444444444444"))));
assertTrue(parsed.getTablePath("ks1", "tb3").get().equals(Paths.get("/var/lib/cassandra/data/data/ks1/tb3-33333333333333333333333333333333")));
assertFalse(parsed.getTablePath("ks1", "sdad").isPresent());
assertFalse(parsed.getTablePath("sdad", "sdad").isPresent());
assertEquals(Paths.get("/var/lib/cassandra/data/data/ks1"), parsed.getKeyspacePath("ks1").get());
assertEquals(3, parsed.getKeyspacePaths().size());
// database entities
DatabaseEntities databaseEntities = parsed.toDatabaseEntities(false);
assertFalse(databaseEntities.areEmpty());
assertTrue(databaseEntities.getKeyspaces().containsAll(Arrays.asList("ks1", "ks2")));
databaseEntities.getKeyspacesAndTables().entries().forEach(entry -> {
assertTrue(parsed.getTableId(entry.getKey(), entry.getValue()).isPresent());
});
assertFalse(databaseEntities.contains("system_schema"));
assertFalse(databaseEntities.contains("asdasda", "asdad"));
}
use of com.instaclustr.esop.impl.DatabaseEntities in project esop by instaclustr.
the class CassandraDataTest method testDatabaseEntities.
@Test
public void testDatabaseEntities() throws Exception {
CassandraData parsed = new CassandraData(tableIdsMap, paths);
DatabaseEntities entities = DatabaseEntities.parse("ks1 .tb1 , kb3. tb3");
try {
parsed.setDatabaseEntitiesFromRequest(entities);
} catch (Exception ex) {
assertEquals(ex.getMessage(), "Tables [kb3.tb3] to process are not present in Cassandra.");
}
parsed.setDatabaseEntitiesFromRequest(DatabaseEntities.parse("ks1 .tb1"));
}
use of com.instaclustr.esop.impl.DatabaseEntities in project esop by instaclustr.
the class KeyspaceTablesTest method testMissingTables.
@Test
public void testMissingTables() {
KeyspaceTables keyspaceTables = new KeyspaceTables();
keyspaceTables.add("ks1", "t1");
keyspaceTables.add("ks2", "t2");
keyspaceTables.add("ks3", "t3");
keyspaceTables.add("ks4", "t4");
// ks5.t5 and ks6.t6 are missing
DatabaseEntities entities = DatabaseEntities.parse("ks1.t1,ks2.t2,ks5.t5,ks6.t6");
Optional<Pair<List<String>, Multimap<String, String>>> result = keyspaceTables.filterNotPresent(entities);
Assert.assertTrue(result.isPresent());
Pair<List<String>, Multimap<String, String>> pair = result.get();
Assert.assertEquals(2, pair.getRight().size());
Assert.assertTrue(pair.getRight().containsEntry("ks5", "t5"));
Assert.assertTrue(pair.getRight().containsEntry("ks6", "t6"));
}
Aggregations