}
public void testReadPartialData() throws Exception
{
final LargeMessageControllerImpl buffer = new LargeMessageControllerImpl(new FakeConsumerInternal(), 10, 10);
buffer.addPacket(new FakePacket(-1, new byte[] { 0, 1, 2, 3, 4 }, true, true));
byte bytes[] = new byte[30];
buffer.readBytes(bytes, 0, 5);
for (byte i = 0; i < 5; i++)
{
Assert.assertEquals(i, bytes[i]);
}
final CountDownLatch latchGo = new CountDownLatch(1);
final AtomicInteger errorCount = new AtomicInteger(0);
Thread t = new Thread()
{
@Override
public void run()
{
try
{
latchGo.countDown();
buffer.readBytes(new byte[5]);
}
catch (IndexOutOfBoundsException ignored)
{
}
catch (IllegalAccessError ignored)
{
}
catch (Throwable e)
{
e.printStackTrace();
errorCount.incrementAndGet();
}
}
};
t.start();
latchGo.await();
buffer.cancel();
t.join();
Assert.assertEquals(0, errorCount.get());