Search in sources :

Example 6 with CacheService

use of io.mycat.cache.CacheService in project Mycat-Server by MyCATApache.

the class HintTest method testHint.

/**
     * 测试注解
     *
     * @throws Exception
     */
@Test
public void testHint() throws Exception {
    SchemaConfig schema = schemaMap.get("TESTDB");
    //使用注解(新注解,/*后面没有空格),路由到1个节点
    String sql = "/*!mycat: sql = select * from employee where sharding_id = 10010 */select * from employee";
    CacheService cacheService = new CacheService();
    RouteService routerService = new RouteService(cacheService);
    RouteResultset rrs = routerService.route(new SystemConfig(), schema, ServerParse.SELECT, sql, "UTF-8", null);
    Assert.assertTrue(rrs.getNodes().length == 1);
    //使用注解(新注解,/*后面有空格),路由到1个节点
    sql = "/*#mycat: sql = select * from employee where sharding_id = 10000 */select * from employee";
    rrs = routerService.route(new SystemConfig(), schema, ServerParse.SELECT, sql, "UTF-8", null);
    Assert.assertTrue(rrs.getNodes().length == 1);
    //不用注解,路由到2个节点
    sql = "select * from employee";
    rrs = routerService.route(new SystemConfig(), schema, ServerParse.SELECT, sql, "UTF-8", null);
    Assert.assertTrue(rrs.getNodes().length == 2);
}
Also used : SystemConfig(io.mycat.config.model.SystemConfig) SchemaConfig(io.mycat.config.model.SchemaConfig) RouteService(io.mycat.route.RouteService) CacheService(io.mycat.cache.CacheService) RouteResultset(io.mycat.route.RouteResultset) Test(org.junit.Test)

Aggregations

CacheService (io.mycat.cache.CacheService)6 SchemaConfig (io.mycat.config.model.SchemaConfig)5 SystemConfig (io.mycat.config.model.SystemConfig)5 Test (org.junit.Test)5 RouteResultset (io.mycat.route.RouteResultset)4 RouteService (io.mycat.route.RouteService)4 TableConfig (io.mycat.config.model.TableConfig)3 ArrayList (java.util.ArrayList)3 CachePool (io.mycat.cache.CachePool)1 CacheStatic (io.mycat.cache.CacheStatic)1 LayerCachePool (io.mycat.cache.LayerCachePool)1 EOFPacket (io.mycat.net.mysql.EOFPacket)1 FieldPacket (io.mycat.net.mysql.FieldPacket)1 RowDataPacket (io.mycat.net.mysql.RowDataPacket)1 ByteBuffer (java.nio.ByteBuffer)1 Map (java.util.Map)1