use of org.apache.activemq.artemis.core.message.impl.CoreMessage 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.core.message.impl.CoreMessage in project activemq-artemis by apache.
the class PageTest method addPageElements.
/**
* @param simpleDestination
* @param page
* @param numberOfElements
* @return
* @throws Exception
*/
protected void addPageElements(final SimpleString simpleDestination, final Page page, final int numberOfElements) throws Exception {
int initialNumberOfMessages = page.getNumberOfMessages();
for (int i = 0; i < numberOfElements; i++) {
ICoreMessage msg = new CoreMessage().initBuffer(100);
for (int j = 0; j < 10; j++) {
msg.getBodyBuffer().writeByte((byte) 'b');
}
msg.setAddress(simpleDestination);
page.write(new PagedMessageImpl(msg, new long[0]));
Assert.assertEquals(initialNumberOfMessages + i + 1, page.getNumberOfMessages());
}
}
use of org.apache.activemq.artemis.core.message.impl.CoreMessage in project activemq-artemis by apache.
the class PagingManagerImplTest method createMessage.
protected ICoreMessage createMessage(final long messageId, final SimpleString destination, final ByteBuffer buffer) {
ICoreMessage msg = new CoreMessage(messageId, 200);
msg.setAddress(destination);
msg.getBodyBuffer().writeBytes(buffer);
return msg;
}
use of org.apache.activemq.artemis.core.message.impl.CoreMessage in project activemq-artemis by apache.
the class ManagementServiceImplTest method testHandleManagementMessageWithOperationWhichFails.
@Test
public void testHandleManagementMessageWithOperationWhichFails() throws Exception {
Configuration config = createBasicConfig().setJMXManagementEnabled(false);
ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(config, false));
server.start();
// invoke attribute and operation on the server
CoreMessage message = new CoreMessage(1, 100);
ManagementHelper.putOperationInvocation(message, ResourceNames.BROKER, "thereIsNoSuchOperation");
ICoreMessage reply = server.getManagementService().handleMessage(message);
Assert.assertFalse(ManagementHelper.hasOperationSucceeded(reply));
Assert.assertNotNull(ManagementHelper.getResult(reply));
}
use of org.apache.activemq.artemis.core.message.impl.CoreMessage in project activemq-artemis by apache.
the class ManagementServiceImplTest method testHandleManagementMessageWithKnownAttribute.
@Test
public void testHandleManagementMessageWithKnownAttribute() throws Exception {
Configuration config = createBasicConfig().setJMXManagementEnabled(false);
ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(config, false));
server.start();
// invoke attribute and operation on the server
ICoreMessage message = new CoreMessage(1, 100);
ManagementHelper.putAttribute(message, ResourceNames.BROKER, "attribute.Does.Not.Exist");
ICoreMessage reply = server.getManagementService().handleMessage(message);
Assert.assertFalse(ManagementHelper.hasOperationSucceeded(reply));
Assert.assertNotNull(ManagementHelper.getResult(reply));
}
Aggregations