METRON-1870 Intermittent Stellar REST test failures (merrimanr via nickwallen) closes apache/metron#1263
Project: http://git-wip-us.apache.org/repos/asf/metron/repo Commit: http://git-wip-us.apache.org/repos/asf/metron/commit/0e2a4348 Tree: http://git-wip-us.apache.org/repos/asf/metron/tree/0e2a4348 Diff: http://git-wip-us.apache.org/repos/asf/metron/diff/0e2a4348 Branch: refs/heads/feature/METRON-1090-stellar-assignment Commit: 0e2a4348465406ad3aca7614bc38a71571b63b83 Parents: 0303d24 Author: merrimanr <merrim...@gmail.com> Authored: Wed Nov 14 13:04:11 2018 -0500 Committer: nickallen <nickal...@apache.org> Committed: Wed Nov 14 13:04:11 2018 -0500 ---------------------------------------------------------------------- .../stellar/dsl/functions/RestFunctions.java | 4 ++-- .../stellar/dsl/functions/RestFunctionsTest.java | 17 +++++++---------- 2 files changed, 9 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/metron/blob/0e2a4348/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/RestFunctions.java ---------------------------------------------------------------------- diff --git a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/RestFunctions.java b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/RestFunctions.java index 7134bfc..354322a 100644 --- a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/RestFunctions.java +++ b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/RestFunctions.java @@ -223,14 +223,14 @@ public class RestFunctions { * @return * @throws IOException */ - private Object doGet(RestConfig restConfig, HttpGet httpGet, HttpClientContext httpClientContext) throws IOException { + protected Object doGet(RestConfig restConfig, HttpGet httpGet, HttpClientContext httpClientContext) throws IOException { // Schedule a command to abort the httpGet request if the timeout is exceeded ScheduledFuture scheduledFuture = scheduledExecutorService.schedule(httpGet::abort, restConfig.getTimeout(), TimeUnit.MILLISECONDS); CloseableHttpResponse response; try { response = httpClient.execute(httpGet, httpClientContext); - } catch(IOException e) { + } catch(Exception e) { // Report a timeout if the httpGet request was aborted. Otherwise rethrow exception. if (httpGet.isAborted()) { throw new IOException(String.format("Total Stellar REST request time to %s exceeded the configured timeout of %d ms.", httpGet.getURI().toString(), restConfig.getTimeout())); http://git-wip-us.apache.org/repos/asf/metron/blob/0e2a4348/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/RestFunctionsTest.java ---------------------------------------------------------------------- diff --git a/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/RestFunctionsTest.java b/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/RestFunctionsTest.java index ba80f02..4b912ef 100644 --- a/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/RestFunctionsTest.java +++ b/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/RestFunctionsTest.java @@ -23,10 +23,9 @@ import org.apache.http.HttpHost; import org.apache.http.auth.AuthScope; import org.apache.http.auth.UsernamePasswordCredentials; import org.apache.http.client.CredentialsProvider; -import org.apache.http.client.HttpClient; import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.methods.HttpGet; import org.apache.http.client.protocol.HttpClientContext; -import org.apache.http.conn.routing.HttpRoute; import org.apache.http.impl.client.BasicCredentialsProvider; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; @@ -66,7 +65,10 @@ import static org.apache.metron.stellar.dsl.functions.RestConfig.STELLAR_REST_SE import static org.apache.metron.stellar.dsl.functions.RestConfig.TIMEOUT; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; @@ -552,15 +554,10 @@ public class RestFunctionsTest { */ @Test public void restGetShouldHandleIOException() throws IllegalArgumentException, IOException { - Map<String, Object> globalConfig = new HashMap<String, Object>() {{ - put(STELLAR_REST_SETTINGS, new HashMap<String, Object>() {{ - put(SOCKET_TIMEOUT, 1); - }}); - }}; - - context.addCapability(Context.Capabilities.GLOBAL_CONFIG, () -> globalConfig); + RestFunctions.RestGet restGet = spy(RestFunctions.RestGet.class); + doThrow(new IOException("io exception")).when(restGet).doGet(any(RestConfig.class), any(HttpGet.class), any(HttpClientContext.class)); - Object result = run(String.format("REST_GET('%s')", getUri), context); + Object result = restGet.apply(Collections.singletonList(getUri), context); Assert.assertNull(result); }