{
return 1024 * 1024;
}
}
TimedBuffer timedBuffer = new TimedBuffer(100, TimedBufferTest.ONE_SECOND / 10, false);
timedBuffer.start();
try
{
timedBuffer.setObserver(new TestObserver());
int x = 0;
byte[] bytes = new byte[10];
for (int j = 0; j < 10; j++)
{
bytes[j] = UnitTestCase.getSamplebyte(x++);
}
HornetQBuffer buff = HornetQBuffers.wrappedBuffer(bytes);
timedBuffer.checkSize(10);
timedBuffer.addBytes(buff, false, dummyCallback);
Thread.sleep(200);
Assert.assertEquals(0, flushTimes.get());
bytes = new byte[10];
for (int j = 0; j < 10; j++)
{
bytes[j] = UnitTestCase.getSamplebyte(x++);
}
buff = HornetQBuffers.wrappedBuffer(bytes);
timedBuffer.checkSize(10);
timedBuffer.addBytes(buff, true, dummyCallback);
Thread.sleep(500);
Assert.assertEquals(1, flushTimes.get());
ByteBuffer flushedBuffer = buffers.get(0);
Assert.assertEquals(20, flushedBuffer.limit());
Assert.assertEquals(20, flushedBuffer.capacity());
flushedBuffer.rewind();
for (int i = 0; i < 20; i++)
{
Assert.assertEquals(UnitTestCase.getSamplebyte(i), flushedBuffer.get());
}
}
finally
{
timedBuffer.stop();
}
}