use of io.shardingjdbc.core.jdbc.core.datasource.ShardingDataSource in project sharding-jdbc by shardingjdbc.
the class OrchestrationShardingNamespaceTest method assertDefaultActualDataNodes.
@Test
public void assertDefaultActualDataNodes() {
ShardingDataSource multiTableRulesDataSource = this.applicationContext.getBean("multiTableRulesDataSource", ShardingDataSource.class);
Object shardingContext = FieldValueUtil.getFieldValue(multiTableRulesDataSource, "shardingContext", true);
ShardingRule shardingRule = (ShardingRule) FieldValueUtil.getFieldValue(shardingContext, "shardingRule");
assertThat(shardingRule.getTableRules().size(), is(2));
Iterator<TableRule> tableRules = shardingRule.getTableRules().iterator();
TableRule orderRule = tableRules.next();
assertThat(orderRule.getActualDataNodes().size(), is(2));
assertTrue(orderRule.getActualDataNodes().contains(new DataNode("dbtbl_0", "t_order")));
assertTrue(orderRule.getActualDataNodes().contains(new DataNode("dbtbl_1", "t_order")));
TableRule orderItemRule = tableRules.next();
assertThat(orderItemRule.getActualDataNodes().size(), is(2));
assertTrue(orderItemRule.getActualDataNodes().contains(new DataNode("dbtbl_0", "t_order_item")));
assertTrue(orderItemRule.getActualDataNodes().contains(new DataNode("dbtbl_1", "t_order_item")));
}
use of io.shardingjdbc.core.jdbc.core.datasource.ShardingDataSource in project sharding-jdbc by shardingjdbc.
the class AbstractSQLTest method clear.
@AfterClass
public static void clear() throws SQLException, ReflectiveOperationException {
if (!shardingDataSources.isEmpty()) {
for (ShardingDataSource each : shardingDataSources.values()) {
each.close();
closeDataSources(getDataSourceMap(each).values());
}
shardingDataSources.clear();
}
}
use of io.shardingjdbc.core.jdbc.core.datasource.ShardingDataSource in project sharding-jdbc by shardingjdbc.
the class AbstractHintTest method initShardingDataSources.
protected final Map<DatabaseType, ShardingDataSource> initShardingDataSources() throws SQLException {
Map<DatabaseType, Map<String, DataSource>> dataSourceMap = createDataSourceMap();
for (Map.Entry<DatabaseType, Map<String, DataSource>> each : dataSourceMap.entrySet()) {
ShardingRule shardingRule = getShardingRule(each);
getShardingDataSources().put(each.getKey(), new ShardingDataSource(each.getValue(), shardingRule));
}
return getShardingDataSources();
}
use of io.shardingjdbc.core.jdbc.core.datasource.ShardingDataSource in project sharding-jdbc by shardingjdbc.
the class RoutingDatabaseOnlyWithHintForDMLTest method assertInsertWithPartialPlaceholders.
@Test
public void assertInsertWithPartialPlaceholders() throws SQLException, DatabaseUnitException {
for (Map.Entry<DatabaseType, ShardingDataSource> each : shardingDataSources.entrySet()) {
for (int i = 1; i <= 10; i++) {
try (HintShardingValueHelper helper = new HintDatabaseShardingValueHelper(i);
Connection connection = each.getValue().getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(String.format(DatabaseTestSQL.INSERT_WITH_PARTIAL_PLACEHOLDERS_SQL, i, i))) {
preparedStatement.setString(1, "insert");
preparedStatement.executeUpdate();
}
}
assertDataSet(each.getValue().getConnection(), each.getKey(), "insert", "insert");
}
}
use of io.shardingjdbc.core.jdbc.core.datasource.ShardingDataSource in project sharding-jdbc by shardingjdbc.
the class ShardingDatabaseOnlyWithHintForDMLTest method assertInsertWithPartialPlaceholders.
@Test
public void assertInsertWithPartialPlaceholders() throws SQLException, DatabaseUnitException {
for (Map.Entry<DatabaseType, ShardingDataSource> each : shardingDataSources.entrySet()) {
for (int i = 1; i <= 10; i++) {
try (HintShardingValueHelper helper = new HintShardingValueHelper(i, i);
Connection connection = each.getValue().getConnection()) {
PreparedStatement preparedStatement = connection.prepareStatement(String.format(DatabaseTestSQL.INSERT_WITH_PARTIAL_PLACEHOLDERS_SQL, i, i));
preparedStatement.setString(1, "insert");
preparedStatement.executeUpdate();
}
}
assertDataSet(each.getValue().getConnection(), each.getKey(), "insert", "insert");
}
}
Aggregations