use of org.apache.activemq.artemis.core.client.impl.LargeMessageControllerImpl in project activemq-artemis by apache.
the class LargeMessageBufferTest method testGetBytes.
// Test Simple getBytes
@Test
public void testGetBytes() throws Exception {
LargeMessageControllerImpl buffer = create15BytesSample();
for (int i = 1; i <= 15; i++) {
try {
Assert.assertEquals(i, buffer.readByte());
} catch (Exception e) {
throw new Exception("Exception at position " + i, e);
}
}
try {
buffer.readByte();
Assert.fail("supposed to throw an exception");
} catch (IndexOutOfBoundsException e) {
}
}
use of org.apache.activemq.artemis.core.client.impl.LargeMessageControllerImpl in project activemq-artemis by apache.
the class LargeMessageBufferTest method testGetBytesILChannelBufferII.
// testing void getBytes(int index, ChannelBuffer dst, int dstIndex, int length)
@Test
public void testGetBytesILChannelBufferII() throws Exception {
LargeMessageControllerImpl buffer = create15BytesSample();
ActiveMQBuffer dstBuffer = ActiveMQBuffers.fixedBuffer(20);
dstBuffer.setIndex(0, 5);
buffer.getBytes(0, dstBuffer);
byte[] compareBytes = new byte[15];
dstBuffer.getBytes(5, compareBytes);
validateAgainstSample(compareBytes);
}
use of org.apache.activemq.artemis.core.client.impl.LargeMessageControllerImpl in project activemq-artemis by apache.
the class LargeMessageBufferTest method testReadLongsOverStream.
@Test
public void testReadLongsOverStream() throws Exception {
LargeMessageControllerImpl buffer = createBufferWithLongs(3, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
ActiveMQBufferInputStream is = new ActiveMQBufferInputStream(buffer);
DataInputStream dataInput = new DataInputStream(is);
for (int i = 1; i <= 15; i++) {
Assert.assertEquals(i, dataInput.readLong());
}
assertEquals(-1, dataInput.read());
dataInput.close();
}
use of org.apache.activemq.artemis.core.client.impl.LargeMessageControllerImpl in project activemq-artemis by apache.
the class LargeMessageBufferTest method testReadPartialData.
@Test
public void testReadPartialData() throws Exception {
final LargeMessageControllerImpl buffer = new LargeMessageControllerImpl(new FakeConsumerInternal(), 10, 10);
buffer.addPacket(new byte[] { 0, 1, 2, 3, 4 }, 1, 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();
ActiveMQTestBase.waitForLatch(latchGo);
buffer.cancel();
t.join();
Assert.assertEquals(0, errorCount.get());
}
use of org.apache.activemq.artemis.core.client.impl.LargeMessageControllerImpl in project activemq-artemis by apache.
the class LargeMessageBufferTest method testInterruptData.
@Test
public void testInterruptData() throws Exception {
LargeMessageControllerImpl readBuffer = splitBuffer(3, new byte[] { 0, 1, 2, 3, 4 });
byte[] bytes = new byte[30];
readBuffer.readBytes(bytes, 0, 5);
for (byte i = 0; i < 5; i++) {
Assert.assertEquals(i, bytes[i]);
}
}
Aggregations