Skip to content

Commit

Permalink
[Spotless] Applying Google Code Format for integ-tests #8 (opensearch…
Browse files Browse the repository at this point in the history
…-project#1962)

* spotless apply for 81 integ-test files (#327)

add ignore failures for build.gradle.



Reverting ignore for checkstyle in integ-test



Addressed PR comments.



Addressed PR comments to expand jav doc.



fixed string formatting



Fixed string formatting.



Fixed string formatting in MatchPhrasePrefixIT

Signed-off-by: Mitchell Gale <[email protected]>

* Apply suggestions from code review

Co-authored-by: Yury-Fridlyand <[email protected]>
Signed-off-by: Mitchell Gale <[email protected]>

* address PR comments

Signed-off-by: Mitchell Gale <[email protected]>

---------

Signed-off-by: Mitchell Gale <[email protected]>
Signed-off-by: Mitchell Gale <[email protected]>
Co-authored-by: Yury-Fridlyand <[email protected]>
  • Loading branch information
MitchellGale and Yury-Fridlyand authored Aug 16, 2023
1 parent e8e94d0 commit c60a4f1
Show file tree
Hide file tree
Showing 80 changed files with 7,155 additions and 5,542 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/


package org.opensearch.sql.correctness;

import static org.opensearch.sql.util.TestUtils.getResourceFilePath;
Expand Down Expand Up @@ -32,11 +31,12 @@
import org.opensearch.sql.correctness.testset.TestDataSet;
import org.opensearch.test.OpenSearchIntegTestCase;

/**
* Correctness integration test by performing comparison test with other databases.
*/
/** Correctness integration test by performing comparison test with other databases. */
@OpenSearchIntegTestCase.SuiteScopeTestCase
@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.SUITE, numDataNodes = 3, supportsDedicatedMasters = false)
@OpenSearchIntegTestCase.ClusterScope(
scope = OpenSearchIntegTestCase.Scope.SUITE,
numDataNodes = 3,
supportsDedicatedMasters = false)
@ThreadLeakScope(ThreadLeakScope.Scope.NONE)
public class CorrectnessIT extends OpenSearchIntegTestCase {

Expand All @@ -47,8 +47,8 @@ public void performComparisonTest() throws URISyntaxException {
TestConfig config = new TestConfig(getCmdLineArgs());
LOG.info("Starting comparison test {}", config);

try (ComparisonTest test = new ComparisonTest(getThisDBConnection(config),
getOtherDBConnections(config))) {
try (ComparisonTest test =
new ComparisonTest(getThisDBConnection(config), getOtherDBConnections(config))) {
LOG.info("Loading test data set...");
test.connect();
for (TestDataSet dataSet : config.getTestDataSets()) {
Expand Down Expand Up @@ -81,9 +81,7 @@ private DBConnection getThisDBConnection(TestConfig config) throws URISyntaxExce
return new JDBCConnection("DB Tested", dbUrl);
}

/**
* Use OpenSearch cluster given on CLI arg or internal embedded in SQLIntegTestCase
*/
/** Use OpenSearch cluster given on CLI arg or internal embedded in SQLIntegTestCase */
private DBConnection getOpenSearchConnection(TestConfig config) throws URISyntaxException {
RestClient client;
String openSearchHost = config.getOpenSearchHostUrl();
Expand All @@ -96,14 +94,11 @@ private DBConnection getOpenSearchConnection(TestConfig config) throws URISyntax
return new OpenSearchConnection("jdbc:opensearch://" + openSearchHost, client);
}

/**
* Create database connection with database name and connect URL
*/
/** Create database connection with database name and connect URL */
private DBConnection[] getOtherDBConnections(TestConfig config) {
return config.getOtherDbConnectionNameAndUrls().
entrySet().stream().
map(e -> new JDBCConnection(e.getKey(), e.getValue())).
toArray(DBConnection[]::new);
return config.getOtherDbConnectionNameAndUrls().entrySet().stream()
.map(e -> new JDBCConnection(e.getKey(), e.getValue()))
.toArray(DBConnection[]::new);
}

private void store(TestReport report) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/


package org.opensearch.sql.correctness.report;

import static org.opensearch.sql.correctness.report.TestCaseReport.TestResult.FAILURE;
Expand All @@ -12,22 +11,17 @@
import lombok.Getter;
import lombok.ToString;

/**
* Report for test case that ends with an error.
*/
/** Report for test case that ends with an error. */
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Getter
public class ErrorTestCase extends TestCaseReport {

/**
* Root cause of the error
*/
/** Root cause of the error */
private final String reason;

public ErrorTestCase(int id, String sql, String reason) {
super(id, sql, FAILURE);
this.reason = reason;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/


package org.opensearch.sql.correctness.report;

import static org.opensearch.sql.correctness.report.TestCaseReport.TestResult.FAILURE;
Expand All @@ -16,41 +15,31 @@
import lombok.ToString;
import org.opensearch.sql.correctness.runner.resultset.DBResult;

/**
* Report for test case that fails due to inconsistent result set.
*/
/** Report for test case that fails due to inconsistent result set. */
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Getter
public class FailedTestCase extends TestCaseReport {

/**
* Inconsistent result sets for reporting
*/
/** Inconsistent result sets for reporting */
private final List<DBResult> resultSets;

/**
* Explain where the difference is caused the test failure.
*/
/** Explain where the difference is caused the test failure. */
private final String explain;

/**
* Errors occurred for partial other databases.
*/
/** Errors occurred for partial other databases. */
private final String errors;


public FailedTestCase(int id, String sql, List<DBResult> resultSets, String errors) {
super(id, sql, FAILURE);
this.resultSets = resultSets;
this.resultSets.sort(Comparator.comparing(DBResult::getDatabaseName));
this.errors = errors;

// Generate explanation by diff the first result with remaining
this.explain = resultSets.subList(1, resultSets.size())
.stream()
.map(result -> resultSets.get(0).diff(result))
.collect(Collectors.joining(", "));
this.explain =
resultSets.subList(1, resultSets.size()).stream()
.map(result -> resultSets.get(0).diff(result))
.collect(Collectors.joining(", "));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/


package org.opensearch.sql.correctness.runner;

import static com.google.common.collect.ObjectArrays.concat;
Expand All @@ -25,24 +24,16 @@
import org.opensearch.sql.correctness.testset.TestQuerySet;
import org.opensearch.sql.legacy.utils.StringUtils;

/**
* Comparison test runner for query result correctness.
*/
/** Comparison test runner for query result correctness. */
public class ComparisonTest implements AutoCloseable {

/**
* Next id for test case
*/
/** Next id for test case */
private int testCaseId = 1;

/**
* Connection for database being tested
*/
/** Connection for database being tested */
private final DBConnection thisConnection;

/**
* Database connections for reference databases
*/
/** Database connections for reference databases */
private final DBConnection[] otherDbConnections;

public ComparisonTest(DBConnection thisConnection, DBConnection[] otherDbConnections) {
Expand All @@ -53,9 +44,7 @@ public ComparisonTest(DBConnection thisConnection, DBConnection[] otherDbConnect
Arrays.sort(this.otherDbConnections, Comparator.comparing(DBConnection::getDatabaseName));
}

/**
* Open database connection.
*/
/** Open database connection. */
public void connect() {
for (DBConnection conn : concat(thisConnection, otherDbConnections)) {
conn.connect();
Expand Down Expand Up @@ -87,8 +76,11 @@ public TestReport verify(TestQuerySet querySet) {
DBResult openSearchResult = thisConnection.select(sql);
report.addTestCase(compareWithOtherDb(sql, openSearchResult));
} catch (Exception e) {
report.addTestCase(new ErrorTestCase(nextId(), sql,
StringUtils.format("%s: %s", e.getClass().getSimpleName(), extractRootCause(e))));
report.addTestCase(
new ErrorTestCase(
nextId(),
sql,
StringUtils.format("%s: %s", e.getClass().getSimpleName(), extractRootCause(e))));
}
}
return report;
Expand Down Expand Up @@ -116,9 +108,7 @@ public void close() {
}
}

/**
* Execute the query and compare with current result
*/
/** Execute the query and compare with current result */
private TestCaseReport compareWithOtherDb(String sql, DBResult openSearchResult) {
List<DBResult> mismatchResults = Lists.newArrayList(openSearchResult);
StringBuilder reasons = new StringBuilder();
Expand All @@ -137,7 +127,8 @@ private TestCaseReport compareWithOtherDb(String sql, DBResult openSearchResult)
}
}

if (mismatchResults.size() == 1) { // Only OpenSearch result on list. Cannot find other database support this query
if (mismatchResults.size()
== 1) { // Only OpenSearch result on list. Cannot find other database support this query
return new ErrorTestCase(nextId(), sql, "No other databases support this query: " + reasons);
}
return new FailedTestCase(nextId(), sql, mismatchResults, reasons.toString());
Expand All @@ -150,8 +141,8 @@ private int nextId() {
private void insertTestDataInBatch(DBConnection conn, String tableName, List<Object[]> testData) {
Iterator<Object[]> iterator = testData.iterator();
String[] fieldNames = (String[]) iterator.next(); // first row is header of column names
Iterators.partition(iterator, 100).
forEachRemaining(batch -> conn.insert(tableName, fieldNames, batch));
Iterators.partition(iterator, 100)
.forEachRemaining(batch -> conn.insert(tableName, fieldNames, batch));
}

private String extractRootCause(Throwable e) {
Expand All @@ -167,5 +158,4 @@ private String extractRootCause(Throwable e) {
}
return e.toString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,36 @@
* SPDX-License-Identifier: Apache-2.0
*/


package org.opensearch.sql.correctness.runner.connection;

import java.util.List;
import org.opensearch.sql.correctness.runner.resultset.DBResult;

/**
* Abstraction for different databases.
*/
/** Abstraction for different databases. */
public interface DBConnection {

/**
* @return database name
*/
String getDatabaseName();

/**
* Connect to database by opening a connection.
*/
/** Connect to database by opening a connection. */
void connect();

/**
* Create table with the schema.
*
* @param tableName table name
* @param schema schema json in OpenSearch mapping format
* @param schema schema json in OpenSearch mapping format
*/
void create(String tableName, String schema);

/**
* Insert batch of data to database.
*
* @param tableName table name
* @param tableName table name
* @param columnNames column names
* @param batch batch of rows
* @param batch batch of rows
*/
void insert(String tableName, String[] columnNames, List<Object[]> batch);

Expand All @@ -56,9 +51,6 @@ public interface DBConnection {
*/
void drop(String tableName);

/**
* Close the database connection.
*/
/** Close the database connection. */
void close();

}
Loading

0 comments on commit c60a4f1

Please sign in to comment.