use of org.apache.activemq.broker.region.Destination in project activemq-artemis by apache.
the class DurableUnsubscribeTest method testDestroy.
public void testDestroy() throws Exception {
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
session.createDurableSubscriber(topic, "SubsId2");
session.close();
connection.close();
connection = null;
Thread.sleep(1000);
Destination d = broker.getDestination(topic);
assertEquals("Subscription is missing.", 1, d.getConsumers().size());
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName[] subNames = broker.getAdminView().getInactiveDurableTopicSubscribers();
mbs.invoke(subNames[0], "destroy", new Object[0], new String[0]);
assertEquals("Subscription exists.", 0, d.getConsumers().size());
}
use of org.apache.activemq.broker.region.Destination in project activemq-artemis by apache.
the class MemoryLimitTest method testCursorBatch.
@Test(timeout = 120000)
public void testCursorBatch() throws Exception {
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://localhost?jms.prefetchPolicy.all=10");
factory.setOptimizeAcknowledge(true);
Connection conn = factory.createConnection();
conn.start();
Session sess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
Queue queue = sess.createQueue("STORE");
final ProducerThread producer = new ProducerThread(sess, queue) {
@Override
protected Message createMessage(int i) throws Exception {
BytesMessage bytesMessage = sess.createBytesMessage();
bytesMessage.writeBytes(payload);
return bytesMessage;
}
};
producer.setMessageCount(2000);
producer.start();
producer.join();
Thread.sleep(1000);
// assert we didn't break high watermark (70%) usage
final Destination dest = broker.getDestination((ActiveMQQueue) queue);
LOG.info("Destination usage: " + dest.getMemoryUsage());
int percentUsage = dest.getMemoryUsage().getPercentUsage();
assertTrue("Should be less than 70% of limit but was: " + percentUsage, percentUsage <= 71);
LOG.info("Broker usage: " + broker.getSystemUsage().getMemoryUsage());
assertTrue(broker.getSystemUsage().getMemoryUsage().getPercentUsage() <= 71);
// consume one message
MessageConsumer consumer = sess.createConsumer(queue);
Message msg = consumer.receive(5000);
msg.acknowledge();
// this should free some space and allow us to get new batch of messages in the memory
// exceeding the limit
assertTrue("Limit is exceeded", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
LOG.info("Destination usage: " + dest.getMemoryUsage());
return dest.getMemoryUsage().getPercentUsage() >= 200;
}
}));
LOG.info("Broker usage: " + broker.getSystemUsage().getMemoryUsage());
assertTrue(broker.getSystemUsage().getMemoryUsage().getPercentUsage() >= 200);
// let's make sure we can consume all messages
for (int i = 1; i < 2000; i++) {
msg = consumer.receive(5000);
if (msg == null) {
dumpAllThreads("NoMessage");
}
assertNotNull("Didn't receive message " + i, msg);
msg.acknowledge();
}
}
use of org.apache.activemq.broker.region.Destination in project gocd by gocd.
the class ActiveMqMessagingService method removeQueue.
@Override
public void removeQueue(String queueName) {
try {
ActiveMQQueue destination = new ActiveMQQueue(queueName);
ConnectionContext connectionContext = BrokerSupport.getConnectionContext(broker.getBroker());
Destination brokerDestination = broker.getDestination(destination);
List<Subscription> consumers = brokerDestination.getConsumers();
for (Subscription consumer : consumers) {
consumer.remove(connectionContext, brokerDestination);
brokerDestination.removeSubscription(connectionContext, consumer, 0);
}
broker.getBroker().removeDestination(connectionContext, destination, 1000);
broker.removeDestination(destination);
} catch (Exception e) {
throw bomb(e);
}
}
use of org.apache.activemq.broker.region.Destination in project activemq-artemis by apache.
the class NetworkRemovesSubscriptionsTest method testWithoutSessionAndSubsciberClose.
public void testWithoutSessionAndSubsciberClose() throws Exception {
TopicConnection connection = connectionFactory.createTopicConnection();
connection.start();
for (int i = 0; i < 100; i++) {
TopicSession subscriberSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
TopicSubscriber subscriber = subscriberSession.createSubscriber(topic);
assertNotNull(subscriber);
}
connection.close();
Thread.sleep(1000);
Destination dest = backEnd.getRegionBroker().getDestinationMap().get(topic);
assertNotNull(dest);
assertTrue(dest.getConsumers().isEmpty());
}
use of org.apache.activemq.broker.region.Destination in project activemq-artemis by apache.
the class NetworkRemovesSubscriptionsTest method testWithoutSessionAndSubsciberClosePlayAround.
/**
* Running this test you can produce a leak of only 2 ConsumerInfo on BE
* broker, NOT 200 as in other cases!
*/
public void testWithoutSessionAndSubsciberClosePlayAround() throws Exception {
TopicConnection connection = connectionFactory.createTopicConnection();
connection.start();
for (int i = 0; i < 100; i++) {
TopicSession subscriberSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
TopicSubscriber subscriber = subscriberSession.createSubscriber(topic);
DummyMessageListener listener = new DummyMessageListener();
subscriber.setMessageListener(listener);
if (i != 50) {
subscriber.close();
subscriberSession.close();
}
}
connection.close();
Thread.sleep(1000);
Destination dest = backEnd.getRegionBroker().getDestinationMap().get(topic);
assertNotNull(dest);
assertTrue(dest.getConsumers().isEmpty());
}
Aggregations