use of com.alibaba.cobar.parser.ast.expression.primary.PlaceHolder in project cobar by alibaba.
the class PartitionByStringTest method testPartition.
@SuppressWarnings("unchecked")
public void testPartition() {
PartitionByString sut = new PartitionByString("test ", (List<Expression>) ListUtil.createList(new PlaceHolder("member_id", "MEMBER_ID").setCacheEvalRst(false)));
sut.setCacheEvalRst(false);
sut.setHashSlice("-2:");
sut.setPartitionCount("1024");
sut.setPartitionLength("1");
sut.init();
Assert.assertEquals((int) execute(sut, "12"), (int) execute(sut, "012"));
Assert.assertEquals((int) execute(sut, "112"), (int) execute(sut, "012"));
Assert.assertEquals((int) execute(sut, "2"), (int) execute(sut, "2"));
sut = new PartitionByString("test ", (List<Expression>) ListUtil.createList(new PlaceHolder("member_id", "MEMBER_ID").setCacheEvalRst(false)));
sut.setCacheEvalRst(false);
sut.setHashSlice("-2:-1");
sut.setPartitionCount("1024");
sut.setPartitionLength("1");
sut.init();
Assert.assertEquals(49, (int) execute(sut, "012"));
Assert.assertEquals(49, (int) execute(sut, "12"));
Assert.assertEquals(49, (int) execute(sut, "15"));
Assert.assertEquals(0, (int) execute(sut, "2"));
Assert.assertEquals(56, (int) execute(sut, "888888"));
Assert.assertEquals(56, (int) execute(sut, "89"));
Assert.assertEquals(56, (int) execute(sut, "780"));
sut = new PartitionByString("test ", (List<Expression>) ListUtil.createList(new PlaceHolder("member_id", "MEMBER_ID").setCacheEvalRst(false)));
sut.setCacheEvalRst(false);
sut.setHashSlice("1:-1");
sut.setPartitionCount("1024");
sut.setPartitionLength("1");
sut.init();
Assert.assertEquals(49, (int) execute(sut, "012"));
Assert.assertEquals(49, (int) execute(sut, "219"));
Assert.assertEquals(0, (int) execute(sut, "2"));
Assert.assertEquals(512, (int) execute(sut, "888888"));
}
use of com.alibaba.cobar.parser.ast.expression.primary.PlaceHolder in project cobar by alibaba.
the class PartitionByStringTest method testPartitionNoStartOrNoEnd.
@SuppressWarnings("unchecked")
public void testPartitionNoStartOrNoEnd() {
String testKey = "abcdefghij";
// 无start, 不越界
PartitionByString sut = new PartitionByString("test ", (List<Expression>) ListUtil.createList(new PlaceHolder("member_id", "MEMBER_ID").setCacheEvalRst(false)));
sut.setCacheEvalRst(false);
sut.setHashSlice(":6");
sut.setPartitionCount("1024");
sut.setPartitionLength("1");
sut.init();
Assert.assertEquals(99, (int) execute(sut, testKey));
Assert.assertEquals(99, (int) execute(sut, testKey.substring(0, 6) + "abcd"));
Assert.assertEquals(99, (int) execute(sut, testKey.substring(0, 6) + "sila"));
Assert.assertTrue((99 != (int) execute(sut, "c" + testKey.substring(1, 5) + "sil2")));
sut = new PartitionByString("test ", (List<Expression>) ListUtil.createList(new PlaceHolder("member_id", "MEMBER_ID").setCacheEvalRst(false)));
sut.setCacheEvalRst(false);
sut.setHashSlice(":-4");
sut.setPartitionCount("1024");
sut.setPartitionLength("1");
sut.init();
Assert.assertEquals(99, (int) execute(sut, testKey));
Assert.assertEquals(99, (int) execute(sut, testKey.substring(0, 6) + "abcd"));
Assert.assertEquals(99, (int) execute(sut, testKey.substring(0, 6) + "sila"));
Assert.assertTrue((99 != (int) execute(sut, "c" + testKey.substring(1, 5) + "sil2")));
// 无start, 越界
sut = new PartitionByString("test ", (List<Expression>) ListUtil.createList(new PlaceHolder("member_id", "MEMBER_ID").setCacheEvalRst(false)));
sut.setCacheEvalRst(false);
sut.setHashSlice(":15");
sut.setPartitionCount("1024");
sut.setPartitionLength("1");
sut.init();
Assert.assertEquals(165, (int) execute(sut, testKey));
Assert.assertEquals(647, (int) execute(sut, "b" + testKey));
sut = new PartitionByString("test ", (List<Expression>) ListUtil.createList(new PlaceHolder("member_id", "MEMBER_ID").setCacheEvalRst(false)));
sut.setCacheEvalRst(false);
sut.setHashSlice(":-15");
sut.setPartitionCount("1024");
sut.setPartitionLength("1");
sut.init();
Assert.assertEquals(0, (int) execute(sut, UUID.randomUUID().toString().substring(0, 10)));
Assert.assertEquals(0, (int) execute(sut, UUID.randomUUID().toString().substring(0, 10)));
// 无end, 不越界
sut = new PartitionByString("test ", (List<Expression>) ListUtil.createList(new PlaceHolder("member_id", "MEMBER_ID").setCacheEvalRst(false)));
sut.setCacheEvalRst(false);
sut.setHashSlice("2:");
sut.setPartitionCount("1024");
sut.setPartitionLength("1");
sut.init();
Assert.assertEquals(388, (int) execute(sut, testKey));
Assert.assertEquals(388, (int) execute(sut, "ab" + testKey.substring(2, 10)));
Assert.assertEquals(388, (int) execute(sut, "e&" + testKey.substring(2, 10)));
Assert.assertTrue((388 != (int) execute(sut, "c" + testKey.substring(1, 5) + "sil2")));
sut = new PartitionByString("test ", (List<Expression>) ListUtil.createList(new PlaceHolder("member_id", "MEMBER_ID").setCacheEvalRst(false)));
sut.setCacheEvalRst(false);
sut.setHashSlice("-5:");
sut.setPartitionCount("1024");
sut.setPartitionLength("1");
sut.init();
Assert.assertEquals(808, (int) execute(sut, testKey));
Assert.assertEquals(808, (int) execute(sut, "abT*1" + testKey.substring(5, 10)));
Assert.assertEquals(808, (int) execute(sut, "ab^^!" + testKey.substring(5, 10)));
// 无end, 越界
sut = new PartitionByString("test ", (List<Expression>) ListUtil.createList(new PlaceHolder("member_id", "MEMBER_ID").setCacheEvalRst(false)));
sut.setCacheEvalRst(false);
sut.setHashSlice("-15:");
sut.setPartitionCount("1024");
sut.setPartitionLength("1");
sut.init();
Assert.assertEquals(165, (int) execute(sut, testKey));
Assert.assertEquals(647, (int) execute(sut, "b" + testKey));
sut = new PartitionByString("test ", (List<Expression>) ListUtil.createList(new PlaceHolder("member_id", "MEMBER_ID").setCacheEvalRst(false)));
sut.setCacheEvalRst(false);
sut.setHashSlice("15:");
sut.setPartitionCount("1024");
sut.setPartitionLength("1");
sut.init();
Assert.assertEquals(0, (int) execute(sut, UUID.randomUUID().toString().substring(0, 10)));
Assert.assertEquals(0, (int) execute(sut, UUID.randomUUID().toString().substring(0, 10)));
// 无start 无end
sut = new PartitionByString("test ", (List<Expression>) ListUtil.createList(new PlaceHolder("member_id", "MEMBER_ID").setCacheEvalRst(false)));
sut.setCacheEvalRst(false);
sut.setHashSlice(":");
sut.setPartitionCount("1024");
sut.setPartitionLength("1");
sut.init();
Assert.assertEquals(165, (int) execute(sut, testKey));
Assert.assertEquals(452, (int) execute(sut, "b" + testKey.substring(1)));
}
Aggregations