diff --git a/integ-test/src/test/java/com/amazon/opendistroforelasticsearch/sql/correctness/runner/connection/ESConnection.java b/integ-test/src/test/java/com/amazon/opendistroforelasticsearch/sql/correctness/runner/connection/ESConnection.java index 04dbecae0f..f6ca6c52cb 100644 --- a/integ-test/src/test/java/com/amazon/opendistroforelasticsearch/sql/correctness/runner/connection/ESConnection.java +++ b/integ-test/src/test/java/com/amazon/opendistroforelasticsearch/sql/correctness/runner/connection/ESConnection.java @@ -18,6 +18,7 @@ import com.amazon.opendistroforelasticsearch.sql.correctness.runner.resultset.DBResult; import java.io.IOException; import java.util.List; +import java.util.Properties; import org.elasticsearch.client.Request; import org.elasticsearch.client.Response; import org.elasticsearch.client.RestClient; @@ -39,7 +40,7 @@ public class ESConnection implements DBConnection { private final RestClient client; public ESConnection(String connectionUrl, RestClient client) { - this.connection = new JDBCConnection("Elasticsearch", connectionUrl); + this.connection = new JDBCConnection("Elasticsearch", connectionUrl, populateProperties()); this.client = client; } @@ -84,6 +85,20 @@ public void close() { connection.close(); } + private Properties populateProperties() { + Properties properties = new Properties(); + if (Boolean.parseBoolean(System.getProperty("https", "false"))) { + properties.put("useSSL", "true"); + } + if (!System.getProperty("user", "").isEmpty()) { + properties.put("user", System.getProperty("user")); + properties.put("password", System.getProperty("password", "")); + properties.put("trustSelfSigned", "true"); + properties.put("hostnameVerification", "false"); + } + return properties; + } + private void performRequest(Request request) { try { Response response = client.performRequest(request); diff --git a/integ-test/src/test/java/com/amazon/opendistroforelasticsearch/sql/correctness/runner/connection/JDBCConnection.java b/integ-test/src/test/java/com/amazon/opendistroforelasticsearch/sql/correctness/runner/connection/JDBCConnection.java index 2aff6b982c..4bcfb8ee73 100644 --- a/integ-test/src/test/java/com/amazon/opendistroforelasticsearch/sql/correctness/runner/connection/JDBCConnection.java +++ b/integ-test/src/test/java/com/amazon/opendistroforelasticsearch/sql/correctness/runner/connection/JDBCConnection.java @@ -29,6 +29,7 @@ import java.sql.Statement; import java.util.Arrays; import java.util.List; +import java.util.Properties; import org.json.JSONObject; /** @@ -49,20 +50,36 @@ public class JDBCConnection implements DBConnection { */ private final String connectionUrl; + /** + * JDBC driver config properties. + */ + private final Properties properties; + /** * Current live connection */ private Connection connection; public JDBCConnection(String databaseName, String connectionUrl) { + this(databaseName, connectionUrl, new Properties()); + } + + /** + * Create a JDBC connection with parameters given (but not connect to database at the moment). + * @param databaseName database name + * @param connectionUrl connection URL + * @param properties config properties + */ + public JDBCConnection(String databaseName, String connectionUrl, Properties properties) { this.databaseName = databaseName; this.connectionUrl = connectionUrl; + this.properties = properties; } @Override public void connect() { try { - connection = DriverManager.getConnection(connectionUrl); + connection = DriverManager.getConnection(connectionUrl, properties); } catch (Exception e) { throw new IllegalStateException("Failed to open connection", e); } diff --git a/integ-test/src/test/java/com/amazon/opendistroforelasticsearch/sql/legacy/RestIntegTestCase.java b/integ-test/src/test/java/com/amazon/opendistroforelasticsearch/sql/legacy/RestIntegTestCase.java index b75b618dc3..ef3a101acb 100644 --- a/integ-test/src/test/java/com/amazon/opendistroforelasticsearch/sql/legacy/RestIntegTestCase.java +++ b/integ-test/src/test/java/com/amazon/opendistroforelasticsearch/sql/legacy/RestIntegTestCase.java @@ -54,7 +54,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.rest.RestStatus; -import org.elasticsearch.test.rest.ESRestTestCase; import org.junit.AfterClass; import org.junit.Assert; import org.junit.Before; @@ -72,7 +71,7 @@ *

* TODO: this base class should extends ODFERestTestCase */ -public abstract class RestIntegTestCase extends ESRestTestCase { +public abstract class RestIntegTestCase extends ODFERestTestCase { @Before public void setUpIndices() throws Exception { @@ -134,7 +133,7 @@ public static void dumpCoverage() { */ @AfterClass public static void cleanUpIndices() throws IOException { - wipeAllIndices(); + wipeAllODFEIndices(); wipeAllClusterSettings(); } diff --git a/integ-test/src/test/java/com/amazon/opendistroforelasticsearch/sql/sql/CorrectnessTestBase.java b/integ-test/src/test/java/com/amazon/opendistroforelasticsearch/sql/sql/CorrectnessTestBase.java index d31f297728..69c58b2c5d 100644 --- a/integ-test/src/test/java/com/amazon/opendistroforelasticsearch/sql/sql/CorrectnessTestBase.java +++ b/integ-test/src/test/java/com/amazon/opendistroforelasticsearch/sql/sql/CorrectnessTestBase.java @@ -67,6 +67,10 @@ protected void init() throws Exception { */ @AfterClass public static void cleanUp() { + if (runner == null) { + return; + } + try { TestConfig config = new TestConfig(emptyMap()); for (TestDataSet dataSet : config.getTestDataSets()) {