use of org.apache.activemq.artemis.api.core.ActiveMQBuffer in project activemq-artemis by apache.
the class FailoverTestBase method assertLargeMessageBody.
/**
* Large message version of {@link #assertMessageBody(int, ClientMessage)}.
*
* @param i
* @param message
*/
protected static void assertLargeMessageBody(final int i, final ClientMessage message) {
ActiveMQBuffer buffer = message.getBodyBuffer();
for (int j = 0; j < LARGE_MESSAGE_SIZE; j++) {
Assert.assertTrue("msg " + i + ", expecting " + LARGE_MESSAGE_SIZE + " bytes, got " + j, buffer.readable());
Assert.assertEquals("equal at " + j, ActiveMQTestBase.getSamplebyte(j), buffer.readByte());
}
}
use of org.apache.activemq.artemis.api.core.ActiveMQBuffer in project activemq-artemis by apache.
the class FailoverWithDivertTest method createLargeMessage.
private ClientMessage createLargeMessage(ClientSession session, final int largeSize) {
ClientMessage message = session.createMessage(true);
ActiveMQBuffer bodyBuffer = message.getBodyBuffer();
final int propSize = 10240;
while (bodyBuffer.writerIndex() < largeSize) {
byte[] prop = new byte[propSize];
bodyBuffer.writeBytes(prop);
}
return message;
}
use of org.apache.activemq.artemis.api.core.ActiveMQBuffer in project activemq-artemis by apache.
the class BackupSyncLargeMessageTest method testBackupStartsWhenLiveIsReceivingLargeMessage.
/**
* LargeMessages are passed from the client to the server in chunks. Here we test the backup
* starting the data synchronization with the live in the middle of a multiple chunks large
* message upload from the client to the live server.
*
* @throws Exception
*/
@Test
public void testBackupStartsWhenLiveIsReceivingLargeMessage() throws Exception {
final ClientSession session = addClientSession(sessionFactory.createSession(true, true));
session.createQueue(FailoverTestBase.ADDRESS, FailoverTestBase.ADDRESS, null, true);
final ClientProducer producer = session.createProducer(FailoverTestBase.ADDRESS);
final ClientMessage message = session.createMessage(true);
final int largeMessageSize = 1000 * MIN_LARGE_MESSAGE;
message.setBodyInputStream(ActiveMQTestBase.createFakeLargeStream(largeMessageSize));
final AtomicBoolean caughtException = new AtomicBoolean(false);
final CountDownLatch latch = new CountDownLatch(1);
final CountDownLatch latch2 = new CountDownLatch(1);
Runnable r = new Runnable() {
@Override
public void run() {
try {
latch.countDown();
producer.send(message);
sendMessages(session, producer, 20);
session.commit();
} catch (ActiveMQException e) {
e.printStackTrace();
caughtException.set(true);
} finally {
latch2.countDown();
}
}
};
Executors.defaultThreadFactory().newThread(r).start();
waitForLatch(latch);
startBackupFinishSyncing();
ActiveMQTestBase.waitForLatch(latch2);
crash(session);
assertFalse("no exceptions while sending message", caughtException.get());
session.start();
ClientConsumer consumer = session.createConsumer(FailoverTestBase.ADDRESS);
ClientMessage msg = consumer.receive(2000);
ActiveMQBuffer buffer = msg.getBodyBuffer();
for (int j = 0; j < largeMessageSize; j++) {
Assert.assertTrue("large msg , expecting " + largeMessageSize + " bytes, got " + j, buffer.readable());
Assert.assertEquals("equal at " + j, ActiveMQTestBase.getSamplebyte(j), buffer.readByte());
}
receiveMessages(consumer, 0, 20, true);
assertNull("there should be no more messages!", consumer.receiveImmediate());
consumer.close();
session.commit();
}
use of org.apache.activemq.artemis.api.core.ActiveMQBuffer in project activemq-artemis by apache.
the class PagingOMETest method testPageCleanup.
@Test
@BMRules(rules = { @BMRule(name = "fakeOME", targetClass = "org.apache.activemq.artemis.core.paging.cursor.PagedReferenceImpl", targetMethod = "getPagedMessage", targetLocation = "ENTRY", action = "org.apache.activemq.artemis.tests.extras.byteman.PagingOMETest.refCheck()") })
public void testPageCleanup() throws Exception {
clearDataRecreateServerDirs();
Configuration config = createDefaultConfig(false);
config.setJournalSyncNonTransactional(false);
HashMap<String, AddressSettings> map = new HashMap<>();
AddressSettings value = new AddressSettings();
map.put(ADDRESS.toString(), value);
server = createServer(true, config, PAGE_SIZE, PAGE_MAX, map);
server.start();
final int numberOfMessages = 2;
locator = createInVMNonHALocator();
locator.setBlockOnNonDurableSend(true);
locator.setBlockOnDurableSend(true);
locator.setBlockOnAcknowledge(false);
locator.setConsumerWindowSize(0);
sf = createSessionFactory(locator);
ClientSession session = sf.createSession(false, false, false);
session.createQueue(ADDRESS, ADDRESS, null, true);
Queue queue = server.locateQueue(ADDRESS);
queue.getPageSubscription().getPagingStore().startPaging();
Assert.assertTrue(queue.getPageSubscription().getPagingStore().isPaging());
ClientProducer producer = session.createProducer(PagingOMETest.ADDRESS);
ClientMessage message = null;
byte[] body = new byte[MESSAGE_SIZE];
ByteBuffer bb = ByteBuffer.wrap(body);
for (int j = 1; j <= MESSAGE_SIZE; j++) {
bb.put(getSamplebyte(j));
}
for (int i = 0; i < numberOfMessages; i++) {
message = session.createMessage(true);
ActiveMQBuffer bodyLocal = message.getBodyBuffer();
bodyLocal.writeBytes(body);
producer.send(message);
if (i % 1000 == 0) {
session.commit();
}
}
session.commit();
session = sf.createSession(false, false, false);
session.start();
Wait.assertTrue(() -> numberOfMessages == queue.getMessageCount());
// The consumer has to be created after the queue.getMessageCount assertion
// otherwise delivery could alter the messagecount and give us a false failure
ClientConsumer consumer = session.createConsumer(PagingOMETest.ADDRESS);
ClientMessage msg = null;
msg = consumer.receive(1000);
failureActive = true;
msg.individualAcknowledge();
try {
session.commit();
Assert.fail("exception expected");
} catch (Exception expected) {
}
failureActive = false;
session.rollback();
session.close();
sf.close();
locator.close();
server.stop();
server.start();
locator = createInVMNonHALocator();
locator.setBlockOnNonDurableSend(true);
locator.setBlockOnDurableSend(true);
locator.setBlockOnAcknowledge(false);
locator.setConsumerWindowSize(0);
sf = createSessionFactory(locator);
session = sf.createSession(false, false, false);
consumer = session.createConsumer(PagingOMETest.ADDRESS);
session.start();
for (int i = 0; i < numberOfMessages; i++) {
msg = consumer.receive(1000);
Assert.assertNotNull(msg);
msg.individualAcknowledge();
}
Assert.assertNull(consumer.receiveImmediate());
session.commit();
session.close();
sf.close();
server.stop();
}
use of org.apache.activemq.artemis.api.core.ActiveMQBuffer in project activemq-artemis by apache.
the class PagingTest method testRollbackOnSendThenSendMore.
@Test
public void testRollbackOnSendThenSendMore() throws Exception {
clearDataRecreateServerDirs();
Configuration config = createDefaultInVMConfig();
server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
server.start();
locator.setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true);
sf = createSessionFactory(locator);
ClientSession session = sf.createSession(null, null, false, false, true, false, 0);
session.createQueue(PagingTest.ADDRESS, PagingTest.ADDRESS, null, true);
Queue queue = server.locateQueue(ADDRESS);
queue.getPageSubscription().getPagingStore().startPaging();
ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
ClientMessage message;
for (int i = 0; i < 20; i++) {
message = session.createMessage(true);
ActiveMQBuffer bodyLocal = message.getBodyBuffer();
bodyLocal.writeBytes(new byte[100 * 4]);
message.putIntProperty(new SimpleString("id"), i);
producer.send(message);
session.commit();
queue.getPageSubscription().getPagingStore().forceAnotherPage();
}
for (int i = 20; i < 24; i++) {
message = session.createMessage(true);
ActiveMQBuffer bodyLocal = message.getBodyBuffer();
bodyLocal.writeBytes(new byte[100 * 4]);
message.putIntProperty(new SimpleString("id"), i);
producer.send(message);
}
session.rollback();
ClientSession consumerSession = sf.createSession(false, false);
queue.getPageSubscription().getPagingStore().disableCleanup();
queue.getPageSubscription().getPagingStore().getCursorProvider().cleanup();
consumerSession.start();
ClientConsumer consumer = consumerSession.createConsumer(ADDRESS, SimpleString.toSimpleString("id > 0"));
for (int i = 0; i < 19; i++) {
ClientMessage messageRec = consumer.receive(5000);
System.err.println("msg::" + messageRec);
Assert.assertNotNull(messageRec);
messageRec.acknowledge();
consumerSession.commit();
// The only reason I'm calling cleanup directly is that it would be easy to debug in case of bugs
// if you see an issue with cleanup here, enjoy debugging this method
queue.getPageSubscription().getPagingStore().getCursorProvider().cleanup();
}
queue.getPageSubscription().getPagingStore().enableCleanup();
consumerSession.close();
session.close();
sf.close();
server.stop();
}
Aggregations