use of org.apache.activemq.command.ActiveMQQueue in project activemq-artemis by apache.
the class BrokerTest method testQueueOnlyOnceDeliveryWith2Consumers.
public void testQueueOnlyOnceDeliveryWith2Consumers() throws Exception {
ActiveMQDestination destination = new ActiveMQQueue("TEST");
// Setup a first connection
StubConnection connection1 = createConnection();
ConnectionInfo connectionInfo1 = createConnectionInfo();
SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
ProducerInfo producerInfo = createProducerInfo(sessionInfo1);
connection1.send(connectionInfo1);
connection1.send(sessionInfo1);
connection1.send(producerInfo);
ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
consumerInfo1.setPrefetchSize(1);
connection1.request(consumerInfo1);
// Setup a second connection
StubConnection connection2 = createConnection();
ConnectionInfo connectionInfo2 = createConnectionInfo();
SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
consumerInfo2.setPrefetchSize(1);
connection2.send(connectionInfo2);
connection2.send(sessionInfo2);
connection2.request(consumerInfo2);
// Send the messages
connection1.send(createMessage(producerInfo, destination, deliveryMode));
connection1.send(createMessage(producerInfo, destination, deliveryMode));
connection1.send(createMessage(producerInfo, destination, deliveryMode));
connection1.request(createMessage(producerInfo, destination, deliveryMode));
for (int i = 0; i < 2; i++) {
Message m1 = receiveMessage(connection1);
Message m2 = receiveMessage(connection2);
assertNotNull("m1 is null for index: " + i, m1);
assertNotNull("m2 is null for index: " + i, m2);
assertNotSame(m1.getMessageId(), m2.getMessageId());
connection1.send(createAck(consumerInfo1, m1, 1, MessageAck.STANDARD_ACK_TYPE));
connection2.send(createAck(consumerInfo2, m2, 1, MessageAck.STANDARD_ACK_TYPE));
}
assertNoMessagesLeft(connection1);
assertNoMessagesLeft(connection2);
}
use of org.apache.activemq.command.ActiveMQQueue in project activemq-artemis by apache.
the class BrokerTest method initCombosForTestConsumerClose.
public void initCombosForTestConsumerClose() {
addCombinationValues("deliveryMode", new Object[] { Integer.valueOf(DeliveryMode.NON_PERSISTENT), Integer.valueOf(DeliveryMode.PERSISTENT) });
addCombinationValues("destination", new Object[] { new ActiveMQTopic("TEST"), new ActiveMQQueue("TEST") });
}
use of org.apache.activemq.command.ActiveMQQueue in project activemq-artemis by apache.
the class RedeliveryPolicyTest method testInitialRedeliveryDelayZero.
public void testInitialRedeliveryDelayZero() throws Exception {
// Receive a message with the JMS API
RedeliveryPolicy policy = connection.getRedeliveryPolicy();
policy.setInitialRedeliveryDelay(0);
policy.setUseExponentialBackOff(false);
policy.setMaximumRedeliveries(1);
connection.start();
Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
ActiveMQQueue destination = new ActiveMQQueue("TEST");
MessageProducer producer = session.createProducer(destination);
MessageConsumer consumer = session.createConsumer(destination);
// Send the messages
producer.send(session.createTextMessage("1st"));
producer.send(session.createTextMessage("2nd"));
session.commit();
TextMessage m;
m = (TextMessage) consumer.receive(100);
assertNotNull(m);
assertEquals("1st", m.getText());
session.rollback();
m = (TextMessage) consumer.receive(100);
assertNotNull(m);
assertEquals("1st", m.getText());
m = (TextMessage) consumer.receive(100);
assertNotNull(m);
assertEquals("2nd", m.getText());
session.commit();
session.commit();
}
use of org.apache.activemq.command.ActiveMQQueue in project activemq-artemis by apache.
the class RedeliveryPolicyTest method testExponentialRedeliveryPolicyDelaysDeliveryOnRollback.
/**
* @throws Exception
*/
public void testExponentialRedeliveryPolicyDelaysDeliveryOnRollback() throws Exception {
// Receive a message with the JMS API
RedeliveryPolicy policy = connection.getRedeliveryPolicy();
policy.setInitialRedeliveryDelay(0);
policy.setRedeliveryDelay(500);
policy.setBackOffMultiplier((short) 2);
policy.setUseExponentialBackOff(true);
connection.start();
Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
ActiveMQQueue destination = new ActiveMQQueue(getName());
MessageProducer producer = session.createProducer(destination);
MessageConsumer consumer = session.createConsumer(destination);
// Send the messages
producer.send(session.createTextMessage("1st"));
producer.send(session.createTextMessage("2nd"));
session.commit();
TextMessage m;
m = (TextMessage) consumer.receive(1000);
assertNotNull(m);
assertEquals("1st", m.getText());
session.rollback();
// No delay on first rollback..
m = (TextMessage) consumer.receive(100);
assertNotNull(m);
session.rollback();
// Show subsequent re-delivery delay is incrementing.
m = (TextMessage) consumer.receive(100);
assertNull(m);
m = (TextMessage) consumer.receive(700);
assertNotNull(m);
assertEquals("1st", m.getText());
session.rollback();
// Show re-delivery delay is incrementing exponentially
m = (TextMessage) consumer.receive(100);
assertNull(m);
m = (TextMessage) consumer.receive(500);
assertNull(m);
m = (TextMessage) consumer.receive(700);
assertNotNull(m);
assertEquals("1st", m.getText());
}
use of org.apache.activemq.command.ActiveMQQueue in project activemq-artemis by apache.
the class RedeliveryPolicyTest method testMaximumRedeliveryDelay.
/**
* @throws Exception
*/
public void testMaximumRedeliveryDelay() throws Exception {
// Receive a message with the JMS API
RedeliveryPolicy policy = connection.getRedeliveryPolicy();
policy.setInitialRedeliveryDelay(10);
policy.setUseExponentialBackOff(true);
policy.setMaximumRedeliveries(-1);
policy.setRedeliveryDelay(50);
policy.setMaximumRedeliveryDelay(1000);
policy.setBackOffMultiplier((short) 2);
policy.setUseExponentialBackOff(true);
connection.start();
Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
ActiveMQQueue destination = new ActiveMQQueue("TEST");
MessageProducer producer = session.createProducer(destination);
MessageConsumer consumer = session.createConsumer(destination);
// Send the messages
producer.send(session.createTextMessage("1st"));
producer.send(session.createTextMessage("2nd"));
session.commit();
TextMessage m;
for (int i = 0; i < 10; ++i) {
// we should be able to get the 1st message redelivered until a session.commit is called
m = (TextMessage) consumer.receive(2000);
assertNotNull(m);
assertEquals("1st", m.getText());
session.rollback();
}
m = (TextMessage) consumer.receive(2000);
assertNotNull(m);
assertEquals("1st", m.getText());
session.commit();
m = (TextMessage) consumer.receive(2000);
assertNotNull(m);
assertEquals("2nd", m.getText());
session.commit();
assertTrue(policy.getNextRedeliveryDelay(Long.MAX_VALUE) == 1000);
}
Aggregations