use of org.apache.activemq.broker.jmx.DestinationViewMBean in project camel by apache.
the class QueueProducerQoSTest method testInOutQueueProducerTTL.
@Test
public void testInOutQueueProducerTTL() throws Exception {
mockExpiredAdvisory.expectedMessageCount(1);
String endpoint = String.format("sjms:queue:%s?ttl=1000&exchangePattern=InOut&responseTimeOut=500", TEST_INOUT_DESTINATION_NAME);
try {
template.requestBody(endpoint, "test message");
fail("we aren't expecting any consumers, so should not succeed");
} catch (Exception e) {
// we are expecting an exception here because there are no consumers on this queue,
// so we will not be able to do a real InOut/request-response, but that's okay
// we're just interested in the message becoming expired
}
assertMockEndpointsSatisfied();
DestinationViewMBean queue = getQueueMBean(TEST_INOUT_DESTINATION_NAME);
assertEquals("There were unexpected messages left in the queue: " + TEST_INOUT_DESTINATION_NAME, 0, queue.getQueueSize());
}
use of org.apache.activemq.broker.jmx.DestinationViewMBean in project activemq-artemis by apache.
the class TwoBrokerTempQueueAdvisoryTest method createView.
protected DestinationViewMBean createView(String broker, String destination, byte type) throws Exception {
String domain = "org.apache.activemq";
ObjectName name;
if (type == ActiveMQDestination.QUEUE_TYPE) {
name = new ObjectName(domain + ":type=Broker,brokerName=" + broker + ",destinationType=Queue,destinationName=" + destination);
} else {
name = new ObjectName(domain + ":type=Broker,brokerName=" + broker + ",destinationType=Topic,destinationName=" + destination);
}
return (DestinationViewMBean) brokers.get(broker).broker.getManagementContext().newProxyInstance(name, DestinationViewMBean.class, true);
}
use of org.apache.activemq.broker.jmx.DestinationViewMBean in project activemq-artemis by apache.
the class XARecoveryBrokerTest method getProxyToDestination.
private DestinationViewMBean getProxyToDestination(ActiveMQDestination destination) throws MalformedObjectNameException, JMSException {
final ObjectName objectName = new ObjectName("org.apache.activemq:type=Broker,brokerName=" + broker.getBrokerName() + ",destinationType=" + JMXSupport.encodeObjectNamePart(destination.getDestinationTypeAsString()) + ",destinationName=" + JMXSupport.encodeObjectNamePart(destination.getPhysicalName()));
DestinationViewMBean proxy = (DestinationViewMBean) broker.getManagementContext().newProxyInstance(objectName, DestinationViewMBean.class, true);
return proxy;
}
use of org.apache.activemq.broker.jmx.DestinationViewMBean in project activemq-artemis by apache.
the class ExpiredMessagesWithNoConsumerTest method testExpiredMessagesWithVerySlowConsumerCanContinue.
public void testExpiredMessagesWithVerySlowConsumerCanContinue() throws Exception {
createBroker();
final long queuePrefetch = 600;
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(connectionUri + "?jms.prefetchPolicy.queuePrefetch=" + queuePrefetch);
connection = factory.createConnection();
session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
producer = session.createProducer(destination);
final int ttl = 4000;
producer.setTimeToLive(ttl);
final long sendCount = 1500;
final CountDownLatch receivedOneCondition = new CountDownLatch(1);
final CountDownLatch waitCondition = new CountDownLatch(1);
final AtomicLong received = new AtomicLong();
MessageConsumer consumer = session.createConsumer(destination);
consumer.setMessageListener(new MessageListener() {
@Override
public void onMessage(Message message) {
try {
if (LOG.isDebugEnabled()) {
LOG.debug("Got my message: " + message);
}
receivedOneCondition.countDown();
received.incrementAndGet();
waitCondition.await(5, TimeUnit.MINUTES);
if (LOG.isDebugEnabled()) {
LOG.debug("acking message: " + message);
}
message.acknowledge();
} catch (Exception e) {
e.printStackTrace();
fail(e.toString());
}
}
});
connection.start();
final Thread producingThread = new Thread("Producing Thread") {
@Override
public void run() {
try {
int i = 0;
long tStamp = System.currentTimeMillis();
while (i++ < sendCount) {
producer.send(session.createTextMessage("test"));
if (i % 100 == 0) {
LOG.info("sent: " + i + " @ " + ((System.currentTimeMillis() - tStamp) / 100) + "m/ms");
tStamp = System.currentTimeMillis();
}
}
} catch (Throwable ex) {
ex.printStackTrace();
}
}
};
producingThread.start();
assertTrue("got one message", receivedOneCondition.await(20, TimeUnit.SECONDS));
assertTrue("producer failed to complete within allocated time", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
producingThread.join(1000);
return !producingThread.isAlive();
}
}, Wait.MAX_WAIT_MILLIS * 10));
final DestinationViewMBean view = createView(destination);
assertTrue("Not all dispatched up to default prefetch ", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return queuePrefetch == view.getDispatchCount();
}
}));
assertTrue("all non inflight have expired ", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
LOG.info("enqueue=" + view.getEnqueueCount() + ", dequeue=" + view.getDequeueCount() + ", inflight=" + view.getInFlightCount() + ", expired= " + view.getExpiredCount() + ", size= " + view.getQueueSize());
return view.getExpiredCount() > 0 && (view.getEnqueueCount() - view.getInFlightCount()) == view.getExpiredCount();
}
}));
LOG.info("enqueue=" + view.getEnqueueCount() + ", dequeue=" + view.getDequeueCount() + ", inflight=" + view.getInFlightCount() + ", expired= " + view.getExpiredCount() + ", size= " + view.getQueueSize());
// let the ack happen
waitCondition.countDown();
Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return 0 == view.getInFlightCount();
}
});
LOG.info("enqueue=" + view.getEnqueueCount() + ", dequeue=" + view.getDequeueCount() + ", inflight=" + view.getInFlightCount() + ", expired= " + view.getExpiredCount() + ", size= " + view.getQueueSize());
assertEquals("inflight didn't reduce to duck", 0, view.getInFlightCount());
assertEquals("size doesn't get back to 0 ", 0, view.getQueueSize());
assertEquals("dequeues don't match sent/expired ", sendCount, view.getDequeueCount());
// produce some more
producer.setTimeToLive(0);
long tStamp = System.currentTimeMillis();
for (int i = 0; i < sendCount; i++) {
producer.send(session.createTextMessage("test-" + i));
if (i % 100 == 0) {
LOG.info("sent: " + i + " @ " + ((System.currentTimeMillis() - tStamp) / 100) + "m/ms");
tStamp = System.currentTimeMillis();
}
}
Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return received.get() >= sendCount;
}
});
consumer.close();
Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return 0 == view.getInFlightCount();
}
});
assertEquals("inflight did not go to zero on close", 0, view.getInFlightCount());
LOG.info("done: " + getName());
}
use of org.apache.activemq.broker.jmx.DestinationViewMBean in project camel by apache.
the class QueueProducerQoSTest method testInOnlyQueueProducerTTL.
@Test
public void testInOnlyQueueProducerTTL() throws Exception {
mockExpiredAdvisory.expectedMessageCount(1);
String endpoint = String.format("sjms:queue:%s?ttl=1000", TEST_INONLY_DESTINATION_NAME);
template.sendBody(endpoint, "test message");
assertMockEndpointsSatisfied();
DestinationViewMBean queue = getQueueMBean(TEST_INONLY_DESTINATION_NAME);
assertEquals("There were unexpected messages left in the queue: " + TEST_INONLY_DESTINATION_NAME, 0, queue.getQueueSize());
}
Aggregations