// 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.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
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.JMSException;
import javax.jms.Session;
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;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
    public void setUp(TestInfo info) throws Exception {
        super.setUp(info);
        sessions.clear();
    }

    @Test
    public void testCreateSessionBlocksWhenMaxSessionsLoanedOutUntilReturned() throws Exception {
        JmsPoolConnectionFactory cf = createPooledConnectionFactory();

        try {
            cf.setMaxConnections(3);
            cf.setMaxSessionsPerConnection(1);
            cf.setBlockIfSessionPoolIsFull(true);
            connection = cf.createConnection();

            // start test runner threads. It is expected that the second thread
            // blocks on the call to createSession()

            ExecutorService executor = Executors.newFixedThreadPool(1);
            final Future<Boolean> result1 = executor.submit(new SessionTakerAndReturner());
            final Future<Boolean> result2 = executor.submit(new SessionTaker());

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

                @Override
                public boolean isSatisfied() throws Exception {
                    return result1.isDone();
                }
            }, 5000, 10));

// 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/PooledConnectionFactoryMaximumActiveTest.java
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
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.JMSException;
import javax.jms.Session;
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;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

    public void setUp(TestInfo info) throws Exception {
        super.setUp(info);
        sessions.clear();
    }

    @Test
    public void testCreateSessionBlocksWhenMaxSessionsLoanedOutUntilReturned() throws Exception {
        JmsPoolConnectionFactory cf = createPooledConnectionFactory();

        try {
            cf.setMaxConnections(3);
            cf.setMaxSessionsPerConnection(1);
            cf.setBlockIfSessionPoolIsFull(true);
            connection = cf.createConnection();

            // start test runner threads. It is expected that the second thread
            // blocks on the call to createSession()

            ExecutorService executor = Executors.newFixedThreadPool(1);
            final Future<Boolean> result1 = executor.submit(new SessionTakerAndReturner());
            final Future<Boolean> result2 = executor.submit(new SessionTaker());

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

                @Override
                public boolean isSatisfied() throws Exception {
                    return result1.isDone();
                }
            }, 5000, 10));

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