use of com.dangdang.ddframe.rdb.sharding.api.rule.DynamicDataNode in project sharding-jdbc by dangdangdotcom.
the class YamlShardingDataSourceTest method assertDynamic.
@Test
public void assertDynamic() throws IOException, NoSuchFieldException, IllegalAccessException, URISyntaxException {
Map<String, DataSource> dataSourceMap = new HashMap<>(1);
dataSourceMap.put("ds", createDataSource());
ShardingRule shardingRule = getShardingRule(dataSourceMap, "/config/config-dynamic.yaml");
int i = 0;
for (TableRule each : shardingRule.getTableRules()) {
i++;
assertThat(each.getActualTables().size(), is(2));
assertThat(each.getActualTables(), hasItem(new DynamicDataNode("db0")));
assertThat(each.getActualTables(), hasItem(new DynamicDataNode("db1")));
switch(i) {
case 1:
assertThat(each.getLogicTable(), is("config"));
break;
case 2:
assertThat(each.getLogicTable(), is("t_order"));
break;
case 3:
assertThat(each.getLogicTable(), is("t_order_item"));
break;
default:
fail();
}
}
}
Aggregations