Search in sources :

Example 1 with BulkStringEofMarkJudger

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

the class BulkStringEofJudgerTest method testEofMarkSmall.

@Test
public void testEofMarkSmall() {
    byte[] eofmark = randomString(RedisClientProtocol.RUN_ID_LENGTH).getBytes();
    BulkStringEofMarkJudger judger = new BulkStringEofMarkJudger(eofmark);
    for (int i = 0; i < (1 << 20); i++) {
        JudgeResult result = judger.end(Unpooled.wrappedBuffer(randomString(1).getBytes()));
        Assert.assertFalse(result.isEnd());
        Assert.assertEquals(1, result.getReadLen());
    }
    for (int i = 0; i < eofmark.length; i++) {
        JudgeResult result = judger.end(Unpooled.wrappedBuffer(new byte[] { eofmark[i] }));
        Assert.assertEquals(1, result.getReadLen());
        if (i < eofmark.length - 1) {
            Assert.assertFalse(result.isEnd());
        } else {
            Assert.assertTrue(result.isEnd());
        }
    }
}
Also used : BulkStringEofMarkJudger(com.ctrip.xpipe.redis.core.protocal.protocal.AbstractBulkStringEoFJudger.BulkStringEofMarkJudger) JudgeResult(com.ctrip.xpipe.redis.core.protocal.protocal.BulkStringEofJudger.JudgeResult) AbstractRedisTest(com.ctrip.xpipe.redis.core.AbstractRedisTest) Test(org.junit.Test)

Example 2 with BulkStringEofMarkJudger

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

the class BulkStringEofJudgerTest method testEofMarkBig.

@Test
public void testEofMarkBig() {
    byte[] eofmark = randomString(RedisClientProtocol.RUN_ID_LENGTH).getBytes();
    BulkStringEofMarkJudger judger = new BulkStringEofMarkJudger(eofmark);
    String data = randomString();
    JudgeResult result = judger.end(Unpooled.wrappedBuffer(data.getBytes()));
    Assert.assertFalse(result.isEnd());
    Assert.assertEquals(data.length(), result.getReadLen());
    String real = randomString() + new String(eofmark);
    result = judger.end(Unpooled.wrappedBuffer(real.getBytes()));
    Assert.assertTrue(result.isEnd());
    Assert.assertEquals(real.length(), result.getReadLen());
}
Also used : BulkStringEofMarkJudger(com.ctrip.xpipe.redis.core.protocal.protocal.AbstractBulkStringEoFJudger.BulkStringEofMarkJudger) JudgeResult(com.ctrip.xpipe.redis.core.protocal.protocal.BulkStringEofJudger.JudgeResult) AbstractRedisTest(com.ctrip.xpipe.redis.core.AbstractRedisTest) Test(org.junit.Test)

Aggregations

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