use of io.mycat.config.model.SystemConfig in project Mycat_plus by coderczp.
the class DruidMysqlRouteStrategyTest method testNonPartitionSQL.
public void testNonPartitionSQL() throws Exception {
SchemaConfig schema = schemaMap.get("cndb");
String sql = null;
RouteResultset rrs = null;
schema = schemaMap.get("dubbo2");
sql = "SHOW TABLES from db_name like 'solo'";
rrs = routeStrategy.route(new SystemConfig(), schema, 9, sql, null, null, cachePool);
Assert.assertEquals(false, rrs.isCacheAble());
Assert.assertEquals(-1L, rrs.getLimitSize());
Assert.assertEquals(1, rrs.getNodes().length);
Assert.assertEquals("dn1", rrs.getNodes()[0].getName());
Assert.assertEquals("SHOW TABLES like 'solo'", rrs.getNodes()[0].getStatement());
schema = schemaMap.get("dubbo");
sql = "SHOW TABLES from db_name like 'solo'";
rrs = routeStrategy.route(new SystemConfig(), schema, 9, sql, null, null, cachePool);
Assert.assertEquals(false, rrs.isCacheAble());
Assert.assertEquals(-1L, rrs.getLimitSize());
Assert.assertEquals(1, rrs.getNodes().length);
Assert.assertEquals("dubbo_dn", rrs.getNodes()[0].getName());
Assert.assertEquals("SHOW TABLES like 'solo'", rrs.getNodes()[0].getStatement());
sql = "desc cndb.offer";
rrs = routeStrategy.route(new SystemConfig(), schema, 1, sql, null, null, cachePool);
Assert.assertEquals(false, rrs.isCacheAble());
Assert.assertEquals(-1L, rrs.getLimitSize());
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 = routeStrategy.route(new SystemConfig(), schema, 9, sql, null, null, cachePool);
Assert.assertEquals(false, rrs.isCacheAble());
Map<String, RouteResultsetNode> nodeMap = getNodeMap(rrs, 3);
NodeNameAsserter nameAsserter = new NodeNameAsserter("detail_dn0", "offer_dn0", "independent_dn0");
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 io.mycat.config.model.SystemConfig in project Mycat_plus by coderczp.
the class DruidMysqlRouteStrategyTest method testGroupLimit.
public void testGroupLimit() throws Exception {
final SchemaConfig schema = schemaMap.get("cndb");
String sql = null;
RouteResultset rrs = null;
sql = "select count(*) from (select * from(select * from offer_detail where offer_id='123' or offer_id='234' limit 88)offer where offer.member_id='abc' limit 60) w " + " where w.member_id ='pavarotti17' limit 99";
rrs = routeStrategy.route(new SystemConfig(), schema, 1, sql, null, null, cachePool);
Assert.assertEquals(true, rrs.isCacheAble());
// Assert.assertEquals(88L, rrs.getLimitSize());
// Assert.assertEquals(RouteResultset.SUM_FLAG, rrs.getFlag());
Map<String, RouteResultsetNode> nodeMap = getNodeMap(rrs, 2);
NodeNameAsserter nameAsserter = new NodeNameAsserter("detail_dn29", "detail_dn15");
nameAsserter.assertRouteNodeNames(nodeMap.keySet());
sql = "select count(*) from (select * from(select max(id) from offer_detail where offer_id='123' or offer_id='234' limit 88)offer where offer.member_id='abc' limit 60) w " + " where w.member_id ='pavarotti17' limit 99";
rrs = routeStrategy.route(new SystemConfig(), schema, 1, sql, null, null, cachePool);
Assert.assertEquals(true, rrs.isCacheAble());
nodeMap = getNodeMap(rrs, 2);
nameAsserter = new NodeNameAsserter("detail_dn29", "detail_dn15");
nameAsserter.assertRouteNodeNames(nodeMap.keySet());
sql = "select * from (select * from(select max(id) from offer_detail where offer_id='123' or offer_id='234' limit 88)offer where offer.member_id='abc' limit 60) w " + " where w.member_id ='pavarotti17' limit 99";
rrs = routeStrategy.route(new SystemConfig(), schema, 1, sql, null, null, cachePool);
Assert.assertEquals(true, rrs.isCacheAble());
nodeMap = getNodeMap(rrs, 2);
nameAsserter = new NodeNameAsserter("detail_dn29", "detail_dn15");
nameAsserter.assertRouteNodeNames(nodeMap.keySet());
sql = "select * from (select count(*) from(select * from offer_detail where offer_id='123' or offer_id='234' limit 88)offer where offer.member_id='abc' limit 60) w " + " where w.member_id ='pavarotti17' limit 99";
rrs = routeStrategy.route(new SystemConfig(), schema, 1, sql, null, null, cachePool);
Assert.assertEquals(true, rrs.isCacheAble());
// Assert.assertEquals(88L, rrs.getLimitSize());
// Assert.assertEquals(RouteResultset.SUM_FLAG, rrs.getFlag());
nodeMap = getNodeMap(rrs, 2);
nameAsserter = new NodeNameAsserter("detail_dn29", "detail_dn15");
nameAsserter.assertRouteNodeNames(nodeMap.keySet());
}
use of io.mycat.config.model.SystemConfig in project Mycat_plus by coderczp.
the class DruidMysqlRouteStrategyTest method testAggregateExpr.
/**
* 测试函数COUNT
*
* @throws Exception
*/
@Test
public void testAggregateExpr() throws Exception {
SchemaConfig schema = schemaMap.get("TESTDB");
String sql = "select id, name, count(name) from employee group by name;";
RouteResultset rrs = routeStrategy.route(new SystemConfig(), schema, ServerParse.SELECT, sql, null, null, cachePool);
Assert.assertTrue(rrs.getMergeCols().containsKey("COUNT2"));
sql = "select id, name, count(name) as c from employee group by name;";
rrs = routeStrategy.route(new SystemConfig(), schema, ServerParse.SELECT, sql, null, null, cachePool);
Assert.assertTrue(rrs.getMergeCols().containsKey("c"));
sql = "select id, name, count(name) c from employee group by name;";
rrs = routeStrategy.route(new SystemConfig(), schema, ServerParse.SELECT, sql, null, null, cachePool);
Assert.assertTrue(rrs.getMergeCols().containsKey("c"));
}
use of io.mycat.config.model.SystemConfig in project Mycat_plus by coderczp.
the class DruidMysqlRouteStrategyTest method testMultiLevelOr.
/**
* 测试多层or语句
*
* @throws Exception
*/
@Test
public void testMultiLevelOr() throws Exception {
SchemaConfig schema = schemaMap.get("TESTDB");
String sql = "select id from travelrecord " + " where id = 1 and ( fee=3 or days=5 or (traveldate = '2015-05-04 00:00:07.375' " + " and (user_id=2 or fee=days or fee = 0))) and name = 'zhangsan'";
RouteResultset rrs = routeStrategy.route(new SystemConfig(), schema, ServerParse.SELECT, sql, null, null, cachePool);
Assert.assertTrue(rrs.getNodes().length == 1);
sql = "select id from travelrecord " + " where id = 1 and ( fee=3 or days=5 or (traveldate = '2015-05-04 00:00:07.375' " + " and (user_id=2 or fee=days or fee = 0))) and name = 'zhangsan' or id = 2000001";
rrs = routeStrategy.route(new SystemConfig(), schema, ServerParse.SELECT, sql, null, null, cachePool);
Assert.assertTrue(rrs.getNodes().length == 2);
sql = "select id from travelrecord " + " where id = 1 and ( fee=3 or days=5 or (traveldate = '2015-05-04 00:00:07.375' " + " and (user_id=2 or fee=days or fee = 0))) and name = 'zhangsan' or id = 2000001 or id = 4000001";
rrs = routeStrategy.route(new SystemConfig(), schema, ServerParse.SELECT, sql, null, null, cachePool);
Assert.assertTrue(rrs.getNodes().length == 3);
}
use of io.mycat.config.model.SystemConfig in project Mycat_plus by coderczp.
the class DruidMysqlRouteStrategyTest method testMoreGlobalTableroute.
public void testMoreGlobalTableroute() throws Exception {
String sql = null;
SchemaConfig schema = schemaMap.get("TESTDB");
RouteResultset rrs = null;
// select of global table route to only one datanode defined
sql = "select * from company,area where area.company_id=company.id ";
schema = schemaMap.get("TESTDB");
rrs = routeStrategy.route(new SystemConfig(), schema, -1, sql, null, null, cachePool);
Assert.assertEquals(1, rrs.getNodes().length);
// 全局表涉及到多个节点时,不缓存路由结果
Assert.assertEquals(false, rrs.isCacheAble());
}
Aggregations