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();
}
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();
}
}
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();
}
Aggregations