Skip to content

Commit

Permalink
Support distinct session for test and control in verifier
Browse files Browse the repository at this point in the history
  • Loading branch information
arhimondr authored and losipiuk committed Apr 5, 2022
1 parent 50423a7 commit 77bace2
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 20 deletions.
3 changes: 2 additions & 1 deletion service/trino-verifier/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ CREATE TABLE verifier_queries(
test_postqueries TEXT,
test_username VARCHAR(256) NOT NULL default 'verifier-test',
test_password VARCHAR(256),
test_session_properties_json VARCHAR(2048),
control_catalog VARCHAR(256) NOT NULL,
control_schema VARCHAR(256) NOT NULL,
control_prequeries TEXT,
control_query TEXT NOT NULL,
control_postqueries TEXT,
control_username VARCHAR(256) NOT NULL default 'verifier-test',
control_password VARCHAR(256),
session_properties_json VARCHAR(2048),
control_session_properties_json VARCHAR(2048),
PRIMARY KEY (id)
);
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,39 @@ public class QueryPairMapper
public QueryPair map(ResultSet resultSet, StatementContext context)
throws SQLException
{
Map<String, String> sessionProperties = ImmutableMap.of();
String json = resultSet.getString("session_properties_json");
if (json != null) {
sessionProperties = propertiesJsonCodec.fromJson(json);
Map<String, String> testSessionProperties = ImmutableMap.of();
String testSessionPropertiesJson = resultSet.getString("test_session_properties_json");
if (testSessionPropertiesJson != null) {
testSessionProperties = propertiesJsonCodec.fromJson(testSessionPropertiesJson);
}

Map<String, String> controlSessionProperties = ImmutableMap.of();
String controlSessionPropertiesJson = resultSet.getString("control_session_properties_json");
if (controlSessionPropertiesJson != null) {
controlSessionProperties = propertiesJsonCodec.fromJson(controlSessionPropertiesJson);
}

return new QueryPair(
resultSet.getString("suite"),
resultSet.getString("name"),
new Query(resultSet.getString("test_catalog"), resultSet.getString("test_schema"), fromJsonString(resultSet.getString("test_prequeries")), resultSet.getString("test_query"),
new Query(
resultSet.getString("test_catalog"),
resultSet.getString("test_schema"),
fromJsonString(resultSet.getString("test_prequeries")),
resultSet.getString("test_query"),
fromJsonString(resultSet.getString("test_postqueries")),
resultSet.getString("test_username"), resultSet.getString("test_password"), sessionProperties),
new Query(resultSet.getString("control_catalog"), resultSet.getString("control_schema"), fromJsonString(resultSet.getString("control_prequeries")), resultSet.getString("control_query"),
resultSet.getString("test_username"),
resultSet.getString("test_password"),
testSessionProperties),
new Query(
resultSet.getString("control_catalog"),
resultSet.getString("control_schema"),
fromJsonString(resultSet.getString("control_prequeries")),
resultSet.getString("control_query"),
fromJsonString(resultSet.getString("control_postqueries")),
resultSet.getString("control_username"), resultSet.getString("control_password"), sessionProperties));
resultSet.getString("control_username"),
resultSet.getString("control_password"),
controlSessionProperties));
}

private static List<String> fromJsonString(String jsonString)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ public class Validator
private final boolean verboseResultsComparison;
private final QueryPair queryPair;
private final boolean explainOnly;
private final Map<String, String> sessionProperties;
private final Map<String, String> controlSessionProperties;
private final Map<String, String> testSessionProperties;
private final int precision;
private final int controlTeardownRetries;
private final int testTeardownRetries;
Expand Down Expand Up @@ -136,8 +137,8 @@ public Validator(
this.runTearDownOnResultMismatch = runTearDownOnResultMismatch;

this.queryPair = requireNonNull(queryPair, "queryPair is null");
// Test and Control always have the same session properties.
this.sessionProperties = queryPair.getTest().getSessionProperties();
this.controlSessionProperties = queryPair.getControl().getSessionProperties();
this.testSessionProperties = queryPair.getTest().getSessionProperties();
}

public boolean isSkipped()
Expand Down Expand Up @@ -265,7 +266,8 @@ private void tearDownControl()
controlPassword,
controlTimeout,
controlPostQueryResults,
controlTeardownRetries);
controlTeardownRetries,
controlSessionProperties);
if (controlTearDownResult.getState() != State.SUCCESS) {
log.warn("Control table teardown failed");
}
Expand All @@ -280,7 +282,8 @@ private void tearDownTest()
testPassword,
testTimeout,
testPostQueryResults,
testTeardownRetries);
testTeardownRetries,
testSessionProperties);
if (testTearDownResult.getState() != State.SUCCESS) {
log.warn("Test table teardown failed");
}
Expand Down Expand Up @@ -358,7 +361,8 @@ private QueryResult executePreAndMainForTest()
testPassword,
testTimeout,
testPostQueryResults,
testTeardownRetries);
testTeardownRetries,
testSessionProperties);
}

private QueryResult executePreAndMainForControl()
Expand All @@ -371,7 +375,8 @@ private QueryResult executePreAndMainForControl()
controlPassword,
controlTimeout,
controlPostQueryResults,
controlTeardownRetries);
controlTeardownRetries,
controlSessionProperties);
}

private QueryResult executePreAndMain(
Expand All @@ -382,7 +387,8 @@ private QueryResult executePreAndMain(
String password,
Duration timeout,
List<QueryResult> postQueryResults,
int teardownRetries)
int teardownRetries,
Map<String, String> sessionProperties)
{
try {
// startup
Expand All @@ -397,7 +403,7 @@ private QueryResult executePreAndMain(
return queryResult;
}
catch (Exception e) {
executeTearDown(query, gateway, username, password, timeout, postQueryResults, teardownRetries);
executeTearDown(query, gateway, username, password, timeout, postQueryResults, teardownRetries, sessionProperties);
throw e;
}
}
Expand All @@ -409,7 +415,8 @@ private QueryResult executeTearDown(
String password,
Duration timeout,
List<QueryResult> postQueryResults,
int teardownRetries)
int teardownRetries,
Map<String, String> sessionProperties)
{
int attempt = 0;
QueryResult tearDownResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ public interface VerifierDao
", test_postqueries\n" +
", test_username\n" +
", test_password\n" +
", test_session_properties_json\n" +
", control_catalog\n" +
", control_schema\n" +
", control_prequeries\n" +
", control_query\n" +
", control_postqueries\n" +
", control_username\n" +
", control_password\n" +
", session_properties_json\n" +
", control_session_properties_json\n" +
"FROM verifier_queries\n" +
"WHERE suite = :suite\n" +
"ORDER BY id\n" +
Expand Down

0 comments on commit 77bace2

Please sign in to comment.