use of io.shardingjdbc.core.rule.ShardingRule in project sharding-jdbc by shardingjdbc.
the class OrchestrationShardingNamespaceTest method assertMultiTableRulesDataSource.
@Test
public void assertMultiTableRulesDataSource() {
ShardingRule shardingRule = getShardingRule("multiTableRulesDataSource");
assertThat(shardingRule.getTableRules().size(), is(2));
Iterator<TableRule> tableRules = shardingRule.getTableRules().iterator();
assertThat(tableRules.next().getLogicTable(), is("t_order"));
assertThat(tableRules.next().getLogicTable(), is("t_order_item"));
}
use of io.shardingjdbc.core.rule.ShardingRule in project sharding-jdbc by shardingjdbc.
the class OrchestrationShardingNamespaceTest method assertTableRuleWithAttributesDataSource.
@Test
public void assertTableRuleWithAttributesDataSource() {
ShardingRule shardingRule = getShardingRule("tableRuleWithAttributesDataSource");
assertThat(shardingRule.getTableRules().size(), is(1));
TableRule tableRule = shardingRule.getTableRules().iterator().next();
assertThat(tableRule.getLogicTable(), is("t_order"));
assertThat(tableRule.getActualDataNodes().size(), is(8));
assertTrue(tableRule.getActualDataNodes().contains(new DataNode("dbtbl_0", "t_order_0")));
assertTrue(tableRule.getActualDataNodes().contains(new DataNode("dbtbl_0", "t_order_1")));
assertTrue(tableRule.getActualDataNodes().contains(new DataNode("dbtbl_0", "t_order_2")));
assertTrue(tableRule.getActualDataNodes().contains(new DataNode("dbtbl_0", "t_order_3")));
assertTrue(tableRule.getActualDataNodes().contains(new DataNode("dbtbl_1", "t_order_0")));
assertTrue(tableRule.getActualDataNodes().contains(new DataNode("dbtbl_1", "t_order_1")));
assertTrue(tableRule.getActualDataNodes().contains(new DataNode("dbtbl_1", "t_order_2")));
assertTrue(tableRule.getActualDataNodes().contains(new DataNode("dbtbl_1", "t_order_3")));
assertTrue(Arrays.equals(tableRule.getDatabaseShardingStrategy().getShardingColumns().toArray(new String[] {}), new String[] { this.applicationContext.getBean("standardStrategy", StandardShardingStrategyConfiguration.class).getShardingColumn() }));
assertTrue(Arrays.equals(tableRule.getTableShardingStrategy().getShardingColumns().toArray(new String[] {}), new String[] { this.applicationContext.getBean("inlineStrategy", InlineShardingStrategyConfiguration.class).getShardingColumn() }));
assertThat(tableRule.getGenerateKeyColumn(), is("order_id"));
assertThat(tableRule.getKeyGenerator().getClass().getName(), is(IncrementKeyGenerator.class.getCanonicalName()));
}
use of io.shardingjdbc.core.rule.ShardingRule in project sharding-jdbc by shardingjdbc.
the class OrchestrationShardingNamespaceTest method assertSimpleShardingDataSource.
@Test
public void assertSimpleShardingDataSource() {
Map<String, DataSource> dataSourceMap = getDataSourceMap("simpleShardingDataSource");
ShardingRule shardingRule = getShardingRule("simpleShardingDataSource");
assertNotNull(dataSourceMap.get("dbtbl_0"));
assertThat(shardingRule.getTableRules().size(), is(1));
assertThat(shardingRule.getTableRules().iterator().next().getLogicTable(), is("t_order"));
}
use of io.shardingjdbc.core.rule.ShardingRule in project sharding-jdbc by shardingjdbc.
the class ShardingDataSourceTest method assertRenewWithoutChangeExecutorPoolEngine.
@Test
public void assertRenewWithoutChangeExecutorPoolEngine() throws SQLException, NoSuchFieldException, IllegalAccessException {
DataSource originalDataSource = mockDataSource("H2");
Map<String, DataSource> originalDataSourceMap = new HashMap<>(1, 1);
originalDataSourceMap.put("ds", originalDataSource);
ShardingDataSource shardingDataSource = createShardingDataSource(originalDataSourceMap);
ExecutorEngine originExecutorEngine = getExecutorEngine(shardingDataSource);
DataSource newDataSource = mockDataSource("H2");
Map<String, DataSource> newDataSourceMap = new HashMap<>(1, 1);
newDataSourceMap.put("ds", newDataSource);
shardingDataSource.renew(newDataSourceMap, new ShardingRule(createShardingRuleConfig(newDataSourceMap), newDataSourceMap.keySet()), new Properties());
assertThat(originExecutorEngine, is(getExecutorEngine(shardingDataSource)));
}
use of io.shardingjdbc.core.rule.ShardingRule in project sharding-jdbc by shardingjdbc.
the class ShardingDataSourceTest method assertRenewWithChangeExecutorEnginePoolSize.
@Test
public void assertRenewWithChangeExecutorEnginePoolSize() throws SQLException, NoSuchFieldException, IllegalAccessException {
DataSource originalDataSource = mockDataSource("H2");
Map<String, DataSource> originalDataSourceMap = new HashMap<>(1, 1);
originalDataSourceMap.put("ds", originalDataSource);
ShardingDataSource shardingDataSource = createShardingDataSource(originalDataSourceMap);
final ExecutorEngine originExecutorEngine = getExecutorEngine(shardingDataSource);
DataSource newDataSource = mockDataSource("H2");
Map<String, DataSource> newDataSourceMap = new HashMap<>(1, 1);
newDataSourceMap.put("ds", newDataSource);
Properties props = new Properties();
props.setProperty(ShardingPropertiesConstant.EXECUTOR_SIZE.getKey(), "100");
shardingDataSource.renew(newDataSourceMap, new ShardingRule(createShardingRuleConfig(newDataSourceMap), newDataSourceMap.keySet()), props);
assertThat(originExecutorEngine, not(getExecutorEngine(shardingDataSource)));
}
Aggregations