use of io.shardingjdbc.core.api.config.strategy.ComplexShardingStrategyConfiguration in project sharding-jdbc by shardingjdbc.
the class ShowTablesMergedResultTest method setUp.
@Before
public void setUp() throws SQLException {
TableRuleConfiguration tableRuleConfig = new TableRuleConfiguration();
tableRuleConfig.setLogicTable("table");
tableRuleConfig.setActualDataNodes("ds.table_${0..2}");
tableRuleConfig.setTableShardingStrategyConfig(new ComplexShardingStrategyConfiguration("field1, field2, field3", new TestComplexKeysShardingAlgorithm()));
ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
shardingRuleConfig.getTableRuleConfigs().add(tableRuleConfig);
shardingRule = new ShardingRule(shardingRuleConfig, Lists.newArrayList("ds"));
resultSet = mock(ResultSet.class);
ResultSetMetaData resultSetMetaData = mock(ResultSetMetaData.class);
when(resultSet.getMetaData()).thenReturn(resultSetMetaData);
when(resultSetMetaData.getColumnCount()).thenReturn(1);
List<ResultSet> resultSets = Lists.newArrayList(resultSet);
for (ResultSet each : resultSets) {
when(each.next()).thenReturn(true, false);
}
queryResults = new ArrayList<>(resultSets.size());
for (ResultSet each : resultSets) {
queryResults.add(new TestQueryResult(each));
}
}
use of io.shardingjdbc.core.api.config.strategy.ComplexShardingStrategyConfiguration in project sharding-jdbc by shardingjdbc.
the class AbstractStatementParserTest method createShardingRule.
protected final ShardingRule createShardingRule() {
DataSource dataSource = mock(DataSource.class);
Connection connection = mock(Connection.class);
DatabaseMetaData databaseMetaData = mock(DatabaseMetaData.class);
try {
when(dataSource.getConnection()).thenReturn(connection);
when(connection.getMetaData()).thenReturn(databaseMetaData);
when(databaseMetaData.getDatabaseProductName()).thenReturn("H2");
} catch (final SQLException ex) {
throw new RuntimeException(ex);
}
TableRuleConfiguration tableRuleConfig = new TableRuleConfiguration();
tableRuleConfig.setLogicTable("TABLE_XXX");
tableRuleConfig.setActualDataNodes("ds.table_${0..2}");
tableRuleConfig.setTableShardingStrategyConfig(new ComplexShardingStrategyConfiguration("field1, field2, field3, field4, field5, field6, field7", new TestComplexKeysShardingAlgorithm()));
ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
shardingRuleConfig.getTableRuleConfigs().add(tableRuleConfig);
return new ShardingRule(shardingRuleConfig, Lists.newArrayList("ds"));
}
use of io.shardingjdbc.core.api.config.strategy.ComplexShardingStrategyConfiguration in project sharding-jdbc by shardingjdbc.
the class ShardingRuleConfigurationConverterTest method assertFromJsonForComplexStrategy.
@Test
public void assertFromJsonForComplexStrategy() {
ShardingRuleConfiguration actual = ShardingRuleConfigurationConverter.fromJson(getJsonForComplexStrategy());
assertCommon(actual);
ComplexShardingStrategyConfiguration actualShardingStrategy = (ComplexShardingStrategyConfiguration) actual.getDefaultTableShardingStrategyConfig();
assertThat(actualShardingStrategy.getShardingColumns(), is("order_id,item_id"));
assertThat(actualShardingStrategy.getShardingAlgorithm(), instanceOf(TestComplexKeysShardingAlgorithm.class));
}
use of io.shardingjdbc.core.api.config.strategy.ComplexShardingStrategyConfiguration in project sharding-jdbc by shardingjdbc.
the class ShardingNamespaceTest method assertComplexStrategy.
@Test
public void assertComplexStrategy() {
ComplexShardingStrategyConfiguration complexStrategy = this.applicationContext.getBean("complexStrategy", ComplexShardingStrategyConfiguration.class);
assertThat(complexStrategy.getShardingColumns(), is("order_id,user_id"));
assertThat(complexStrategy.getShardingAlgorithm(), instanceOf(DefaultComplexKeysShardingAlgorithm.class));
}
Aggregations