Search in sources :

Example 6 with TableRuleConfiguration

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

the class ShardingRuleTest method assertIsAllInDefaultDataSource.

@Test
public void assertIsAllInDefaultDataSource() {
    ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
    TableRuleConfiguration tableRuleConfig = createTableRuleConfig();
    shardingRuleConfig.getTableRuleConfigs().add(tableRuleConfig);
    ShardingRule actual = new ShardingRule(shardingRuleConfig, createDataSourceNames());
    assertTrue(actual.isAllInDefaultDataSource(Collections.singletonList("table_0")));
    assertFalse(actual.isAllInDefaultDataSource(Collections.singletonList("logic_table")));
}
Also used : ShardingRuleConfiguration(io.shardingjdbc.core.api.config.ShardingRuleConfiguration) TableRuleConfiguration(io.shardingjdbc.core.api.config.TableRuleConfiguration) Test(org.junit.Test)

Example 7 with TableRuleConfiguration

use of io.shardingjdbc.core.api.config.TableRuleConfiguration 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 8 with TableRuleConfiguration

use of io.shardingjdbc.core.api.config.TableRuleConfiguration 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 TableRuleConfiguration

use of io.shardingjdbc.core.api.config.TableRuleConfiguration 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 TableRuleConfiguration

use of io.shardingjdbc.core.api.config.TableRuleConfiguration 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

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