use of io.shardingjdbc.core.rule.ShardingRule in project sharding-jdbc by shardingjdbc.
the class OrchestrationShardingNamespaceTest method assertShardingRuleWithAttributesDataSource.
@Test
public void assertShardingRuleWithAttributesDataSource() {
Map<String, DataSource> dataSourceMap = getDataSourceMap("shardingRuleWithAttributesDataSource");
ShardingRule shardingRule = getShardingRule("shardingRuleWithAttributesDataSource");
assertNotNull(dataSourceMap.get("dbtbl_0"));
assertNotNull(dataSourceMap.get("dbtbl_1"));
assertThat(shardingRule.getDefaultDataSourceName(), is("dbtbl_0"));
assertTrue(Arrays.equals(shardingRule.getDefaultDatabaseShardingStrategy().getShardingColumns().toArray(new String[] {}), new String[] { this.applicationContext.getBean("standardStrategy", StandardShardingStrategyConfiguration.class).getShardingColumn() }));
assertTrue(Arrays.equals(shardingRule.getDefaultTableShardingStrategy().getShardingColumns().toArray(new String[] {}), new String[] { this.applicationContext.getBean("inlineStrategy", InlineShardingStrategyConfiguration.class).getShardingColumn() }));
assertThat(shardingRule.getDefaultKeyGenerator().getClass().getName(), is(IncrementKeyGenerator.class.getCanonicalName()));
}
use of io.shardingjdbc.core.rule.ShardingRule in project sharding-jdbc by shardingjdbc.
the class OrchestrationShardingNamespaceTest method getShardingRule.
private ShardingRule getShardingRule(final String shardingDataSourceName) {
ShardingDataSource shardingDataSource = this.applicationContext.getBean(shardingDataSourceName, ShardingDataSource.class);
Object shardingContext = FieldValueUtil.getFieldValue(shardingDataSource, "shardingContext", true);
return (ShardingRule) FieldValueUtil.getFieldValue(shardingContext, "shardingRule");
}
use of io.shardingjdbc.core.rule.ShardingRule in project sharding-jdbc by shardingjdbc.
the class OrchestrationShardingNamespaceTest method assertBindingTableRuleDatasource.
@Test
public void assertBindingTableRuleDatasource() {
ShardingRule shardingRule = getShardingRule("bindingTableRuleDatasource");
assertThat(shardingRule.getBindingTableRules().size(), is(1));
BindingTableRule bindingTableRule = shardingRule.getBindingTableRules().iterator().next();
assertThat(bindingTableRule.getBindingActualTable("dbtbl_0", "t_order", "t_order_item"), is("t_order"));
assertThat(bindingTableRule.getBindingActualTable("dbtbl_1", "t_order", "t_order_item"), is("t_order"));
}
use of io.shardingjdbc.core.rule.ShardingRule in project sharding-jdbc by shardingjdbc.
the class ShardingConnectionTest method setUp.
@Before
public void setUp() {
ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
TableRuleConfiguration tableRuleConfig = new TableRuleConfiguration();
tableRuleConfig.setLogicTable("test");
shardingRuleConfig.getTableRuleConfigs().add(tableRuleConfig);
Map<String, DataSource> dataSourceMap = new HashMap<>(1, 1);
dataSourceMap.put(DS_NAME, masterSlaveDataSource);
ShardingContext shardingContext = new ShardingContext(dataSourceMap, new ShardingRule(shardingRuleConfig, dataSourceMap.keySet()), null, null, false);
connection = new ShardingConnection(shardingContext);
}
use of io.shardingjdbc.core.rule.ShardingRule in project sharding-jdbc by shardingjdbc.
the class ShardingDataSourceTest method assertRenewWithDatabaseTypeChanged.
// TODO to be discuss
// @Test(expected = IllegalStateException.class)
@Test
public void assertRenewWithDatabaseTypeChanged() throws SQLException {
DataSource originalDataSource = mockDataSource("H2");
Map<String, DataSource> originalDataSourceMap = new HashMap<>(1, 1);
originalDataSourceMap.put("ds", originalDataSource);
ShardingDataSource shardingDataSource = createShardingDataSource(originalDataSourceMap);
DataSource newDataSource = mockDataSource("MySQL");
Map<String, DataSource> newDataSourceMap = new HashMap<>(1, 1);
newDataSourceMap.put("ds", newDataSource);
shardingDataSource.renew(newDataSourceMap, new ShardingRule(createShardingRuleConfig(newDataSourceMap), newDataSourceMap.keySet()), new Properties());
}
Aggregations