Search in sources :

Example 1 with Condition

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();
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) Condition(org.apache.activemq.util.Wait.Condition) MessageConsumer(javax.jms.MessageConsumer) Message(javax.jms.Message) Connection(javax.jms.Connection) MessageListener(javax.jms.MessageListener) Session(javax.jms.Session)

Example 2 with Condition

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());
            }
        }
    }
}
Also used : Condition(org.apache.activemq.util.Wait.Condition) DestinationStatistics(org.apache.activemq.broker.region.DestinationStatistics) RegionBroker(org.apache.activemq.broker.region.RegionBroker) JMSException(javax.jms.JMSException) JMSException(javax.jms.JMSException)

Aggregations

Condition (org.apache.activemq.util.Wait.Condition)2 Connection (javax.jms.Connection)1 JMSException (javax.jms.JMSException)1 Message (javax.jms.Message)1 MessageConsumer (javax.jms.MessageConsumer)1 MessageListener (javax.jms.MessageListener)1 Session (javax.jms.Session)1 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)1 DestinationStatistics (org.apache.activemq.broker.region.DestinationStatistics)1 RegionBroker (org.apache.activemq.broker.region.RegionBroker)1