// 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.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import javax.jms.Connection;
import javax.jms.JMSException;
import javax.jms.JMSRuntimeException;
import javax.jms.QueueConnectionFactory;
import javax.jms.Session;
import javax.jms.TopicConnectionFactory;
import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.command.ConnectionId;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.messaginghub.pooled.jms.util.Wait;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
        } finally {
            cf.stop();
        }
    }

    @Test
    public void testConnectionsArePooledAsyncCreate() throws Exception {
        final JmsPoolConnectionFactory cf = createPooledConnectionFactory();
        cf.setMaxConnections(1);

        final ConcurrentLinkedQueue<JmsPoolConnection> connections = new ConcurrentLinkedQueue<JmsPoolConnection>();

        try {
            final JmsPoolConnection primary = (JmsPoolConnection) cf.createConnection();
            final ExecutorService executor = Executors.newFixedThreadPool(10);
            final int numConnections = 100;

            for (int i = 0; i < numConnections; ++i) {
                executor.execute(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            connections.add((JmsPoolConnection) cf.createConnection());
                        } catch (JMSException e) {
                        }
                    }
                });
            }

// 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/PooledConnectionFactoryTest.java
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import javax.jms.Connection;
import javax.jms.JMSException;
import javax.jms.JMSRuntimeException;
import javax.jms.QueueConnectionFactory;
import javax.jms.Session;
import javax.jms.TopicConnectionFactory;
import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.command.ConnectionId;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.messaginghub.pooled.jms.util.Wait;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

        } finally {
            cf.stop();
        }
    }

    @Test
    public void testConnectionsArePooledAsyncCreate() throws Exception {
        final JmsPoolConnectionFactory cf = createPooledConnectionFactory();
        cf.setMaxConnections(1);

        final ConcurrentLinkedQueue<JmsPoolConnection> connections = new ConcurrentLinkedQueue<JmsPoolConnection>();

        try {
            final JmsPoolConnection primary = (JmsPoolConnection) cf.createConnection();
            final ExecutorService executor = Executors.newFixedThreadPool(10);
            final int numConnections = 100;

            for (int i = 0; i < numConnections; ++i) {
                executor.execute(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            connections.add((JmsPoolConnection) cf.createConnection());
                        } catch (JMSException e) {
                        }
                    }
                });
            }

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