use of org.apache.activemq.artemis.api.core.client.ClientSessionFactory in project activemq-artemis by apache.
the class LargeMessageTest method testDeleteOnNoBinding.
@Test
public void testDeleteOnNoBinding() throws Exception {
final int messageSize = (int) (3.5 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE);
ActiveMQServer server = createServer(true, isNetty(), storeType);
server.start();
ClientSessionFactory sf = addSessionFactory(createSessionFactory(locator));
ClientSession session = addClientSession(sf.createSession(false, true, false));
ClientProducer producer = session.createProducer(UUID.randomUUID().toString());
Message clientFile = createLargeClientMessageStreaming(session, messageSize, true);
producer.send(clientFile);
session.close();
validateNoFilesOnLargeDir();
}
use of org.apache.activemq.artemis.api.core.client.ClientSessionFactory in project activemq-artemis by apache.
the class LargeMessageTest method testBufferMultipleLargeMessages.
@Test
public void testBufferMultipleLargeMessages() throws Exception {
ClientSession session = null;
ActiveMQServer server = null;
final int SIZE = 10 * 1024;
final int NUMBER_OF_MESSAGES = 30;
try {
server = createServer(true, isNetty(), storeType);
server.start();
locator.setMinLargeMessageSize(1024).setConsumerWindowSize(1024 * 1024);
ClientSessionFactory sf = addSessionFactory(createSessionFactory(locator));
session = sf.createSession(null, null, false, false, false, false, 0);
session.createQueue(ADDRESS, ADDRESS, null, true);
ClientProducer producer = session.createProducer(ADDRESS);
for (int i = 0; i < NUMBER_OF_MESSAGES; i++) {
ClientMessage clientFile = session.createMessage(true);
clientFile.setBodyInputStream(ActiveMQTestBase.createFakeLargeStream(SIZE));
producer.send(clientFile);
}
session.commit();
producer.close();
session.start();
ClientConsumerInternal consumer = (ClientConsumerInternal) session.createConsumer(ADDRESS);
// Wait the consumer to be complete with 10 messages before getting others
long timeout = System.currentTimeMillis() + 10000;
while (consumer.getBufferSize() < NUMBER_OF_MESSAGES && timeout > System.currentTimeMillis()) {
Thread.sleep(10);
}
Assert.assertEquals(NUMBER_OF_MESSAGES, consumer.getBufferSize());
// Reads the messages, rollback.. read them again
for (int trans = 0; trans < 2; trans++) {
for (int i = 0; i < NUMBER_OF_MESSAGES; i++) {
ClientMessage msg = consumer.receive(10000);
Assert.assertNotNull(msg);
// it will ignore the buffer (not read it) on the first try
if (trans == 0) {
for (int byteRead = 0; byteRead < SIZE; byteRead++) {
Assert.assertEquals(ActiveMQTestBase.getSamplebyte(byteRead), msg.getBodyBuffer().readByte());
}
}
msg.acknowledge();
}
if (trans == 0) {
session.rollback();
} else {
session.commit();
}
}
Assert.assertEquals(0, ((Queue) server.getPostOffice().getBinding(ADDRESS).getBindable()).getDeliveringCount());
Assert.assertEquals(0, getMessageCount(((Queue) server.getPostOffice().getBinding(ADDRESS).getBindable())));
} finally {
try {
session.close();
} catch (Throwable ignored) {
}
try {
server.stop();
} catch (Throwable ignored) {
}
}
}
use of org.apache.activemq.artemis.api.core.client.ClientSessionFactory in project activemq-artemis by apache.
the class LargeMessageTest method testTwoBindingsTwoStartedConsumers.
@Test
public void testTwoBindingsTwoStartedConsumers() 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();
SimpleString[] queue = new SimpleString[] { new SimpleString("queue1"), new SimpleString("queue2") };
ClientSessionFactory sf = addSessionFactory(createSessionFactory(locator));
ClientSession session = sf.createSession(null, null, false, true, true, false, 0);
session.createQueue(ADDRESS, queue[0], null, true);
session.createQueue(ADDRESS, queue[1], null, true);
int numberOfBytes = 400000;
Message clientFile = createLargeClientMessageStreaming(session, numberOfBytes);
ClientProducer producer = session.createProducer(ADDRESS);
session.start();
producer.send(clientFile);
producer.close();
ClientConsumer consumer = session.createConsumer(queue[1]);
ClientMessage msg = consumer.receive(LargeMessageTest.RECEIVE_WAIT_TIME);
msg.getBodyBuffer().readByte();
Assert.assertNull(consumer.receiveImmediate());
Assert.assertNotNull(msg);
msg.acknowledge();
consumer.close();
log.debug("Stopping");
session.stop();
ClientConsumer consumer1 = session.createConsumer(queue[0]);
session.start();
msg = consumer1.receive(LargeMessageTest.RECEIVE_WAIT_TIME);
Assert.assertNotNull(msg);
msg.acknowledge();
consumer1.close();
session.commit();
session.close();
validateNoFilesOnLargeDir();
}
use of org.apache.activemq.artemis.api.core.client.ClientSessionFactory in project activemq-artemis by apache.
the class LargeMessageTest method testReceiveMultipleMessages.
@Test
public void testReceiveMultipleMessages() throws Exception {
ClientSession session = null;
ActiveMQServer server = null;
final int SIZE = 10 * 1024;
final int NUMBER_OF_MESSAGES = 1000;
try {
server = createServer(true, isNetty(), storeType);
server.start();
locator.setMinLargeMessageSize(1024).setConsumerWindowSize(1024 * 1024);
ClientSessionFactory sf = addSessionFactory(createSessionFactory(locator));
session = sf.createSession(null, null, false, false, false, false, 0);
session.createQueue(ADDRESS, ADDRESS, null, true);
ClientProducer producer = session.createProducer(ADDRESS);
for (int i = 0; i < NUMBER_OF_MESSAGES; i++) {
ClientMessage clientFile = session.createMessage(true);
clientFile.setBodyInputStream(ActiveMQTestBase.createFakeLargeStream(SIZE));
producer.send(clientFile);
}
session.commit();
producer.close();
session.start();
// Reads the messages, rollback.. read them again
for (int trans = 0; trans < 2; trans++) {
ClientConsumerInternal consumer = (ClientConsumerInternal) session.createConsumer(ADDRESS);
// Wait the consumer to be complete with 10 messages before getting others
long timeout = System.currentTimeMillis() + 10000;
while (consumer.getBufferSize() < 10 && timeout > System.currentTimeMillis()) {
Thread.sleep(10);
}
for (int i = 0; i < NUMBER_OF_MESSAGES; i++) {
ClientMessage msg = consumer.receive(10000);
Assert.assertNotNull(msg);
// it will ignore the buffer (not read it) on the first try
if (trans == 0) {
for (int byteRead = 0; byteRead < SIZE; byteRead++) {
Assert.assertEquals(ActiveMQTestBase.getSamplebyte(byteRead), msg.getBodyBuffer().readByte());
}
}
msg.acknowledge();
}
if (trans == 0) {
session.rollback();
} else {
session.commit();
}
consumer.close();
}
Assert.assertEquals(0, ((Queue) server.getPostOffice().getBinding(ADDRESS).getBindable()).getDeliveringCount());
Assert.assertEquals(0, getMessageCount(((Queue) server.getPostOffice().getBinding(ADDRESS).getBindable())));
} finally {
try {
session.close();
} catch (Throwable ignored) {
}
try {
server.stop();
} catch (Throwable ignored) {
}
}
}
use of org.apache.activemq.artemis.api.core.client.ClientSessionFactory in project activemq-artemis by apache.
the class LargeMessageTest method testDLAOnExpiryNonDurableMessage.
@Test
public void testDLAOnExpiryNonDurableMessage() 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));
SimpleString ADDRESS_DLA = ADDRESS.concat("-dla");
SimpleString ADDRESS_EXPIRY = ADDRESS.concat("-expiry");
AddressSettings addressSettings = new AddressSettings().setDeadLetterAddress(ADDRESS_DLA).setExpiryAddress(ADDRESS_EXPIRY).setMaxDeliveryAttempts(1);
server.getAddressSettingsRepository().addMatch("*", addressSettings);
session = sf.createSession(false, false, false);
session.createQueue(ADDRESS, ADDRESS, true);
session.createQueue(ADDRESS_DLA, ADDRESS_DLA, true);
session.createQueue(ADDRESS_EXPIRY, ADDRESS_EXPIRY, true);
ClientProducer producer = session.createProducer(ADDRESS);
Message clientFile = createLargeClientMessageStreaming(session, messageSize, false);
clientFile.setExpiration(System.currentTimeMillis());
producer.send(clientFile);
session.commit();
session.start();
ClientConsumer consumerExpired = session.createConsumer(ADDRESS);
// to kick expiry quicker than waiting reaper thread
Assert.assertNull(consumerExpired.receiveImmediate());
consumerExpired.close();
ClientConsumer consumerExpiry = session.createConsumer(ADDRESS_EXPIRY);
ClientMessage msg1 = consumerExpiry.receive(5000);
assertTrue(msg1.isLargeMessage());
Assert.assertNotNull(msg1);
msg1.acknowledge();
for (int j = 0; j < messageSize; j++) {
Assert.assertEquals(ActiveMQTestBase.getSamplebyte(j), msg1.getBodyBuffer().readByte());
}
session.rollback();
consumerExpiry.close();
for (int i = 0; i < 10; i++) {
consumerExpiry = session.createConsumer(ADDRESS_DLA);
msg1 = consumerExpiry.receive(5000);
Assert.assertNotNull(msg1);
msg1.acknowledge();
for (int j = 0; j < messageSize; j++) {
Assert.assertEquals(ActiveMQTestBase.getSamplebyte(j), msg1.getBodyBuffer().readByte());
}
session.rollback();
consumerExpiry.close();
}
session.close();
session = sf.createSession(false, false, false);
session.start();
consumerExpiry = session.createConsumer(ADDRESS_DLA);
msg1 = consumerExpiry.receive(5000);
Assert.assertNotNull(msg1);
msg1.acknowledge();
for (int i = 0; i < messageSize; i++) {
Assert.assertEquals(ActiveMQTestBase.getSamplebyte(i), msg1.getBodyBuffer().readByte());
}
session.commit();
consumerExpiry.close();
session.commit();
session.close();
server.stop();
server.start();
validateNoFilesOnLargeDir();
}
Aggregations