use of org.apache.activemq.broker.artemiswrapper.ArtemisBrokerWrapper in project activemq-artemis by apache.
the class OptimizedAckTest method testReceivedMessageStillInflight.
public void testReceivedMessageStillInflight() throws Exception {
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createQueue("test");
MessageProducer producer = session.createProducer(queue);
for (int i = 0; i < 10; i++) {
producer.send(session.createTextMessage("Hello" + i));
}
MessageConsumer consumer = session.createConsumer(queue);
// check queue delivering count is 10
ArtemisBrokerWrapper broker = (ArtemisBrokerWrapper) ArtemisBrokerHelper.getBroker().getBroker();
Binding binding = broker.getServer().getPostOffice().getBinding(new SimpleString("test"));
final QueueImpl coreQueue = (QueueImpl) binding.getBindable();
assertTrue("delivering count is 10", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return 10 == coreQueue.getDeliveringCount();
}
}));
for (int i = 0; i < 6; i++) {
javax.jms.Message msg = consumer.receive(4000);
assertNotNull(msg);
assertEquals("all prefetch is still in flight: " + i, 10, coreQueue.getDeliveringCount());
}
for (int i = 6; i < 10; i++) {
javax.jms.Message msg = consumer.receive(4000);
assertNotNull(msg);
assertTrue("most are acked but 3 remain", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return 3 == coreQueue.getDeliveringCount();
}
}));
}
}
use of org.apache.activemq.broker.artemiswrapper.ArtemisBrokerWrapper in project activemq-artemis by apache.
the class OptimizedAckTest method testVerySlowReceivedMessageStillInflight.
public void testVerySlowReceivedMessageStillInflight() throws Exception {
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createQueue("test");
MessageProducer producer = session.createProducer(queue);
for (int i = 0; i < 10; i++) {
producer.send(session.createTextMessage("Hello" + i));
}
MessageConsumer consumer = session.createConsumer(queue);
// check queue delivering count is 10
ArtemisBrokerWrapper broker = (ArtemisBrokerWrapper) ArtemisBrokerHelper.getBroker().getBroker();
Binding binding = broker.getServer().getPostOffice().getBinding(new SimpleString("test"));
final QueueImpl coreQueue = (QueueImpl) binding.getBindable();
assertTrue("prefetch full", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return 10 == coreQueue.getDeliveringCount();
}
}));
for (int i = 0; i < 6; i++) {
Thread.sleep(400);
javax.jms.Message msg = consumer.receive(4000);
assertNotNull(msg);
assertEquals("all prefetch is still in flight: " + i, 10, coreQueue.getDeliveringCount());
}
for (int i = 6; i < 10; i++) {
Thread.sleep(400);
javax.jms.Message msg = consumer.receive(4000);
assertNotNull(msg);
assertTrue("most are acked but 3 remain", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return 3 == coreQueue.getDeliveringCount();
}
}));
}
}
use of org.apache.activemq.broker.artemiswrapper.ArtemisBrokerWrapper in project activemq-artemis by apache.
the class BrokerTest method testQueueTransactedAck.
public void testQueueTransactedAck() throws Exception {
// Setup a first connection
StubConnection connection1 = createConnection();
ConnectionInfo connectionInfo1 = createConnectionInfo();
SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
ProducerInfo producerInfo1 = createProducerInfo(sessionInfo1);
connection1.send(connectionInfo1);
connection1.send(sessionInfo1);
connection1.send(producerInfo1);
destination = createDestinationInfo(connection1, connectionInfo1, destinationType);
ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
consumerInfo1.setPrefetchSize(100);
connection1.send(consumerInfo1);
// Send the messages
for (int i = 0; i < 4; i++) {
Message message = createMessage(producerInfo1, destination, deliveryMode);
connection1.send(message);
}
// Begin the transaction.
LocalTransactionId txid = createLocalTransaction(sessionInfo1);
connection1.send(createBeginTransaction(connectionInfo1, txid));
// Acknowledge the first 2 messages.
for (int i = 0; i < 2; i++) {
Message m1 = receiveMessage(connection1);
assertNotNull("m1 is null for index: " + i, m1);
MessageAck ack = createAck(consumerInfo1, m1, 1, MessageAck.STANDARD_ACK_TYPE);
ack.setTransactionId(txid);
connection1.request(ack);
}
// Commit the transaction.
connection1.send(createCommitTransaction1Phase(connectionInfo1, txid));
// due to async tx operations, we need some time for message count to go down
Thread.sleep(1000);
ArtemisBrokerWrapper wrapper = (ArtemisBrokerWrapper) broker.getBroker();
long messageCount = wrapper.getAMQueueMessageCount(destination);
// The queue should now only have the remaining 2 messages
assertEquals(2, messageCount);
}
Aggregations