@Test public void testByteBufSimpleStringPool() { final int capacity = 8; final int chars = Integer.toString(capacity).length(); final SimpleString.ByteBufSimpleStringPool pool = new SimpleString.ByteBufSimpleStringPool(capacity, chars); final int bytes = new SimpleString(Integer.toString(capacity)).sizeof(); final ByteBuf bb = Unpooled.buffer(bytes, bytes); for (int i = 0; i < capacity; i++) { final SimpleString s = new SimpleString(Integer.toString(i)); bb.resetWriterIndex(); SimpleString.writeSimpleString(bb, s); bb.resetReaderIndex(); final SimpleString expectedPooled = pool.getOrCreate(bb); bb.resetReaderIndex(); Assert.assertSame(expectedPooled, pool.getOrCreate(bb)); bb.resetReaderIndex(); } }
@Test public void testByteBufSimpleStringPoolTooLong() { final SimpleString tooLong = new SimpleString("aa"); final ByteBuf bb = Unpooled.buffer(tooLong.sizeof(), tooLong.sizeof()); SimpleString.writeSimpleString(bb, tooLong); final SimpleString.ByteBufSimpleStringPool pool = new SimpleString.ByteBufSimpleStringPool(1, tooLong.length() - 1); Assert.assertNotSame(pool.getOrCreate(bb), pool.getOrCreate(bb.resetReaderIndex())); }
public static SimpleString readSimpleString(ByteBuf buffer, ByteBufSimpleStringPool pool) { if (pool == null) { return readSimpleString(buffer); } return pool.getOrCreate(buffer); }
public static SimpleString readSimpleString(ByteBuf buffer, ByteBufSimpleStringPool pool) { if (pool == null) { return readSimpleString(buffer); } return pool.getOrCreate(buffer); }
public static SimpleString readSimpleString(ByteBuf buffer, ByteBufSimpleStringPool pool) { if (pool == null) { return readSimpleString(buffer); } return pool.getOrCreate(buffer); }
public static SimpleString readSimpleString(ByteBuf buffer, ByteBufSimpleStringPool pool) { if (pool == null) { return readSimpleString(buffer); } return pool.getOrCreate(buffer); }
public static SimpleString readSimpleString(ByteBuf buffer, ByteBufSimpleStringPool pool) { if (pool == null) { return readSimpleString(buffer); } return pool.getOrCreate(buffer); }
public static SimpleString readSimpleString(ByteBuf buffer, ByteBufSimpleStringPool pool) { if (pool == null) { return readSimpleString(buffer); } return pool.getOrCreate(buffer); }
public static SimpleString readSimpleString(ByteBuf buffer, ByteBufSimpleStringPool pool) { if (pool == null) { return readSimpleString(buffer); } return pool.getOrCreate(buffer); }