Search in sources :

Example 1 with MockResultSet

use of com.dangdang.ddframe.rdb.sharding.merger.fixture.MockResultSet in project sharding-jdbc by dangdangdotcom.

the class OrderByResultSetTest method assertNextForDesc.

@Test
public void assertNextForDesc() throws SQLException {
    ResultSet resultSet = ResultSetFactory.getResultSet(Arrays.<ResultSet>asList(new MockResultSet<>(4, 1), new MockResultSet<>(4, 2), new MockResultSet<Integer>()), createMergeContext(OrderByType.DESC));
    assertTrue(resultSet.next());
    assertThat(resultSet.getInt(1), is(4));
    assertTrue(resultSet.next());
    assertThat(resultSet.getInt(1), is(4));
    assertTrue(resultSet.next());
    assertThat(resultSet.getInt(1), is(2));
    assertTrue(resultSet.next());
    assertThat(resultSet.getInt(1), is(1));
    assertFalse(resultSet.next());
}
Also used : MockResultSet(com.dangdang.ddframe.rdb.sharding.merger.fixture.MockResultSet) ResultSet(java.sql.ResultSet) MockResultSet(com.dangdang.ddframe.rdb.sharding.merger.fixture.MockResultSet) Test(org.junit.Test)

Example 2 with MockResultSet

use of com.dangdang.ddframe.rdb.sharding.merger.fixture.MockResultSet in project sharding-jdbc by dangdangdotcom.

the class IteratorResultSetTest method assertNextWithLimitForPartData.

@Test
public void assertNextWithLimitForPartData() throws SQLException {
    MergeContext mergeContext = new MergeContext();
    mergeContext.setLimit(new Limit(1, 1, -1, -1));
    ResultSet resultSet = ResultSetFactory.getResultSet(Arrays.<ResultSet>asList(new MockResultSet<>(1), new MockResultSet<>(2, 4), new MockResultSet<Integer>()), mergeContext);
    int count = 0;
    while (resultSet.next()) {
        count++;
    }
    assertThat(count, is(1));
}
Also used : ResultSet(java.sql.ResultSet) MockResultSet(com.dangdang.ddframe.rdb.sharding.merger.fixture.MockResultSet) MergeContext(com.dangdang.ddframe.rdb.sharding.parser.result.merger.MergeContext) Limit(com.dangdang.ddframe.rdb.sharding.parser.result.merger.Limit) MockResultSet(com.dangdang.ddframe.rdb.sharding.merger.fixture.MockResultSet) Test(org.junit.Test)

Example 3 with MockResultSet

use of com.dangdang.ddframe.rdb.sharding.merger.fixture.MockResultSet in project sharding-jdbc by dangdangdotcom.

the class MemoryOrderByResultSetTest method assertSort.

@Test
public void assertSort() throws SQLException {
    AbstractMemoryOrderByResultSet rs = new AbstractMemoryOrderByResultSet(Arrays.<ResultSet>asList(new MockResultSet<>(1, 3, 5, 6, 6), new MockResultSet<>(8, 6, 4, 2)), Collections.singletonList(new OrderByColumn(1, OrderByColumn.OrderByType.ASC))) {
    };
    List<Integer> actualList = new ArrayList<>();
    while (rs.next()) {
        actualList.add(rs.getInt(1));
    }
    assertThat(actualList, is(Arrays.asList(1, 2, 3, 4, 5, 6, 6, 6, 8)));
    rs.close();
    assertThat(rs.isClosed(), is(true));
    rs = new AbstractMemoryOrderByResultSet(Arrays.<ResultSet>asList(new MockResultSet<>(1, 3, 5, 6, 6), new MockResultSet<>(8, 6, 4, 2)), Collections.singletonList(new OrderByColumn(1, OrderByColumn.OrderByType.DESC))) {
    };
    actualList.clear();
    while (rs.next()) {
        actualList.add(rs.getInt("nAmE"));
    }
    assertThat(actualList, is(Arrays.asList(8, 6, 6, 6, 5, 4, 3, 2, 1)));
}
Also used : ArrayList(java.util.ArrayList) MockResultSet(com.dangdang.ddframe.rdb.sharding.merger.fixture.MockResultSet) ResultSet(java.sql.ResultSet) MockResultSet(com.dangdang.ddframe.rdb.sharding.merger.fixture.MockResultSet) OrderByColumn(com.dangdang.ddframe.rdb.sharding.parser.result.merger.OrderByColumn) Test(org.junit.Test)

Example 4 with MockResultSet

use of com.dangdang.ddframe.rdb.sharding.merger.fixture.MockResultSet in project sharding-jdbc by dangdangdotcom.

the class OrderByResultSetTest method assertNextForAsc.

@Test
public void assertNextForAsc() throws SQLException {
    ResultSet resultSet = ResultSetFactory.getResultSet(Arrays.<ResultSet>asList(new MockResultSet<>(1, 4), new MockResultSet<>(2, 4), new MockResultSet<Integer>()), createMergeContext(OrderByType.ASC));
    assertTrue(resultSet.next());
    assertThat(resultSet.getInt(1), is(1));
    assertTrue(resultSet.next());
    assertThat(resultSet.getInt(1), is(2));
    assertTrue(resultSet.next());
    assertThat(resultSet.getInt(1), is(4));
    assertTrue(resultSet.next());
    assertThat(resultSet.getInt(1), is(4));
    assertFalse(resultSet.next());
}
Also used : MockResultSet(com.dangdang.ddframe.rdb.sharding.merger.fixture.MockResultSet) ResultSet(java.sql.ResultSet) MockResultSet(com.dangdang.ddframe.rdb.sharding.merger.fixture.MockResultSet) Test(org.junit.Test)

Example 5 with MockResultSet

use of com.dangdang.ddframe.rdb.sharding.merger.fixture.MockResultSet in project sharding-jdbc by dangdangdotcom.

the class IteratorResultSetTest method assertNextWithLimitForAllData.

@Test
public void assertNextWithLimitForAllData() throws SQLException {
    MergeContext mergeContext = new MergeContext();
    mergeContext.setLimit(new Limit(1, 10, -1, -1));
    ResultSet resultSet = ResultSetFactory.getResultSet(Arrays.<ResultSet>asList(new MockResultSet<>(1), new MockResultSet<>(2, 4), new MockResultSet<Integer>()), mergeContext);
    int count = 0;
    while (resultSet.next()) {
        count++;
    }
    assertThat(count, is(2));
}
Also used : ResultSet(java.sql.ResultSet) MockResultSet(com.dangdang.ddframe.rdb.sharding.merger.fixture.MockResultSet) MergeContext(com.dangdang.ddframe.rdb.sharding.parser.result.merger.MergeContext) Limit(com.dangdang.ddframe.rdb.sharding.parser.result.merger.Limit) MockResultSet(com.dangdang.ddframe.rdb.sharding.merger.fixture.MockResultSet) Test(org.junit.Test)

Aggregations

MockResultSet (com.dangdang.ddframe.rdb.sharding.merger.fixture.MockResultSet)8 Test (org.junit.Test)8 ResultSet (java.sql.ResultSet)7 MergeContext (com.dangdang.ddframe.rdb.sharding.parser.result.merger.MergeContext)3 Limit (com.dangdang.ddframe.rdb.sharding.parser.result.merger.Limit)2 OrderByColumn (com.dangdang.ddframe.rdb.sharding.parser.result.merger.OrderByColumn)2 ArrayList (java.util.ArrayList)2 Calendar (java.util.Calendar)2 MockRowSetResultSet (com.dangdang.ddframe.rdb.sharding.jdbc.fixture.MockRowSetResultSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1