use of org.apache.activemq.artemis.api.core.ActiveMQBuffer 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);
}
use of org.apache.activemq.artemis.api.core.ActiveMQBuffer in project activemq-artemis by apache.
the class LargeMessageBufferTest method testReadBytesOnStreaming.
@Test
public void testReadBytesOnStreaming() throws Exception {
byte[] byteArray = new byte[1024];
for (int i = 0; i < byteArray.length; i++) {
byteArray[i] = getSamplebyte(i);
}
ActiveMQBuffer splitbuffer = splitBuffer(3, byteArray);
ActiveMQBufferInputStream is = new ActiveMQBufferInputStream(splitbuffer);
for (int i = 0; i < 100; i++) {
assertEquals(getSamplebyte(i), (byte) is.read());
}
for (int i = 100; i < byteArray.length; i += 10) {
byte[] readBytes = new byte[10];
int size = is.read(readBytes);
for (int j = 0; j < size; j++) {
assertEquals(getSamplebyte(i + j), readBytes[j]);
}
}
is.close();
}
use of org.apache.activemq.artemis.api.core.ActiveMQBuffer in project activemq-artemis by apache.
the class PageCursorStressTest method testConsumeLivePage.
@Test
public void testConsumeLivePage() throws Exception {
PagingStoreImpl pageStore = lookupPageStore(ADDRESS);
pageStore.startPaging();
final int NUM_MESSAGES = 100;
final int messageSize = 1024 * 1024;
PageCursorProvider cursorProvider = this.server.getPagingManager().getPageStore(ADDRESS).getCursorProvider();
System.out.println("cursorProvider = " + cursorProvider);
PageSubscription cursor = this.server.getPagingManager().getPageStore(ADDRESS).getCursorProvider().getSubscription(queue.getID());
System.out.println("Cursor: " + cursor);
RoutingContextImpl ctx = generateCTX();
LinkedListIterator<PagedReference> iterator = cursor.iterator();
for (int i = 0; i < NUM_MESSAGES; i++) {
// if (i % 100 == 0)
System.out.println("read/written " + i);
ActiveMQBuffer buffer = RandomUtil.randomBuffer(messageSize, i + 1L);
Message msg = new CoreMessage(i, buffer.writerIndex());
msg.putIntProperty("key", i);
msg.getBodyBuffer().writeBytes(buffer, 0, buffer.writerIndex());
Assert.assertTrue(pageStore.page(msg, ctx.getTransaction(), ctx.getContextListing(ADDRESS), lock));
PagedReference readMessage = iterator.next();
assertNotNull(readMessage);
assertEquals(i, readMessage.getMessage().getIntProperty("key").intValue());
assertNull(iterator.next());
}
OperationContextImpl.clearContext();
ctx = generateCTX();
pageStore = lookupPageStore(ADDRESS);
cursor = this.server.getPagingManager().getPageStore(ADDRESS).getCursorProvider().getSubscription(queue.getID());
iterator = cursor.iterator();
for (int i = 0; i < NUM_MESSAGES * 2; i++) {
if (i % 100 == 0)
System.out.println("Paged " + i);
if (i >= NUM_MESSAGES) {
ActiveMQBuffer buffer = RandomUtil.randomBuffer(messageSize, i + 1L);
Message msg = new CoreMessage(i, buffer.writerIndex());
msg.putIntProperty("key", i);
msg.getBodyBuffer().writeBytes(buffer, 0, buffer.writerIndex());
Assert.assertTrue(pageStore.page(msg, ctx.getTransaction(), ctx.getContextListing(ADDRESS), lock));
}
PagedReference readMessage = iterator.next();
assertNotNull(readMessage);
assertEquals(i, readMessage.getMessage().getIntProperty("key").intValue());
}
OperationContextImpl.clearContext();
pageStore = lookupPageStore(ADDRESS);
cursor = this.server.getPagingManager().getPageStore(ADDRESS).getCursorProvider().getSubscription(queue.getID());
iterator = cursor.iterator();
for (int i = 0; i < NUM_MESSAGES * 3; i++) {
if (i % 100 == 0)
System.out.println("Paged " + i);
if (i >= NUM_MESSAGES * 2 - 1) {
ActiveMQBuffer buffer = RandomUtil.randomBuffer(messageSize, i + 1L);
Message msg = new CoreMessage(i, buffer.writerIndex());
msg.putIntProperty("key", i + 1);
msg.getBodyBuffer().writeBytes(buffer, 0, buffer.writerIndex());
Assert.assertTrue(pageStore.page(msg, ctx.getTransaction(), ctx.getContextListing(ADDRESS), lock));
}
PagedReference readMessage = iterator.next();
assertNotNull(readMessage);
cursor.ack(readMessage);
assertEquals(i, readMessage.getMessage().getIntProperty("key").intValue());
}
PagedReference readMessage = iterator.next();
assertEquals(NUM_MESSAGES * 3, readMessage.getMessage().getIntProperty("key").intValue());
cursor.ack(readMessage);
server.getStorageManager().waitOnOperations();
pageStore.flushExecutors();
assertFalse(pageStore.isPaging());
server.stop();
createServer();
assertFalse(pageStore.isPaging());
waitCleanup();
assertFalse(lookupPageStore(ADDRESS).isPaging());
}
use of org.apache.activemq.artemis.api.core.ActiveMQBuffer in project activemq-artemis by apache.
the class TimedBufferTest method testFillBuffer.
@Test
public void testFillBuffer() {
final ArrayList<ByteBuffer> buffers = new ArrayList<>();
final AtomicInteger flushTimes = new AtomicInteger(0);
class TestObserver implements TimedBufferObserver {
@Override
public void flushBuffer(final ByteBuffer buffer, final boolean sync, final List<IOCallback> callbacks) {
buffers.add(buffer);
flushTimes.incrementAndGet();
}
/* (non-Javadoc)
* @see org.apache.activemq.artemis.utils.timedbuffer.TimedBufferObserver#newBuffer(int, int)
*/
@Override
public ByteBuffer newBuffer(final int minSize, final int maxSize) {
return ByteBuffer.allocate(maxSize);
}
@Override
public int getRemainingBytes() {
return 1024 * 1024;
}
}
TimedBuffer timedBuffer = new TimedBuffer(null, 100, TimedBufferTest.ONE_SECOND_IN_NANOS, false);
timedBuffer.start();
try {
timedBuffer.setObserver(new TestObserver());
int x = 0;
for (int i = 0; i < 10; i++) {
byte[] bytes = new byte[10];
for (int j = 0; j < 10; j++) {
bytes[j] = ActiveMQTestBase.getSamplebyte(x++);
}
ActiveMQBuffer buff = ActiveMQBuffers.wrappedBuffer(bytes);
timedBuffer.checkSize(10);
timedBuffer.addBytes(buff, false, dummyCallback);
}
timedBuffer.checkSize(1);
Assert.assertEquals(1, flushTimes.get());
ByteBuffer flushedBuffer = buffers.get(0);
Assert.assertEquals(100, flushedBuffer.limit());
Assert.assertEquals(100, flushedBuffer.capacity());
flushedBuffer.rewind();
for (int i = 0; i < 100; i++) {
Assert.assertEquals(ActiveMQTestBase.getSamplebyte(i), flushedBuffer.get());
}
} finally {
timedBuffer.stop();
}
}
use of org.apache.activemq.artemis.api.core.ActiveMQBuffer in project activemq-artemis by apache.
the class UTF8Test method testWriteUTF.
@Test
public void testWriteUTF() throws Exception {
ActiveMQBuffer buffer = ActiveMQBuffers.fixedBuffer(10 * 1024);
for (int c = 0; c < TIMES; c++) {
final long start = System.currentTimeMillis();
for (long i = 0; i < numberOfIteractions; i++) {
buffer.clear();
buffer.writeUTF(str);
blackHole = buffer;
}
final long spentTime = System.currentTimeMillis() - start;
System.out.println("Time writeUTF = " + spentTime + " ms");
System.out.println("Throughput writeUTF = " + numberOfIteractions / spentTime + " ops/ms");
}
}
Aggregations