DataSourcesMetaData { public Collection<String> getAllInstanceDataSourceNames() { Collection<String> result = new LinkedList<>(); for (Entry<String, DataSourceMetaData> entry : dataSourceMetaDataMap.entrySet()) { if (!isExisted(entry.getKey(), result)) { result.add(entry.getKey()); } } return result; } DataSourcesMetaData(final DatabaseType databaseType, final Map<String, DatabaseAccessConfiguration> databaseAccessConfigMap); Collection<String> getAllInstanceDataSourceNames(); DataSourceMetaData getDataSourceMetaData(final String dataSourceName);  }
@Test public void assertGetAllInstanceDataSourceNamesForShardingRuleByDifferentDataSource() { Map<String, DatabaseAccessConfiguration> databaseAccessConfigurationMap = new HashMap<>(2, 1); databaseAccessConfigurationMap.put("ds_0", new DatabaseAccessConfiguration("jdbc:mysql: databaseAccessConfigurationMap.put("ds_1", new DatabaseAccessConfiguration("jdbc:mysql: DataSourcesMetaData dataSourcesMetaData = new DataSourcesMetaData(DatabaseTypes.getActualDatabaseType("MySQL"), databaseAccessConfigurationMap); Collection<String> allInstanceDataSourceNames = dataSourcesMetaData.getAllInstanceDataSourceNames(); assertNotNull(allInstanceDataSourceNames); assertThat(allInstanceDataSourceNames.size(), is(2)); assertTrue(allInstanceDataSourceNames.contains("ds_0") && allInstanceDataSourceNames.contains("ds_1")); }
@Test public void assertGetAllInstanceDataSourceNamesForShardingRuleBySameDataSource() { Map<String, DatabaseAccessConfiguration> databaseAccessConfigurationMap = new HashMap<>(2, 1); databaseAccessConfigurationMap.put("ds_0", new DatabaseAccessConfiguration("jdbc:mysql: databaseAccessConfigurationMap.put("ds_1", new DatabaseAccessConfiguration("jdbc:mysql: DataSourcesMetaData dataSourcesMetaData = new DataSourcesMetaData(DatabaseTypes.getActualDatabaseType("MySQL"), databaseAccessConfigurationMap); Collection<String> allInstanceDataSourceNames = dataSourcesMetaData.getAllInstanceDataSourceNames(); assertNotNull(allInstanceDataSourceNames); assertThat(allInstanceDataSourceNames.size(), is(1)); assertTrue(allInstanceDataSourceNames.contains("ds_0") || allInstanceDataSourceNames.contains("ds_1")); }