Search in sources :

Example 6 with DatabaseEntities

use of com.instaclustr.esop.impl.DatabaseEntities in project esop by instaclustr.

the class CassandraDataTest method testCassandraDataForRenamingEntities.

@Test
public // --entities=ks1.tb1,ks1.tb2 --rename=ks1.tb2=ks1.tb1 -> invalid as "to" is in entities
void testCassandraDataForRenamingEntities() {
    CassandraData parsed = new CassandraData(tableIdsMap, paths);
    parsed.setDatabaseEntitiesFromRequest(DatabaseEntities.parse("ks1.tb1,  ks1.tb3,   ks2.tb3,   ks2.tb4"));
    parsed.setRenamedEntitiesFromRequest(RenamedEntities.parse(new HashMap<String, String>() {

        {
            put("ks1.tb1", "ks1.tb2");
            put("ks2.tb3", "ks2.tb2");
        }
    }));
    DatabaseEntities databaseEntitiesToProcessForRestore = parsed.getDatabaseEntitiesToProcessForRestore();
    assertTrue(databaseEntitiesToProcessForRestore.contains("ks1", "tb2"));
    assertTrue(databaseEntitiesToProcessForRestore.contains("ks2", "tb2"));
    assertTrue(databaseEntitiesToProcessForRestore.contains("ks1", "tb3"));
    assertTrue(databaseEntitiesToProcessForRestore.contains("ks2", "tb4"));
    assertFalse(databaseEntitiesToProcessForRestore.contains("ks1", "tb1"));
    assertFalse(databaseEntitiesToProcessForRestore.contains("ks2", "tb3"));
    assertEquals(2, databaseEntitiesToProcessForRestore.getKeyspaces().size());
    assertEquals(4, databaseEntitiesToProcessForRestore.getKeyspacesAndTables().size());
}
Also used : CassandraData(com.instaclustr.esop.impl.CassandraData) DatabaseEntities(com.instaclustr.esop.impl.DatabaseEntities) HashMap(java.util.HashMap) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 7 with DatabaseEntities

use of com.instaclustr.esop.impl.DatabaseEntities in project esop by instaclustr.

the class CassandraDataTest method testDatabaseEntitiesOnSpacesOnly.

@Test
public void testDatabaseEntitiesOnSpacesOnly() throws Exception {
    for (String entity : Stream.of("  ks1  .tb1  ks3.    tb3  ", "ks1.tb1  ks3.tb3", "  ks1 .tb1  ks3.tb3  ", " ks1.tb1  ks3.tb3,  ", " ks1.tb1,ks3.tb3", ",,,ks1.tb1,,,ks3.tb3,,,").collect(Collectors.toList())) {
        DatabaseEntities parsed = DatabaseEntities.parse(entity);
        Assert.assertTrue(parsed.getKeyspacesAndTables().containsEntry("ks1", "tb1"), entity);
        Assert.assertTrue(parsed.getKeyspacesAndTables().containsEntry("ks3", "tb3"), entity);
        Assert.assertEquals(parsed.getKeyspacesAndTables().size(), 2, entity);
    }
    for (String entity : Stream.of("  ks1  ks3  ", "ks1 ks3", " ks1,ks3,   ,", ",,,ks1,ks3,,,").collect(Collectors.toList())) {
        DatabaseEntities parsed = DatabaseEntities.parse(entity);
        Assert.assertTrue(parsed.getKeyspaces().contains("ks1"), entity);
        Assert.assertTrue(parsed.getKeyspaces().contains("ks3"), entity);
        Assert.assertEquals(parsed.getKeyspaces().size(), 2, entity);
    }
}
Also used : DatabaseEntities(com.instaclustr.esop.impl.DatabaseEntities) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 8 with DatabaseEntities

use of com.instaclustr.esop.impl.DatabaseEntities in project esop by instaclustr.

the class CassandraDataTest method testRenamedEntitiesWithDatabaseEntities.

@Test
public void testRenamedEntitiesWithDatabaseEntities() {
    CassandraData parsed = new CassandraData(tableIdsMap, paths);
    DatabaseEntities entities = DatabaseEntities.parse("ks1.tb1,ks1.tb2");
    parsed.setDatabaseEntitiesFromRequest(entities);
    parsed.setRenamedEntitiesFromRequest(new HashMap<String, String>() {

        {
            put("ks1.tb2", "ks1.tb3");
        }
    });
}
Also used : CassandraData(com.instaclustr.esop.impl.CassandraData) DatabaseEntities(com.instaclustr.esop.impl.DatabaseEntities) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 9 with DatabaseEntities

use of com.instaclustr.esop.impl.DatabaseEntities in project esop by instaclustr.

the class KeyspaceTablesTest method testMissingKeyspaces.

@Test
public void testMissingKeyspaces() {
    KeyspaceTables keyspaceTables = new KeyspaceTables();
    keyspaceTables.add("ks1", "t1");
    keyspaceTables.add("ks2", "t2");
    keyspaceTables.add("ks3", "t3");
    keyspaceTables.add("ks4", "t4");
    // ks5 and ks6 are missing
    DatabaseEntities entities = DatabaseEntities.parse("ks1,ks5,ks6");
    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.getLeft().size());
    Assert.assertTrue(pair.getLeft().contains("ks5"));
    Assert.assertTrue(pair.getLeft().contains("ks6"));
}
Also used : DatabaseEntities(com.instaclustr.esop.impl.DatabaseEntities) Multimap(com.google.common.collect.Multimap) KeyspaceTables(com.instaclustr.esop.impl.KeyspaceTable.KeyspaceTables) List(java.util.List) Pair(org.apache.commons.lang3.tuple.Pair) Test(org.testng.annotations.Test)

Example 10 with DatabaseEntities

use of com.instaclustr.esop.impl.DatabaseEntities in project esop by instaclustr.

the class KeyspaceTablesTest method testEmpty.

@Test
public void testEmpty() {
    KeyspaceTables keyspaceTables = new KeyspaceTables();
    keyspaceTables.add("ks1", "t1");
    keyspaceTables.add("ks2", "t2");
    keyspaceTables.add("ks3", "t3");
    keyspaceTables.add("ks4", "t4");
    DatabaseEntities entities = DatabaseEntities.parse("");
    Optional<Pair<List<String>, Multimap<String, String>>> result = keyspaceTables.filterNotPresent(entities);
    Assert.assertFalse(result.isPresent());
}
Also used : DatabaseEntities(com.instaclustr.esop.impl.DatabaseEntities) KeyspaceTables(com.instaclustr.esop.impl.KeyspaceTable.KeyspaceTables) Pair(org.apache.commons.lang3.tuple.Pair) Test(org.testng.annotations.Test)

Aggregations

DatabaseEntities (com.instaclustr.esop.impl.DatabaseEntities)13 Test (org.testng.annotations.Test)12 List (java.util.List)6 CassandraData (com.instaclustr.esop.impl.CassandraData)5 Manifest (com.instaclustr.esop.impl.Manifest)5 ManifestEntry (com.instaclustr.esop.impl.ManifestEntry)5 BeforeTest (org.testng.annotations.BeforeTest)5 Path (java.nio.file.Path)4 Pair (org.apache.commons.lang3.tuple.Pair)4 KeyspaceTables (com.instaclustr.esop.impl.KeyspaceTable.KeyspaceTables)3 Snapshot (com.instaclustr.esop.impl.Snapshots.Snapshot)3 Keyspace (com.instaclustr.esop.impl.Snapshots.Snapshot.Keyspace)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Multimap (com.google.common.collect.Multimap)2 Guice (com.google.inject.Guice)2 Inject (com.google.inject.Inject)2 Injector (com.google.inject.Injector)2 Module (com.google.inject.Module)2