use of org.apache.activemq.artemis.api.core.Message in project activemq-artemis by apache.
the class LargeMessageCompressTest method testLargeMessageCompression.
@Test
public void testLargeMessageCompression() throws Exception {
final int messageSize = (int) (3.5 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE);
ActiveMQServer server = createServer(true, isNetty());
server.start();
ClientSessionFactory sf = createSessionFactory(locator);
ClientSession session = addClientSession(sf.createSession(false, false, false));
session.createTemporaryQueue(ADDRESS, ADDRESS);
ClientProducer producer = session.createProducer(ADDRESS);
Message clientFile = createLargeClientMessageStreaming(session, messageSize, true);
producer.send(clientFile);
session.commit();
session.start();
ClientConsumer consumer = session.createConsumer(ADDRESS);
ClientMessage msg1 = consumer.receive(1000);
Assert.assertNotNull(msg1);
for (int i = 0; i < messageSize; i++) {
byte b = msg1.getBodyBuffer().readByte();
assertEquals("position = " + i, getSamplebyte(i), b);
}
msg1.acknowledge();
session.commit();
consumer.close();
session.close();
validateNoFilesOnLargeDir();
}
use of org.apache.activemq.artemis.api.core.Message in project activemq-artemis by apache.
the class ActiveMQCrashTest method testHang.
@Test
public void testHang() throws Exception {
Configuration configuration = createDefaultInVMConfig().setPersistenceEnabled(false);
server = addServer(ActiveMQServers.newActiveMQServer(configuration));
server.start();
server.getRemotingService().addIncomingInterceptor(new AckInterceptor(server));
// Force an ack at once - this means the send call will block
locator.setConfirmationWindowSize(1);
ClientSessionFactory clientSessionFactory = createSessionFactory(locator);
ClientSession session = clientSessionFactory.createSession();
session.setSendAcknowledgementHandler(new SendAcknowledgementHandler() {
@Override
public void sendAcknowledged(final Message message) {
ackReceived = true;
}
});
ClientProducer producer = session.createProducer("fooQueue");
ClientMessage msg = session.createMessage(false);
msg.putStringProperty("someKey", "someValue");
producer.send(msg);
Thread.sleep(250);
Assert.assertFalse(ackReceived);
session.close();
}
use of org.apache.activemq.artemis.api.core.Message in project activemq-artemis by apache.
the class LargeMessageTest method internalTestResendMessage.
public void internalTestResendMessage(final long messageSize) throws Exception {
clearDataRecreateServerDirs();
ClientSession session = null;
try {
ActiveMQServer server = createServer(true, isNetty(), storeType);
server.start();
ClientSessionFactory sf = addSessionFactory(createSessionFactory(locator));
session = sf.createSession(false, false, false);
session.createQueue(ADDRESS, ADDRESS, true);
SimpleString ADDRESS2 = ADDRESS.concat("-2");
session.createQueue(ADDRESS2, ADDRESS2, true);
ClientProducer producer = session.createProducer(ADDRESS);
ClientProducer producer2 = session.createProducer(ADDRESS2);
Message clientFile = createLargeClientMessageStreaming(session, messageSize, false);
producer.send(clientFile);
session.commit();
session.start();
ClientConsumer consumer = session.createConsumer(ADDRESS);
ClientConsumer consumer2 = session.createConsumer(ADDRESS2);
ClientMessage msg1 = consumer.receive(10000);
msg1.acknowledge();
producer2.send(msg1);
session.commit();
ClientMessage msg2 = consumer2.receive(10000);
Assert.assertNotNull(msg2);
msg2.acknowledge();
session.commit();
Assert.assertEquals(messageSize, msg2.getBodySize());
compareString(messageSize, msg2);
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 testDeleteOnDrop.
@Test
public void testDeleteOnDrop() throws Exception {
fillAddress();
final int messageSize = (int) (3.5 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE);
ClientSessionFactory sf = addSessionFactory(createSessionFactory(locator));
ClientSession session = addClientSession(sf.createSession(false, true, false));
ClientProducer producer = session.createProducer(ADDRESS);
Message clientFile = createLargeClientMessageStreaming(session, messageSize, true);
// Send large message which should be dropped and deleted from the filesystem
producer.send(clientFile);
validateNoFilesOnLargeDir();
}
use of org.apache.activemq.artemis.api.core.Message in project activemq-artemis by apache.
the class LargeMessageTest method testDLALargeMessage.
@Test
public void testDLALargeMessage() throws Exception {
final int messageSize = (int) (3.5 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE);
ClientSession session = null;
ActiveMQServer server = createServer(true, isNetty(), storeType);
server.start();
ClientSessionFactory sf = addSessionFactory(createSessionFactory(locator));
session = addClientSession(sf.createSession(false, false, false));
session.createQueue(ADDRESS, ADDRESS, true);
session.createQueue(ADDRESS, ADDRESS.concat("-2"), true);
SimpleString ADDRESS_DLA = ADDRESS.concat("-dla");
AddressSettings addressSettings = new AddressSettings().setDeadLetterAddress(ADDRESS_DLA).setMaxDeliveryAttempts(1);
server.getAddressSettingsRepository().addMatch("*", addressSettings);
session.createQueue(ADDRESS_DLA, ADDRESS_DLA, true);
ClientProducer producer = session.createProducer(ADDRESS);
Message clientFile = createLargeClientMessageStreaming(session, messageSize, true);
producer.send(clientFile);
session.commit();
session.start();
ClientConsumer consumer = session.createConsumer(ADDRESS_DLA);
ClientConsumer consumerRollback = session.createConsumer(ADDRESS);
ClientMessage msg1 = consumerRollback.receive(1000);
Assert.assertNotNull(msg1);
msg1.acknowledge();
session.rollback();
consumerRollback.close();
msg1 = consumer.receive(10000);
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_DLA);
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();
if (storeType != StoreConfiguration.StoreType.DATABASE) {
validateNoFilesOnLargeDir(server.getConfiguration().getLargeMessagesDirectory(), isCompressedTest ? 0 : 1);
}
consumer = session.createConsumer(ADDRESS.concat("-2"));
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();
if (storeType != StoreConfiguration.StoreType.DATABASE) {
validateNoFilesOnLargeDir();
}
}
Aggregations