Search in sources :

Example 11 with TestQueryResult

use of io.shardingjdbc.core.merger.fixture.TestQueryResult in project sharding-jdbc by shardingjdbc.

the class ShowTablesMergedResultTest method setUp.

@Before
public void setUp() throws SQLException {
    TableRuleConfiguration tableRuleConfig = new TableRuleConfiguration();
    tableRuleConfig.setLogicTable("table");
    tableRuleConfig.setActualDataNodes("ds.table_${0..2}");
    tableRuleConfig.setTableShardingStrategyConfig(new ComplexShardingStrategyConfiguration("field1, field2, field3", new TestComplexKeysShardingAlgorithm()));
    ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
    shardingRuleConfig.getTableRuleConfigs().add(tableRuleConfig);
    shardingRule = new ShardingRule(shardingRuleConfig, Lists.newArrayList("ds"));
    resultSet = mock(ResultSet.class);
    ResultSetMetaData resultSetMetaData = mock(ResultSetMetaData.class);
    when(resultSet.getMetaData()).thenReturn(resultSetMetaData);
    when(resultSetMetaData.getColumnCount()).thenReturn(1);
    List<ResultSet> resultSets = Lists.newArrayList(resultSet);
    for (ResultSet each : resultSets) {
        when(each.next()).thenReturn(true, false);
    }
    queryResults = new ArrayList<>(resultSets.size());
    for (ResultSet each : resultSets) {
        queryResults.add(new TestQueryResult(each));
    }
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) TestQueryResult(io.shardingjdbc.core.merger.fixture.TestQueryResult) ShardingRuleConfiguration(io.shardingjdbc.core.api.config.ShardingRuleConfiguration) ComplexShardingStrategyConfiguration(io.shardingjdbc.core.api.config.strategy.ComplexShardingStrategyConfiguration) ResultSet(java.sql.ResultSet) ShardingRule(io.shardingjdbc.core.rule.ShardingRule) TestComplexKeysShardingAlgorithm(io.shardingjdbc.core.api.algorithm.fixture.TestComplexKeysShardingAlgorithm) TableRuleConfiguration(io.shardingjdbc.core.api.config.TableRuleConfiguration) Before(org.junit.Before)

Example 12 with TestQueryResult

use of io.shardingjdbc.core.merger.fixture.TestQueryResult in project sharding-jdbc by shardingjdbc.

the class DQLMergeEngineTest method setUp.

@Before
public void setUp() throws SQLException {
    ResultSet resultSet = mock(ResultSet.class);
    when(resultSet.getObject(1)).thenReturn(0);
    ResultSetMetaData resultSetMetaData = mock(ResultSetMetaData.class);
    when(resultSet.getMetaData()).thenReturn(resultSetMetaData);
    when(resultSetMetaData.getColumnCount()).thenReturn(1);
    when(resultSetMetaData.getColumnLabel(1)).thenReturn("count(*)");
    queryResults = Collections.<QueryResult>singletonList(new TestQueryResult(resultSet));
    selectStatement = new SelectStatement();
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) TestQueryResult(io.shardingjdbc.core.merger.fixture.TestQueryResult) SelectStatement(io.shardingjdbc.core.parsing.parser.sql.dql.select.SelectStatement) ResultSet(java.sql.ResultSet) Before(org.junit.Before)

Example 13 with TestQueryResult

use of io.shardingjdbc.core.merger.fixture.TestQueryResult in project sharding-jdbc by shardingjdbc.

the class GroupByValueTest method assertGetGroupByValues.

@Test
public void assertGetGroupByValues() throws SQLException {
    List<?> actual = new GroupByValue(new TestQueryResult(resultSet), Arrays.asList(new OrderItem(1, OrderDirection.ASC, OrderDirection.ASC), new OrderItem(3, OrderDirection.DESC, OrderDirection.ASC))).getGroupValues();
    List<?> expected = Arrays.asList("1", "3");
    assertTrue(actual.equals(expected));
}
Also used : TestQueryResult(io.shardingjdbc.core.merger.fixture.TestQueryResult) OrderItem(io.shardingjdbc.core.parsing.parser.context.OrderItem) Test(org.junit.Test)

Example 14 with TestQueryResult

use of io.shardingjdbc.core.merger.fixture.TestQueryResult in project sharding-jdbc by shardingjdbc.

the class GroupByValueTest method assertGroupByValueNotEquals.

@Test
public void assertGroupByValueNotEquals() throws SQLException {
    GroupByValue groupByValue1 = new GroupByValue(new TestQueryResult(resultSet), Arrays.asList(new OrderItem(1, OrderDirection.ASC, OrderDirection.ASC), new OrderItem(3, OrderDirection.DESC, OrderDirection.ASC)));
    GroupByValue groupByValue2 = new GroupByValue(new TestQueryResult(resultSet), Arrays.asList(new OrderItem(3, OrderDirection.ASC, OrderDirection.ASC), new OrderItem(1, OrderDirection.DESC, OrderDirection.ASC)));
    assertFalse(groupByValue1.equals(groupByValue2));
    assertFalse(groupByValue1.hashCode() == groupByValue2.hashCode());
}
Also used : TestQueryResult(io.shardingjdbc.core.merger.fixture.TestQueryResult) OrderItem(io.shardingjdbc.core.parsing.parser.context.OrderItem) Test(org.junit.Test)

Example 15 with TestQueryResult

use of io.shardingjdbc.core.merger.fixture.TestQueryResult in project sharding-jdbc by shardingjdbc.

the class IteratorStreamMergedResultTest method assertNextForMix.

@Test
public void assertNextForMix() throws SQLException {
    queryResults.add(new TestQueryResult(mock(ResultSet.class)));
    queryResults.add(new TestQueryResult(mock(ResultSet.class)));
    queryResults.add(new TestQueryResult(mock(ResultSet.class)));
    when(queryResults.get(1).next()).thenReturn(true, false);
    when(queryResults.get(3).next()).thenReturn(true, false);
    when(queryResults.get(5).next()).thenReturn(true, false);
    mergeEngine = new DQLMergeEngine(queryResults, selectStatement);
    MergedResult actual = mergeEngine.merge();
    assertTrue(actual.next());
    assertTrue(actual.next());
    assertTrue(actual.next());
    assertFalse(actual.next());
}
Also used : TestQueryResult(io.shardingjdbc.core.merger.fixture.TestQueryResult) MergedResult(io.shardingjdbc.core.merger.MergedResult) DQLMergeEngine(io.shardingjdbc.core.merger.dql.DQLMergeEngine) Test(org.junit.Test)

Aggregations

TestQueryResult (io.shardingjdbc.core.merger.fixture.TestQueryResult)22 Before (org.junit.Before)14 ResultSet (java.sql.ResultSet)13 ResultSetMetaData (java.sql.ResultSetMetaData)11 OrderItem (io.shardingjdbc.core.parsing.parser.context.OrderItem)9 SelectStatement (io.shardingjdbc.core.parsing.parser.sql.dql.select.SelectStatement)8 Test (org.junit.Test)7 TestComplexKeysShardingAlgorithm (io.shardingjdbc.core.api.algorithm.fixture.TestComplexKeysShardingAlgorithm)2 ShardingRuleConfiguration (io.shardingjdbc.core.api.config.ShardingRuleConfiguration)2 TableRuleConfiguration (io.shardingjdbc.core.api.config.TableRuleConfiguration)2 ComplexShardingStrategyConfiguration (io.shardingjdbc.core.api.config.strategy.ComplexShardingStrategyConfiguration)2 AggregationSelectItem (io.shardingjdbc.core.parsing.parser.context.selectitem.AggregationSelectItem)2 ShardingRule (io.shardingjdbc.core.rule.ShardingRule)2 MergedResult (io.shardingjdbc.core.merger.MergedResult)1 DQLMergeEngine (io.shardingjdbc.core.merger.dql.DQLMergeEngine)1 TestStreamMergedResult (io.shardingjdbc.core.merger.dql.common.fixture.TestStreamMergedResult)1