@Test public void testCreateAndDropTable() throws Exception { catalog.createDatabase("tmpdb1", TajoConstants.DEFAULT_TABLESPACE_NAME); assertTrue(catalog.existDatabase("tmpdb1")); catalog.createDatabase("tmpdb2", TajoConstants.DEFAULT_TABLESPACE_NAME); assertTrue(catalog.existDatabase("tmpdb2")); TableDesc table1 = createMockupTable("tmpdb1", "table1"); catalog.createTable(table1); TableDesc table2 = createMockupTable("tmpdb2", "table2"); catalog.createTable(table2); Set<String> tmpdb1 = Sets.newHashSet(catalog.getAllTableNames("tmpdb1")); assertEquals(1, tmpdb1.size()); assertTrue(tmpdb1.contains("table1")); Set<String> tmpdb2 = Sets.newHashSet(catalog.getAllTableNames("tmpdb2")); assertEquals(1, tmpdb2.size()); assertTrue(tmpdb2.contains("table2")); catalog.dropDatabase("tmpdb1"); assertFalse(catalog.existDatabase("tmpdb1")); tmpdb2 = Sets.newHashSet(catalog.getAllTableNames("tmpdb2")); assertEquals(1, tmpdb2.size()); assertTrue(tmpdb2.contains("table2")); catalog.dropDatabase("tmpdb2"); assertFalse(catalog.existDatabase("tmpdb2")); }
@Test public void testDropDatabaseWithAllTables() throws Exception { Map<String, List<String>> createdTablesMap = createBaseDatabaseAndTables(); // Each time we drop one database, check all databases and their tables. for (String databaseName : new ArrayList<>(createdTablesMap.keySet())) { // drop one database assertTrue(catalog.existDatabase(databaseName)); catalog.dropDatabase(databaseName); createdTablesMap.remove(databaseName); // check all tables which belong to other databases for (Map.Entry<String, List<String>> entry : createdTablesMap.entrySet()) { assertTrue(catalog.existDatabase(entry.getKey())); // checking all tables for this database Collection<String> tablesForThisDatabase = catalog.getAllTableNames(entry.getKey()); assertEquals(createdTablesMap.get(entry.getKey()).size(), tablesForThisDatabase.size()); for (String tableName : tablesForThisDatabase) { assertTrue( createdTablesMap .get(entry.getKey()) .contains(IdentifierUtil.extractSimpleName(tableName))); } } } // Finally, default and system database will remain. So, its result is 1. assertEquals(2, catalog.getAllDatabaseNames().size()); }
@Test public void testCreateAndDropManyDatabases() throws Exception { List<String> createdDatabases = new ArrayList<>(); InfoSchemaMetadataDictionary dictionary = new InfoSchemaMetadataDictionary(); String namePrefix = "database_"; final int NUM = 10; for (int i = 0; i < NUM; i++) { String databaseName = namePrefix + i; assertFalse(catalog.existDatabase(databaseName)); catalog.createDatabase(databaseName, TajoConstants.DEFAULT_TABLESPACE_NAME); assertTrue(catalog.existDatabase(databaseName)); createdDatabases.add(databaseName); } Collection<String> allDatabaseNames = catalog.getAllDatabaseNames(); for (String databaseName : allDatabaseNames) { assertTrue( databaseName.equals(DEFAULT_DATABASE_NAME) || createdDatabases.contains(databaseName) || dictionary.isSystemDatabase(databaseName)); } // additional ones are 'default' and 'system' databases. assertEquals(NUM + 2, allDatabaseNames.size()); Collections.shuffle(createdDatabases); for (String tobeDropped : createdDatabases) { assertTrue(catalog.existDatabase(tobeDropped)); catalog.dropDatabase(tobeDropped); assertFalse(catalog.existDatabase(tobeDropped)); } }
@Test public void testCreateAndDropDatabases() throws Exception { assertFalse(catalog.existDatabase("testCreateAndDropDatabases")); catalog.createDatabase("testCreateAndDropDatabases", TajoConstants.DEFAULT_TABLESPACE_NAME); assertTrue(catalog.existDatabase("testCreateAndDropDatabases")); catalog.dropDatabase("testCreateAndDropDatabases"); }