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