use of org.apache.activemq.artemis.api.core.Message in project activemq-artemis by apache.
the class LargeMessageTest method testExpiryLargeMessage.
@Test
public void testExpiryLargeMessage() throws Exception {
final int messageSize = 3 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE;
ClientSession session = null;
try {
ActiveMQServer server = createServer(true, isNetty(), storeType);
server.start();
SimpleString ADDRESS_EXPIRY = ADDRESS.concat("-expiry");
AddressSettings addressSettings = new AddressSettings().setExpiryAddress(ADDRESS_EXPIRY);
server.getAddressSettingsRepository().addMatch("*", addressSettings);
ClientSessionFactory sf = addSessionFactory(createSessionFactory(locator));
session = sf.createSession(false, false, false);
session.createQueue(ADDRESS, ADDRESS, true);
session.createQueue(ADDRESS_EXPIRY, ADDRESS_EXPIRY, true);
ClientProducer producer = session.createProducer(ADDRESS);
Message clientFile = createLargeClientMessageStreaming(session, messageSize, true);
clientFile.setExpiration(System.currentTimeMillis());
producer.send(clientFile);
session.commit();
session.start();
ClientConsumer consumer = session.createConsumer(ADDRESS_EXPIRY);
// Creating a consumer just to make the expiry process go faster and not have to wait for the reaper
ClientConsumer consumer2 = session.createConsumer(ADDRESS);
Assert.assertNull(consumer2.receiveImmediate());
ClientMessage msg1 = consumer.receive(50000);
Assert.assertNotNull(msg1);
for (int i = 0; i < messageSize; i++) {
Assert.assertEquals(ActiveMQTestBase.getSamplebyte(i), msg1.getBodyBuffer().readByte());
}
session.close();
server.stop();
server = createServer(true, isNetty(), storeType);
server.start();
sf = createSessionFactory(locator);
session = sf.createSession(false, false, false);
session.start();
consumer = session.createConsumer(ADDRESS_EXPIRY);
msg1 = consumer.receive(10000);
Assert.assertNotNull(msg1);
for (int i = 0; i < messageSize; i++) {
Assert.assertEquals(ActiveMQTestBase.getSamplebyte(i), msg1.getBodyBuffer().readByte());
}
msg1.acknowledge();
session.commit();
session.close();
validateNoFilesOnLargeDir();
} finally {
try {
session.close();
} catch (Throwable ignored) {
}
}
}
use of org.apache.activemq.artemis.api.core.Message in project activemq-artemis by apache.
the class LargeMessageTest method simpleRollbackInternalTest.
public void simpleRollbackInternalTest(final boolean isXA) throws Exception {
// there are two bindings.. one is ACKed, the other is not, the server is restarted
// The other binding is acked... The file must be deleted
ActiveMQServer server = createServer(true, isNetty(), storeType);
server.start();
ClientSessionFactory sf = addSessionFactory(createSessionFactory(locator));
ClientSession session = sf.createSession(isXA, false, false);
Xid xid = null;
if (isXA) {
xid = newXID();
session.start(xid, XAResource.TMNOFLAGS);
}
session.createQueue(ADDRESS, ADDRESS, null, true);
int numberOfBytes = 200000;
session.start();
ClientProducer producer = session.createProducer(ADDRESS);
ClientConsumer consumer = session.createConsumer(ADDRESS);
for (int n = 0; n < 10; n++) {
Message clientFile = createLargeClientMessageStreaming(session, numberOfBytes, n % 2 == 0);
producer.send(clientFile);
Assert.assertNull(consumer.receiveImmediate());
if (isXA) {
session.end(xid, XAResource.TMSUCCESS);
session.rollback(xid);
xid = newXID();
session.start(xid, XAResource.TMNOFLAGS);
} else {
session.rollback();
}
clientFile = createLargeClientMessageStreaming(session, numberOfBytes, n % 2 == 0);
producer.send(clientFile);
Assert.assertNull(consumer.receiveImmediate());
if (isXA) {
session.end(xid, XAResource.TMSUCCESS);
session.commit(xid, true);
xid = newXID();
session.start(xid, XAResource.TMNOFLAGS);
} else {
session.commit();
}
for (int i = 0; i < 2; i++) {
ClientMessage clientMessage = consumer.receive(5000);
Assert.assertNotNull(clientMessage);
Assert.assertEquals(numberOfBytes, clientMessage.getBodySize());
clientMessage.acknowledge();
if (isXA) {
if (i == 0) {
session.end(xid, XAResource.TMSUCCESS);
session.prepare(xid);
session.rollback(xid);
xid = newXID();
session.start(xid, XAResource.TMNOFLAGS);
} else {
session.end(xid, XAResource.TMSUCCESS);
session.commit(xid, true);
xid = newXID();
session.start(xid, XAResource.TMNOFLAGS);
}
} else {
if (i == 0) {
session.rollback();
} else {
session.commit();
}
}
}
}
session.close();
validateNoFilesOnLargeDir();
}
use of org.apache.activemq.artemis.api.core.Message in project activemq-artemis by apache.
the class DeadLetterAddressTest method testReceiveWithListeners.
@Test
public void testReceiveWithListeners() throws Exception {
SimpleString dla = new SimpleString("DLA");
SimpleString qName = new SimpleString("q1");
AddressSettings addressSettings = new AddressSettings().setMaxDeliveryAttempts(2).setDeadLetterAddress(dla);
server.getAddressSettingsRepository().addMatch(qName.toString(), addressSettings);
SimpleString dlq = new SimpleString("DLQ1");
clientSession.createQueue(dla, dlq, null, false);
clientSession.createQueue(qName, qName, null, false);
ClientProducer producer = clientSession.createProducer(qName);
producer.send(createTextMessage(clientSession, "heyho!"));
ClientConsumer clientConsumer = clientSession.createConsumer(qName);
final CountDownLatch latch = new CountDownLatch(2);
TestHandler handler = new TestHandler(latch, clientSession);
clientConsumer.setMessageHandler(handler);
clientSession.start();
assertTrue(latch.await(5, TimeUnit.SECONDS));
assertEquals(handler.count, 2);
clientConsumer = clientSession.createConsumer(dlq);
Message m = clientConsumer.receive(5000);
Assert.assertNotNull(m);
Assert.assertEquals(m.getBodyBuffer().readString(), "heyho!");
}
use of org.apache.activemq.artemis.api.core.Message in project activemq-artemis by apache.
the class InterruptedLargeMessageTest method testConsumeAfterRestart.
@Test
public void testConsumeAfterRestart() throws Exception {
ClientSession session = null;
LargeMessageTestInterceptorIgnoreLastPacket.clearInterrupt();
ActiveMQServer server = createServer(true, isNetty());
server.start();
QueueFactory original = server.getQueueFactory();
locator.setBlockOnNonDurableSend(true).setBlockOnDurableSend(true);
ClientSessionFactory sf = createSessionFactory(locator);
session = sf.createSession(false, true, true);
session.createQueue(ADDRESS, ADDRESS, true);
ClientProducer producer = session.createProducer(ADDRESS);
for (int i = 0; i < 10; i++) {
Message clientFile = createLargeClientMessageStreaming(session, LARGE_MESSAGE_SIZE, true);
producer.send(clientFile);
}
session.commit();
session.close();
sf.close();
server.stop();
server.start();
sf = createSessionFactory(locator);
session = sf.createSession(false, false);
ClientConsumer cons = session.createConsumer(ADDRESS);
session.start();
for (int i = 0; i < 10; i++) {
ClientMessage msg = cons.receive(5000);
Assert.assertNotNull(msg);
msg.saveToOutputStream(new java.io.OutputStream() {
@Override
public void write(int b) throws IOException {
}
});
msg.acknowledge();
session.commit();
}
((ActiveMQServerImpl) server).replaceQueueFactory(original);
server.fail(false);
server.start();
server.stop();
validateNoFilesOnLargeDir();
}
use of org.apache.activemq.artemis.api.core.Message in project activemq-artemis by apache.
the class InterruptedLargeMessageTest method testSendPaging.
@Test
public void testSendPaging() throws Exception {
ClientSession session = null;
LargeMessageTestInterceptorIgnoreLastPacket.disableInterrupt();
ActiveMQServer server = createServer(true, createDefaultConfig(isNetty()), 10000, 20000, new HashMap<String, AddressSettings>());
// server.getConfiguration()
// .getIncomingInterceptorClassNames()
// .add(LargeMessageTestInterceptorIgnoreLastPacket.class.getName());
server.start();
locator.setBlockOnNonDurableSend(true).setBlockOnDurableSend(true);
ClientSessionFactory sf = createSessionFactory(locator);
session = sf.createSession(false, true, true);
session.createQueue(ADDRESS, ADDRESS, true);
server.getPagingManager().getPageStore(ADDRESS).startPaging();
ClientProducer producer = session.createProducer(ADDRESS);
for (int i = 0; i < 10; i++) {
Message clientFile = createLargeClientMessageStreaming(session, LARGE_MESSAGE_SIZE, true);
producer.send(clientFile);
}
session.commit();
validateNoFilesOnLargeDir(server.getConfiguration().getLargeMessagesDirectory(), 10);
for (int h = 0; h < 5; h++) {
session.close();
sf.close();
server.stop();
server.start();
sf = createSessionFactory(locator);
session = sf.createSession(false, false);
ClientConsumer cons = session.createConsumer(ADDRESS);
session.start();
for (int i = 0; i < 10; i++) {
ClientMessage clientMessage = cons.receive(5000);
Assert.assertNotNull(clientMessage);
for (int countByte = 0; countByte < LARGE_MESSAGE_SIZE; countByte++) {
Assert.assertEquals(ActiveMQTestBase.getSamplebyte(countByte), clientMessage.getBodyBuffer().readByte());
}
clientMessage.acknowledge();
}
if (h == 4) {
session.commit();
} else {
session.rollback();
}
session.close();
sf.close();
}
server.fail(false);
server.start();
validateNoFilesOnLargeDir();
}
Aggregations