Search in sources :

Example 51 with RouteResultset

use of io.mycat.route.RouteResultset in project Mycat-Server by MyCATApache.

the class DruidMysqlRouteStrategyTest method testBetweenExpr.

/**
     * 测试between语句的路由
     *
     * @throws Exception
     */
@Test
public void testBetweenExpr() throws Exception {
    //    	0-200M=0
    //    	200M1-400M=1
    //    	400M1-600M=2
    //    	600M1-800M=3
    //    	800M1-1000M=4
    SchemaConfig schema = schemaMap.get("TESTDB");
    String sql = "select * from customer where id between 1 and 5;";
    RouteResultset rrs = routeStrategy.route(new SystemConfig(), schema, ServerParse.SELECT, sql, null, null, cachePool);
    Assert.assertTrue(rrs.getNodes().length == 1);
    Assert.assertTrue(rrs.getNodes()[0].getName().equals("dn1"));
    sql = "select * from customer where id between 1 and 2000001;";
    rrs = routeStrategy.route(new SystemConfig(), schema, ServerParse.SELECT, sql, null, null, cachePool);
    Assert.assertTrue(rrs.getNodes().length == 2);
    sql = "select * from customer where id between 2000001 and 3000001;";
    rrs = routeStrategy.route(new SystemConfig(), schema, ServerParse.SELECT, sql, null, null, cachePool);
    Assert.assertTrue(rrs.getNodes().length == 1);
    Assert.assertTrue(rrs.getNodes()[0].getName().equals("dn2"));
    sql = "delete from customer where id between 2000001 and 3000001;";
    rrs = routeStrategy.route(new SystemConfig(), schema, ServerParse.SELECT, sql, null, null, cachePool);
    Assert.assertTrue(rrs.getNodes().length == 1);
    Assert.assertTrue(rrs.getNodes()[0].getName().equals("dn2"));
    sql = "update customer set name='newName' where id between 2000001 and 3000001;";
    rrs = routeStrategy.route(new SystemConfig(), schema, ServerParse.SELECT, sql, null, null, cachePool);
    Assert.assertTrue(rrs.getNodes().length == 1);
    Assert.assertTrue(rrs.getNodes()[0].getName().equals("dn2"));
}
Also used : SystemConfig(io.mycat.config.model.SystemConfig) SchemaConfig(io.mycat.config.model.SchemaConfig) RouteResultset(io.mycat.route.RouteResultset) Test(org.junit.Test)

Example 52 with RouteResultset

use of io.mycat.route.RouteResultset in project Mycat-Server by MyCATApache.

the class DruidMysqlRouteStrategyTest method testGlobalTableOr.

/**
     * 测试 global table 的or语句
     * 
     *
     * @throws Exception
     */
@Test
public void testGlobalTableOr() throws Exception {
    SchemaConfig schema = schemaMap.get("TESTDB");
    String sql = "select id from company where 1 = 1 and name ='company1' or name = 'company2'";
    for (int i = 0; i < 20; i++) {
        RouteResultset rrs = routeStrategy.route(new SystemConfig(), schema, ServerParse.SELECT, sql, null, null, cachePool);
        Assert.assertTrue(rrs.getNodes().length == 1);
    }
}
Also used : SystemConfig(io.mycat.config.model.SystemConfig) SchemaConfig(io.mycat.config.model.SchemaConfig) RouteResultset(io.mycat.route.RouteResultset) Test(org.junit.Test)

Aggregations

RouteResultset (io.mycat.route.RouteResultset)52 SchemaConfig (io.mycat.config.model.SchemaConfig)34 SystemConfig (io.mycat.config.model.SystemConfig)32 RouteResultsetNode (io.mycat.route.RouteResultsetNode)15 Test (org.junit.Test)13 SQLNonTransientException (java.sql.SQLNonTransientException)11 MySqlStatementParser (com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)7 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)6 TableConfig (io.mycat.config.model.TableConfig)6 CacheService (io.mycat.cache.CacheService)4 RouteService (io.mycat.route.RouteService)4 ByteBuffer (java.nio.ByteBuffer)4 ArrayList (java.util.ArrayList)4 NoSuchElementException (java.util.NoSuchElementException)4 SQLStatementParser (com.alibaba.druid.sql.parser.SQLStatementParser)3 DruidShardingParseInfo (io.mycat.route.parser.druid.DruidShardingParseInfo)3 RouteCalculateUnit (io.mycat.route.parser.druid.RouteCalculateUnit)3 TreeSet (java.util.TreeSet)3 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)2 MySqlInsertStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlInsertStatement)2