use of org.apache.activemq.command.ActiveMQDestination in project activemq-artemis by apache.
the class AdvisoryBrokerTest method testProducerAdvisories.
public void testProducerAdvisories() throws Exception {
ActiveMQDestination queue = new ActiveMQQueue("test");
ActiveMQDestination destination = AdvisorySupport.getProducerAdvisoryTopic(queue);
// Setup a first connection
StubConnection connection1 = createConnection();
ConnectionInfo connectionInfo1 = createConnectionInfo();
SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
consumerInfo1.setPrefetchSize(100);
connection1.send(connectionInfo1);
connection1.send(sessionInfo1);
connection1.send(consumerInfo1);
assertNoMessagesLeft(connection1);
// Setup a producer.
StubConnection connection2 = createConnection();
ConnectionInfo connectionInfo2 = createConnectionInfo();
SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
ProducerInfo producerInfo2 = createProducerInfo(sessionInfo2);
producerInfo2.setDestination(queue);
connection2.send(connectionInfo2);
connection2.send(sessionInfo2);
connection2.send(producerInfo2);
// We should get an advisory of the new producer.
Message m1 = receiveMessage(connection1);
assertNotNull(m1);
assertNotNull(m1.getDataStructure());
assertEquals(((ProducerInfo) m1.getDataStructure()).getProducerId(), producerInfo2.getProducerId());
// Close the second connection.
connection2.request(closeConnectionInfo(connectionInfo2));
connection2.stop();
// We should get an advisory of the producer closing
m1 = receiveMessage(connection1);
assertNotNull(m1);
assertNotNull(m1.getDataStructure());
RemoveInfo r = (RemoveInfo) m1.getDataStructure();
assertEquals(r.getObjectId(), producerInfo2.getProducerId());
assertNoMessagesLeft(connection2);
}
use of org.apache.activemq.command.ActiveMQDestination in project activemq-artemis by apache.
the class DestinationRemoveRestartTest method doCheckRemoveActionAfterRestart.
public void doCheckRemoveActionAfterRestart() throws Exception {
boolean res = true;
final ActiveMQDestination[] list = broker.getRegionBroker().getDestinations();
for (final ActiveMQDestination element : list) {
final Destination destination = broker.getDestination(element);
if (destination.getActiveMQDestination().getPhysicalName().equals(destinationName)) {
res = false;
break;
}
}
assertTrue("The removed destination is reloaded after restart !", res);
}
use of org.apache.activemq.command.ActiveMQDestination in project activemq-artemis by apache.
the class MessageGroupTest method testGroupedMessagesDeliveredToOnlyOneConsumer.
public void testGroupedMessagesDeliveredToOnlyOneConsumer() throws Exception {
ActiveMQDestination destination = new ActiveMQQueue("TEST");
// Setup a first connection
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer1 = session.createConsumer(destination);
MessageProducer producer = session.createProducer(destination);
// Send the messages.
for (int i = 0; i < 4; i++) {
TextMessage message = session.createTextMessage("message " + i);
message.setStringProperty("JMSXGroupID", "TEST-GROUP");
message.setIntProperty("JMSXGroupSeq", i + 1);
LOG.info("sending message: " + message);
producer.send(message);
}
// the first 3
for (int i = 0; i < 3; i++) {
TextMessage m1 = (TextMessage) consumer1.receive(500);
assertNotNull("m1 is null for index: " + i, m1);
assertEquals(m1.getIntProperty("JMSXGroupSeq"), i + 1);
}
// Setup a second connection
Connection connection1 = factory.createConnection(userName, password);
connection1.start();
Session session2 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer2 = session2.createConsumer(destination);
// Close the first consumer.
consumer1.close();
// The last messages should now go the the second consumer.
for (int i = 0; i < 1; i++) {
TextMessage m1 = (TextMessage) consumer2.receive(500);
assertNotNull("m1 is null for index: " + i, m1);
assertEquals(m1.getIntProperty("JMSXGroupSeq"), 4 + i);
}
// assert that there are no other messages left for the consumer 2
Message m = consumer2.receive(100);
assertNull("consumer 2 has some messages left", m);
}
use of org.apache.activemq.command.ActiveMQDestination in project activemq-artemis by apache.
the class MessageGroupTest method testAddingConsumer.
public void testAddingConsumer() throws Exception {
ActiveMQDestination destination = new ActiveMQQueue("TEST");
// Setup a first connection
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(destination);
// MessageConsumer consumer = session.createConsumer(destination);
TextMessage message = session.createTextMessage("message");
message.setStringProperty("JMSXGroupID", "TEST-GROUP");
LOG.info("sending message: " + message);
producer.send(message);
MessageConsumer consumer = session.createConsumer(destination);
TextMessage msg = (TextMessage) consumer.receive();
assertNotNull(msg);
boolean first = msg.getBooleanProperty("JMSXGroupFirstForConsumer");
assertTrue(first);
}
use of org.apache.activemq.command.ActiveMQDestination in project activemq-artemis by apache.
the class MessageGroupConfigTest method doTestGroupConfiguration.
public MessageGroupMap doTestGroupConfiguration(String type, Class classType) throws Exception {
broker = new BrokerService();
PolicyEntry defaultEntry = new PolicyEntry();
defaultEntry.setMessageGroupMapFactoryType(type);
PolicyMap policyMap = new PolicyMap();
policyMap.setDefaultEntry(defaultEntry);
broker.setDestinationPolicy(policyMap);
broker.start();
super.topic = false;
ActiveMQDestination destination = (ActiveMQDestination) createDestination("org.apache.foo");
Queue brokerDestination = (Queue) broker.getDestination(destination);
assertNotNull(brokerDestination);
MessageGroupMap messageGroupMap = brokerDestination.getMessageGroupOwners();
assertNotNull(messageGroupMap);
assertTrue(messageGroupMap.getClass().isAssignableFrom(classType));
return messageGroupMap;
}
Aggregations