Search in sources :

Example 26 with SchemaConfig

use of io.mycat.config.model.SchemaConfig in project Mycat-Server by MyCATApache.

the class DruidMysqlRouteStrategyTest method testGlobalTableSingleNodeLimit.

public void testGlobalTableSingleNodeLimit() throws Exception {
    SchemaConfig schema = schemaMap.get("TESTDB");
    String sql = "select * from globalsn";
    RouteResultset rrs = null;
    rrs = routeStrategy.route(new SystemConfig(), schema, ServerParse.SELECT, sql, null, null, cachePool);
    Assert.assertEquals(100L, rrs.getLimitSize());
}
Also used : SystemConfig(io.mycat.config.model.SystemConfig) SchemaConfig(io.mycat.config.model.SchemaConfig) RouteResultset(io.mycat.route.RouteResultset)

Example 27 with SchemaConfig

use of io.mycat.config.model.SchemaConfig in project Mycat-Server by MyCATApache.

the class DruidMysqlRouteStrategyTest method testAlias.

/**
     * 测试别名路由
     *
     * @throws Exception
     */
public void testAlias() throws Exception {
    SchemaConfig schema = schemaMap.get("TESTDB");
    RouteResultset rrs = null;
    //不支持childtable 批量插入
    //update 全局表
    String sql = "update company a set name = '' where a.id = 1;";
    rrs = routeStrategy.route(new SystemConfig(), schema, 1, sql, null, null, cachePool);
    Assert.assertEquals(3, rrs.getNodes().length);
    //update带别名时的路由
    sql = "update travelrecord a set name = '' where a.id = 1;";
    rrs = routeStrategy.route(new SystemConfig(), schema, 1, sql, null, null, cachePool);
    Assert.assertEquals(1, rrs.getNodes().length);
    //别名大小写路由
    sql = "select * from travelrecord A where a.id = 1;";
    rrs = routeStrategy.route(new SystemConfig(), schema, 1, sql, null, null, cachePool);
    Assert.assertEquals(1, rrs.getNodes().length);
}
Also used : SystemConfig(io.mycat.config.model.SystemConfig) SchemaConfig(io.mycat.config.model.SchemaConfig) RouteResultset(io.mycat.route.RouteResultset)

Example 28 with SchemaConfig

use of io.mycat.config.model.SchemaConfig in project Mycat-Server by MyCATApache.

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 29 with SchemaConfig

use of io.mycat.config.model.SchemaConfig in project Mycat-Server by MyCATApache.

the class DruidMysqlSqlParserTest method testLimitPage.

@Test
public void testLimitPage() throws SQLNonTransientException {
    String sql = "select * from offer order by id desc limit 5,10";
    SchemaConfig schema = schemaMap.get("mysqldb");
    RouteResultset rrs = routeStrategy.route(new SystemConfig(), schema, -1, sql, null, null, cachePool);
    Assert.assertEquals(2, rrs.getNodes().length);
    Assert.assertEquals(5, rrs.getLimitStart());
    Assert.assertEquals(10, rrs.getLimitSize());
    Assert.assertEquals(0, rrs.getNodes()[0].getLimitStart());
    Assert.assertEquals(15, rrs.getNodes()[0].getLimitSize());
    Assert.assertEquals("dn1", rrs.getNodes()[0].getName());
    Assert.assertEquals("dn2", rrs.getNodes()[1].getName());
    sql = rrs.getNodes()[0].getStatement();
    rrs = routeStrategy.route(new SystemConfig(), schema, -1, sql, null, null, cachePool);
    Assert.assertEquals(0, rrs.getNodes()[0].getLimitStart());
    Assert.assertEquals(15, rrs.getNodes()[0].getLimitSize());
    Assert.assertEquals(0, rrs.getLimitStart());
    Assert.assertEquals(15, rrs.getLimitSize());
    sql = "select * from offer1 order by id desc limit 5,10";
    rrs = routeStrategy.route(new SystemConfig(), schema, -1, sql, null, null, cachePool);
    Assert.assertEquals(1, rrs.getNodes().length);
    Assert.assertEquals(5, rrs.getLimitStart());
    Assert.assertEquals(10, rrs.getLimitSize());
    Assert.assertEquals(5, rrs.getNodes()[0].getLimitStart());
    Assert.assertEquals(10, rrs.getNodes()[0].getLimitSize());
    Assert.assertEquals("dn1", rrs.getNodes()[0].getName());
    sql = "select * from offer1 order by id desc limit 10";
    rrs = routeStrategy.route(new SystemConfig(), schema, -1, sql, null, null, cachePool);
    Assert.assertEquals(1, rrs.getNodes().length);
    Assert.assertEquals(0, rrs.getLimitStart());
    Assert.assertEquals(10, rrs.getLimitSize());
    Assert.assertEquals(0, rrs.getNodes()[0].getLimitStart());
    Assert.assertEquals(10, rrs.getNodes()[0].getLimitSize());
    Assert.assertEquals("dn1", rrs.getNodes()[0].getName());
}
Also used : SystemConfig(io.mycat.config.model.SystemConfig) SchemaConfig(io.mycat.config.model.SchemaConfig) Test(org.junit.Test)

Example 30 with SchemaConfig

use of io.mycat.config.model.SchemaConfig in project Mycat-Server by MyCATApache.

the class DruidOracleSqlParserTest method testInsertUpdate.

@Test
public void testInsertUpdate() throws Exception {
    SchemaConfig schema = schemaMap.get("oracledb");
    String sql = "insert into offer1(group_id,offer_id,member_id)values(234,123,'abc')";
    RouteResultset rrs = routeStrategy.route(new SystemConfig(), schema, -1, sql, null, null, cachePool);
    Assert.assertEquals(1, rrs.getNodes().length);
    Assert.assertEquals(false, rrs.isCacheAble());
    Assert.assertEquals(-1, rrs.getLimitSize());
    Assert.assertEquals(0, rrs.getNodes()[0].getLimitStart());
    Assert.assertEquals(-1, rrs.getNodes()[0].getLimitSize());
    Assert.assertEquals("d_oracle1", rrs.getNodes()[0].getName());
    Assert.assertEquals("insert into offer1(group_id,offer_id,member_id)values(234,123,'abc')", rrs.getNodes()[0].getStatement());
    sql = "update offer set name='x'";
    rrs = routeStrategy.route(new SystemConfig(), schema, -1, sql, null, null, cachePool);
    Assert.assertEquals(2, rrs.getNodes().length);
    Assert.assertEquals(-1, rrs.getLimitSize());
    Assert.assertEquals(false, rrs.isCacheAble());
    Assert.assertEquals(0, rrs.getNodes()[0].getLimitStart());
    Assert.assertEquals(-1, rrs.getNodes()[0].getLimitSize());
}
Also used : SystemConfig(io.mycat.config.model.SystemConfig) SchemaConfig(io.mycat.config.model.SchemaConfig) Test(org.junit.Test)

Aggregations

SchemaConfig (io.mycat.config.model.SchemaConfig)79 SystemConfig (io.mycat.config.model.SystemConfig)54 RouteResultset (io.mycat.route.RouteResultset)34 Test (org.junit.Test)31 TableConfig (io.mycat.config.model.TableConfig)12 MycatConfig (io.mycat.config.MycatConfig)9 RouteResultsetNode (io.mycat.route.RouteResultsetNode)7 SQLNonTransientException (java.sql.SQLNonTransientException)7 PhysicalDBNode (io.mycat.backend.datasource.PhysicalDBNode)6 RowDataPacket (io.mycat.net.mysql.RowDataPacket)6 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)5 MySqlStatementParser (com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)5 CacheService (io.mycat.cache.CacheService)5 MycatCluster (io.mycat.config.MycatCluster)5 UserConfig (io.mycat.config.model.UserConfig)5 ArrayList (java.util.ArrayList)5 NoSuchElementException (java.util.NoSuchElementException)5 EOFPacket (io.mycat.net.mysql.EOFPacket)4 FieldPacket (io.mycat.net.mysql.FieldPacket)4 RouteService (io.mycat.route.RouteService)4