Search in sources :

Example 1 with DynamicDataNode

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();
        }
    }
}
Also used : TableRule(com.dangdang.ddframe.rdb.sharding.api.rule.TableRule) DynamicDataNode(com.dangdang.ddframe.rdb.sharding.api.rule.DynamicDataNode) HashMap(java.util.HashMap) ShardingRule(com.dangdang.ddframe.rdb.sharding.api.rule.ShardingRule) YamlShardingDataSource(com.dangdang.ddframe.rdb.sharding.config.yaml.api.YamlShardingDataSource) BasicDataSource(org.apache.commons.dbcp.BasicDataSource) ShardingDataSource(com.dangdang.ddframe.rdb.sharding.jdbc.ShardingDataSource) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Aggregations

DynamicDataNode (com.dangdang.ddframe.rdb.sharding.api.rule.DynamicDataNode)1 ShardingRule (com.dangdang.ddframe.rdb.sharding.api.rule.ShardingRule)1 TableRule (com.dangdang.ddframe.rdb.sharding.api.rule.TableRule)1 YamlShardingDataSource (com.dangdang.ddframe.rdb.sharding.config.yaml.api.YamlShardingDataSource)1 ShardingDataSource (com.dangdang.ddframe.rdb.sharding.jdbc.ShardingDataSource)1 HashMap (java.util.HashMap)1 DataSource (javax.sql.DataSource)1 BasicDataSource (org.apache.commons.dbcp.BasicDataSource)1 Test (org.junit.Test)1