Skip to content

Commit

Permalink
Address PR #1315 comments. #1315 (review)
Browse files Browse the repository at this point in the history
Signed-off-by: Yury-Fridlyand <[email protected]>
  • Loading branch information
Yury-Fridlyand committed Feb 14, 2023
1 parent dbc5b32 commit 76055a1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 205 deletions.
83 changes: 9 additions & 74 deletions integ-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ apply plugin: 'com.wiredforcode.spawn'
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }

// Add extra repository for the JDBC driver if given by user
if (System.getProperty("jdbcRepo") != null && new File(System.getProperty("jdbcRepo")).isDirectory()) {
maven { url new File(System.getProperty("jdbcRepo")) }
}
}

ext {
Expand Down Expand Up @@ -148,38 +153,6 @@ task stopPrometheus(type: KillProcessTask) {

stopPrometheus.mustRunAfter startPrometheus

task cloneJdbcDriverRepo {
if (file("${buildDir}/sql-jdbc").exists()) {
exec {
workingDir "${buildDir}/sql-jdbc"
commandLine 'git', 'remote', 'remove', 'origin'
}
exec {
workingDir "${buildDir}/sql-jdbc"
commandLine 'git', 'remote', 'add', 'origin', System.getProperty('jdbcRepo', 'https://github.com/opensearch-project/sql-jdbc.git')
}
exec {
workingDir "${buildDir}/sql-jdbc"
commandLine 'git', 'fetch', 'origin'
}
exec {
workingDir "${buildDir}/sql-jdbc"
commandLine 'git', 'reset', '--hard', 'origin/' + System.getProperty("jdbcBranch", 'main')
}
} else {
exec {
workingDir buildDir
// clone the sql-jdbc repo locally
commandLine 'git', 'clone', '--branch', System.getProperty("jdbcBranch", 'main'), System.getProperty('jdbcRepo', 'https://github.com/opensearch-project/sql-jdbc.git')
}
}
// TODO would fail on windows
exec {
workingDir "${buildDir}/sql-jdbc"
commandLine 'sh', 'gradlew', 'shadowJar'
}
}

task integJdbcTest(type: RestIntegTestTask) {
useJUnitPlatform()
dependsOn ':opensearch-sql-plugin:bundlePlugin'
Expand All @@ -190,47 +163,12 @@ task integJdbcTest(type: RestIntegTestTask) {
logger.quiet "${desc.className}.${desc.name}: ${result.resultType} ${(result.getEndTime() - result.getStartTime())/1000}s"
}

systemProperty 'tests.security.manager', 'false'
systemProperty('project.root', project.projectDir.absolutePath)

systemProperty "https", System.getProperty("https")
systemProperty "user", System.getProperty("user")
systemProperty "password", System.getProperty("password")

// Set default query size limit
systemProperty 'defaultQuerySizeLimit', '10000'

// Tell the test JVM if the cluster JVM is running under a debugger so that tests can use longer timeouts for
// requests. The 'doFirst' delays reading the debug setting on the cluster till execution time.
doFirst { systemProperty 'cluster.debug', getDebug() }

if (System.getProperty("test.debug") != null) {
jvmArgs '-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005'
}

filter {
includeTestsMatching 'org.opensearch.sql.jdbc.*'
}
}

task integDevJdbcTest(type: RestIntegTestTask) {
useJUnitPlatform()
dependsOn ':opensearch-sql-plugin:bundlePlugin'
testLogging {
events "passed", "skipped", "failed"
}
afterTest { desc, result ->
logger.quiet "${desc.className}.${desc.name}: ${result.resultType} ${(result.getEndTime() - result.getStartTime())/1000}s"
if (System.getProperty("jdbcDriverVersion") != null) {
systemProperty "jdbcDriverVersion", System.getProperty("jdbcDriverVersion")
}

if (System.getProperty("jdbcFile") != null) {
file("${buildDir}/sql-jdbc/build/libs").mkdirs()
copy {
from System.getProperty("jdbcFile")
into "${buildDir}/sql-jdbc/build/libs"
}
} else {
dependsOn cloneJdbcDriverRepo
systemProperty "jdbcFile", System.getProperty("jdbcFile")
}

systemProperty 'tests.security.manager', 'false'
Expand All @@ -252,7 +190,7 @@ task integDevJdbcTest(type: RestIntegTestTask) {
}

filter {
includeTestsMatching 'org.opensearch.sql.devJdbc.*'
includeTestsMatching 'org.opensearch.sql.jdbc.*'
}
}

Expand Down Expand Up @@ -306,7 +244,6 @@ integTest {

// Exclude JDBC related tests
exclude 'org/opensearch/sql/jdbc/**'
exclude 'org/opensearch/sql/devJdbc/**'
}


Expand Down Expand Up @@ -334,7 +271,6 @@ task comparisonTest(type: RestIntegTestTask) {

// Exclude JDBC related tests
exclude 'org/opensearch/sql/jdbc/**'
exclude 'org/opensearch/sql/devJdbc/**'

// Enable logging output to console
testLogging.showStandardStreams true
Expand Down Expand Up @@ -535,5 +471,4 @@ task integTestRemote(type: RestIntegTestTask) {
exclude 'org/opensearch/sql/legacy/QueryAnalysisIT.class'
exclude 'org/opensearch/sql/legacy/OrderIT.class'
exclude 'org/opensearch/sql/jdbc/**'
exclude 'org/opensearch/sql/devJdbc/**'
}
129 changes: 0 additions & 129 deletions integ-test/src/test/java/org/opensearch/sql/devJdbc/CursorIT.java

This file was deleted.

29 changes: 27 additions & 2 deletions integ-test/src/test/java/org/opensearch/sql/jdbc/CursorIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,21 @@
import static org.opensearch.sql.legacy.plugin.RestSqlAction.QUERY_API_ENDPOINT;
import static org.opensearch.sql.util.TestUtils.getResponseBody;

import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.List;
import javax.annotation.Nullable;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
import lombok.SneakyThrows;
import org.json.JSONObject;
import org.junit.AfterClass;
import org.junit.Assume;
import org.junit.BeforeClass;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -59,7 +64,18 @@ public void init() {
@BeforeClass
@SneakyThrows
public static void initConnection() {
connection = DriverManager.getConnection(getConnectionString());
var driverFile = System.getProperty("jdbcFile");
if (driverFile != null) {
URLClassLoader loader = new URLClassLoader(
new URL[]{new File(driverFile).toURI().toURL()},
ClassLoader.getSystemClassLoader()
);
Driver driver = (Driver) Class.forName("org.opensearch.jdbc.Driver", true, loader)
.getDeclaredConstructor().newInstance();
connection = driver.connect(getConnectionString(), null);
} else {
connection = DriverManager.getConnection(getConnectionString());
}
}

@AfterAll
Expand All @@ -73,6 +89,15 @@ public static void closeConnection() {
}
}

@Test
@SneakyThrows
public void check_driver_version() {
var version = System.getProperty("jdbcDriverVersion");
Assume.assumeTrue("Parameter `jdbcDriverVersion` is not given, test platform uses default driver version",
version != null);
assertEquals(version, connection.getMetaData().getDriverVersion());
}

@Test
@SneakyThrows
public void select_all_no_cursor() {
Expand Down

0 comments on commit 76055a1

Please sign in to comment.