List of usage examples for org.apache.commons.httpclient NoHttpResponseException NoHttpResponseException
public NoHttpResponseException()
From source file:com.basho.riak.client.http.util.logging.LogNoHttpResponseRetryHandlerTest.java
/** * Test method for/*from w w w. jav a 2 s. c o m*/ * {@link com.basho.riak.client.http.util.logging.LogNoHttpResponseRetryHandler#retryMethod(org.apache.commons.httpclient.HttpMethod, java.io.IOException, int)} * . */ @Test public void retry() { final HttpMethod method = new GetMethod(); final IOException noHttpResponseException = new NoHttpResponseException(); final IOException otherException = new ConnectTimeoutException(); final int executionCount = 0; // when retry is called with a NoHtpResponseException // dump should be called on the appender LogNoHttpResponseRetryHandler handler = new LogNoHttpResponseRetryHandler(MOCK_APPENDER_NAME); boolean expected = new DefaultHttpMethodRetryHandler().retryMethod(method, noHttpResponseException, executionCount); boolean actual = handler.retryMethod(method, noHttpResponseException, executionCount); verify(mockAppender, times(1)).dump(); assertEquals(expected, actual); expected = new DefaultHttpMethodRetryHandler().retryMethod(method, otherException, executionCount); actual = handler.retryMethod(method, otherException, executionCount); // dump must not have been called again! verify(mockAppender, times(1)).dump(); // but the behaviour of the handler should still match the default assertEquals(expected, actual); }
From source file:com.basho.riak.client.http.util.logging.ConcurrentLoggingTest.java
/** * Test method for/*from w ww . j av a2 s . com*/ * {@link com.basho.riak.client.http.util.logging.LogNoHttpResponseRetryHandler#retryMethod(org.apache.commons.httpclient.HttpMethod, java.io.IOException, int)} * . * * @throws InterruptedException */ @Test public void retry_concurrentLogAndDump() throws InterruptedException { // create a bunch of threads // each must log 10 statements and call flush // ALL the statements must be present BUT ONCE in // the mock delegate appender (order does not matter) final int numThreads = 10; final LogNoHttpResponseRetryHandler handler = new LogNoHttpResponseRetryHandler(); ExecutorService es = Executors.newFixedThreadPool(numThreads); List<Callable<Void>> tasks = new ArrayList<Callable<Void>>(numThreads); final CountDownLatch startLatch = new CountDownLatch(1); final CountDownLatch dumpLatch = new CountDownLatch(10); for (int i = 0; i < numThreads; i++) { final int threadCounter = i; tasks.add(new Callable<Void>() { @Override public Void call() { Logger logger = Logger.getLogger("httpclient.wire"); try { startLatch.await(); for (int j = 0; j < 10; j++) { logger.debug(String.format(MESSAGE, new Object[] { threadCounter, j })); } dumpLatch.countDown(); dumpLatch.await(); handler.retryMethod(new GetMethod(), new NoHttpResponseException(), 0); return null; } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException(e); } } }); } startLatch.countDown(); es.invokeAll(tasks); verify(mockLogger, times(100)).callAppenders(logEventCaptor.capture()); TreeSet<Integer> check = new TreeSet<Integer>(); for (LoggingEvent le : logEventCaptor.getAllValues()) { // verify that each of Thread:Iter is present for 0-90-9 int loc = Integer.parseInt(le.getMessage().toString()); check.add(loc); } assertEquals(100, check.size()); assertEquals(0, (int) check.first()); assertEquals(99, (int) check.last()); }