use of io.mycat.config.model.SchemaConfig in project Mycat-Server by MyCATApache.
the class DruidMysqlRouteStrategyTest method testOr.
/**
* 测试or语句的路由
*
* @throws Exception
*/
@Test
public void testOr() 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 sharding_id=10000 or 1=1;";
RouteResultset rrs = routeStrategy.route(new SystemConfig(), schema, ServerParse.SELECT, sql, null, null, cachePool);
Assert.assertTrue(rrs.getNodes().length == 2);
Assert.assertTrue(rrs.getNodes()[0].getName().equals("dn1"));
Assert.assertTrue(rrs.getNodes()[1].getName().equals("dn2"));
sql = "select * from customer where sharding_id = 10000 or sharding_id = 10010";
rrs = routeStrategy.route(new SystemConfig(), schema, ServerParse.SELECT, sql, null, null, cachePool);
Assert.assertTrue(rrs.getNodes()[0].getName().equals("dn1"));
Assert.assertTrue(rrs.getNodes()[1].getName().equals("dn2"));
sql = "select * from customer where sharding_id = 10000 or user_id = 'wangwu'";
rrs = routeStrategy.route(new SystemConfig(), schema, ServerParse.SELECT, sql, null, null, cachePool);
Assert.assertTrue(rrs.getNodes()[0].getName().equals("dn1"));
Assert.assertTrue(rrs.getNodes()[1].getName().equals("dn2"));
}
use of io.mycat.config.model.SchemaConfig 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"));
}
use of io.mycat.config.model.SchemaConfig 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);
}
}
use of io.mycat.config.model.SchemaConfig in project Mycat-Server by MyCATApache.
the class DruidMysqlSqlParserTest method testLockTableSql.
@Test
public void testLockTableSql() throws SQLNonTransientException {
String sql = "lock tables goods write";
SchemaConfig schema = schemaMap.get("TESTDB");
RouteResultset rrs = routeStrategy.route(new SystemConfig(), schema, ServerParse.LOCK, sql, null, null, cachePool);
Assert.assertEquals(3, rrs.getNodes().length);
}
use of io.mycat.config.model.SchemaConfig in project Mycat-Server by MyCATApache.
the class DruidOracleSqlParserTest method testLimitToOraclePage.
@Test
public void testLimitToOraclePage() throws SQLNonTransientException {
String sql = "select * from offer order by id desc limit 5,10";
SchemaConfig schema = schemaMap.get("oracledb");
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("d_oracle1", rrs.getNodes()[0].getName());
Assert.assertEquals("d_oracle2", 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("d_oracle1", rrs.getNodes()[0].getName());
}
Aggregations