Skip to content

Commit

Permalink
[Spotless] Applying Google Code Format for integ-tests #10 (opensearc…
Browse files Browse the repository at this point in the history
…h-project#1967)

* [Spotless] Applying Google Code Format for integ-tests #10 (#329)

* Add spotless apply 33 files.

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

* Addressed PR comments.

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

* Address PR comments.

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

* fixing integ test failure.

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

---------

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

* Update integ-test/src/test/java/org/opensearch/sql/correctness/tests/TestConfigTest.java

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

* Apply suggestions from code review

Co-authored-by: Guian Gumpac <[email protected]>
Signed-off-by: Mitchell Gale <[email protected]>

* Apply suggestions from code review

Co-authored-by: Guian Gumpac <[email protected]>
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]>
Co-authored-by: Guian Gumpac <[email protected]>
  • Loading branch information
3 people authored Aug 16, 2023
1 parent c60a4f1 commit 491a73b
Show file tree
Hide file tree
Showing 33 changed files with 1,569 additions and 1,484 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 java.util.stream.Collectors.joining;
Expand All @@ -19,11 +18,13 @@
import org.opensearch.sql.legacy.utils.StringUtils;

/**
* <pre>
* Test configuration parse the following information from command line arguments:
* 1) Test schema and data
* 2) Test queries
* 3) OpenSearch connection URL
* 4) Other database connection URLs
* </pre>
*/
public class TestConfig {

Expand All @@ -37,9 +38,7 @@ public class TestConfig {

private final String openSearchHostUrl;

/**
* Test against some database rather than OpenSearch via our JDBC driver
*/
/** Test against some database rather than OpenSearch via our JDBC driver */
private final String dbConnectionUrl;

private final Map<String, String> otherDbConnectionNameAndUrls = new HashMap<>();
Expand Down Expand Up @@ -75,12 +74,14 @@ public Map<String, String> getOtherDbConnectionNameAndUrls() {

private TestDataSet[] buildDefaultTestDataSet() {
return new TestDataSet[] {
new TestDataSet("opensearch_dashboards_sample_data_flights",
readFile("opensearch_dashboards_sample_data_flights.json"),
readFile("opensearch_dashboards_sample_data_flights.csv")),
new TestDataSet("opensearch_dashboards_sample_data_ecommerce",
readFile("opensearch_dashboards_sample_data_ecommerce.json"),
readFile("opensearch_dashboards_sample_data_ecommerce.csv")),
new TestDataSet(
"opensearch_dashboards_sample_data_flights",
readFile("opensearch_dashboards_sample_data_flights.json"),
readFile("opensearch_dashboards_sample_data_flights.csv")),
new TestDataSet(
"opensearch_dashboards_sample_data_ecommerce",
readFile("opensearch_dashboards_sample_data_ecommerce.json"),
readFile("opensearch_dashboards_sample_data_ecommerce.csv")),
};
}

Expand Down Expand Up @@ -118,31 +119,33 @@ private static String readFile(String relativePath) {
@Override
public String toString() {
return "\n=================================\n"
+ "Tested Database : " + openSearchHostUrlToString() + '\n'
+ "Other Databases :\n" + otherDbConnectionInfoToString() + '\n'
+ "Test data set(s) :\n" + testDataSetsToString() + '\n'
+ "Test query set : " + testQuerySet + '\n'
+ "=================================\n";
+ "Tested Database : "
+ openSearchHostUrlToString()
+ "\nOther Databases :\n"
+ otherDbConnectionInfoToString()
+ "\nTest data set(s) :\n"
+ testDataSetsToString()
+ "\nTest query set : "
+ testQuerySet
+ "\n=================================\n";
}

private String testDataSetsToString() {
return Arrays.stream(testDataSets).
map(TestDataSet::toString).
collect(joining("\n"));
return Arrays.stream(testDataSets).map(TestDataSet::toString).collect(joining("\n"));
}

private String openSearchHostUrlToString() {
if (!dbConnectionUrl.isEmpty()) {
return dbConnectionUrl;
}
return openSearchHostUrl.isEmpty() ? "(Use internal OpenSearch in workspace)" :
openSearchHostUrl;
return openSearchHostUrl.isEmpty()
? "(Use internal OpenSearch in workspace)"
: openSearchHostUrl;
}

private String otherDbConnectionInfoToString() {
return otherDbConnectionNameAndUrls.entrySet().stream().
map(e -> StringUtils.format(" %s = %s", e.getKey(), e.getValue())).
collect(joining("\n"));
return otherDbConnectionNameAndUrls.entrySet().stream()
.map(e -> StringUtils.format(" %s = %s", e.getKey(), e.getValue()))
.collect(joining("\n"));
}

}
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.SUCCESS;
Expand All @@ -12,9 +11,7 @@
import lombok.Getter;
import lombok.ToString;

/**
* Report for successful test case result.
*/
/** Report for successful test case result. */
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Getter
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.SUCCESS;
Expand All @@ -12,22 +11,19 @@
import lombok.Getter;
import lombok.ToString;

/**
* Base class for different test result.
*/
/** Base class for different test result. */
@EqualsAndHashCode
@ToString
public abstract class TestCaseReport {

public enum TestResult {
SUCCESS, FAILURE;
SUCCESS,
FAILURE;
}

@Getter
private final int id;
@Getter private final int id;

@Getter
private final String sql;
@Getter private final String sql;

private final TestResult result;

Expand All @@ -40,5 +36,4 @@ public TestCaseReport(int id, String sql, TestResult result) {
public String getResult() {
return result == SUCCESS ? "Success" : "Failed";
}

}
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 java.util.ArrayList;
Expand All @@ -12,9 +11,7 @@
import lombok.Getter;
import lombok.ToString;

/**
* Test report class to generate JSON report.
*/
/** Test report class to generate JSON report. */
@EqualsAndHashCode
@ToString
@Getter
Expand All @@ -37,5 +34,4 @@ public void addTestCase(TestCaseReport testCase) {
summary.addFailure();
}
}

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


package org.opensearch.sql.correctness.report;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;

/**
* Test summary section.
*/
/** Test summary section. */
@EqualsAndHashCode
@ToString
@Getter
Expand All @@ -33,5 +30,4 @@ public void addFailure() {
failure++;
total++;
}

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


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

import lombok.Data;

/**
* Column type in schema
*/
/** Column type in schema */
@Data
public class Type {

/**
* Column name
*/
/** Column name */
private final String name;

/**
* Column type
*/
/** Column type */
private final String type;

}
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.tests;

import static java.util.Collections.emptyMap;
Expand All @@ -18,9 +17,7 @@
import org.junit.Test;
import org.opensearch.sql.correctness.TestConfig;

/**
* Tests for {@link TestConfig}
*/
/** Tests for {@link TestConfig} */
public class TestConfigTest {

@Test
Expand All @@ -31,9 +28,7 @@ public void testDefaultConfig() {
config.getOtherDbConnectionNameAndUrls(),
allOf(
hasEntry("H2", "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1"),
hasEntry("SQLite", "jdbc:sqlite::memory:")
)
);
hasEntry("SQLite", "jdbc:sqlite::memory:")));
}

@Test
Expand All @@ -45,18 +40,16 @@ public void testCustomESUrls() {

@Test
public void testCustomDbUrls() {
Map<String, String> args = ImmutableMap.of("otherDbUrls",
"H2=jdbc:h2:mem:test;DB_CLOSE_DELAY=-1,"
+ "Derby=jdbc:derby:memory:myDb;create=true");
Map<String, String> args =
ImmutableMap.of(
"otherDbUrls",
"H2=jdbc:h2:mem:test;DB_CLOSE_DELAY=-1,Derby=jdbc:derby:memory:myDb;create=true");

TestConfig config = new TestConfig(args);
assertThat(
config.getOtherDbConnectionNameAndUrls(),
allOf(
hasEntry("H2", "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1"),
hasEntry("Derby", "jdbc:derby:memory:myDb;create=true")
)
);
hasEntry("Derby", "jdbc:derby:memory:myDb;create=true")));
}

}
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.tests;

import static org.hamcrest.MatcherAssert.assertThat;
Expand All @@ -13,9 +12,7 @@
import org.junit.Test;
import org.opensearch.sql.correctness.testset.TestDataSet;

/**
* Tests for {@link TestDataSet}
*/
/** Tests for {@link TestDataSet} */
public class TestDataSetTest {

@Test
Expand All @@ -40,9 +37,7 @@ public void testDataSetWithSingleColumnData() {
new Object[] {"field"},
new Object[] {"hello"},
new Object[] {"world"},
new Object[] {"123"}
)
);
new Object[] {"123"}));
}

@Test
Expand All @@ -61,16 +56,13 @@ public void testDataSetWithMultiColumnsData() {
+ " }\n"
+ "}";

TestDataSet dataSet = new TestDataSet("test", mappings,
"field1,field2\nhello,123\nworld,456");
TestDataSet dataSet = new TestDataSet("test", mappings, "field1,field2\nhello,123\nworld,456");
assertThat(
dataSet.getDataRows(),
contains(
new Object[] {"field1", "field2"},
new Object[] {"hello", 123},
new Object[] {"world", 456}
)
);
new Object[] {"world", 456}));
}

@Test
Expand All @@ -86,17 +78,15 @@ public void testDataSetWithEscapedComma() {
+ " }\n"
+ "}";

TestDataSet dataSet = new TestDataSet("test", mappings,
"field\n\"hello,world,123\"\n123\n\"[abc,def,ghi]\"");
TestDataSet dataSet =
new TestDataSet("test", mappings, "field\n\"hello,world,123\"\n123\n\"[abc,def,ghi]\"");
assertThat(
dataSet.getDataRows(),
contains(
new Object[] {"field"},
new Object[] {"hello,world,123"},
new Object[] {"123"},
new Object[] {"[abc,def,ghi]"}
)
);
new Object[] {"[abc,def,ghi]"}));
}

@Test
Expand All @@ -115,17 +105,13 @@ public void testDataSetWithNullData() {
+ " }\n"
+ "}";

TestDataSet dataSet = new TestDataSet("test", mappings,
"field1,field2\n,123\nworld,\n,");
TestDataSet dataSet = new TestDataSet("test", mappings, "field1,field2\n,123\nworld,\n,");
assertThat(
dataSet.getDataRows(),
contains(
new Object[] {"field1", "field2"},
new Object[] {null, 123},
new Object[] {"world", null},
new Object[] {null, null}
)
);
new Object[] {null, null}));
}

}
Loading

0 comments on commit 491a73b

Please sign in to comment.