@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)); } }