Search in sources :

Example 66 with SystemConfig

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);
    }
}
Also used : SystemConfig(io.mycat.config.model.SystemConfig) SchemaConfig(io.mycat.config.model.SchemaConfig) RouteResultsetNode(io.mycat.route.RouteResultsetNode) RouteResultset(io.mycat.route.RouteResultset)

Example 67 with SystemConfig

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());
}
Also used : SystemConfig(io.mycat.config.model.SystemConfig) SchemaConfig(io.mycat.config.model.SchemaConfig) RouteResultsetNode(io.mycat.route.RouteResultsetNode) RouteResultset(io.mycat.route.RouteResultset)

Example 68 with SystemConfig

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"));
}
Also used : SystemConfig(io.mycat.config.model.SystemConfig) SchemaConfig(io.mycat.config.model.SchemaConfig) RouteResultset(io.mycat.route.RouteResultset) Test(org.junit.Test)

Example 69 with SystemConfig

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);
}
Also used : SystemConfig(io.mycat.config.model.SystemConfig) SchemaConfig(io.mycat.config.model.SchemaConfig) RouteResultset(io.mycat.route.RouteResultset) Test(org.junit.Test)

Example 70 with SystemConfig

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());
}
Also used : SystemConfig(io.mycat.config.model.SystemConfig) SchemaConfig(io.mycat.config.model.SchemaConfig) RouteResultset(io.mycat.route.RouteResultset)

Aggregations

SystemConfig (io.mycat.config.model.SystemConfig)120 SchemaConfig (io.mycat.config.model.SchemaConfig)110 RouteResultset (io.mycat.route.RouteResultset)64 Test (org.junit.Test)60 RouteResultsetNode (io.mycat.route.RouteResultsetNode)14 CacheService (io.mycat.cache.CacheService)10 SQLNonTransientException (java.sql.SQLNonTransientException)10 NoSuchElementException (java.util.NoSuchElementException)10 RouteService (io.mycat.route.RouteService)8 ArrayList (java.util.ArrayList)8 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)6 MySqlStatementParser (com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)6 TableConfig (io.mycat.config.model.TableConfig)6 PhysicalDBPool (io.mycat.backend.datasource.PhysicalDBPool)2 DirectByteBufferPool (io.mycat.buffer.DirectByteBufferPool)2 NettyBufferPool (io.mycat.buffer.NettyBufferPool)2 MycatConfig (io.mycat.config.MycatConfig)2 ManagerConnectionFactory (io.mycat.manager.ManagerConnectionFactory)2 MyCatMemory (io.mycat.memory.MyCatMemory)2 AIOAcceptor (io.mycat.net.AIOAcceptor)2