use of io.mycat.config.model.SchemaConfig in project Mycat-Server by MyCATApache.
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(new SystemConfig(), schema, ServerParse.SELECT, sql, null, null, cachePool);
Assert.assertEquals(100L, rrs.getLimitSize());
}
use of io.mycat.config.model.SchemaConfig in project Mycat-Server by MyCATApache.
the class DruidMysqlRouteStrategyTest method testAlias.
/**
* 测试别名路由
*
* @throws Exception
*/
public void testAlias() throws Exception {
SchemaConfig schema = schemaMap.get("TESTDB");
RouteResultset rrs = null;
//不支持childtable 批量插入
//update 全局表
String sql = "update company a set name = '' where a.id = 1;";
rrs = routeStrategy.route(new SystemConfig(), schema, 1, sql, null, null, cachePool);
Assert.assertEquals(3, rrs.getNodes().length);
//update带别名时的路由
sql = "update travelrecord a set name = '' where a.id = 1;";
rrs = routeStrategy.route(new SystemConfig(), schema, 1, sql, null, null, cachePool);
Assert.assertEquals(1, rrs.getNodes().length);
//别名大小写路由
sql = "select * from travelrecord A where a.id = 1;";
rrs = routeStrategy.route(new SystemConfig(), schema, 1, sql, null, null, cachePool);
Assert.assertEquals(1, rrs.getNodes().length);
}
use of io.mycat.config.model.SchemaConfig in project Mycat-Server by MyCATApache.
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(new SystemConfig(), schema, 9, sql, null, 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(new SystemConfig(), schema, 9, sql, null, 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(new SystemConfig(), schema, 1, sql, null, 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(new SystemConfig(), schema, 9, sql, null, 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 io.mycat.config.model.SchemaConfig in project Mycat-Server by MyCATApache.
the class DruidMysqlSqlParserTest method testLimitPage.
@Test
public void testLimitPage() throws SQLNonTransientException {
String sql = "select * from offer order by id desc limit 5,10";
SchemaConfig schema = schemaMap.get("mysqldb");
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("dn1", rrs.getNodes()[0].getName());
Assert.assertEquals("dn2", 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("dn1", rrs.getNodes()[0].getName());
sql = "select * from offer1 order by id desc limit 10";
rrs = routeStrategy.route(new SystemConfig(), schema, -1, sql, null, null, cachePool);
Assert.assertEquals(1, rrs.getNodes().length);
Assert.assertEquals(0, rrs.getLimitStart());
Assert.assertEquals(10, rrs.getLimitSize());
Assert.assertEquals(0, rrs.getNodes()[0].getLimitStart());
Assert.assertEquals(10, rrs.getNodes()[0].getLimitSize());
Assert.assertEquals("dn1", rrs.getNodes()[0].getName());
}
use of io.mycat.config.model.SchemaConfig in project Mycat-Server by MyCATApache.
the class DruidOracleSqlParserTest method testInsertUpdate.
@Test
public void testInsertUpdate() throws Exception {
SchemaConfig schema = schemaMap.get("oracledb");
String sql = "insert into offer1(group_id,offer_id,member_id)values(234,123,'abc')";
RouteResultset rrs = routeStrategy.route(new SystemConfig(), schema, -1, sql, null, null, cachePool);
Assert.assertEquals(1, rrs.getNodes().length);
Assert.assertEquals(false, rrs.isCacheAble());
Assert.assertEquals(-1, rrs.getLimitSize());
Assert.assertEquals(0, rrs.getNodes()[0].getLimitStart());
Assert.assertEquals(-1, rrs.getNodes()[0].getLimitSize());
Assert.assertEquals("d_oracle1", rrs.getNodes()[0].getName());
Assert.assertEquals("insert into offer1(group_id,offer_id,member_id)values(234,123,'abc')", rrs.getNodes()[0].getStatement());
sql = "update offer set name='x'";
rrs = routeStrategy.route(new SystemConfig(), schema, -1, sql, null, null, cachePool);
Assert.assertEquals(2, rrs.getNodes().length);
Assert.assertEquals(-1, rrs.getLimitSize());
Assert.assertEquals(false, rrs.isCacheAble());
Assert.assertEquals(0, rrs.getNodes()[0].getLimitStart());
Assert.assertEquals(-1, rrs.getNodes()[0].getLimitSize());
}
Aggregations