use of com.actiontech.dble.config.model.SchemaConfig in project dble by actiontech.
the class DruidMysqlRouteStrategyTest method testBetweenExpr.
/**
* testBetweenExpr
*
* @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(schema, ServerParse.SELECT, sql, 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(schema, ServerParse.SELECT, sql, null, cachePool);
Assert.assertTrue(rrs.getNodes().length == 2);
sql = "select * from customer where id between 2000001 and 3000001;";
rrs = routeStrategy.route(schema, ServerParse.SELECT, sql, 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(schema, ServerParse.SELECT, sql, 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(schema, ServerParse.SELECT, sql, null, cachePool);
Assert.assertTrue(rrs.getNodes().length == 1);
Assert.assertTrue(rrs.getNodes()[0].getName().equals("dn2"));
}
use of com.actiontech.dble.config.model.SchemaConfig in project dble by actiontech.
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(schema, 9, sql, 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(schema, 9, sql, 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(schema, 1, sql, 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(schema, 9, sql, 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);
}
}
use of com.actiontech.dble.config.model.SchemaConfig in project dble by actiontech.
the class DruidMysqlRouteStrategyTest method testBatchInsert.
/**
* support insert into ... values (),()...
* not support insert into ... select...
*
* @throws Exception
*/
public void testBatchInsert() throws Exception {
SchemaConfig schema = schemaMap.get("TESTDB");
RouteResultset rrs = null;
// not supprot childtable batch insert
String sql = "insert into orders (id,name,customer_id) values(1,'testonly',1),(2,'testonly',2000001)";
try {
rrs = routeStrategy.route(schema, 1, sql, null, cachePool);
} catch (Exception e) {
Assert.assertEquals("ChildTable multi insert not provided", e.getMessage());
}
sql = "insert into employee (id,name,customer_id) select id,name,customer_id from customer";
try {
rrs = routeStrategy.route(schema, 1, sql, null, cachePool);
} catch (Exception e) {
Assert.assertEquals("TODO:insert into .... select .... not supported!", e.getMessage());
}
sql = "insert into employee (id,name,sharding_id) values(1,'testonly',10000),(2,'testonly',10010)";
rrs = routeStrategy.route(schema, 1, sql, null, cachePool);
Assert.assertEquals(2, rrs.getNodes().length);
Assert.assertEquals(false, rrs.isCacheAble());
Assert.assertEquals("dn1", rrs.getNodes()[0].getName());
Assert.assertEquals("dn2", rrs.getNodes()[1].getName());
String node1Sql = formatSql("insert into employee (id,name,sharding_id) values(1,'testonly',10000)");
String node2Sql = formatSql("insert into employee (id,name,sharding_id) values(2,'testonly',10010)");
RouteResultsetNode[] nodes = rrs.getNodes();
Assert.assertEquals(node1Sql, nodes[0].getStatement());
Assert.assertEquals(node2Sql, nodes[1].getStatement());
}
use of com.actiontech.dble.config.model.SchemaConfig in project dble by actiontech.
the class DruidMysqlRouteStrategyTest method testGlobalTableOr.
/**
* testGlobalTableOr
*
* @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(schema, ServerParse.SELECT, sql, null, cachePool);
Assert.assertTrue(rrs.getNodes().length == 1);
}
}
use of com.actiontech.dble.config.model.SchemaConfig in project dble by actiontech.
the class DruidMysqlRouteStrategyTest method testAlias.
/**
* testAlias
*
* @throws Exception
*/
public void testAlias() throws Exception {
SchemaConfig schema = schemaMap.get("TESTDB");
RouteResultset rrs = null;
// update global table
String sql = "update company a set name = '' where a.id = 1;";
rrs = routeStrategy.route(schema, 1, sql, null, cachePool);
Assert.assertEquals(3, rrs.getNodes().length);
// update with alias
sql = "update travelrecord a set name = '' where a.id = 1;";
rrs = routeStrategy.route(schema, 1, sql, null, cachePool);
Assert.assertEquals(1, rrs.getNodes().length);
// alias with lowercase
sql = "select * from travelrecord A where a.id = 1;";
rrs = routeStrategy.route(schema, 1, sql, null, cachePool);
Assert.assertEquals(1, rrs.getNodes().length);
}
Aggregations