use of com.alibaba.cobar.parser.ast.expression.primary.RowExpression in project cobar by alibaba.
the class ServerRouteTest method testRouteInsertLong.
public void testRouteInsertLong() throws Exception {
StringBuilder sb = new StringBuilder("insert into offer_detail (offer_id, gmt) values ");
for (int i = 0; i < 1024; ++i) {
if (i > 0)
sb.append(", ");
sb.append("(" + i + ", now())");
}
SchemaConfig schema = schemaMap.get("cndb");
RouteResultset rrs = ServerRouter.route(schema, sb.toString(), null, null);
Assert.assertEquals(-1l, rrs.getLimitSize());
Map<String, RouteResultsetNode> nodeMap = getNodeMap(rrs, 128);
IndexedNodeNameAsserter nameAsserter = new IndexedNodeNameAsserter("detail_dn", 0, 128);
nameAsserter.assertRouteNodeNames(nodeMap.keySet());
RouteNodeAsserter asserter = new RouteNodeAsserter(nameAsserter, new ParseredSQLAsserter() {
@Override
protected void assertAST(SQLStatement stmt, int nodeIndex) {
DMLInsertStatement insert = (DMLInsertStatement) stmt;
List<RowExpression> rows = insert.getRowList();
Assert.assertNotNull(rows);
Assert.assertEquals(8, rows.size());
List<Integer> vals = new ArrayList<Integer>(8);
for (RowExpression row : rows) {
int val = ((Number) row.getRowExprList().get(0).evaluation(null)).intValue();
vals.add(val);
}
Assert.assertEquals(8, vals.size());
for (int i = 8 * nodeIndex; i < 8 * nodeIndex + 8; ++i) {
Assert.assertTrue(vals.contains(i));
}
}
});
for (RouteResultsetNode node : nodeMap.values()) {
asserter.assertNode(node);
}
}
Aggregations