// 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 javax.jms.Session;
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;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import javax.jms.Connection;
import javax.jms.IllegalStateException;
import javax.jms.JMSException;
        // test: try to call setClientID() after start()
        // should result in an exception
        try {
            conn.start();
            conn.setClientID("newID3");
            fail("Calling setClientID() after start() mut raise a JMSException.");
        } catch (IllegalStateException ise) {
            LOG.debug("Correctly received " + ise);
        } finally {
            cf.stop();
        }

        LOG.debug("Test finished.");
    }

    /**
     * Tests the behavior of the sessionPool of the PooledConnectionFactory when
     * maximum number of sessions are reached.
     *
     * @throws Exception
     */
    @Test
    public void testCreateSessionDoesNotBlockWhenNotConfiguredTo() throws Exception {
        // using separate thread for testing so that we can interrupt the test
        // if the call to get a new session blocks.

        // start test runner thread
        ExecutorService executor = Executors.newSingleThreadExecutor();
        final Future<Boolean> result = executor.submit(new TestRunner());

// 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/PooledConnectionTest.java
import javax.jms.Session;
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;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import javax.jms.Connection;
import javax.jms.IllegalStateException;
import javax.jms.JMSException;

        // test: try to call setClientID() after start()
        // should result in an exception
        try {
            conn.start();
            conn.setClientID("newID3");
            fail("Calling setClientID() after start() mut raise a JMSException.");
        } catch (IllegalStateException ise) {
            LOG.debug("Correctly received " + ise);
        } finally {
            cf.stop();
        }

        LOG.debug("Test finished.");
    }

    /**
     * Tests the behavior of the sessionPool of the PooledConnectionFactory when
     * maximum number of sessions are reached.
     *
     * @throws Exception
     */
    @Test
    public void testCreateSessionDoesNotBlockWhenNotConfiguredTo() throws Exception {
        // using separate thread for testing so that we can interrupt the test
        // if the call to get a new session blocks.

        // start test runner thread
        ExecutorService executor = Executors.newSingleThreadExecutor();
        final Future<Boolean> result = executor.submit(new TestRunner());

        boolean testPassed = Wait.waitFor(new Wait.Condition() {