use of io.shardingjdbc.core.api.config.TableRuleConfiguration in project sharding-jdbc by shardingjdbc.
the class TableRuleTest method createTableRuleConfig.
private TableRuleConfiguration createTableRuleConfig() {
TableRuleConfiguration result = new TableRuleConfiguration();
result.setLogicTable("LOGIC_TABLE");
result.setActualDataNodes("ds${0..1}.table_${0..2}");
return result;
}
use of io.shardingjdbc.core.api.config.TableRuleConfiguration in project sharding-jdbc by shardingjdbc.
the class TableRuleTest method assertGetActualTableNames.
@Test
public void assertGetActualTableNames() {
TableRuleConfiguration tableRuleConfig = new TableRuleConfiguration();
tableRuleConfig.setLogicTable("LOGIC_TABLE");
tableRuleConfig.setActualDataNodes("ds${0..1}.table_${0..2}");
TableRule actual = new TableRule(tableRuleConfig, createDataSourceNames());
assertThat(actual.getActualTableNames("ds0"), is((Collection<String>) Sets.newLinkedHashSet(Arrays.asList("table_0", "table_1", "table_2"))));
assertThat(actual.getActualTableNames("ds1"), is((Collection<String>) Sets.newLinkedHashSet(Arrays.asList("table_0", "table_1", "table_2"))));
assertThat(actual.getActualTableNames("ds2"), is((Collection<String>) Collections.<String>emptySet()));
}
use of io.shardingjdbc.core.api.config.TableRuleConfiguration in project sharding-jdbc by shardingjdbc.
the class TableRuleTest method assertFindActualTableIndex.
@Test
public void assertFindActualTableIndex() {
TableRuleConfiguration tableRuleConfig = new TableRuleConfiguration();
tableRuleConfig.setLogicTable("LOGIC_TABLE");
tableRuleConfig.setActualDataNodes("ds${0..1}.table_${0..2}");
TableRule actual = new TableRule(tableRuleConfig, createDataSourceNames());
assertThat(actual.findActualTableIndex("ds1", "table_1"), is(4));
}
use of io.shardingjdbc.core.api.config.TableRuleConfiguration in project sharding-jdbc by shardingjdbc.
the class TableRuleTest method assertNotFindActualTableIndex.
@Test
public void assertNotFindActualTableIndex() {
TableRuleConfiguration tableRuleConfig = new TableRuleConfiguration();
tableRuleConfig.setLogicTable("LOGIC_TABLE");
tableRuleConfig.setActualDataNodes("ds${0..1}.table_${0..2}");
TableRule actual = new TableRule(tableRuleConfig, createDataSourceNames());
assertThat(actual.findActualTableIndex("ds2", "table_2"), is(-1));
}
use of io.shardingjdbc.core.api.config.TableRuleConfiguration in project sharding-jdbc by shardingjdbc.
the class ShardingRuleConfigurationConverterTest method assertCommon.
private void assertCommon(final ShardingRuleConfiguration actual) {
assertThat(actual.getTableRuleConfigs().size(), is(2));
Iterator<TableRuleConfiguration> actualTableRuleConfigs = actual.getTableRuleConfigs().iterator();
TableRuleConfiguration orderTableRuleConfig = actualTableRuleConfigs.next();
assertThat(orderTableRuleConfig.getLogicTable(), is("t_order"));
assertThat(orderTableRuleConfig.getActualDataNodes(), is("t_order_${[0, 1]}"));
TableRuleConfiguration orderItemTableRuleConfig = actualTableRuleConfigs.next();
assertThat(orderItemTableRuleConfig.getLogicTable(), is("t_order_item"));
assertThat(orderItemTableRuleConfig.getActualDataNodes(), is("t_order_item_${[0, 1]}"));
assertThat(actual.getBindingTableGroups().size(), is(1));
assertThat(actual.getBindingTableGroups().iterator().next(), is("t_order, t_order_item"));
}
Aggregations