Search in sources :

Example 61 with ShardingRuleConfiguration

use of io.shardingjdbc.core.api.config.ShardingRuleConfiguration in project sharding-jdbc by shardingjdbc.

the class ShardingRuleTest method assertShardingRuleWithDatabaseStrategy.

@Test
public void assertShardingRuleWithDatabaseStrategy() {
    ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
    TableRuleConfiguration tableRuleConfig = createTableRuleConfig();
    shardingRuleConfig.getTableRuleConfigs().add(tableRuleConfig);
    shardingRuleConfig.setDefaultDatabaseShardingStrategyConfig(new NoneShardingStrategyConfiguration());
    ShardingRule actual = new ShardingRule(shardingRuleConfig, createDataSourceNames());
    assertTrue(actual.getDefaultDatabaseShardingStrategy().getShardingColumns().isEmpty());
    assertTrue(actual.getDefaultTableShardingStrategy().getShardingColumns().isEmpty());
}
Also used : NoneShardingStrategyConfiguration(io.shardingjdbc.core.api.config.strategy.NoneShardingStrategyConfiguration) ShardingRuleConfiguration(io.shardingjdbc.core.api.config.ShardingRuleConfiguration) TableRuleConfiguration(io.shardingjdbc.core.api.config.TableRuleConfiguration) Test(org.junit.Test)

Example 62 with ShardingRuleConfiguration

use of io.shardingjdbc.core.api.config.ShardingRuleConfiguration in project sharding-jdbc by shardingjdbc.

the class ShardingRuleTest method assertIsNotShardingColumn.

@Test
public void assertIsNotShardingColumn() {
    ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
    shardingRuleConfig.getTableRuleConfigs().add(createTableRuleConfigWithAllStrategies());
    assertFalse(new ShardingRule(shardingRuleConfig, createDataSourceNames()).isShardingColumn(new Column("column", "other_Table")));
}
Also used : ShardingRuleConfiguration(io.shardingjdbc.core.api.config.ShardingRuleConfiguration) Column(io.shardingjdbc.core.parsing.parser.context.condition.Column) Test(org.junit.Test)

Example 63 with ShardingRuleConfiguration

use of io.shardingjdbc.core.api.config.ShardingRuleConfiguration in project sharding-jdbc by shardingjdbc.

the class ShardingRuleTest method assertFindDataNodeByLogicTableFailure.

@Test(expected = ShardingConfigurationException.class)
public void assertFindDataNodeByLogicTableFailure() {
    ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
    shardingRuleConfig.setDefaultDataSourceName("ds3");
    TableRuleConfiguration tableRuleConfig = createTableRuleConfig();
    shardingRuleConfig.getTableRuleConfigs().add(tableRuleConfig);
    new ShardingRule(shardingRuleConfig, createDataSourceNames()).findDataNodeByLogicTable("logic_table_x");
}
Also used : ShardingRuleConfiguration(io.shardingjdbc.core.api.config.ShardingRuleConfiguration) TableRuleConfiguration(io.shardingjdbc.core.api.config.TableRuleConfiguration) Test(org.junit.Test)

Example 64 with ShardingRuleConfiguration

use of io.shardingjdbc.core.api.config.ShardingRuleConfiguration 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"));
}
Also used : NoneShardingStrategyConfiguration(io.shardingjdbc.core.api.config.strategy.NoneShardingStrategyConfiguration) ShardingRuleConfiguration(io.shardingjdbc.core.api.config.ShardingRuleConfiguration) TableRuleConfiguration(io.shardingjdbc.core.api.config.TableRuleConfiguration) Test(org.junit.Test)

Example 65 with ShardingRuleConfiguration

use of io.shardingjdbc.core.api.config.ShardingRuleConfiguration in project sharding-jdbc by shardingjdbc.

the class ShardingRuleTest method assertIsShardingColumnForTableShardingStrategy.

@Test
public void assertIsShardingColumnForTableShardingStrategy() {
    ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
    shardingRuleConfig.getTableRuleConfigs().add(createTableRuleConfigWithTableStrategies());
    assertTrue(new ShardingRule(shardingRuleConfig, createDataSourceNames()).isShardingColumn(new Column("column", "logic_Table")));
}
Also used : ShardingRuleConfiguration(io.shardingjdbc.core.api.config.ShardingRuleConfiguration) Column(io.shardingjdbc.core.parsing.parser.context.condition.Column) Test(org.junit.Test)

Aggregations

ShardingRuleConfiguration (io.shardingjdbc.core.api.config.ShardingRuleConfiguration)65 TableRuleConfiguration (io.shardingjdbc.core.api.config.TableRuleConfiguration)43 Test (org.junit.Test)41 ShardingRule (io.shardingjdbc.core.rule.ShardingRule)16 NoneShardingStrategyConfiguration (io.shardingjdbc.core.api.config.strategy.NoneShardingStrategyConfiguration)15 ComplexShardingStrategyConfiguration (io.shardingjdbc.core.api.config.strategy.ComplexShardingStrategyConfiguration)8 StandardShardingStrategyConfiguration (io.shardingjdbc.core.api.config.strategy.StandardShardingStrategyConfiguration)7 ShardingDataSource (io.shardingjdbc.core.jdbc.core.datasource.ShardingDataSource)7 DatabaseType (io.shardingjdbc.core.constant.DatabaseType)6 LinkedList (java.util.LinkedList)6 Map (java.util.Map)6 DataSource (javax.sql.DataSource)6 SQLShardingRule (io.shardingjdbc.core.integrate.jaxb.SQLShardingRule)5 Column (io.shardingjdbc.core.parsing.parser.context.condition.Column)5 NoneShardingStrategy (io.shardingjdbc.core.routing.strategy.none.NoneShardingStrategy)5 Before (org.junit.Before)5 TestComplexKeysShardingAlgorithm (io.shardingjdbc.core.api.algorithm.fixture.TestComplexKeysShardingAlgorithm)4 HintShardingStrategyConfiguration (io.shardingjdbc.core.api.config.strategy.HintShardingStrategyConfiguration)3 ComplexKeysModuloDatabaseShardingAlgorithm (io.shardingjdbc.core.integrate.fixture.ComplexKeysModuloDatabaseShardingAlgorithm)3 TestPreciseShardingAlgorithm (io.shardingjdbc.core.api.algorithm.fixture.TestPreciseShardingAlgorithm)2