// Path: pooled-jms/src/test/java/org/messaginghub/pooled/jms/util/Wait.java
// public class Wait {
// 
//     public static final long MAX_WAIT_MILLIS = 30 * 1000;
//     public static final long SLEEP_MILLIS = 200;
// 
//     public interface Condition {
//         boolean isSatisfied() throws Exception;
//     }
// 
//     public static boolean waitFor(Condition condition) throws Exception {
//         return waitFor(condition, MAX_WAIT_MILLIS);
//     }
// 
//     public static boolean waitFor(final Condition condition, final long duration) throws Exception {
//         return waitFor(condition, duration, SLEEP_MILLIS);
//     }
// 
//     public static boolean waitFor(final Condition condition, final long duration, final long sleepMillis) throws Exception {
// 
//         final long expiry = System.currentTimeMillis() + duration;
//         boolean conditionSatisfied = condition.isSatisfied();
//         while (!conditionSatisfied && System.currentTimeMillis() < expiry) {
//             TimeUnit.MILLISECONDS.sleep(sleepMillis);
//             conditionSatisfied = condition.isSatisfied();
//         }
//         return conditionSatisfied;
//     }
// }


import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.concurrent.TimeUnit;
import javax.jms.Connection;
import javax.jms.JMSException;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Session;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.jmx.QueueViewMBean;
import org.apache.activemq.command.ActiveMQQueue;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.Timeout;
import org.messaginghub.pooled.jms.util.Wait;
                directConn2.close();
            }
        } catch (JMSException jms_exc) {
        }

        try {
            pooledConnFact.stop();
        } catch (Throwable error) {}

        super.tearDown();
    }

    private void produceMessages() throws Exception {
        Session session = directConn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageProducer producer = session.createProducer(queue);
        for (int i = 0; i < MESSAGE_COUNT; ++i) {
            producer.send(session.createTextMessage("Test Message: " + i));
        }
        producer.close();
    }

    @Test
    public void testLingeringPooledSessionsHoldingPrefetchedMessages() throws Exception {
        produceMessages();

        Session pooledSession1 = pooledConn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
        pooledSession1.createConsumer(queue);

        final QueueViewMBean view = getProxyToQueue(queue.getPhysicalName());

// Path: pooled-jms/src/test/java/org/messaginghub/pooled/jms/util/Wait.java
// public class Wait {
// 
//     public static final long MAX_WAIT_MILLIS = 30 * 1000;
//     public static final long SLEEP_MILLIS = 200;
// 
//     public interface Condition {
//         boolean isSatisfied() throws Exception;
//     }
// 
//     public static boolean waitFor(Condition condition) throws Exception {
//         return waitFor(condition, MAX_WAIT_MILLIS);
//     }
// 
//     public static boolean waitFor(final Condition condition, final long duration) throws Exception {
//         return waitFor(condition, duration, SLEEP_MILLIS);
//     }
// 
//     public static boolean waitFor(final Condition condition, final long duration, final long sleepMillis) throws Exception {
// 
//         final long expiry = System.currentTimeMillis() + duration;
//         boolean conditionSatisfied = condition.isSatisfied();
//         while (!conditionSatisfied && System.currentTimeMillis() < expiry) {
//             TimeUnit.MILLISECONDS.sleep(sleepMillis);
//             conditionSatisfied = condition.isSatisfied();
//         }
//         return conditionSatisfied;
//     }
// }


// Path: pooled-jms-interop-tests/pooled-jms-activemq-tests/src/test/java/org/messaginghub/pooled/jms/PooledConnectionSessionCleanupTest.java
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.concurrent.TimeUnit;
import javax.jms.Connection;
import javax.jms.JMSException;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Session;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.jmx.QueueViewMBean;
import org.apache.activemq.command.ActiveMQQueue;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.Timeout;
import org.messaginghub.pooled.jms.util.Wait;

                directConn2.close();
            }
        } catch (JMSException jms_exc) {
        }

        try {
            pooledConnFact.stop();
        } catch (Throwable error) {}

        super.tearDown();
    }

    private void produceMessages() throws Exception {
        Session session = directConn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageProducer producer = session.createProducer(queue);
        for (int i = 0; i < MESSAGE_COUNT; ++i) {
            producer.send(session.createTextMessage("Test Message: " + i));
        }
        producer.close();
    }

    @Test
    public void testLingeringPooledSessionsHoldingPrefetchedMessages() throws Exception {
        produceMessages();

        Session pooledSession1 = pooledConn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
        pooledSession1.createConsumer(queue);

        final QueueViewMBean view = getProxyToQueue(queue.getPhysicalName());

        assertTrue(Wait.waitFor(new Wait.Condition() {