Search in sources :

Example 16 with LargeMessageControllerImpl

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

the class LargeMessageBufferTest method testReadDataOverCached.

@Test
public void testReadDataOverCached() throws Exception {
    clearDataRecreateServerDirs();
    ActiveMQBuffer dynamic = ActiveMQBuffers.dynamicBuffer(1);
    String str1 = RandomUtil.randomString();
    String str2 = RandomUtil.randomString();
    double d1 = RandomUtil.randomDouble();
    float f1 = RandomUtil.randomFloat();
    dynamic.writeUTF(str1);
    dynamic.writeString(str2);
    dynamic.writeDouble(d1);
    dynamic.writeFloat(f1);
    LargeMessageControllerImpl readBuffer = splitBuffer(3, dynamic.toByteBuffer().array(), getTestFile());
    Assert.assertEquals(str1, readBuffer.readUTF());
    Assert.assertEquals(str2, readBuffer.readString());
    Assert.assertEquals(d1, readBuffer.readDouble(), 0.00000001);
    Assert.assertEquals(f1, readBuffer.readFloat(), 0.000001);
    readBuffer.readerIndex(0);
    Assert.assertEquals(str1, readBuffer.readUTF());
    Assert.assertEquals(str2, readBuffer.readString());
    Assert.assertEquals(d1, readBuffer.readDouble(), 0.00000001);
    Assert.assertEquals(f1, readBuffer.readFloat(), 0.000001);
    readBuffer.close();
}
Also used : LargeMessageControllerImpl(org.apache.activemq.artemis.core.client.impl.LargeMessageControllerImpl) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Example 17 with LargeMessageControllerImpl

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

the class LargeMessageBufferTest method testSplitBufferOnFile.

@Test
public void testSplitBufferOnFile() throws Exception {
    LargeMessageControllerImpl outBuffer = new LargeMessageControllerImpl(new FakeConsumerInternal(), 1024 * 1024, 1, getTestFile(), 1024);
    try {
        long count = 0;
        for (int i = 0; i < 10; i++) {
            byte[] buffer = new byte[10240];
            for (int j = 0; j < 10240; j++) {
                buffer[j] = getSamplebyte(count++);
            }
            outBuffer.addPacket(buffer, 1, true);
        }
        outBuffer.readerIndex(0);
        for (int i = 0; i < 10240 * 10; i++) {
            assertEquals("position " + i, getSamplebyte(i), outBuffer.readByte());
        }
        outBuffer.readerIndex(0);
        for (int i = 0; i < 10240 * 10; i++) {
            assertEquals("position " + i, getSamplebyte(i), outBuffer.readByte());
        }
    } finally {
        outBuffer.close();
    }
}
Also used : LargeMessageControllerImpl(org.apache.activemq.artemis.core.client.impl.LargeMessageControllerImpl) Test(org.junit.Test)

Example 18 with LargeMessageControllerImpl

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

the class LargeMessageBufferTest method testStreamDataWaitCompletionOnSlowComingBuffer.

@Test
public void testStreamDataWaitCompletionOnSlowComingBuffer() 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());
    Thread sender = new Thread() {

        @Override
        public void run() {
            try {
                Thread.sleep(100);
                outBuffer.addPacket(new byte[] { 0 }, 1, true);
                Thread.sleep(100);
                outBuffer.addPacket(new byte[] { 0 }, 1, true);
                Thread.sleep(200);
                outBuffer.addPacket(new byte[] { 0 }, 1, false);
            } catch (Exception e) {
            }
        }
    };
    sender.start();
    assertTrue(outBuffer.waitCompletion(5000));
    sender.join();
}
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) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) 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