From 20ea927b7570264d31748b54e58fd613a5938d8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Szczerbi=C5=84ski?= Date: Fri, 23 Aug 2024 12:20:10 +0200 Subject: [PATCH] Format code --- .../client/jdbc/BaseWiremockTest.java | 449 +++++++++--------- .../snowflake/client/jdbc/ProxyLatestIT.java | 52 +- .../client/jdbc/RestRequestTest.java | 30 +- .../client/jdbc/RestRequestWiremockTest.java | 142 +++--- 4 files changed, 311 insertions(+), 362 deletions(-) diff --git a/src/test/java/net/snowflake/client/jdbc/BaseWiremockTest.java b/src/test/java/net/snowflake/client/jdbc/BaseWiremockTest.java index a51acab9b..e0376ec8d 100644 --- a/src/test/java/net/snowflake/client/jdbc/BaseWiremockTest.java +++ b/src/test/java/net/snowflake/client/jdbc/BaseWiremockTest.java @@ -1,7 +1,20 @@ package net.snowflake.client.jdbc; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; +import static junit.framework.TestCase.assertEquals; +import static net.snowflake.client.AbstractDriverIT.getConnectionParameters; +import static net.snowflake.client.jdbc.SnowflakeUtil.systemGetProperty; +import static org.awaitility.Awaitility.await; +import static org.junit.Assume.*; + +import java.io.File; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.ServerSocket; +import java.nio.file.Paths; +import java.sql.*; +import java.time.Duration; +import java.util.Map; +import java.util.Properties; import net.snowflake.client.RunningNotOnGithubActionsMac; import net.snowflake.client.RunningNotOnJava21; import net.snowflake.client.RunningNotOnJava8; @@ -14,236 +27,216 @@ import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; -import org.apache.http.util.EntityUtils; import org.junit.After; import org.junit.AfterClass; import org.junit.BeforeClass; -import java.io.File; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.net.ServerSocket; -import java.nio.file.Paths; -import java.sql.*; -import java.time.Duration; -import java.util.Map; -import java.util.Objects; -import java.util.Properties; - -import static junit.framework.TestCase.assertEquals; -import static net.snowflake.client.AbstractDriverIT.getConnectionParameters; -import static net.snowflake.client.jdbc.SnowflakeUtil.systemGetProperty; -import static org.awaitility.Awaitility.await; -import static org.junit.Assert.assertTrue; -import static org.junit.Assume.*; - public abstract class BaseWiremockTest { - protected static final SFLogger logger = SFLoggerFactory.getLogger(BaseWiremockTest.class); - protected static final String WIREMOCK_HOME_DIR = ".wiremock"; - protected static final String WIREMOCK_M2_PATH = - "/.m2/repository/org/wiremock/wiremock-standalone/3.8.0/wiremock-standalone-3.8.0.jar"; - protected static final String WIREMOCK_HOST = "localhost"; - protected static final String TRUST_STORE_PROPERTY = "javax.net.ssl.trustStore"; - protected static int httpProxyPort; - protected static int httpsProxyPort; - private static String originalTrustStorePath; - protected static Process wiremockStandalone; - - @BeforeClass - public static void setUpClass() { - assumeFalse(RunningNotOnJava8.isRunningOnJava8()); - assumeFalse(RunningNotOnJava21.isRunningOnJava21()); - assumeFalse( - RunningNotOnGithubActionsMac - .isRunningOnGithubActionsMac()); // disabled until issue with access to localhost - // (https://github.com/snowflakedb/snowflake-jdbc/pull/1807#discussion_r1686229430) is fixed on - // github actions mac image. Ticket to enable when fixed: SNOW-1555950 - originalTrustStorePath = systemGetProperty(TRUST_STORE_PROPERTY); - startWiremockStandAlone(); - } - - @After - public void tearDown() { - restoreTrustStorePathProperty(); - resetWiremock(); - HttpUtil.httpClient.clear(); - } - - @AfterClass - public static void tearDownClass() { - stopWiremockStandAlone(); - } - - protected static void startWiremockStandAlone() { - // retrying in case of fail in port bindings - await() - .alias("wait for wiremock responding") - .atMost(Duration.ofSeconds(10)) - .until( - () -> { - try { - httpProxyPort = findFreePort(); - httpsProxyPort = findFreePort(); - wiremockStandalone = - new ProcessBuilder( - "java", - "-jar", - getWiremockStandAlonePath(), - "--root-dir", - System.getProperty("user.dir") - + File.separator - + WIREMOCK_HOME_DIR - + File.separator, - "--enable-browser-proxying", // work as forward proxy - "--proxy-pass-through", - "false", // pass through only matched requests - "--port", - String.valueOf(httpProxyPort), - "--https-port", - String.valueOf(httpsProxyPort), - "--https-keystore", - getResourceURL("wiremock" + File.separator + "ca-cert.jks"), - "--ca-keystore", - getResourceURL("wiremock" + File.separator + "ca-cert.jks")) - .inheritIO() - .start(); - waitForWiremock(); - return true; - } catch (Exception e) { - logger.warn("Failed to start wiremock, retrying: ", e); - return false; - } - }); - } - - protected void resetWiremock() { - HttpPost postRequest; - postRequest = new HttpPost("http://" + WIREMOCK_HOST + ":" + getAdminPort() + "/__admin/reset"); - try (CloseableHttpClient client = HttpClients.createDefault(); - CloseableHttpResponse response = client.execute(postRequest)) { - assertEquals(200, response.getStatusLine().getStatusCode()); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - private static String getWiremockStandAlonePath() { - return System.getProperty("user.home") + WIREMOCK_M2_PATH; - } - - private static void waitForWiremock() { - await() - .pollDelay(Duration.ofSeconds(1)) - .atMost(Duration.ofSeconds(3)) - .until(BaseWiremockTest::isWiremockResponding); - } - - private static boolean isWiremockResponding() { - try (CloseableHttpClient httpClient = HttpClients.createDefault()) { - HttpGet request = - new HttpGet(String.format("http://%s:%d/__admin/mappings", WIREMOCK_HOST, httpProxyPort)); - CloseableHttpResponse response = httpClient.execute(request); - return response.getStatusLine().getStatusCode() == 200; - } catch (Exception e) { - logger.warn("Waiting for wiremock to respond: ", e); - } - return false; - } - - protected static void stopWiremockStandAlone() { - if (wiremockStandalone != null) { - wiremockStandalone.destroyForcibly(); - await() - .alias("stop wiremock") - .atMost(Duration.ofSeconds(10)) - .until(() -> !wiremockStandalone.isAlive()); - } - } - - private static int findFreePort() { - try { - ServerSocket socket = new ServerSocket(0); - int port = socket.getLocalPort(); - socket.close(); - return port; - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - protected Properties getProperties() { - Map params = getConnectionParameters(); - Properties props = new Properties(); - props.put("host", params.get("host")); - props.put("port", params.get("port")); - props.put("account", params.get("account")); - props.put("user", params.get("user")); - props.put("role", params.get("role")); - props.put("password", params.get("password")); - props.put("warehouse", params.get("warehouse")); - props.put("db", params.get("database")); - props.put("ssl", params.get("ssl")); - props.put("insecureMode", true); // OCSP disabled for wiremock proxy tests - return props; - } - - protected HttpPost createWiremockPostRequest(String body, String path) { - HttpPost postRequest = new HttpPost("http://" + WIREMOCK_HOST + ":" + getAdminPort() + path); - final StringEntity entity; - try { - entity = new StringEntity(body); - } catch (UnsupportedEncodingException e) { - throw new RuntimeException(e); - } - postRequest.setEntity(entity); - postRequest.setHeader("Accept", "application/json"); - postRequest.setHeader("Content-type", "application/json"); - return postRequest; - } - - protected static void restoreTrustStorePathProperty() { - if (originalTrustStorePath != null) { - System.setProperty(TRUST_STORE_PROPERTY, originalTrustStorePath); - } else { - System.clearProperty(TRUST_STORE_PROPERTY); - } - } - - private int getAdminPort() { - return httpProxyPort; - } - - private static String getResourceURL(String relativePath) { - return Paths.get(systemGetProperty("user.dir"), "src", "test", "resources", relativePath) - .toAbsolutePath() - .toString(); - } - - protected void setCustomTrustStorePropertyPath() { - System.setProperty( - TRUST_STORE_PROPERTY, getResourceURL("wiremock" + File.separator + "ca-cert.jks")); - } - - protected void importMapping(String mappingImport) { - HttpPost request = createWiremockPostRequest(mappingImport, "/__admin/mappings/import"); - try (CloseableHttpClient httpClient = HttpClients.createDefault(); - CloseableHttpResponse response = httpClient.execute(request)) { - assumeTrue( response.getStatusLine().getStatusCode() == 200); - } catch (Exception e) { - logger.error("Importing mapping failed", e); - assumeNoException(e); - } - } - - protected void addMapping(String mapping) { - HttpPost postRequest = createWiremockPostRequest(mapping, "/__admin/mappings"); - try (CloseableHttpClient client = HttpClients.createDefault(); - CloseableHttpResponse response = client.execute(postRequest)) { - assertEquals(201, response.getStatusLine().getStatusCode()); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - + protected static final SFLogger logger = SFLoggerFactory.getLogger(BaseWiremockTest.class); + protected static final String WIREMOCK_HOME_DIR = ".wiremock"; + protected static final String WIREMOCK_M2_PATH = + "/.m2/repository/org/wiremock/wiremock-standalone/3.8.0/wiremock-standalone-3.8.0.jar"; + protected static final String WIREMOCK_HOST = "localhost"; + protected static final String TRUST_STORE_PROPERTY = "javax.net.ssl.trustStore"; + protected static int httpProxyPort; + protected static int httpsProxyPort; + private static String originalTrustStorePath; + protected static Process wiremockStandalone; + + @BeforeClass + public static void setUpClass() { + assumeFalse(RunningNotOnJava8.isRunningOnJava8()); + assumeFalse(RunningNotOnJava21.isRunningOnJava21()); + assumeFalse( + RunningNotOnGithubActionsMac + .isRunningOnGithubActionsMac()); // disabled until issue with access to localhost + // (https://github.com/snowflakedb/snowflake-jdbc/pull/1807#discussion_r1686229430) is fixed on + // github actions mac image. Ticket to enable when fixed: SNOW-1555950 + originalTrustStorePath = systemGetProperty(TRUST_STORE_PROPERTY); + startWiremockStandAlone(); + } + + @After + public void tearDown() { + restoreTrustStorePathProperty(); + resetWiremock(); + HttpUtil.httpClient.clear(); + } + + @AfterClass + public static void tearDownClass() { + stopWiremockStandAlone(); + } + + protected static void startWiremockStandAlone() { + // retrying in case of fail in port bindings + await() + .alias("wait for wiremock responding") + .atMost(Duration.ofSeconds(10)) + .until( + () -> { + try { + httpProxyPort = findFreePort(); + httpsProxyPort = findFreePort(); + wiremockStandalone = + new ProcessBuilder( + "java", + "-jar", + getWiremockStandAlonePath(), + "--root-dir", + System.getProperty("user.dir") + + File.separator + + WIREMOCK_HOME_DIR + + File.separator, + "--enable-browser-proxying", // work as forward proxy + "--proxy-pass-through", + "false", // pass through only matched requests + "--port", + String.valueOf(httpProxyPort), + "--https-port", + String.valueOf(httpsProxyPort), + "--https-keystore", + getResourceURL("wiremock" + File.separator + "ca-cert.jks"), + "--ca-keystore", + getResourceURL("wiremock" + File.separator + "ca-cert.jks")) + .inheritIO() + .start(); + waitForWiremock(); + return true; + } catch (Exception e) { + logger.warn("Failed to start wiremock, retrying: ", e); + return false; + } + }); + } + + protected void resetWiremock() { + HttpPost postRequest; + postRequest = new HttpPost("http://" + WIREMOCK_HOST + ":" + getAdminPort() + "/__admin/reset"); + try (CloseableHttpClient client = HttpClients.createDefault(); + CloseableHttpResponse response = client.execute(postRequest)) { + assertEquals(200, response.getStatusLine().getStatusCode()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + private static String getWiremockStandAlonePath() { + return System.getProperty("user.home") + WIREMOCK_M2_PATH; + } + + private static void waitForWiremock() { + await() + .pollDelay(Duration.ofSeconds(1)) + .atMost(Duration.ofSeconds(3)) + .until(BaseWiremockTest::isWiremockResponding); + } + + private static boolean isWiremockResponding() { + try (CloseableHttpClient httpClient = HttpClients.createDefault()) { + HttpGet request = + new HttpGet(String.format("http://%s:%d/__admin/mappings", WIREMOCK_HOST, httpProxyPort)); + CloseableHttpResponse response = httpClient.execute(request); + return response.getStatusLine().getStatusCode() == 200; + } catch (Exception e) { + logger.warn("Waiting for wiremock to respond: ", e); + } + return false; + } + + protected static void stopWiremockStandAlone() { + if (wiremockStandalone != null) { + wiremockStandalone.destroyForcibly(); + await() + .alias("stop wiremock") + .atMost(Duration.ofSeconds(10)) + .until(() -> !wiremockStandalone.isAlive()); + } + } + + private static int findFreePort() { + try { + ServerSocket socket = new ServerSocket(0); + int port = socket.getLocalPort(); + socket.close(); + return port; + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + protected Properties getProperties() { + Map params = getConnectionParameters(); + Properties props = new Properties(); + props.put("host", params.get("host")); + props.put("port", params.get("port")); + props.put("account", params.get("account")); + props.put("user", params.get("user")); + props.put("role", params.get("role")); + props.put("password", params.get("password")); + props.put("warehouse", params.get("warehouse")); + props.put("db", params.get("database")); + props.put("ssl", params.get("ssl")); + props.put("insecureMode", true); // OCSP disabled for wiremock proxy tests + return props; + } + + protected HttpPost createWiremockPostRequest(String body, String path) { + HttpPost postRequest = new HttpPost("http://" + WIREMOCK_HOST + ":" + getAdminPort() + path); + final StringEntity entity; + try { + entity = new StringEntity(body); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } + postRequest.setEntity(entity); + postRequest.setHeader("Accept", "application/json"); + postRequest.setHeader("Content-type", "application/json"); + return postRequest; + } + + protected static void restoreTrustStorePathProperty() { + if (originalTrustStorePath != null) { + System.setProperty(TRUST_STORE_PROPERTY, originalTrustStorePath); + } else { + System.clearProperty(TRUST_STORE_PROPERTY); + } + } + + private int getAdminPort() { + return httpProxyPort; + } + + private static String getResourceURL(String relativePath) { + return Paths.get(systemGetProperty("user.dir"), "src", "test", "resources", relativePath) + .toAbsolutePath() + .toString(); + } + + protected void setCustomTrustStorePropertyPath() { + System.setProperty( + TRUST_STORE_PROPERTY, getResourceURL("wiremock" + File.separator + "ca-cert.jks")); + } + + protected void importMapping(String mappingImport) { + HttpPost request = createWiremockPostRequest(mappingImport, "/__admin/mappings/import"); + try (CloseableHttpClient httpClient = HttpClients.createDefault(); + CloseableHttpResponse response = httpClient.execute(request)) { + assumeTrue(response.getStatusLine().getStatusCode() == 200); + } catch (Exception e) { + logger.error("Importing mapping failed", e); + assumeNoException(e); + } + } + + protected void addMapping(String mapping) { + HttpPost postRequest = createWiremockPostRequest(mapping, "/__admin/mappings"); + try (CloseableHttpClient client = HttpClients.createDefault(); + CloseableHttpResponse response = client.execute(postRequest)) { + assertEquals(201, response.getStatusLine().getStatusCode()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } } diff --git a/src/test/java/net/snowflake/client/jdbc/ProxyLatestIT.java b/src/test/java/net/snowflake/client/jdbc/ProxyLatestIT.java index c1c29e30d..22781d3d9 100644 --- a/src/test/java/net/snowflake/client/jdbc/ProxyLatestIT.java +++ b/src/test/java/net/snowflake/client/jdbc/ProxyLatestIT.java @@ -1,45 +1,25 @@ package net.snowflake.client.jdbc; import static junit.framework.TestCase.assertEquals; -import static net.snowflake.client.AbstractDriverIT.getConnectionParameters; -import static net.snowflake.client.jdbc.SnowflakeUtil.systemGetProperty; -import static org.awaitility.Awaitility.await; import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeFalse; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import java.io.File; import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.net.ServerSocket; -import java.nio.file.Paths; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; -import java.time.Duration; -import java.util.Map; import java.util.Objects; import java.util.Properties; -import net.snowflake.client.RunningNotOnGithubActionsMac; -import net.snowflake.client.RunningNotOnJava21; -import net.snowflake.client.RunningNotOnJava8; import net.snowflake.client.category.TestCategoryOthers; -import net.snowflake.client.core.HttpUtil; -import net.snowflake.client.log.SFLogger; -import net.snowflake.client.log.SFLoggerFactory; import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; -import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; import org.junit.After; -import org.junit.AfterClass; -import org.junit.BeforeClass; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -101,13 +81,13 @@ private String getSnowflakeUrl(Properties props) { private void proxyAll(Properties props) { String template = - "{\n" + - " \"request\": {\n" + - " \"method\": \"ANY\",\n" + - " \"urlPattern\": \".*\"\n" + - " }\n," + - " \"response\": { \"proxyBaseUrl\": \"%s\" }\n" + - "}"; + "{\n" + + " \"request\": {\n" + + " \"method\": \"ANY\",\n" + + " \"urlPattern\": \".*\"\n" + + " }\n," + + " \"response\": { \"proxyBaseUrl\": \"%s\" }\n" + + "}"; String body = String.format(template, getSnowflakeUrl(props)); addMapping(body); } @@ -123,11 +103,11 @@ private void verifyProxyNotUsed() { private void connectAndVerifySimpleQuery(Properties props) throws SQLException { try (Connection con = - DriverManager.getConnection( - String.format("jdbc:snowflake://%s:%s", props.get("host"), props.get("port")), - props); - Statement stmt = con.createStatement(); - ResultSet rs = stmt.executeQuery("select 1")) { + DriverManager.getConnection( + String.format("jdbc:snowflake://%s:%s", props.get("host"), props.get("port")), + props); + Statement stmt = con.createStatement(); + ResultSet rs = stmt.executeQuery("select 1")) { assertTrue(rs.next()); assertEquals(1, rs.getInt(1)); } @@ -137,14 +117,14 @@ private void verifyRequestToProxy(String pathPattern, int expectedCount) { String body = String.format("{ \"method\":\"POST\",\"urlPattern\": \".*%s.*\" }", pathPattern); HttpPost postRequest = createWiremockPostRequest(body, "/__admin/requests/count"); try (CloseableHttpClient client = HttpClients.createDefault(); - CloseableHttpResponse response = client.execute(postRequest)) { + CloseableHttpResponse response = client.execute(postRequest)) { String responseString = EntityUtils.toString(response.getEntity()); ObjectMapper mapper = new ObjectMapper(); JsonNode json = mapper.readTree(responseString); assertEquals( - "expected request count not matched for pattern: " + pathPattern, - expectedCount, - json.get("count").asInt()); + "expected request count not matched for pattern: " + pathPattern, + expectedCount, + json.get("count").asInt()); } catch (IOException e) { throw new RuntimeException(e); } diff --git a/src/test/java/net/snowflake/client/jdbc/RestRequestTest.java b/src/test/java/net/snowflake/client/jdbc/RestRequestTest.java index efab11459..6e1a26428 100644 --- a/src/test/java/net/snowflake/client/jdbc/RestRequestTest.java +++ b/src/test/java/net/snowflake/client/jdbc/RestRequestTest.java @@ -497,21 +497,21 @@ public CloseableHttpResponse answer(InvocationOnMock invocation) throws Throwabl public void testConnectionClosedRetriesSuccessful() throws IOException, SnowflakeSQLException { CloseableHttpClient client = mock(CloseableHttpClient.class); when(client.execute(any(HttpUriRequest.class))) - .then( - new Answer() { - int callCount = 0; - @Override - public CloseableHttpResponse answer(InvocationOnMock invocationOnMock) throws Throwable { - callCount += 1; - if (callCount >= 1) { - return successResponse(); - } - else { - throw new SocketException("Connection reset"); - } - } - } - ); + .then( + new Answer() { + int callCount = 0; + + @Override + public CloseableHttpResponse answer(InvocationOnMock invocationOnMock) + throws Throwable { + callCount += 1; + if (callCount >= 1) { + return successResponse(); + } else { + throw new SocketException("Connection reset"); + } + } + }); execute(client, "fakeurl.com/?requestId=abcd-1234", 0, 0, 0, true, false, 1); } diff --git a/src/test/java/net/snowflake/client/jdbc/RestRequestWiremockTest.java b/src/test/java/net/snowflake/client/jdbc/RestRequestWiremockTest.java index 09a7f0f3e..ef32c5f9d 100644 --- a/src/test/java/net/snowflake/client/jdbc/RestRequestWiremockTest.java +++ b/src/test/java/net/snowflake/client/jdbc/RestRequestWiremockTest.java @@ -1,98 +1,74 @@ package net.snowflake.client.jdbc; -import net.snowflake.client.RunningNotOnGithubActionsMac; -import net.snowflake.client.RunningNotOnJava21; -import net.snowflake.client.RunningNotOnJava8; +import static org.junit.Assume.*; + +import java.util.concurrent.atomic.AtomicBoolean; import net.snowflake.client.core.ExecTimeTelemetryData; -import net.snowflake.client.log.SFLogger; -import net.snowflake.client.log.SFLoggerFactory; -import org.apache.http.ConnectionClosedException; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.util.EntityUtils; -import org.junit.AfterClass; -import org.junit.BeforeClass; import org.junit.Test; -import java.io.File; -import java.io.IOException; -import java.net.ServerSocket; -import java.nio.file.Paths; -import java.sql.SQLException; -import java.time.Duration; -import java.util.Objects; -import java.util.Properties; -import java.util.concurrent.atomic.AtomicBoolean; - -import static net.snowflake.client.jdbc.SnowflakeUtil.systemGetProperty; -import static org.awaitility.Awaitility.await; -import static org.junit.Assume.*; - public class RestRequestWiremockTest extends BaseWiremockTest { - String connectionResetByPeerScenario = "{\n" + - " \"mappings\": [\n" + - " {\n" + - " \"scenarioName\": \"Connection reset by peer\",\n" + - " \"requiredScenarioState\": \"Started\",\n" + - " \"newScenarioState\": \"Connection is stable\",\n" + - " \"request\": {\n" + - " \"method\": \"GET\",\n" + - " \"url\": \"/endpoint\"\n" + - " },\n" + - " \"response\": {\n" + - " \"fault\": \"CONNECTION_RESET_BY_PEER\"\n" + - " }\n" + - " },\n" + - " {\n" + - " \"scenarioName\": \"Connection reset by peer\",\n" + - " \"requiredScenarioState\": \"Connection is stable\",\n" + - " \"request\": {\n" + - " \"method\": \"GET\",\n" + - " \"url\": \"/endpoint\"\n" + - " },\n" + - " \"response\": {\n" + - " \"status\": 200\n" + - " }\n" + - " }\n" + - " ],\n" + - " \"importOptions\": {\n" + - " \"duplicatePolicy\": \"IGNORE\",\n" + - " \"deleteAllNotInImport\": true\n" + - " }" + - "}"; + String connectionResetByPeerScenario = + "{\n" + + " \"mappings\": [\n" + + " {\n" + + " \"scenarioName\": \"Connection reset by peer\",\n" + + " \"requiredScenarioState\": \"Started\",\n" + + " \"newScenarioState\": \"Connection is stable\",\n" + + " \"request\": {\n" + + " \"method\": \"GET\",\n" + + " \"url\": \"/endpoint\"\n" + + " },\n" + + " \"response\": {\n" + + " \"fault\": \"CONNECTION_RESET_BY_PEER\"\n" + + " }\n" + + " },\n" + + " {\n" + + " \"scenarioName\": \"Connection reset by peer\",\n" + + " \"requiredScenarioState\": \"Connection is stable\",\n" + + " \"request\": {\n" + + " \"method\": \"GET\",\n" + + " \"url\": \"/endpoint\"\n" + + " },\n" + + " \"response\": {\n" + + " \"status\": 200\n" + + " }\n" + + " }\n" + + " ],\n" + + " \"importOptions\": {\n" + + " \"duplicatePolicy\": \"IGNORE\",\n" + + " \"deleteAllNotInImport\": true\n" + + " }" + + "}"; - @Test - public void testProxyIsUsedWhenSetInProperties() throws Exception { - importMapping(connectionResetByPeerScenario); - HttpClientBuilder httpClientBuilder = HttpClientBuilder - .create() - .disableAutomaticRetries(); - try (CloseableHttpClient httpClient = httpClientBuilder.build()) { - HttpGet request = - new HttpGet(String.format("http://%s:%d/endpoint", WIREMOCK_HOST, httpProxyPort)); - RestRequest.execute( - httpClient, - request, - 0, - 0, - 0, - 0, - 0, - new AtomicBoolean(false), - false, - false, - false, - false, - new ExecTimeTelemetryData()); + @Test + public void testProxyIsUsedWhenSetInProperties() throws Exception { + importMapping(connectionResetByPeerScenario); + HttpClientBuilder httpClientBuilder = HttpClientBuilder.create().disableAutomaticRetries(); + try (CloseableHttpClient httpClient = httpClientBuilder.build()) { + HttpGet request = + new HttpGet(String.format("http://%s:%d/endpoint", WIREMOCK_HOST, httpProxyPort)); + RestRequest.execute( + httpClient, + request, + 0, + 0, + 0, + 0, + 0, + new AtomicBoolean(false), + false, + false, + false, + false, + new ExecTimeTelemetryData()); - CloseableHttpResponse response = httpClient.execute(request); - assert (response.getStatusLine().getStatusCode() == 200); - } + CloseableHttpResponse response = httpClient.execute(request); + assert (response.getStatusLine().getStatusCode() == 200); } + } }