use of io.mycat.config.model.SystemConfig in project Mycat_plus by coderczp.
the class DDLRouteTest method testTableMetaRead.
@Test
public void testTableMetaRead() throws Exception {
final SchemaConfig schema = schemaMap.get("cndb");
String sql = "desc offer";
RouteResultset rrs = routeStrategy.route(new SystemConfig(), schema, ServerParse.DESCRIBE, sql, null, null, cachePool);
Assert.assertEquals(false, rrs.isCacheAble());
Assert.assertEquals(-1L, rrs.getLimitSize());
Assert.assertEquals(1, rrs.getNodes().length);
// random return one node
// Assert.assertEquals("offer_dn[0]", rrs.getNodes()[0].getName());
Assert.assertEquals("desc offer", rrs.getNodes()[0].getStatement());
sql = " desc cndb.offer";
rrs = routeStrategy.route(new SystemConfig(), schema, ServerParse.DESCRIBE, sql, null, null, cachePool);
Assert.assertEquals(false, rrs.isCacheAble());
Assert.assertEquals(-1L, rrs.getLimitSize());
Assert.assertEquals(1, rrs.getNodes().length);
// random return one node
// Assert.assertEquals("offer_dn[0]", rrs.getNodes()[0].getName());
Assert.assertEquals("desc offer", rrs.getNodes()[0].getStatement());
sql = " desc cndb.offer col1";
rrs = routeStrategy.route(new SystemConfig(), schema, ServerParse.DESCRIBE, sql, null, null, cachePool);
Assert.assertEquals(false, rrs.isCacheAble());
Assert.assertEquals(-1L, rrs.getLimitSize());
Assert.assertEquals(1, rrs.getNodes().length);
// random return one node
// Assert.assertEquals("offer_dn[0]", rrs.getNodes()[0].getName());
Assert.assertEquals("desc offer col1", rrs.getNodes()[0].getStatement());
sql = "SHOW FULL COLUMNS FROM offer IN db_name WHERE true";
rrs = routeStrategy.route(new SystemConfig(), schema, ServerParse.SHOW, sql, null, null, cachePool);
Assert.assertEquals(false, rrs.isCacheAble());
Assert.assertEquals(-1L, rrs.getLimitSize());
Assert.assertEquals(1, rrs.getNodes().length);
// random return one node
// Assert.assertEquals("offer_dn[0]", rrs.getNodes()[0].getName());
Assert.assertEquals("SHOW FULL COLUMNS FROM offer WHERE true", rrs.getNodes()[0].getStatement());
sql = "SHOW FULL COLUMNS FROM db.offer IN db_name WHERE true";
rrs = routeStrategy.route(new SystemConfig(), schema, ServerParse.SHOW, sql, null, null, cachePool);
Assert.assertEquals(-1L, rrs.getLimitSize());
Assert.assertEquals(false, rrs.isCacheAble());
Assert.assertEquals(1, rrs.getNodes().length);
// random return one node
// Assert.assertEquals("offer_dn[0]", rrs.getNodes()[0].getName());
Assert.assertEquals("SHOW FULL COLUMNS FROM offer WHERE true", rrs.getNodes()[0].getStatement());
sql = "SHOW FULL TABLES FROM `TESTDB` WHERE Table_type != 'VIEW'";
rrs = routeStrategy.route(new SystemConfig(), schema, ServerParse.SHOW, sql, null, null, cachePool);
Assert.assertEquals(-1L, rrs.getLimitSize());
Assert.assertEquals(false, rrs.isCacheAble());
Assert.assertEquals("SHOW FULL TABLES WHERE Table_type != 'VIEW'", rrs.getNodes()[0].getStatement());
sql = "SHOW INDEX IN offer FROM db_name";
rrs = routeStrategy.route(new SystemConfig(), schema, ServerParse.SHOW, sql, null, null, cachePool);
Assert.assertEquals(false, rrs.isCacheAble());
Assert.assertEquals(-1L, rrs.getLimitSize());
Assert.assertEquals(1, rrs.getNodes().length);
// random return one node
// Assert.assertEquals("offer_dn[0]", rrs.getNodes()[0].getName());
Assert.assertEquals("SHOW INDEX FROM offer", rrs.getNodes()[0].getStatement());
}
use of io.mycat.config.model.SystemConfig in project Mycat_plus by coderczp.
the class DDLRouteTest method testSpecialCharDDL.
@Test
public void testSpecialCharDDL() throws Exception {
SchemaConfig schema = schemaMap.get("TESTDB");
CacheService cacheService = new CacheService();
RouteService routerService = new RouteService(cacheService);
// alter table test
String sql = " ALTER TABLE COMPANY\r\nADD COLUMN TEST VARCHAR(255) NULL AFTER CREATE_DATE,\r\n CHARACTER SET = UTF8";
sql = RouterUtil.getFixedSql(sql);
List<String> dataNodes = new ArrayList<>();
String tablename = RouterUtil.getTableName(sql, RouterUtil.getAlterTablePos(sql, 0));
Map<String, TableConfig> tables = schema.getTables();
TableConfig tc;
if (tables != null && (tc = tables.get(tablename)) != null) {
dataNodes = tc.getDataNodes();
}
int nodeSize = dataNodes.size();
int rs = ServerParse.parse(sql);
int sqlType = rs & 0xff;
RouteResultset rrs = routerService.route(new SystemConfig(), schema, sqlType, sql, "UTF-8", null);
Assert.assertTrue("COMPANY".equals(tablename));
Assert.assertTrue(rrs.getNodes().length == nodeSize);
}
use of io.mycat.config.model.SystemConfig in project Mycat_plus by coderczp.
the class DruidMysqlCreateTableTest method testCreate.
@Test
public void testCreate() throws SQLNonTransientException {
SchemaConfig schema = schemaMap.get("mysqldb");
RouteResultset rrs = routeStrategy.route(new SystemConfig(), schema, -1, originSql1, null, null, cachePool);
Assert.assertEquals(2, rrs.getNodes().length);
String sql = rrs.getNodes()[0].getStatement();
Assert.assertTrue(parseSql(sql));
}
use of io.mycat.config.model.SystemConfig in project Mycat_plus by coderczp.
the class DruidMysqlCreateTableTest method testInsert.
// @Test
public void testInsert() throws SQLNonTransientException {
SchemaConfig schema = schemaMap.get("mysqldb");
RouteResultset rrs = routeStrategy.route(new SystemConfig(), schema, -1, "insert into autoslot (id,sid) values(1,2) ", null, null, cachePool);
Assert.assertEquals(1, rrs.getNodes().length);
Assert.assertTrue(isInsertHasSlot(rrs.getStatement()));
}
use of io.mycat.config.model.SystemConfig in project Mycat_plus by coderczp.
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"));
}
Aggregations