use of com.alibaba.cobar.config.model.SchemaConfig in project cobar by alibaba.
the class ServerRouteTest method testNonPartitionSQL.
public void testNonPartitionSQL() throws Exception {
SchemaConfig schema = schemaMap.get("cndb");
String sql = " select * from `dual`";
RouteResultset rrs = ServerRouter.route(schema, sql, null, null);
Assert.assertEquals(1, rrs.getNodes().length);
Assert.assertEquals((int) RouteResultsetNode.DEFAULT_REPLICA_INDEX, rrs.getNodes()[0].getReplicaIndex());
Assert.assertEquals("cndb_dn", rrs.getNodes()[0].getName());
Assert.assertEquals(" select * from `dual`", rrs.getNodes()[0].getStatement());
schema = schemaMap.get("dubbo");
sql = " select * from `dual`";
rrs = ServerRouter.route(schema, sql, null, null);
Assert.assertEquals(1, rrs.getNodes().length);
Assert.assertEquals((int) RouteResultsetNode.DEFAULT_REPLICA_INDEX, rrs.getNodes()[0].getReplicaIndex());
Assert.assertEquals("dubbo_dn", rrs.getNodes()[0].getName());
Assert.assertEquals(" select * from `dual`", rrs.getNodes()[0].getStatement());
schema = schemaMap.get("dubbo");
sql = " select * from dubbo.`dual`";
rrs = ServerRouter.route(schema, sql, null, null);
Assert.assertEquals(1, rrs.getNodes().length);
Assert.assertEquals((int) RouteResultsetNode.DEFAULT_REPLICA_INDEX, rrs.getNodes()[0].getReplicaIndex());
Assert.assertEquals("dubbo_dn", rrs.getNodes()[0].getName());
Assert.assertEquals(" select * from dubbo.`dual`", rrs.getNodes()[0].getStatement());
sql = "SHOW TABLES from db_name like 'solo'";
rrs = ServerRouter.route(schema, sql, null, null);
Assert.assertEquals(-1L, rrs.getLimitSize());
Assert.assertEquals((int) RouteResultsetNode.DEFAULT_REPLICA_INDEX, rrs.getNodes()[0].getReplicaIndex());
Assert.assertEquals(1, rrs.getNodes().length);
Assert.assertEquals("dubbo_dn", rrs.getNodes()[0].getName());
Assert.assertEquals("SHOW TABLES from db_name like 'solo'", rrs.getNodes()[0].getStatement());
sql = "desc cndb.offer";
rrs = ServerRouter.route(schema, sql, null, null);
Assert.assertEquals(-1L, rrs.getLimitSize());
Assert.assertEquals((int) RouteResultsetNode.DEFAULT_REPLICA_INDEX, rrs.getNodes()[0].getReplicaIndex());
Assert.assertEquals(1, rrs.getNodes().length);
Assert.assertEquals("dubbo_dn", rrs.getNodes()[0].getName());
Assert.assertEquals("desc cndb.offer", rrs.getNodes()[0].getStatement());
schema = schemaMap.get("cndb");
sql = "SHOW fulL TaBLES from db_name like 'solo'";
rrs = ServerRouter.route(schema, sql, null, null);
Map<String, RouteResultsetNode> nodeMap = getNodeMap(rrs, 4);
NodeNameAsserter nameAsserter = new NodeNameAsserter("detail_dn[0]", "offer_dn[0]", "cndb_dn", "independent_dn[0]");
nameAsserter.assertRouteNodeNames(nodeMap.keySet());
SimpleSQLAsserter sqlAsserter = new SimpleSQLAsserter();
sqlAsserter.addExpectSQL(0, "SHOW FULL TABLES LIKE 'solo'").addExpectSQL(1, "SHOW FULL TABLES LIKE 'solo'").addExpectSQL(2, "SHOW FULL TABLES LIKE 'solo'").addExpectSQL(3, "SHOW FULL TABLES LIKE 'solo'");
RouteNodeAsserter asserter = new RouteNodeAsserter(nameAsserter, sqlAsserter);
for (RouteResultsetNode node : nodeMap.values()) {
asserter.assertNode(node);
}
}
use of com.alibaba.cobar.config.model.SchemaConfig in project cobar by alibaba.
the class ServerRoutePerformance method perf.
public void perf() throws Exception {
TestProvider provider;
provider = new InsertLongSQLGen();
provider = new InsertLongSQLGenShort();
provider = new SelectShort();
provider = new InsertLong();
provider = new SelectLongIn();
provider = new ShardingMultiTableSpace();
provider = new ShardingDefaultSpace();
provider = new ShardingTableSpace();
SchemaConfig schema = getSchema();
String sql = provider.getSql();
System.out.println(ServerRouter.route(schema, sql, null, null));
long start = System.currentTimeMillis();
provider.route(schema, 1, sql);
long end;
int loop = 200 * 10000;
start = System.currentTimeMillis();
provider.route(schema, loop, sql);
end = System.currentTimeMillis();
System.out.println((end - start) * 1000.0d / loop + " us");
}
Aggregations