List of usage examples for java.util.concurrent ScheduledThreadPoolExecutor getQueue
public BlockingQueue<Runnable> getQueue()
From source file:com.ksc.http.timers.ClientExecutionAndRequestTimerTestUtils.java
/** * If the request completes successfully then the timer task should be canceled and should be * removed from the thread pool to prevent build up of canceled tasks * /*from ww w .j a v a 2s . c om*/ * @param timerExecutor * Executor used by timer implementation */ public static void assertCanceledTasksRemoved(ScheduledThreadPoolExecutor timerExecutor) { waitBeforeAssertOnExecutor(); assertEquals(0, timerExecutor.getQueue().size()); }
From source file:com.amazonaws.http.AmazonHttpClientRequestTimeoutTest.java
@Test public void testRequestTimerCancelledTask() throws IOException, InterruptedException { ClientConfiguration config = new ClientConfiguration().withRequestTimeout(5 * 1000).withMaxErrorRetry(0); HttpClientFactory httpClientFactory = new HttpClientFactory(); HttpClient rawHttpClient = spy(httpClientFactory.createHttpClient(config)); HttpResponseProxy responseProxy = createHttpResponseProxySpy(); doReturn(responseProxy).when(rawHttpClient).execute(any(HttpRequestBase.class), any(HttpContext.class)); String localhostEndpoint = "http://localhost:0"; Request<?> request = new EmptyHttpRequest(localhostEndpoint, HttpMethodName.GET); AmazonHttpClient httpClient = new AmazonHttpClient(config, rawHttpClient, null); try {//from w ww. j av a 2 s . c om httpClient.execute(request, new NullResponseHandler(), new NullErrorResponseHandler(), new ExecutionContext()); Assert.fail("Should have been unable to unmarshall the response!"); } catch (AmazonClientException e) { Assert.assertTrue(e.getCause() instanceof RuntimeException); RuntimeException re = (RuntimeException) e.getCause(); Assert.assertTrue(re.getMessage().contains("Unable to unmarshall response")); } /* Verify the response was buffered when enforcing the request timeout. */ verify(responseProxy).setEntity(any(BufferedHttpEntity.class)); /* Verify cancelled tasks are removed on demand and the core threads die out after the keep alive time. */ ScheduledThreadPoolExecutor httpRequestTimer = httpClient.getHttpRequestTimer().getExecutor(); Assert.assertEquals(0, httpRequestTimer.getCompletedTaskCount()); Assert.assertEquals(0, httpRequestTimer.getQueue().size()); Assert.assertEquals(1, httpRequestTimer.getPoolSize()); Thread.sleep(httpRequestTimer.getKeepAliveTime(TimeUnit.MILLISECONDS) + 1000); Assert.assertEquals(0, httpRequestTimer.getPoolSize()); httpClient.shutdown(); }