use of io.shardingjdbc.core.api.config.TableRuleConfiguration in project sharding-jdbc by shardingjdbc.
the class ShardingRuleTest method createTableRuleConfigWithAllStrategies.
private TableRuleConfiguration createTableRuleConfigWithAllStrategies() {
TableRuleConfiguration result = new TableRuleConfiguration();
result.setLogicTable("LOGIC_TABLE");
result.setActualDataNodes("ds${0..1}.table_${0..2}");
result.setDatabaseShardingStrategyConfig(new StandardShardingStrategyConfiguration("column", new TestPreciseShardingAlgorithm()));
result.setTableShardingStrategyConfig(new NoneShardingStrategyConfiguration());
return result;
}
use of io.shardingjdbc.core.api.config.TableRuleConfiguration in project sharding-jdbc by shardingjdbc.
the class ShardingRuleTest method assertGetNoDatabaseShardingStrategy.
@Test(expected = ShardingConfigurationException.class)
public void assertGetNoDatabaseShardingStrategy() {
ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
TableRuleConfiguration tableRuleConfig = createTableRuleConfigWithDatabaseShardingStrategy(new NoneShardingStrategyConfiguration());
shardingRuleConfig.getTableRuleConfigs().add(tableRuleConfig);
ShardingRule actual = new ShardingRule(shardingRuleConfig, createDataSourceNames());
actual.getDatabaseShardingStrategy(actual.getTableRule("other_Table"));
}
use of io.shardingjdbc.core.api.config.TableRuleConfiguration in project sharding-jdbc by shardingjdbc.
the class TableRuleTest method assertCreateFullTableRule.
@Test
public void assertCreateFullTableRule() {
TableRuleConfiguration tableRuleConfig = new TableRuleConfiguration();
tableRuleConfig.setLogicTable("LOGIC_TABLE");
tableRuleConfig.setActualDataNodes("ds${0..1}.table_${0..2}");
tableRuleConfig.setDatabaseShardingStrategyConfig(new NoneShardingStrategyConfiguration());
tableRuleConfig.setTableShardingStrategyConfig(new NoneShardingStrategyConfiguration());
tableRuleConfig.setKeyGeneratorColumnName("col_1");
tableRuleConfig.setKeyGenerator(new IncrementKeyGenerator());
tableRuleConfig.setLogicIndex("LOGIC_INDEX");
TableRule actual = new TableRule(tableRuleConfig, createDataSourceNames());
assertThat(actual.getLogicTable(), is("logic_table"));
assertThat(actual.getActualDataNodes().size(), is(6));
assertTrue(actual.getActualDataNodes().contains(new DataNode("ds0", "table_0")));
assertTrue(actual.getActualDataNodes().contains(new DataNode("ds0", "table_1")));
assertTrue(actual.getActualDataNodes().contains(new DataNode("ds0", "table_2")));
assertTrue(actual.getActualDataNodes().contains(new DataNode("ds1", "table_0")));
assertTrue(actual.getActualDataNodes().contains(new DataNode("ds1", "table_1")));
assertTrue(actual.getActualDataNodes().contains(new DataNode("ds1", "table_2")));
assertNotNull(actual.getDatabaseShardingStrategy());
assertNotNull(actual.getTableShardingStrategy());
assertThat(actual.getGenerateKeyColumn(), is("col_1"));
assertThat(actual.getKeyGenerator(), instanceOf(IncrementKeyGenerator.class));
assertThat(actual.getLogicIndex(), is("logic_index"));
}
use of io.shardingjdbc.core.api.config.TableRuleConfiguration in project sharding-jdbc by shardingjdbc.
the class TableRuleTest method assertCreateMinTableRule.
@Test
public void assertCreateMinTableRule() {
TableRuleConfiguration tableRuleConfig = new TableRuleConfiguration();
tableRuleConfig.setLogicTable("LOGIC_TABLE");
TableRule actual = new TableRule(tableRuleConfig, createDataSourceNames());
assertThat(actual.getLogicTable(), is("logic_table"));
assertThat(actual.getActualDataNodes().size(), is(2));
assertTrue(actual.getActualDataNodes().contains(new DataNode("ds0", "LOGIC_TABLE")));
assertTrue(actual.getActualDataNodes().contains(new DataNode("ds1", "LOGIC_TABLE")));
assertNull(actual.getDatabaseShardingStrategy());
assertNull(actual.getTableShardingStrategy());
assertNull(actual.getLogicIndex());
}
use of io.shardingjdbc.core.api.config.TableRuleConfiguration in project sharding-jdbc by shardingjdbc.
the class TableRuleTest method assertGetActualDatasourceNames.
@Test
public void assertGetActualDatasourceNames() {
TableRuleConfiguration tableRuleConfig = new TableRuleConfiguration();
tableRuleConfig.setLogicTable("LOGIC_TABLE");
tableRuleConfig.setActualDataNodes("ds${0..1}.table_${0..2}");
TableRule actual = new TableRule(tableRuleConfig, createDataSourceNames());
assertThat(actual.getActualDatasourceNames(), is((Collection<String>) Sets.newLinkedHashSet(Arrays.asList("ds0", "ds1"))));
}
Aggregations