Search in sources :

Example 1 with BulkStringLengthEofJudger

use of com.ctrip.xpipe.redis.core.protocal.protocal.AbstractBulkStringEoFJudger.BulkStringLengthEofJudger in project x-pipe by ctripcorp.

the class BulkStringEofJudgerTest method testLen.

@Test
public void testLen() {
    int expectedLen = 1 << 20;
    BulkStringLengthEofJudger judger = new BulkStringLengthEofJudger(expectedLen);
    for (int i = 0; i < expectedLen - 1; i++) {
        JudgeResult result = judger.end(Unpooled.wrappedBuffer("a".getBytes()));
        Assert.assertFalse(result.isEnd());
        Assert.assertEquals(1, result.getReadLen());
    }
    JudgeResult result = judger.end(Unpooled.wrappedBuffer("a".getBytes()));
    Assert.assertTrue(result.isEnd());
    Assert.assertEquals(1, result.getReadLen());
    result = judger.end(Unpooled.wrappedBuffer("a".getBytes()));
    Assert.assertTrue(result.isEnd());
    Assert.assertEquals(0, result.getReadLen());
    try {
        result = judger.end(Unpooled.wrappedBuffer("a".getBytes()));
        Assert.fail();
    } catch (Exception e) {
    }
}
Also used : JudgeResult(com.ctrip.xpipe.redis.core.protocal.protocal.BulkStringEofJudger.JudgeResult) BulkStringLengthEofJudger(com.ctrip.xpipe.redis.core.protocal.protocal.AbstractBulkStringEoFJudger.BulkStringLengthEofJudger) AbstractRedisTest(com.ctrip.xpipe.redis.core.AbstractRedisTest) Test(org.junit.Test)

Aggregations

AbstractRedisTest (com.ctrip.xpipe.redis.core.AbstractRedisTest)1 BulkStringLengthEofJudger (com.ctrip.xpipe.redis.core.protocal.protocal.AbstractBulkStringEoFJudger.BulkStringLengthEofJudger)1 JudgeResult (com.ctrip.xpipe.redis.core.protocal.protocal.BulkStringEofJudger.JudgeResult)1 Test (org.junit.Test)1