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));
}
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);
}
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));
}
Aggregations