ConfigCenter { @Subscribe public synchronized void renew(final DataSourcePersistEvent event) { persistDataSourceConfigurations(event.getSchemaName(), event.getDataSourceConfigurations()); } ConfigCenter(final ConfigurationRepository repository); void persistConfigurations(final String schemaName, final Map<String, DataSourceConfiguration> dataSourceConfigs,
                                      final Collection<RuleConfiguration> ruleConfigurations, final boolean isOverwrite); void persistGlobalConfiguration(final Authentication authentication, final Properties props, final boolean isOverwrite); @Subscribe synchronized void renew(final DataSourcePersistEvent event); @Subscribe synchronized void renew(final RulePersistEvent event); @Subscribe synchronized void renew(final SchemaNamePersistEvent event); @Subscribe synchronized void renew(final MetaDataPersistEvent event); Map<String, DataSourceConfiguration> loadDataSourceConfigurations(final String schemaName); Collection<RuleConfiguration> loadRuleConfigurations(final String schemaName); Authentication loadAuthentication(); Properties loadProperties(); Collection<String> getAllSchemaNames(); boolean hasRuleConfiguration(final String schemaName); boolean hasDataSourceConfiguration(final String schemaName); void persistMetaData(final String schemaName, final RuleSchemaMetaData ruleSchemaMetaData); Optional<RuleSchemaMetaData> loadMetaData(final String schemaName); void deleteSchema(final String schemaName);  }
@Test public void assertRenewDataSourceEvent() { DataSourcePersistEvent event = new DataSourcePersistEvent("sharding_db", createDataSourceConfigurations()); ConfigCenter configCenter = new ConfigCenter(configurationRepository); configCenter.renew(event); verify(configurationRepository).persist(eq("/schemas/sharding_db/datasource"), anyString()); }
@Test public void assertRenewRuleEvent() { RulePersistEvent event = new RulePersistEvent("sharding_db", createRuleConfigurations()); ConfigCenter configCenter = new ConfigCenter(configurationRepository); configCenter.renew(event); verify(configurationRepository).persist(eq("/schemas/sharding_db/rule"), anyString()); }
@Test public void assertRenewSchemaNameEventWithDrop() { SchemaNamePersistEvent event = new SchemaNamePersistEvent("sharding_db", true); when(configurationRepository.get("/schemas")).thenReturn("sharding_db,primary_replica_db"); ConfigCenter configCenter = new ConfigCenter(configurationRepository); configCenter.renew(event); verify(configurationRepository).persist(eq("/schemas"), eq("primary_replica_db")); }
@Test public void assertRenewSchemaNameEventWithAdd() { SchemaNamePersistEvent event = new SchemaNamePersistEvent("sharding_db", false); when(configurationRepository.get("/schemas")).thenReturn("primary_replica_db"); ConfigCenter configCenter = new ConfigCenter(configurationRepository); configCenter.renew(event); verify(configurationRepository).persist(eq("/schemas"), eq("primary_replica_db,sharding_db")); }
@Test public void assertRenewSchemaNameEventWithAddAndExist() { SchemaNamePersistEvent event = new SchemaNamePersistEvent("sharding_db", false); when(configurationRepository.get("/schemas")).thenReturn("sharding_db,primary_replica_db"); ConfigCenter configCenter = new ConfigCenter(configurationRepository); configCenter.renew(event); verify(configurationRepository).persist(eq("/schemas"), eq("sharding_db,primary_replica_db")); }
@Test public void assertRenewMetaDataPersistEvent() { MetaDataPersistEvent event = new MetaDataPersistEvent("sharding_db", new RuleSchemaMetaDataYamlSwapper().swapToObject(YamlEngine.unmarshal(readYAML(META_DATA_YAML), YamlRuleSchemaMetaData.class))); ConfigCenter configCenter = new ConfigCenter(configurationRepository); configCenter.renew(event); verify(configurationRepository).persist(eq("/schemas/sharding_db/table"), anyString()); }