use of io.shardingjdbc.core.rule.TableRule in project sharding-jdbc by shardingjdbc.
the class ShardingNamespaceTest 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.TableRule in project sharding-jdbc by shardingjdbc.
the class ShardingNamespaceTest method assertDefaultActualDataNodes.
@Test
public void assertDefaultActualDataNodes() {
ShardingDataSource multiTableRulesDataSource = this.applicationContext.getBean("multiTableRulesDataSource", ShardingDataSource.class);
Object shardingContext = FieldValueUtil.getFieldValue(multiTableRulesDataSource, "shardingContext", true);
ShardingRule shardingRule = (ShardingRule) FieldValueUtil.getFieldValue(shardingContext, "shardingRule");
assertThat(shardingRule.getTableRules().size(), is(2));
Iterator<TableRule> tableRules = shardingRule.getTableRules().iterator();
TableRule orderRule = tableRules.next();
assertThat(orderRule.getActualDataNodes().size(), is(2));
assertTrue(orderRule.getActualDataNodes().contains(new DataNode("dbtbl_0", "t_order")));
assertTrue(orderRule.getActualDataNodes().contains(new DataNode("dbtbl_1", "t_order")));
TableRule orderItemRule = tableRules.next();
assertThat(orderItemRule.getActualDataNodes().size(), is(2));
assertTrue(orderItemRule.getActualDataNodes().contains(new DataNode("dbtbl_0", "t_order_item")));
assertTrue(orderItemRule.getActualDataNodes().contains(new DataNode("dbtbl_1", "t_order_item")));
}
Aggregations