Search in sources :

Example 1 with TestPreciseShardingAlgorithm

use of io.shardingjdbc.core.api.algorithm.fixture.TestPreciseShardingAlgorithm in project sharding-jdbc by shardingjdbc.

the class ShardingStrategyTest method assertDoShardingForBetweenSingleKey.

@Test
public void assertDoShardingForBetweenSingleKey() {
    StandardShardingStrategy strategy = new StandardShardingStrategy(new StandardShardingStrategyConfiguration("column", new TestPreciseShardingAlgorithm(), new TestRangeShardingAlgorithm()));
    assertThat(strategy.doSharding(targets, Collections.<ShardingValue>singletonList(new RangeShardingValue<>("logicTable", "column", Range.open("1", "3")))), is((Collection<String>) Sets.newHashSet("1", "2", "3")));
}
Also used : StandardShardingStrategyConfiguration(io.shardingjdbc.core.api.config.strategy.StandardShardingStrategyConfiguration) TestPreciseShardingAlgorithm(io.shardingjdbc.core.api.algorithm.fixture.TestPreciseShardingAlgorithm) TestRangeShardingAlgorithm(io.shardingjdbc.core.api.algorithm.fixture.TestRangeShardingAlgorithm) Collection(java.util.Collection) PreciseShardingValue(io.shardingjdbc.core.api.algorithm.sharding.PreciseShardingValue) ShardingValue(io.shardingjdbc.core.api.algorithm.sharding.ShardingValue) RangeShardingValue(io.shardingjdbc.core.api.algorithm.sharding.RangeShardingValue) StandardShardingStrategy(io.shardingjdbc.core.routing.strategy.standard.StandardShardingStrategy) Test(org.junit.Test)

Example 2 with TestPreciseShardingAlgorithm

use of io.shardingjdbc.core.api.algorithm.fixture.TestPreciseShardingAlgorithm in project sharding-jdbc by shardingjdbc.

the class ShardingRuleTest method createTableRuleConfigWithTableStrategies.

private TableRuleConfiguration createTableRuleConfigWithTableStrategies() {
    TableRuleConfiguration result = new TableRuleConfiguration();
    result.setLogicTable("LOGIC_TABLE");
    result.setActualDataNodes("ds${0..1}.table_${0..2}");
    result.setTableShardingStrategyConfig(new StandardShardingStrategyConfiguration("column", new TestPreciseShardingAlgorithm()));
    return result;
}
Also used : StandardShardingStrategyConfiguration(io.shardingjdbc.core.api.config.strategy.StandardShardingStrategyConfiguration) TestPreciseShardingAlgorithm(io.shardingjdbc.core.api.algorithm.fixture.TestPreciseShardingAlgorithm) TableRuleConfiguration(io.shardingjdbc.core.api.config.TableRuleConfiguration)

Example 3 with TestPreciseShardingAlgorithm

use of io.shardingjdbc.core.api.algorithm.fixture.TestPreciseShardingAlgorithm in project sharding-jdbc by shardingjdbc.

the class ShardingRuleTest method assertIsShardingColumnForDefaultDatabaseShardingStrategy.

@Test
public void assertIsShardingColumnForDefaultDatabaseShardingStrategy() {
    ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
    shardingRuleConfig.getTableRuleConfigs().add(createTableRuleConfigWithAllStrategies());
    shardingRuleConfig.setDefaultDatabaseShardingStrategyConfig(new StandardShardingStrategyConfiguration("column", new TestPreciseShardingAlgorithm()));
    assertTrue(new ShardingRule(shardingRuleConfig, createDataSourceNames()).isShardingColumn(new Column("column", "")));
}
Also used : StandardShardingStrategyConfiguration(io.shardingjdbc.core.api.config.strategy.StandardShardingStrategyConfiguration) TestPreciseShardingAlgorithm(io.shardingjdbc.core.api.algorithm.fixture.TestPreciseShardingAlgorithm) ShardingRuleConfiguration(io.shardingjdbc.core.api.config.ShardingRuleConfiguration) Column(io.shardingjdbc.core.parsing.parser.context.condition.Column) Test(org.junit.Test)

Example 4 with TestPreciseShardingAlgorithm

use of io.shardingjdbc.core.api.algorithm.fixture.TestPreciseShardingAlgorithm in project sharding-jdbc by shardingjdbc.

the class ShardingRuleTest method assertIsShardingColumnForDefaultTableShardingStrategy.

@Test
public void assertIsShardingColumnForDefaultTableShardingStrategy() {
    ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
    shardingRuleConfig.getTableRuleConfigs().add(createTableRuleConfigWithAllStrategies());
    shardingRuleConfig.setDefaultTableShardingStrategyConfig(new StandardShardingStrategyConfiguration("column", new TestPreciseShardingAlgorithm()));
    assertTrue(new ShardingRule(shardingRuleConfig, createDataSourceNames()).isShardingColumn(new Column("column", "")));
}
Also used : StandardShardingStrategyConfiguration(io.shardingjdbc.core.api.config.strategy.StandardShardingStrategyConfiguration) TestPreciseShardingAlgorithm(io.shardingjdbc.core.api.algorithm.fixture.TestPreciseShardingAlgorithm) ShardingRuleConfiguration(io.shardingjdbc.core.api.config.ShardingRuleConfiguration) Column(io.shardingjdbc.core.parsing.parser.context.condition.Column) Test(org.junit.Test)

Example 5 with TestPreciseShardingAlgorithm

use of io.shardingjdbc.core.api.algorithm.fixture.TestPreciseShardingAlgorithm 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;
}
Also used : StandardShardingStrategyConfiguration(io.shardingjdbc.core.api.config.strategy.StandardShardingStrategyConfiguration) TestPreciseShardingAlgorithm(io.shardingjdbc.core.api.algorithm.fixture.TestPreciseShardingAlgorithm) NoneShardingStrategyConfiguration(io.shardingjdbc.core.api.config.strategy.NoneShardingStrategyConfiguration) TableRuleConfiguration(io.shardingjdbc.core.api.config.TableRuleConfiguration)

Aggregations

TestPreciseShardingAlgorithm (io.shardingjdbc.core.api.algorithm.fixture.TestPreciseShardingAlgorithm)5 StandardShardingStrategyConfiguration (io.shardingjdbc.core.api.config.strategy.StandardShardingStrategyConfiguration)5 Test (org.junit.Test)3 ShardingRuleConfiguration (io.shardingjdbc.core.api.config.ShardingRuleConfiguration)2 TableRuleConfiguration (io.shardingjdbc.core.api.config.TableRuleConfiguration)2 Column (io.shardingjdbc.core.parsing.parser.context.condition.Column)2 TestRangeShardingAlgorithm (io.shardingjdbc.core.api.algorithm.fixture.TestRangeShardingAlgorithm)1 PreciseShardingValue (io.shardingjdbc.core.api.algorithm.sharding.PreciseShardingValue)1 RangeShardingValue (io.shardingjdbc.core.api.algorithm.sharding.RangeShardingValue)1 ShardingValue (io.shardingjdbc.core.api.algorithm.sharding.ShardingValue)1 NoneShardingStrategyConfiguration (io.shardingjdbc.core.api.config.strategy.NoneShardingStrategyConfiguration)1 StandardShardingStrategy (io.shardingjdbc.core.routing.strategy.standard.StandardShardingStrategy)1 Collection (java.util.Collection)1