Skip to content

Commit

Permalink
A bit more cleanup of imports
Browse files Browse the repository at this point in the history
Signed-off-by: currantw <[email protected]>
  • Loading branch information
currantw committed Dec 10, 2024
1 parent 41359b9 commit 2f38dd9
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@

package org.opensearch.sql.correctness.tests;

import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.util.Arrays;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -51,14 +52,14 @@ public void testSuccess() {
.thenReturn(
new DBResult(
"OpenSearch",
List.of(new Type("firstname", "text")),
List.of(new Row(List.of("John")))));
singletonList(new Type("firstname", "text")),
singletonList(new Row(singletonList("John")))));
when(otherDbConnection.select(anyString()))
.thenReturn(
new DBResult(
"Other DB",
List.of(new Type("firstname", "text")),
List.of(new Row(List.of("John")))));
singletonList(new Type("firstname", "text")),
singletonList(new Row(singletonList("John")))));

TestReport expected = new TestReport();
expected.addTestCase(new SuccessTestCase(1, "SELECT * FROM accounts"));
Expand All @@ -71,18 +72,20 @@ public void testFailureDueToInconsistency() {
DBResult openSearchResult =
new DBResult(
"OpenSearch",
List.of(new Type("firstname", "text")),
List.of(new Row(List.of("John"))));
singletonList(new Type("firstname", "text")),
singletonList(new Row(singletonList("John"))));
DBResult otherDbResult =
new DBResult(
"Other DB", List.of(new Type("firstname", "text")), List.of(new Row(List.of("JOHN"))));
"Other DB",
singletonList(new Type("firstname", "text")),
singletonList(new Row(singletonList("JOHN"))));
when(openSearchConnection.select(anyString())).thenReturn(openSearchResult);
when(otherDbConnection.select(anyString())).thenReturn(otherDbResult);

TestReport expected = new TestReport();
expected.addTestCase(
new FailedTestCase(
1, "SELECT * FROM accounts", Arrays.asList(openSearchResult, otherDbResult), ""));
1, "SELECT * FROM accounts", asList(openSearchResult, otherDbResult), ""));
TestReport actual = correctnessTest.verify(querySet("SELECT * FROM accounts"));
assertEquals(expected, actual);
}
Expand All @@ -98,16 +101,18 @@ public void testSuccessFinally() {
DBResult openSearchResult =
new DBResult(
"OpenSearch",
List.of(new Type("firstname", "text")),
List.of(new Row(List.of("John"))));
singletonList(new Type("firstname", "text")),
singletonList(new Row(singletonList("John"))));
DBResult otherDbResult =
new DBResult(
"Other DB", List.of(new Type("firstname", "text")), List.of(new Row(List.of("JOHN"))));
"Other DB",
singletonList(new Type("firstname", "text")),
singletonList(new Row(singletonList("JOHN"))));
DBResult anotherDbResult =
new DBResult(
"Another DB",
List.of(new Type("firstname", "text")),
List.of(new Row(List.of("John"))));
singletonList(new Type("firstname", "text")),
singletonList(new Row(singletonList("John"))));
when(openSearchConnection.select(anyString())).thenReturn(openSearchResult);
when(anotherDbConnection.select(anyString())).thenReturn(anotherDbResult);

Expand All @@ -129,14 +134,18 @@ public void testFailureDueToEventualInconsistency() {
DBResult openSearchResult =
new DBResult(
"OpenSearch",
List.of(new Type("firstname", "text")),
List.of(new Row(List.of("John"))));
singletonList(new Type("firstname", "text")),
singletonList(new Row(singletonList("John"))));
DBResult otherDbResult =
new DBResult(
"Other DB", List.of(new Type("firstname", "text")), List.of(new Row(List.of("JOHN"))));
"Other DB",
singletonList(new Type("firstname", "text")),
singletonList(new Row(singletonList("JOHN"))));
DBResult anotherDbResult =
new DBResult(
"ZZZ DB", List.of(new Type("firstname", "text")), List.of(new Row(List.of("Hank"))));
"ZZZ DB",
singletonList(new Type("firstname", "text")),
singletonList(new Row(singletonList("Hank"))));
when(openSearchConnection.select(anyString())).thenReturn(openSearchResult);
when(otherDbConnection.select(anyString())).thenReturn(otherDbResult);
when(anotherDbConnection.select(anyString())).thenReturn(anotherDbResult);
Expand All @@ -146,7 +155,7 @@ public void testFailureDueToEventualInconsistency() {
new FailedTestCase(
1,
"SELECT * FROM accounts",
Arrays.asList(openSearchResult, otherDbResult, anotherDbResult),
asList(openSearchResult, otherDbResult, anotherDbResult),
""));
TestReport actual = correctnessTest.verify(querySet("SELECT * FROM accounts"));
assertEquals(expected, actual);
Expand All @@ -170,8 +179,8 @@ public void testErrorDueToNoOtherDBSupportThisQuery() {
.thenReturn(
new DBResult(
"OpenSearch",
List.of(new Type("firstname", "text")),
List.of(new Row(List.of("John")))));
singletonList(new Type("firstname", "text")),
singletonList(new Row(singletonList("John")))));
when(otherDbConnection.select(anyString()))
.thenThrow(new RuntimeException("Unsupported feature"));

Expand All @@ -197,14 +206,14 @@ public void testSuccessWhenOneDBSupportThisQuery() {
.thenReturn(
new DBResult(
"OpenSearch",
List.of(new Type("firstname", "text")),
List.of(new Row(List.of("John")))));
singletonList(new Type("firstname", "text")),
singletonList(new Row(singletonList("John")))));
when(anotherDbConnection.select(anyString()))
.thenReturn(
new DBResult(
"Another DB",
List.of(new Type("firstname", "text")),
List.of(new Row(List.of("John")))));
singletonList(new Type("firstname", "text")),
singletonList(new Row(singletonList("John")))));

TestReport expected = new TestReport();
expected.addTestCase(new SuccessTestCase(1, "SELECT * FROM accounts"));
Expand All @@ -223,9 +232,10 @@ public void testFailureDueToInconsistencyAndExceptionMixed() {
DBResult openSearchResult =
new DBResult(
"OpenSearch",
List.of(new Type("firstname", "text")),
List.of(new Row(List.of("John"))));
DBResult otherResult = new DBResult("Other", List.of(new Type("firstname", "text")), List.of());
singletonList(new Type("firstname", "text")),
singletonList(new Row(singletonList("John"))));
DBResult otherResult =
new DBResult("Other", singletonList(new Type("firstname", "text")), emptyList());

when(openSearchConnection.select(anyString())).thenReturn(openSearchResult);
when(otherDbConnection.select(anyString())).thenReturn(otherResult);
Expand All @@ -237,7 +247,7 @@ public void testFailureDueToInconsistencyAndExceptionMixed() {
new FailedTestCase(
1,
"SELECT * FROM accounts",
Arrays.asList(openSearchResult, otherResult),
asList(openSearchResult, otherResult),
"Unsupported feature;"));
TestReport actual = correctnessTest.verify(querySet("SELECT * FROM accounts"));
assertEquals(expected, actual);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

package org.opensearch.sql.correctness.tests;

import static java.util.Arrays.asList;
import static java.util.Collections.singleton;
import static org.junit.Assert.fail;

import java.util.Arrays;
import java.util.List;
import org.json.JSONObject;
import org.junit.Test;
import org.opensearch.sql.correctness.report.ErrorTestCase;
Expand Down Expand Up @@ -56,15 +56,15 @@ public void testFailedReport() {
new FailedTestCase(
1,
"SELECT * FROM accounts",
Arrays.asList(
asList(
new DBResult(
"OpenSearch",
List.of(new Type("firstName", "text")),
List.of(new Row(List.of("hello")))),
singleton(new Type("firstName", "text")),
singleton(new Row(singleton("hello")))),
new DBResult(
"H2",
List.of(new Type("firstName", "text")),
List.of(new Row(List.of("world"))))),
singleton(new Type("firstName", "text")),
singleton(new Row(singleton("world"))))),
"[SQLITE_ERROR] SQL error or missing database;"));
JSONObject actual = new JSONObject(report);
JSONObject expected =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.hamcrest.Matcher;
Expand All @@ -30,10 +29,10 @@ public class BindingTupleResultSetTest {
public void buildDataRowsFromBindingTupleShouldPass() {
assertThat(
row(
Arrays.asList(
List.of(
ColumnNode.builder().name("age").type(Schema.Type.INTEGER).build(),
ColumnNode.builder().name("gender").type(Schema.Type.TEXT).build()),
Arrays.asList(
List.of(
BindingTuple.from(ImmutableMap.of("age", 31, "gender", "m")),
BindingTuple.from(ImmutableMap.of("age", 31, "gender", "f")),
BindingTuple.from(ImmutableMap.of("age", 39, "gender", "m")),
Expand All @@ -49,10 +48,10 @@ public void buildDataRowsFromBindingTupleShouldPass() {
public void buildDataRowsFromBindingTupleIncludeLongValueShouldPass() {
assertThat(
row(
Arrays.asList(
List.of(
ColumnNode.builder().name("longValue").type(Schema.Type.LONG).build(),
ColumnNode.builder().name("gender").type(Schema.Type.TEXT).build()),
Arrays.asList(
List.of(
BindingTuple.from(ImmutableMap.of("longValue", Long.MAX_VALUE, "gender", "m")),
BindingTuple.from(ImmutableMap.of("longValue", Long.MIN_VALUE, "gender", "f")))),
containsInAnyOrder(
Expand All @@ -66,7 +65,7 @@ public void buildDataRowsFromBindingTupleIncludeLongValueShouldPass() {
public void buildDataRowsFromBindingTupleIncludeDateShouldPass() {
assertThat(
row(
Arrays.asList(
List.of(
ColumnNode.builder().alias("dateValue").type(Schema.Type.DATE).build(),
ColumnNode.builder().alias("gender").type(Schema.Type.TEXT).build()),
List.of(
Expand Down

0 comments on commit 2f38dd9

Please sign in to comment.