Search in sources :

Example 6 with LargeMessageControllerImpl

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) {
    }
}
Also used : LargeMessageControllerImpl(org.apache.activemq.artemis.core.client.impl.LargeMessageControllerImpl) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) IOException(java.io.IOException) Test(org.junit.Test)

Example 7 with LargeMessageControllerImpl

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);
}
Also used : LargeMessageControllerImpl(org.apache.activemq.artemis.core.client.impl.LargeMessageControllerImpl) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Example 8 with LargeMessageControllerImpl

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();
}
Also used : LargeMessageControllerImpl(org.apache.activemq.artemis.core.client.impl.LargeMessageControllerImpl) DataInputStream(java.io.DataInputStream) ActiveMQBufferInputStream(org.apache.activemq.artemis.utils.ActiveMQBufferInputStream) Test(org.junit.Test)

Example 9 with LargeMessageControllerImpl

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());
}
Also used : LargeMessageControllerImpl(org.apache.activemq.artemis.core.client.impl.LargeMessageControllerImpl) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 10 with LargeMessageControllerImpl

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]);
    }
}
Also used : LargeMessageControllerImpl(org.apache.activemq.artemis.core.client.impl.LargeMessageControllerImpl) Test(org.junit.Test)

Aggregations

LargeMessageControllerImpl (org.apache.activemq.artemis.core.client.impl.LargeMessageControllerImpl)18 Test (org.junit.Test)17 IOException (java.io.IOException)5 PipedOutputStream (java.io.PipedOutputStream)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 DataOutputStream (java.io.DataOutputStream)4 OutputStream (java.io.OutputStream)4 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)3 DataInputStream (java.io.DataInputStream)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)2 ActiveMQBufferInputStream (org.apache.activemq.artemis.utils.ActiveMQBufferInputStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 PipedInputStream (java.io.PipedInputStream)1