use of com.actiontech.dble.config.model.SchemaConfig in project dble by actiontech.
the class DruidMysqlRouteStrategyTest method testModifySQLLimit.
public void testModifySQLLimit() throws Exception {
final SchemaConfig schema = schemaMap.get("TESTDB");
String sql = null;
RouteResultset rrs = null;
// SQL span multi datanode
sql = "select * from orders limit 2,3";
rrs = routeStrategy.route(schema, ServerParse.SELECT, sql, null, cachePool);
Assert.assertEquals(true, rrs.isCacheAble());
Map<String, RouteResultsetNode> nodeMap = getNodeMap(rrs, 2);
NodeNameAsserter nameAsserter = new NodeNameAsserter("dn2", "dn1");
nameAsserter.assertRouteNodeNames(nodeMap.keySet());
Assert.assertEquals(3, rrs.getLimitSize());
MySqlStatementParser parser = new MySqlStatementParser("SELECT * FROM orders LIMIT 0,5");
SQLStatement statement = parser.parseStatement();
Assert.assertEquals(statement.toString(), rrs.getNodes()[0].getStatement());
// SQL not span multi datanode
sql = "select * from customer where id=10000 limit 2,3";
rrs = routeStrategy.route(schema, ServerParse.SELECT, sql, null, cachePool);
Assert.assertEquals(true, rrs.isCacheAble());
nodeMap = getNodeMap(rrs, 1);
nameAsserter = new NodeNameAsserter("dn1");
nameAsserter.assertRouteNodeNames(nodeMap.keySet());
Assert.assertEquals(3, rrs.getLimitSize());
Assert.assertEquals("select * from customer where id=10000 limit 2,3", rrs.getNodes()[0].getStatement());
}
use of com.actiontech.dble.config.model.SchemaConfig in project dble by actiontech.
the class DruidMysqlRouteStrategyTest method testConfigSchema.
public void testConfigSchema() throws Exception {
try {
SchemaConfig schema = schemaMap.get("config");
String sql = "select * from offer where offer_id=1";
routeStrategy.route(schema, 1, sql, null, cachePool);
Assert.assertFalse(true);
} catch (Exception e) {
Assert.assertEquals("route rule for table OFFER is required: select * from offer where offer_id=1", e.getMessage());
}
try {
SchemaConfig schema = schemaMap.get("config");
String sql = "select * from offer where col11111=1";
routeStrategy.route(schema, 1, sql, null, cachePool);
Assert.assertFalse(true);
} catch (Exception e) {
}
try {
SchemaConfig schema = schemaMap.get("config");
String sql = "select * from offer ";
routeStrategy.route(schema, 1, sql, null, cachePool);
Assert.assertFalse(true);
} catch (Exception e) {
}
}
use of com.actiontech.dble.config.model.SchemaConfig in project dble by actiontech.
the class DruidMysqlRouteStrategyTest method testERroute.
public void testERroute() throws Exception {
SchemaConfig schema = schemaMap.get("TESTDB");
String sql = "insert into orders (id,name,customer_id) values(1,'testonly',1)";
RouteResultset rrs = routeStrategy.route(schema, 1, sql, null, cachePool);
Assert.assertEquals(1, rrs.getNodes().length);
Assert.assertEquals(false, rrs.isCacheAble());
Assert.assertEquals("dn1", rrs.getNodes()[0].getName());
sql = "insert into orders (id,name,customer_id) values(1,'testonly',2000001)";
rrs = routeStrategy.route(schema, 1, sql, null, cachePool);
Assert.assertEquals(false, rrs.isCacheAble());
Assert.assertEquals(1, rrs.getNodes().length);
Assert.assertEquals("dn2", rrs.getNodes()[0].getName());
// can't update join key
sql = "update orders set id=1 ,name='aaa' , customer_id=2000001";
String err = null;
try {
rrs = routeStrategy.route(schema, 1, sql, null, cachePool);
} catch (SQLNonTransientException e) {
err = e.getMessage();
}
Assert.assertEquals(true, err.startsWith("Parent relevant column can't be updated ORDERS->CUSTOMER_ID"));
// route by parent rule ,update sql
sql = "update orders set id=1 ,name='aaa' where customer_id=2000001";
rrs = routeStrategy.route(schema, 1, sql, null, cachePool);
Assert.assertEquals(true, rrs.isCacheAble());
Assert.assertEquals("dn2", rrs.getNodes()[0].getName());
// route by parent rule but can't find datanode
sql = "update orders set id=1 ,name='aaa' where customer_id=-1";
try {
rrs = routeStrategy.route(schema, 1, sql, null, cachePool);
} catch (Exception e) {
err = e.getMessage();
}
Assert.assertEquals(true, err.startsWith("can't find datanode for sharding column:"));
// route by parent rule ,select sql
sql = "select * from orders where customer_id=2000001";
rrs = routeStrategy.route(schema, 1, sql, null, cachePool);
Assert.assertEquals(true, rrs.isCacheAble());
Assert.assertEquals("dn2", rrs.getNodes()[0].getName());
// route by parent rule ,delete sql
sql = "delete from orders where customer_id=2000001";
rrs = routeStrategy.route(schema, 1, sql, null, cachePool);
Assert.assertEquals("dn2", rrs.getNodes()[0].getName());
// test alias in column
sql = "select name as order_name from orders order by order_name limit 10,5";
rrs = routeStrategy.route(schema, 1, sql, null, cachePool);
MySqlStatementParser parser = new MySqlStatementParser("SELECT name AS order_name FROM orders ORDER BY order_name LIMIT 0,15");
SQLStatement statement = parser.parseStatement();
// Assert.assertEquals(sql, rrs.getNodes()[0].getStatement());
}
use of com.actiontech.dble.config.model.SchemaConfig in project dble by actiontech.
the class DruidMysqlRouteStrategyTest method testGroupLimit.
public void testGroupLimit() throws Exception {
final SchemaConfig schema = schemaMap.get("cndb");
String sql = null;
RouteResultset rrs = null;
sql = "select count(*) from (select * from(select * from offer_detail where offer_id='123' or offer_id='234' limit 88)offer where offer.member_id='abc' limit 60) w " + " where w.member_id ='pavarotti17' limit 99";
rrs = routeStrategy.route(schema, 1, sql, null, cachePool);
Assert.assertEquals(true, rrs.isCacheAble());
// Assert.assertEquals(88L, rrs.getLimitSize());
// Assert.assertEquals(RouteResultset.SUM_FLAG, rrs.getFlag());
Map<String, RouteResultsetNode> nodeMap = getNodeMap(rrs, 2);
NodeNameAsserter nameAsserter = new NodeNameAsserter("detail_dn29", "detail_dn15");
nameAsserter.assertRouteNodeNames(nodeMap.keySet());
sql = "select count(*) from (select * from(select max(id) from offer_detail where offer_id='123' or offer_id='234' limit 88)offer where offer.member_id='abc' limit 60) w " + " where w.member_id ='pavarotti17' limit 99";
rrs = routeStrategy.route(schema, 1, sql, null, cachePool);
Assert.assertEquals(true, rrs.isCacheAble());
nodeMap = getNodeMap(rrs, 2);
nameAsserter = new NodeNameAsserter("detail_dn29", "detail_dn15");
nameAsserter.assertRouteNodeNames(nodeMap.keySet());
sql = "select * from (select * from(select max(id) from offer_detail where offer_id='123' or offer_id='234' limit 88)offer where offer.member_id='abc' limit 60) w " + " where w.member_id ='pavarotti17' limit 99";
rrs = routeStrategy.route(schema, 1, sql, null, cachePool);
Assert.assertEquals(true, rrs.isCacheAble());
nodeMap = getNodeMap(rrs, 2);
nameAsserter = new NodeNameAsserter("detail_dn29", "detail_dn15");
nameAsserter.assertRouteNodeNames(nodeMap.keySet());
sql = "select * from (select count(*) from(select * from offer_detail where offer_id='123' or offer_id='234' limit 88)offer where offer.member_id='abc' limit 60) w " + " where w.member_id ='pavarotti17' limit 99";
rrs = routeStrategy.route(schema, 1, sql, null, cachePool);
Assert.assertEquals(true, rrs.isCacheAble());
// Assert.assertEquals(88L, rrs.getLimitSize());
// Assert.assertEquals(RouteResultset.SUM_FLAG, rrs.getFlag());
nodeMap = getNodeMap(rrs, 2);
nameAsserter = new NodeNameAsserter("detail_dn29", "detail_dn15");
nameAsserter.assertRouteNodeNames(nodeMap.keySet());
}
use of com.actiontech.dble.config.model.SchemaConfig in project dble by actiontech.
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(schema, ServerParse.SELECT, sql, null, cachePool);
Assert.assertEquals(100L, rrs.getLimitSize());
}
Aggregations