use of org.apache.activemq.util.Wait.Condition in project activemq-artemis by apache.
the class DestinationGCTest method testDestinationGCWithActiveConsumers.
public void testDestinationGCWithActiveConsumers() throws Exception {
assertEquals(1, broker.getAdminView().getQueues().length);
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://localhost?create=false");
Connection connection = factory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
session.createProducer(otherQueue).close();
MessageConsumer consumer = session.createConsumer(queue);
consumer.setMessageListener(new MessageListener() {
@Override
public void onMessage(Message message) {
}
});
connection.start();
TimeUnit.SECONDS.sleep(5);
assertTrue("After GC runs there should be one Queue.", Wait.waitFor(new Condition() {
@Override
public boolean isSatisified() throws Exception {
return broker.getAdminView().getQueues().length == 1;
}
}));
connection.close();
}
use of org.apache.activemq.util.Wait.Condition in project activemq-artemis by apache.
the class ConsumeTopicPrefetchTest method doValidateConsumerPrefetch.
protected void doValidateConsumerPrefetch(String destination, final long expectedCount, final boolean greaterOrEqual) throws JMSException {
RegionBroker regionBroker = (RegionBroker) BrokerRegistry.getInstance().lookup("localhost").getRegionBroker();
for (org.apache.activemq.broker.region.Destination dest : regionBroker.getTopicRegion().getDestinationMap().values()) {
final org.apache.activemq.broker.region.Destination target = dest;
if (dest.getName().equals(destination)) {
try {
Wait.waitFor(new Condition() {
@Override
public boolean isSatisified() throws Exception {
DestinationStatistics stats = target.getDestinationStatistics();
LOG.info("inflight for : " + target.getName() + ": " + stats.getInflight().getCount());
if (greaterOrEqual) {
return stats.getInflight().getCount() >= expectedCount;
} else {
return stats.getInflight().getCount() == expectedCount;
}
}
});
} catch (Exception e) {
throw new JMSException(e.toString());
}
DestinationStatistics stats = dest.getDestinationStatistics();
LOG.info("inflight for : " + dest.getName() + ": " + stats.getInflight().getCount());
if (greaterOrEqual) {
assertTrue("inflight for: " + dest.getName() + ": " + stats.getInflight().getCount() + " > " + stats.getInflight().getCount(), stats.getInflight().getCount() >= expectedCount);
} else {
assertEquals("inflight for: " + dest.getName() + ": " + stats.getInflight().getCount() + " matches", expectedCount, stats.getInflight().getCount());
}
}
}
}
Aggregations