Search in sources :

Example 6 with MockResultSet

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

the class IteratorResultSetTest method assertNext.

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

Example 7 with MockResultSet

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

the class MemoryOrderByResultSetTest method assertSortMultiColumn.

@Test
public void assertSortMultiColumn() throws SQLException {
    Map<String, Object> rs1 = new LinkedHashMap<>();
    Calendar cal = Calendar.getInstance();
    cal.set(2016, Calendar.JANUARY, 11);
    rs1.put("name", "name");
    rs1.put("time", cal.getTime());
    rs1.put("id", 11);
    Map<String, Object> rs2 = new LinkedHashMap<>();
    cal.set(2016, Calendar.JANUARY, 9);
    rs2.put("name", "dbc");
    rs2.put("time", cal.getTime());
    rs2.put("id", 12);
    Map<String, Object> rs3 = new LinkedHashMap<>();
    cal.set(2016, Calendar.JANUARY, 8);
    rs3.put("name", "dbc");
    rs3.put("time", cal.getTime());
    rs3.put("id", 13);
    OrderByColumn orderByColumn1 = new OrderByColumn("name", OrderByColumn.OrderByType.ASC);
    orderByColumn1.setColumnIndex(1);
    OrderByColumn orderByColumn2 = new OrderByColumn("time", OrderByColumn.OrderByType.DESC);
    orderByColumn2.setColumnIndex(2);
    AbstractMemoryOrderByResultSet rs = new AbstractMemoryOrderByResultSet(Collections.<ResultSet>singletonList(new MockResultSet<>(Arrays.asList(rs1, rs2, rs3))), Arrays.asList(orderByColumn1, orderByColumn2)) {
    };
    List<Map<String, Object>> actualList = new ArrayList<>();
    while (rs.next()) {
        Map<String, Object> map = new TreeMap<>();
        map.put("name", rs.getObject("name"));
        map.put("time", rs.getObject("time"));
        map.put("id", rs.getObject("id"));
        actualList.add(map);
    }
    assertThat(actualList, is(Arrays.asList(rs2, rs3, rs1)));
}
Also used : Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) MockResultSet(com.dangdang.ddframe.rdb.sharding.merger.fixture.MockResultSet) TreeMap(java.util.TreeMap) OrderByColumn(com.dangdang.ddframe.rdb.sharding.parser.result.merger.OrderByColumn) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 8 with MockResultSet

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

the class MemoryResultSetTest method test.

@Test
public void test() throws SQLException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    MockResultSet mockResultSet = new MockResultSet<>(input);
    MockRowSetResultSet rs = new MockRowSetResultSet(mockResultSet);
    assertThat(rs.getStatement(), nullValue());
    assertThat(rs.getFetchSize(), is(1));
    assertThat(rs.getMetaData().getColumnCount(), is(1));
    assertThat(rs.getFetchDirection(), is(ResultSet.FETCH_FORWARD));
    assertThat(rs.getType(), is(ResultSet.TYPE_FORWARD_ONLY));
    assertThat(rs.getConcurrency(), is(ResultSet.CONCUR_READ_ONLY));
    rs.clearWarnings();
    assertThat(rs.getWarnings(), nullValue());
    assertThat(rs.next(), is(true));
    if (scale > 0) {
        assertThat(ResultSet.class.getMethod(methodName, int.class, int.class).invoke(rs, 1, scale), is(result));
        assertThat(ResultSet.class.getMethod(methodName, String.class, int.class).invoke(rs, "name", scale), is(result));
    } else if (null != cal) {
        assertThat(ResultSet.class.getMethod(methodName, int.class, Calendar.class).invoke(rs, 1, cal), is(result));
        assertThat(ResultSet.class.getMethod(methodName, String.class, Calendar.class).invoke(rs, "name", cal), is(result));
    } else {
        assertThat(ResultSet.class.getMethod(methodName, int.class).invoke(rs, 1), is(result));
        assertThat(ResultSet.class.getMethod(methodName, String.class).invoke(rs, "name"), is(result));
    }
    if (null == result || null == input) {
        assertThat(rs.wasNull(), is(true));
    } else {
        assertThat(rs.wasNull(), is(false));
    }
    assertThat(rs.next(), is(false));
    assertThat(rs.isClosed(), is(false));
    rs.close();
    assertThat(rs.isClosed(), is(true));
}
Also used : Calendar(java.util.Calendar) MockRowSetResultSet(com.dangdang.ddframe.rdb.sharding.jdbc.fixture.MockRowSetResultSet) MockRowSetResultSet(com.dangdang.ddframe.rdb.sharding.jdbc.fixture.MockRowSetResultSet) 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)

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