public ConnectionSemaphore newConnectionSemaphore(AsyncHttpClientConfig config) { int acquireFreeChannelTimeout = Math.max(0, config.getAcquireFreeChannelTimeout()); int maxConnections = config.getMaxConnections(); int maxConnectionsPerHost = config.getMaxConnectionsPerHost(); if (maxConnections > 0 && maxConnectionsPerHost > 0) { return new CombinedConnectionSemaphore(maxConnections, maxConnectionsPerHost, acquireFreeChannelTimeout); } if (maxConnections > 0) { return new MaxConnectionSemaphore(maxConnections, acquireFreeChannelTimeout); } if (maxConnectionsPerHost > 0) { return new CombinedConnectionSemaphore(maxConnections, maxConnectionsPerHost, acquireFreeChannelTimeout); } return new NoopConnectionSemaphore(); } }
@Test(timeOut = 3000, dataProvider = "permitsAndRunnersCount") public void combinedCheckPermitCount(int permitCount, int runnerCount) { allSemaphoresCheckPermitCount(new CombinedConnectionSemaphore(permitCount, permitCount, 0), permitCount, runnerCount); allSemaphoresCheckPermitCount(new CombinedConnectionSemaphore(0, permitCount, 0), permitCount, runnerCount); allSemaphoresCheckPermitCount(new CombinedConnectionSemaphore(permitCount, 0, 0), permitCount, runnerCount); }
@Test(timeOut = 1000) public void combinedCheckRelease() throws IOException { checkRelease(new CombinedConnectionSemaphore(1, 1, 0)); }
@Test(timeOut = 1000, invocationCount = NON_DETERMINISTIC__INVOCATION_COUNT, successPercentage = NON_DETERMINISTIC__SUCCESS_PERCENT) public void combinedCheckAcquireTime() { checkAcquireTime(new CombinedConnectionSemaphore(CHECK_ACQUIRE_TIME__PERMITS, CHECK_ACQUIRE_TIME__PERMITS, CHECK_ACQUIRE_TIME__TIMEOUT)); }