Search in sources :

Example 6 with ShardingRuleConfiguration

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

the class ShardingRuleTest method assertGetTableShardingStrategyFromTableRule.

@Test
public void assertGetTableShardingStrategyFromTableRule() {
    ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
    TableRuleConfiguration tableRuleConfig = createTableRuleConfigWithTableShardingStrategy(new NoneShardingStrategyConfiguration());
    shardingRuleConfig.getTableRuleConfigs().add(tableRuleConfig);
    ShardingRule actual = new ShardingRule(shardingRuleConfig, createDataSourceNames());
    assertThat(actual.getDatabaseShardingStrategy(actual.getTableRule("logic_Table")), instanceOf(NoneShardingStrategy.class));
}
Also used : NoneShardingStrategyConfiguration(io.shardingjdbc.core.api.config.strategy.NoneShardingStrategyConfiguration) ShardingRuleConfiguration(io.shardingjdbc.core.api.config.ShardingRuleConfiguration) NoneShardingStrategy(io.shardingjdbc.core.routing.strategy.none.NoneShardingStrategy) TableRuleConfiguration(io.shardingjdbc.core.api.config.TableRuleConfiguration) Test(org.junit.Test)

Example 7 with ShardingRuleConfiguration

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

the class ShardingRuleTest method assertDataSourceNameFromDefaultDataSourceName.

@Test
public void assertDataSourceNameFromDefaultDataSourceName() {
    ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
    shardingRuleConfig.setDefaultDataSourceName("ds3");
    ShardingRule actual = new ShardingRule(shardingRuleConfig, createDataSourceNames());
    assertThat(actual.getDefaultDataSourceName(), is("ds3"));
}
Also used : ShardingRuleConfiguration(io.shardingjdbc.core.api.config.ShardingRuleConfiguration) Test(org.junit.Test)

Example 8 with ShardingRuleConfiguration

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

the class ShardingRuleTest method assertGetDatabaseShardingStrategyFromTableRule.

@Test
public void assertGetDatabaseShardingStrategyFromTableRule() {
    ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
    TableRuleConfiguration tableRuleConfig = createTableRuleConfigWithDatabaseShardingStrategy(new NoneShardingStrategyConfiguration());
    shardingRuleConfig.getTableRuleConfigs().add(tableRuleConfig);
    ShardingRule actual = new ShardingRule(shardingRuleConfig, createDataSourceNames());
    assertThat(actual.getDatabaseShardingStrategy(actual.getTableRule("logic_Table")), instanceOf(NoneShardingStrategy.class));
}
Also used : NoneShardingStrategyConfiguration(io.shardingjdbc.core.api.config.strategy.NoneShardingStrategyConfiguration) ShardingRuleConfiguration(io.shardingjdbc.core.api.config.ShardingRuleConfiguration) NoneShardingStrategy(io.shardingjdbc.core.routing.strategy.none.NoneShardingStrategy) TableRuleConfiguration(io.shardingjdbc.core.api.config.TableRuleConfiguration) Test(org.junit.Test)

Example 9 with ShardingRuleConfiguration

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

the class ShardingRuleTest method assertGetBindingTableRuleForFound.

@Test
public void assertGetBindingTableRuleForFound() {
    ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
    TableRuleConfiguration tableRuleConfig = createTableRuleConfig();
    TableRuleConfiguration subTableRuleConfig = createSubTableRuleConfig();
    shardingRuleConfig.getTableRuleConfigs().add(tableRuleConfig);
    shardingRuleConfig.getTableRuleConfigs().add(subTableRuleConfig);
    shardingRuleConfig.getBindingTableGroups().add(createTableRuleConfig().getLogicTable() + "," + createSubTableRuleConfig().getLogicTable());
    ShardingRule actual = new ShardingRule(shardingRuleConfig, createDataSourceNames());
    assertTrue(actual.findBindingTableRule("logic_Table").isPresent());
    assertThat(actual.findBindingTableRule("logic_Table").get().getTableRules().size(), is(2));
}
Also used : ShardingRuleConfiguration(io.shardingjdbc.core.api.config.ShardingRuleConfiguration) TableRuleConfiguration(io.shardingjdbc.core.api.config.TableRuleConfiguration) Test(org.junit.Test)

Example 10 with ShardingRuleConfiguration

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

the class ShardingRuleTest method assertFindDataNodeByLogicTableSuccess.

@Test
public void assertFindDataNodeByLogicTableSuccess() {
    ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
    TableRuleConfiguration tableRuleConfig = createTableRuleConfig();
    shardingRuleConfig.getTableRuleConfigs().add(tableRuleConfig);
    assertThat(new ShardingRule(shardingRuleConfig, createDataSourceNames()).findDataNodeByLogicTable("logic_table").getDataSourceName(), is("ds0"));
}
Also used : ShardingRuleConfiguration(io.shardingjdbc.core.api.config.ShardingRuleConfiguration) TableRuleConfiguration(io.shardingjdbc.core.api.config.TableRuleConfiguration) 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