Search in sources :

Example 11 with LargeMessageControllerImpl

use of org.apache.activemq.artemis.core.client.impl.LargeMessageControllerImpl in project activemq-artemis by apache.

the class LargeMessageBufferTest method testStreamDataWaitCompletionOnInCompleteBuffer.

@Test
public void testStreamDataWaitCompletionOnInCompleteBuffer() throws Exception {
    final LargeMessageControllerImpl outBuffer = new LargeMessageControllerImpl(new FakeConsumerInternal(), 5, 1000);
    class FakeOutputStream extends OutputStream {

        @Override
        public void write(int b) throws IOException {
        }
    }
    outBuffer.setOutputStream(new FakeOutputStream());
    long time = System.currentTimeMillis();
    try {
        outBuffer.waitCompletion(0);
        fail("supposed to throw an exception");
    } catch (ActiveMQException e) {
    }
    assertTrue("It was supposed to wait at least 1 second", System.currentTimeMillis() - time > 1000);
}
Also used : LargeMessageControllerImpl(org.apache.activemq.artemis.core.client.impl.LargeMessageControllerImpl) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataOutputStream(java.io.DataOutputStream) OutputStream(java.io.OutputStream) PipedOutputStream(java.io.PipedOutputStream) Test(org.junit.Test)

Example 12 with LargeMessageControllerImpl

use of org.apache.activemq.artemis.core.client.impl.LargeMessageControllerImpl in project activemq-artemis by apache.

the class LargeMessageBufferTest method splitBuffer.

private LargeMessageControllerImpl splitBuffer(final int splitFactor, final byte[] bytes, final File file) throws Exception {
    LargeMessageControllerImpl outBuffer = new LargeMessageControllerImpl(new FakeConsumerInternal(), bytes.length, 5000, file);
    ByteArrayInputStream input = new ByteArrayInputStream(bytes);
    while (true) {
        byte[] splitElement = new byte[splitFactor];
        int size = input.read(splitElement);
        if (size <= 0) {
            break;
        }
        if (size < splitFactor) {
            byte[] newSplit = new byte[size];
            System.arraycopy(splitElement, 0, newSplit, 0, size);
            outBuffer.addPacket(newSplit, 1, input.available() > 0);
        } else {
            outBuffer.addPacket(splitElement, 1, input.available() > 0);
        }
    }
    return outBuffer;
}
Also used : LargeMessageControllerImpl(org.apache.activemq.artemis.core.client.impl.LargeMessageControllerImpl) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 13 with LargeMessageControllerImpl

use of org.apache.activemq.artemis.core.client.impl.LargeMessageControllerImpl in project activemq-artemis by apache.

the class LargeMessageBufferTest method testErrorOnSetStreaming.

@Test
public void testErrorOnSetStreaming() throws Exception {
    long start = System.currentTimeMillis();
    final LargeMessageControllerImpl outBuffer = new LargeMessageControllerImpl(new FakeConsumerInternal(), 5, 30000);
    outBuffer.addPacket(new byte[] { 0, 1, 2, 3, 4 }, 1, true);
    final CountDownLatch latchBytesWritten1 = new CountDownLatch(5);
    final CountDownLatch latchBytesWritten2 = new CountDownLatch(10);
    outBuffer.setOutputStream(new OutputStream() {

        @Override
        public void write(final int b) throws IOException {
            latchBytesWritten1.countDown();
            latchBytesWritten2.countDown();
        }
    });
    ActiveMQTestBase.waitForLatch(latchBytesWritten1);
    try {
        outBuffer.readByte();
        Assert.fail("supposed to throw an exception");
    } catch (IllegalAccessError ignored) {
    }
    Assert.assertTrue("It waited too much", System.currentTimeMillis() - start < 30000);
}
Also used : LargeMessageControllerImpl(org.apache.activemq.artemis.core.client.impl.LargeMessageControllerImpl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataOutputStream(java.io.DataOutputStream) OutputStream(java.io.OutputStream) PipedOutputStream(java.io.PipedOutputStream) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 14 with LargeMessageControllerImpl

use of org.apache.activemq.artemis.core.client.impl.LargeMessageControllerImpl in project activemq-artemis by apache.

the class LargeMessageBufferTest method testReadIntegersOverStream.

@Test
public void testReadIntegersOverStream() throws Exception {
    LargeMessageControllerImpl buffer = createBufferWithIntegers(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.readInt());
    }
    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 15 with LargeMessageControllerImpl

use of org.apache.activemq.artemis.core.client.impl.LargeMessageControllerImpl in project activemq-artemis by apache.

the class LargeMessageBufferTest method testStreamDataWaitCompletionOnCompleteBuffer.

@Test
public void testStreamDataWaitCompletionOnCompleteBuffer() throws Exception {
    final LargeMessageControllerImpl outBuffer = create15BytesSample();
    outBuffer.saveBuffer(new OutputStream() {

        @Override
        public void write(final int b) throws IOException {
        // nohting to be done
        }
    });
}
Also used : LargeMessageControllerImpl(org.apache.activemq.artemis.core.client.impl.LargeMessageControllerImpl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataOutputStream(java.io.DataOutputStream) OutputStream(java.io.OutputStream) PipedOutputStream(java.io.PipedOutputStream) IOException(java.io.IOException) 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