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);
}
Aggregations