Search in sources :

Example 51 with TableRuleConfiguration

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

the class ShardingRuleTest method assertGetLogicTableNameFailure.

@Test(expected = ShardingConfigurationException.class)
public void assertGetLogicTableNameFailure() {
    ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
    TableRuleConfiguration tableRuleConfig = createTableRuleConfigWithLogicIndex();
    shardingRuleConfig.getTableRuleConfigs().add(tableRuleConfig);
    new ShardingRule(shardingRuleConfig, createDataSourceNames()).getLogicTableName("");
}
Also used : ShardingRuleConfiguration(io.shardingjdbc.core.api.config.ShardingRuleConfiguration) TableRuleConfiguration(io.shardingjdbc.core.api.config.TableRuleConfiguration) Test(org.junit.Test)

Example 52 with TableRuleConfiguration

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

the class ShardingRuleTest method assertShardingRuleWithTableStrategy.

@Test
public void assertShardingRuleWithTableStrategy() {
    ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
    TableRuleConfiguration tableRuleConfig = createTableRuleConfig();
    shardingRuleConfig.getTableRuleConfigs().add(tableRuleConfig);
    shardingRuleConfig.setDefaultTableShardingStrategyConfig(new NoneShardingStrategyConfiguration());
    ShardingRule actual = new ShardingRule(shardingRuleConfig, createDataSourceNames());
    assertTrue(actual.getDefaultDatabaseShardingStrategy().getShardingColumns().isEmpty());
    assertTrue(actual.getDefaultDatabaseShardingStrategy().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 53 with TableRuleConfiguration

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

the class ShardingRuleTest method assertGetDatabaseShardingStrategyForNullValue.

@Test
public void assertGetDatabaseShardingStrategyForNullValue() {
    ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
    TableRuleConfiguration tableRuleConfig = createTableRuleConfig();
    shardingRuleConfig.getTableRuleConfigs().add(tableRuleConfig);
    shardingRuleConfig.setDefaultDatabaseShardingStrategyConfig(null);
    ShardingRule actual = new ShardingRule(shardingRuleConfig, createDataSourceNames());
    assertNotNull(actual.getDatabaseShardingStrategy(actual.getTableRule("logic_Table")));
}
Also used : ShardingRuleConfiguration(io.shardingjdbc.core.api.config.ShardingRuleConfiguration) TableRuleConfiguration(io.shardingjdbc.core.api.config.TableRuleConfiguration) Test(org.junit.Test)

Example 54 with TableRuleConfiguration

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

the class ShardingRuleTest method assertFindTableRuleByActualTable.

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

Example 55 with TableRuleConfiguration

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

the class ShardingRuleTest method assertGetLogicTableNameSuccess.

@Test
public void assertGetLogicTableNameSuccess() {
    ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
    TableRuleConfiguration tableRuleConfig = createTableRuleConfigWithLogicIndex();
    shardingRuleConfig.getTableRuleConfigs().add(tableRuleConfig);
    assertThat(new ShardingRule(shardingRuleConfig, createDataSourceNames()).getLogicTableName("index_table"), is("logic_table"));
}
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