Search in sources :

Example 1 with ShardingKey

use of io.shardingjdbc.core.hint.ShardingKey in project sharding-jdbc by shardingjdbc.

the class HintManagerTest method assertAddTableShardingValueForIn.

@Test
public void assertAddTableShardingValueForIn() {
    try (HintManager hintManager = HintManager.getInstance()) {
        hintManager.addTableShardingValue("logicTable", "shardingColumn", ShardingOperator.IN, 1, 3, 5);
        ShardingKey shardingKey = new ShardingKey("logicTable", "shardingColumn");
        assertTrue(HintManagerHolder.getTableShardingValue(shardingKey).isPresent());
        assertThat(hintManager.getTableShardingValue(shardingKey).getColumnName(), is("shardingColumn"));
        assertThat(((ListShardingValue) hintManager.getTableShardingValue(shardingKey)).getValues().size(), is(3));
    }
}
Also used : ShardingKey(io.shardingjdbc.core.hint.ShardingKey) ListShardingValue(io.shardingjdbc.core.api.algorithm.sharding.ListShardingValue) Test(org.junit.Test)

Example 2 with ShardingKey

use of io.shardingjdbc.core.hint.ShardingKey in project sharding-jdbc by shardingjdbc.

the class HintManagerTest method assertAddDatabaseShardingValueForEquals.

@Test
public void assertAddDatabaseShardingValueForEquals() {
    try (HintManager hintManager = HintManager.getInstance()) {
        hintManager.addDatabaseShardingValue("logicTable", "shardingColumn", 1);
        ShardingKey shardingKey = new ShardingKey("logicTable", "shardingColumn");
        assertTrue(HintManagerHolder.getDatabaseShardingValue(shardingKey).isPresent());
        assertThat(hintManager.getDatabaseShardingValue(shardingKey).getColumnName(), is("shardingColumn"));
        assertThat(((ListShardingValue<? extends Comparable>) hintManager.getDatabaseShardingValue(shardingKey)).getValues().iterator().next(), is((Comparable) 1));
    }
}
Also used : ShardingKey(io.shardingjdbc.core.hint.ShardingKey) Test(org.junit.Test)

Example 3 with ShardingKey

use of io.shardingjdbc.core.hint.ShardingKey in project sharding-jdbc by shardingjdbc.

the class HintManagerTest method assertAddTableShardingValueForBetween.

@Test
public void assertAddTableShardingValueForBetween() {
    try (HintManager hintManager = HintManager.getInstance()) {
        hintManager.addTableShardingValue("logicTable", "shardingColumn", ShardingOperator.BETWEEN, 1, 10);
        ShardingKey shardingKey = new ShardingKey("logicTable", "shardingColumn");
        assertTrue(HintManagerHolder.getTableShardingValue(shardingKey).isPresent());
        assertThat(hintManager.getTableShardingValue(shardingKey).getColumnName(), is("shardingColumn"));
        assertThat(((RangeShardingValue) hintManager.getTableShardingValue(shardingKey)).getValueRange().lowerEndpoint(), is((Comparable) 1));
        assertThat(((RangeShardingValue) hintManager.getTableShardingValue(shardingKey)).getValueRange().upperEndpoint(), is((Comparable) 10));
    }
}
Also used : RangeShardingValue(io.shardingjdbc.core.api.algorithm.sharding.RangeShardingValue) ShardingKey(io.shardingjdbc.core.hint.ShardingKey) Test(org.junit.Test)

Example 4 with ShardingKey

use of io.shardingjdbc.core.hint.ShardingKey in project sharding-jdbc by shardingjdbc.

the class HintManagerTest method assertAddDatabaseShardingValueForBetween.

@Test
public void assertAddDatabaseShardingValueForBetween() {
    try (HintManager hintManager = HintManager.getInstance()) {
        hintManager.addDatabaseShardingValue("logicTable", "shardingColumn", ShardingOperator.BETWEEN, 1, 10);
        ShardingKey shardingKey = new ShardingKey("logicTable", "shardingColumn");
        assertTrue(HintManagerHolder.getDatabaseShardingValue(shardingKey).isPresent());
        assertThat(hintManager.getDatabaseShardingValue(shardingKey).getColumnName(), is("shardingColumn"));
        assertThat(((RangeShardingValue) hintManager.getDatabaseShardingValue(shardingKey)).getValueRange().lowerEndpoint(), is((Comparable) 1));
        assertThat(((RangeShardingValue) hintManager.getDatabaseShardingValue(shardingKey)).getValueRange().upperEndpoint(), is((Comparable) 10));
    }
}
Also used : RangeShardingValue(io.shardingjdbc.core.api.algorithm.sharding.RangeShardingValue) ShardingKey(io.shardingjdbc.core.hint.ShardingKey) Test(org.junit.Test)

Example 5 with ShardingKey

use of io.shardingjdbc.core.hint.ShardingKey in project sharding-jdbc by shardingjdbc.

the class HintManagerTest method assertAddDatabaseShardingValueForIn.

@Test
public void assertAddDatabaseShardingValueForIn() {
    try (HintManager hintManager = HintManager.getInstance()) {
        hintManager.addDatabaseShardingValue("logicTable", "shardingColumn", ShardingOperator.IN, 1, 3, 5);
        ShardingKey shardingKey = new ShardingKey("logicTable", "shardingColumn");
        assertTrue(HintManagerHolder.getDatabaseShardingValue(shardingKey).isPresent());
        assertThat(hintManager.getDatabaseShardingValue(shardingKey).getColumnName(), is("shardingColumn"));
        assertThat(((ListShardingValue) hintManager.getDatabaseShardingValue(shardingKey)).getValues().size(), is(3));
    }
}
Also used : ShardingKey(io.shardingjdbc.core.hint.ShardingKey) ListShardingValue(io.shardingjdbc.core.api.algorithm.sharding.ListShardingValue) Test(org.junit.Test)

Aggregations

ShardingKey (io.shardingjdbc.core.hint.ShardingKey)9 Test (org.junit.Test)6 ListShardingValue (io.shardingjdbc.core.api.algorithm.sharding.ListShardingValue)2 RangeShardingValue (io.shardingjdbc.core.api.algorithm.sharding.RangeShardingValue)2 ShardingValue (io.shardingjdbc.core.api.algorithm.sharding.ShardingValue)1 RoutingResult (io.shardingjdbc.core.routing.type.RoutingResult)1 TableUnit (io.shardingjdbc.core.routing.type.TableUnit)1