Search in sources :

Example 1 with MasterSlaveRuleConfiguration

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));
}
Also used : MasterSlaveRuleConfiguration(io.shardingjdbc.core.api.config.MasterSlaveRuleConfiguration) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) TestDataSource(io.shardingjdbc.core.fixture.TestDataSource) MasterSlaveDataSource(io.shardingjdbc.core.jdbc.core.datasource.MasterSlaveDataSource) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TestDataSource(io.shardingjdbc.core.fixture.TestDataSource) DataSource(javax.sql.DataSource) MasterSlaveDataSource(io.shardingjdbc.core.jdbc.core.datasource.MasterSlaveDataSource) Test(org.junit.Test)

Example 2 with MasterSlaveRuleConfiguration

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);
}
Also used : MasterSlaveRuleConfiguration(io.shardingjdbc.core.api.config.MasterSlaveRuleConfiguration) Test(org.junit.Test)

Example 3 with MasterSlaveRuleConfiguration

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);
}
Also used : MasterSlaveRuleConfiguration(io.shardingjdbc.core.api.config.MasterSlaveRuleConfiguration) Test(org.junit.Test)

Example 4 with MasterSlaveRuleConfiguration

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());
}
Also used : MasterSlaveRuleConfiguration(io.shardingjdbc.core.api.config.MasterSlaveRuleConfiguration) Test(org.junit.Test)

Example 5 with MasterSlaveRuleConfiguration

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;
}
Also used : MasterSlaveRuleConfiguration(io.shardingjdbc.core.api.config.MasterSlaveRuleConfiguration)

Aggregations

MasterSlaveRuleConfiguration (io.shardingjdbc.core.api.config.MasterSlaveRuleConfiguration)18 Test (org.junit.Test)12 HashMap (java.util.HashMap)7 DataSource (javax.sql.DataSource)7 TestDataSource (io.shardingjdbc.core.fixture.TestDataSource)5 MasterSlaveDataSource (io.shardingjdbc.core.jdbc.core.datasource.MasterSlaveDataSource)3 YamlMasterSlaveRuleConfiguration (io.shardingjdbc.core.yaml.masterslave.YamlMasterSlaveRuleConfiguration)3 ShardingRuleConfiguration (io.shardingjdbc.core.api.config.ShardingRuleConfiguration)2 MasterSlaveConnection (io.shardingjdbc.core.jdbc.core.connection.MasterSlaveConnection)2 OrchestrationFacade (io.shardingjdbc.orchestration.internal.OrchestrationFacade)2 ConfigurationService (io.shardingjdbc.orchestration.internal.config.ConfigurationService)2 YamlOrchestrationMasterSlaveRuleConfiguration (io.shardingjdbc.orchestration.yaml.YamlOrchestrationMasterSlaveRuleConfiguration)2 Connection (java.sql.Connection)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 RoundRobinMasterSlaveLoadBalanceAlgorithm (io.shardingjdbc.core.api.algorithm.masterslave.RoundRobinMasterSlaveLoadBalanceAlgorithm)1 LinkedList (java.util.LinkedList)1 BeforeClass (org.junit.BeforeClass)1