use of io.shardingjdbc.core.api.config.MasterSlaveRuleConfiguration in project sharding-jdbc by shardingjdbc.
the class MasterSlaveDataSourceFactoryTest method assertCreateDataSourceForMultipleSlaves.
@Test
public void assertCreateDataSourceForMultipleSlaves() throws SQLException {
Map<String, DataSource> dataSourceMap = new HashMap<>(3, 1);
dataSourceMap.put("master_ds", new TestDataSource("master_ds"));
dataSourceMap.put("slave_ds_0", new TestDataSource("slave_ds_0"));
dataSourceMap.put("slave_ds_1", new TestDataSource("slave_ds_1"));
Map<String, Object> configMap = new ConcurrentHashMap<>();
configMap.put("key1", "value1");
assertThat(MasterSlaveDataSourceFactory.createDataSource(dataSourceMap, new MasterSlaveRuleConfiguration("logic_ds", "master_ds", Arrays.asList("slave_ds_0", "slave_ds_1")), configMap), instanceOf(MasterSlaveDataSource.class));
MatcherAssert.assertThat(ConfigMapContext.getInstance().getMasterSlaveConfig(), is(configMap));
}
use of io.shardingjdbc.core.api.config.MasterSlaveRuleConfiguration in project sharding-jdbc by shardingjdbc.
the class MasterSlaveRuleTest method assertNewMasterSlaveRuleWithEmptySlaveDataSourceNames.
@Test(expected = IllegalStateException.class)
public void assertNewMasterSlaveRuleWithEmptySlaveDataSourceNames() {
MasterSlaveRuleConfiguration masterSlaveRuleConfig = new MasterSlaveRuleConfiguration("", "", Collections.<String>emptyList(), null);
new MasterSlaveRule(masterSlaveRuleConfig);
}
use of io.shardingjdbc.core.api.config.MasterSlaveRuleConfiguration in project sharding-jdbc by shardingjdbc.
the class MasterSlaveRuleTest method assertNewMasterSlaveRuleSuccess.
@Test
public void assertNewMasterSlaveRuleSuccess() {
MasterSlaveRuleConfiguration masterSlaveRuleConfig = new MasterSlaveRuleConfiguration("master_slave", "master0", Collections.singletonList("slave0"), null);
new MasterSlaveRule(masterSlaveRuleConfig);
}
use of io.shardingjdbc.core.api.config.MasterSlaveRuleConfiguration in project sharding-jdbc by shardingjdbc.
the class YamlMasterSlaveRuleConfigurationTest method assertGetMasterSlaveRuleConfigurationWithoutLoadBalanceAlgorithm.
@Test
public void assertGetMasterSlaveRuleConfigurationWithoutLoadBalanceAlgorithm() {
YamlMasterSlaveRuleConfiguration yamlConfig = createYamlMasterSlaveRuleConfig();
MasterSlaveRuleConfiguration actual = yamlConfig.getMasterSlaveRuleConfiguration();
assertMasterSlaveRuleConfig(actual);
assertNull(actual.getLoadBalanceAlgorithm());
}
use of io.shardingjdbc.core.api.config.MasterSlaveRuleConfiguration in project sharding-jdbc by shardingjdbc.
the class DataSourceService method getAvailableMasterSlaveRuleConfiguration.
/**
* Get available master-slave rule configuration.
*
* @return available master-slave rule configuration
*/
public MasterSlaveRuleConfiguration getAvailableMasterSlaveRuleConfiguration() {
MasterSlaveRuleConfiguration result = configService.loadMasterSlaveRuleConfiguration();
Collection<String> disabledDataSourceNames = getDisabledDataSourceNames();
for (String each : disabledDataSourceNames) {
result.getSlaveDataSourceNames().remove(each);
}
return result;
}
Aggregations