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));
}
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)));
}
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));
}
Aggregations