Search in sources :

Example 1 with TestDataSource

use of io.shardingjdbc.core.fixture.TestDataSource 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 TestDataSource

use of io.shardingjdbc.core.fixture.TestDataSource in project sharding-jdbc by shardingjdbc.

the class ShardingConnectionTest method init.

@BeforeClass
public static void init() throws SQLException {
    DataSource masterDataSource = new TestDataSource("test_ds_master");
    DataSource slaveDataSource = new TestDataSource("test_ds_slave");
    Map<String, DataSource> dataSourceMap = new HashMap<>(2, 1);
    dataSourceMap.put("test_ds_master", masterDataSource);
    dataSourceMap.put("test_ds_slave", slaveDataSource);
    masterSlaveDataSource = new MasterSlaveDataSource(dataSourceMap, new MasterSlaveRuleConfiguration("test_ds", "test_ds_master", Collections.singletonList("test_ds_slave")), Collections.<String, Object>emptyMap());
    ((TestDataSource) slaveDataSource).setThrowExceptionWhenClosing(true);
}
Also used : MasterSlaveRuleConfiguration(io.shardingjdbc.core.api.config.MasterSlaveRuleConfiguration) HashMap(java.util.HashMap) TestDataSource(io.shardingjdbc.core.fixture.TestDataSource) MasterSlaveDataSource(io.shardingjdbc.core.jdbc.core.datasource.MasterSlaveDataSource) TestDataSource(io.shardingjdbc.core.fixture.TestDataSource) DataSource(javax.sql.DataSource) MasterSlaveDataSource(io.shardingjdbc.core.jdbc.core.datasource.MasterSlaveDataSource) BeforeClass(org.junit.BeforeClass)

Example 3 with TestDataSource

use of io.shardingjdbc.core.fixture.TestDataSource in project sharding-jdbc by shardingjdbc.

the class MasterSlaveDataSourceFactoryTest method assertCreateDataSourceForSingleSlave.

@Test
public void assertCreateDataSourceForSingleSlave() throws SQLException {
    Map<String, DataSource> dataSourceMap = new HashMap<>(2, 1);
    dataSourceMap.put("master_ds", new TestDataSource("master_ds"));
    dataSourceMap.put("slave_ds", new TestDataSource("slave_ds"));
    Map<String, Object> configMap = new ConcurrentHashMap<>();
    configMap.put("key1", "value1");
    assertThat(MasterSlaveDataSourceFactory.createDataSource(dataSourceMap, new MasterSlaveRuleConfiguration("logic_ds", "master_ds", Collections.singletonList("slave_ds")), 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)

Aggregations

MasterSlaveRuleConfiguration (io.shardingjdbc.core.api.config.MasterSlaveRuleConfiguration)3 TestDataSource (io.shardingjdbc.core.fixture.TestDataSource)3 MasterSlaveDataSource (io.shardingjdbc.core.jdbc.core.datasource.MasterSlaveDataSource)3 HashMap (java.util.HashMap)3 DataSource (javax.sql.DataSource)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Test (org.junit.Test)2 BeforeClass (org.junit.BeforeClass)1