use of com.actiontech.dble.config.model.SchemaConfig in project dble by actiontech.
the class DDLRouteTest method testSpecialCharDDL.
@Test
public void testSpecialCharDDL() throws Exception {
SchemaConfig schema = schemaMap.get("TESTDB");
CacheService cacheService = new CacheService(false);
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 = "COMPANY";
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(schema, sqlType, sql, null);
Assert.assertTrue("COMPANY".equals(tablename));
Assert.assertTrue(rrs.getNodes().length == nodeSize);
}
use of com.actiontech.dble.config.model.SchemaConfig in project dble by actiontech.
the class DruidMysqlCreateTableTest method testInsert.
// @Test
public void testInsert() throws SQLException {
SchemaConfig schema = schemaMap.get("mysqldb");
RouteResultset rrs = routeStrategy.route(schema, -1, "insert into autoslot (id,sid) values(1,2) ", sc, cachePool);
Assert.assertEquals(1, rrs.getNodes().length);
// Assert.assertTrue(isInsertHasSlot(rrs.getStatement()));
Assert.assertFalse(isInsertHasSlot(rrs.getStatement()));
}
use of com.actiontech.dble.config.model.SchemaConfig in project dble by actiontech.
the class DruidMysqlCreateTableTest method testCreate.
@Test
public void testCreate() throws SQLException {
SchemaConfig schema = schemaMap.get("mysqldb");
RouteResultset rrs = routeStrategy.route(schema, -1, originSql1, sc, cachePool);
Assert.assertEquals(2, rrs.getNodes().length);
String sql = rrs.getNodes()[0].getStatement();
// Assert.assertTrue(parseSql(sql));
Assert.assertFalse(parseSql(sql));
}
use of com.actiontech.dble.config.model.SchemaConfig in project dble by actiontech.
the class DruidMysqlRouteStrategyTest method testMultiLevelOr.
/**
* testMultiLevelOr
*
* @throws Exception
*/
@Test
public void testMultiLevelOr() throws Exception {
SchemaConfig schema = schemaMap.get("TESTDB");
String sql = "select id from travelrecord " + " where id = 1 and ( fee=3 or days=5 or (traveldate = '2015-05-04 00:00:07.375' " + " and (user_id=2 or fee=days or fee = 0))) and name = 'zhangsan'";
RouteResultset rrs = routeStrategy.route(schema, ServerParse.SELECT, sql, null, cachePool);
Assert.assertTrue(rrs.getNodes().length == 1);
sql = "select id from travelrecord " + " where id = 1 and ( fee=3 or days=5 or (traveldate = '2015-05-04 00:00:07.375' " + " and (user_id=2 or fee=days or fee = 0))) and name = 'zhangsan' or id = 2000001";
rrs = routeStrategy.route(schema, ServerParse.SELECT, sql, null, cachePool);
Assert.assertTrue(rrs.getNodes().length == 2);
sql = "select id from travelrecord " + " where id = 1 and ( fee=3 or days=5 or (traveldate = '2015-05-04 00:00:07.375' " + " and (user_id=2 or fee=days or fee = 0))) and name = 'zhangsan' or id = 2000001 or id = 4000001";
rrs = routeStrategy.route(schema, ServerParse.SELECT, sql, null, cachePool);
Assert.assertTrue(rrs.getNodes().length == 3);
}
use of com.actiontech.dble.config.model.SchemaConfig in project dble by actiontech.
the class DruidMysqlRouteStrategyTest method testDuplicatePartitionKey.
public void testDuplicatePartitionKey() throws Exception {
String sql = null;
SchemaConfig schema = schemaMap.get("cndb");
RouteResultset rrs = null;
sql = "select * from cndb.offer where (offer_id, group_id ) In (123,234)";
schema = schemaMap.get("cndb");
rrs = routeStrategy.route(schema, 1, sql, null, cachePool);
Assert.assertEquals(true, rrs.isCacheAble());
Assert.assertEquals(-1L, rrs.getLimitSize());
Assert.assertEquals(128, rrs.getNodes().length);
for (int i = 0; i < 128; i++) {
Assert.assertEquals("select * from offer where (offer_id, group_id ) In (123,234)", rrs.getNodes()[i].getStatement());
}
sql = "SELECT * FROM offer WHERE FALSE OR offer_id = 123 AND member_id = 123 OR member_id = 123 AND member_id = 234 OR member_id = 123 AND member_id = 345 OR member_id = 123 AND member_id = 456 OR offer_id = 234 AND group_id = 123 OR offer_id = 234 AND group_id = 234 OR offer_id = 234 AND group_id = 345 OR offer_id = 234 AND group_id = 456 OR offer_id = 345 AND group_id = 123 OR offer_id = 345 AND group_id = 234 OR offer_id = 345 AND group_id = 345 OR offer_id = 345 AND group_id = 456 OR offer_id = 456 AND group_id = 123 OR offer_id = 456 AND group_id = 234 OR offer_id = 456 AND group_id = 345 OR offer_id = 456 AND group_id = 456";
schema = schemaMap.get("cndb");
rrs = routeStrategy.route(schema, 1, sql, null, cachePool);
Assert.assertEquals(true, rrs.isCacheAble());
getNodeMap(rrs, 128);
sql = "select * from offer where false" + " or offer_id=123 and group_id=123" + " or group_id=123 and offer_id=234" + " or offer_id=123 and group_id=345" + " or offer_id=123 and group_id=456 ";
schema = schemaMap.get("cndb");
rrs = routeStrategy.route(schema, 1, sql, null, cachePool);
Assert.assertEquals(true, rrs.isCacheAble());
Assert.assertEquals(-1L, rrs.getLimitSize());
}
Aggregations