Skip to content
Permalink
Browse files
[NO ISSUE] Misc utility / cleanup
Change-Id: Iae424fb99220630cb3a240cfef4cbba39b9da06b
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/11803
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Michael Blow <mblow@apache.org>
Reviewed-by: Murtadha Hubail <mhubail@apache.org>
  • Loading branch information
mblow committed Jun 30, 2021
1 parent 5daf5ea commit 803484b3966d308fbc21d04da955be81fc88958d
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 114 deletions.
@@ -19,7 +19,6 @@
package org.apache.asterix.test.common;

import java.io.File;
import java.util.BitSet;
import java.util.List;
import java.util.Map;

@@ -32,8 +31,7 @@ public interface IPollTask {

/**
* Execute the poll task
*
* @param testCaseCtx
* @param testCaseCtx
* @param ctx
* @param variableCtx
* @param statement
@@ -44,11 +42,9 @@ public interface IPollTask {
* @param expectedResultFileCtxs
* @param testFile
* @param actualPath
* @param expectedWarnings
*/
void execute(TestCaseContext testCaseCtx, TestFileContext ctx, Map<String, Object> variableCtx, String statement,
boolean isDmlRecoveryTest, ProcessBuilder pb, CompilationUnit cUnit, MutableInt queryCount,
List<TestFileContext> expectedResultFileCtxs, File testFile, String actualPath, BitSet expectedWarnings)
throws Exception;
List<TestFileContext> expectedResultFileCtxs, File testFile, String actualPath) throws Exception;

}
@@ -1143,16 +1143,16 @@ public void executeTest(String actualPath, TestCaseContext testCaseCtx, ProcessB

public void executeTestFile(TestCaseContext testCaseCtx, TestFileContext ctx, Map<String, Object> variableCtx,
String statement, boolean isDmlRecoveryTest, ProcessBuilder pb, CompilationUnit cUnit,
MutableInt queryCount, List<TestFileContext> expectedResultFileCtxs, File testFile, String actualPath,
BitSet expectedWarnings) throws Exception {
MutableInt queryCount, List<TestFileContext> expectedResultFileCtxs, File testFile, String actualPath)
throws Exception {
InputStream resultStream;
File qbcFile;
boolean failed = false;
File expectedResultFile;
switch (ctx.getType()) {
case "ddl":
ExtractedResult ddlExtractedResult = executeSqlppUpdateOrDdl(statement, OutputFormat.CLEAN_JSON, cUnit);
validateWarning(ddlExtractedResult, testCaseCtx, cUnit, testFile, expectedWarnings);
validateWarning(ddlExtractedResult, testCaseCtx, cUnit, testFile);
break;
case "update":
// isDmlRecoveryTest: set IP address
@@ -1166,11 +1166,11 @@ public void executeTestFile(TestCaseContext testCaseCtx, TestFileContext ctx, Ma
case "pollpost":
poll(testCaseCtx, ctx, variableCtx, statement, isDmlRecoveryTest, pb, cUnit, queryCount,
expectedResultFileCtxs, testFile, actualPath, ctx.getType().substring("poll".length()),
expectedWarnings, plainExecutor);
plainExecutor);
break;
case "polldynamic":
polldynamic(testCaseCtx, ctx, variableCtx, statement, isDmlRecoveryTest, pb, cUnit, queryCount,
expectedResultFileCtxs, testFile, actualPath, expectedWarnings);
expectedResultFileCtxs, testFile, actualPath);
break;
case "query":
case "async":
@@ -1195,7 +1195,7 @@ public void executeTestFile(TestCaseContext testCaseCtx, TestFileContext ctx, Ma
variableCtx, ctx, expectedResultFile, actualResultFile, queryCount,
expectedResultFileCtxs.size(), cUnit.getParameter(), ComparisonEnum.TEXT);

validateWarning(extractedResult, testCaseCtx, cUnit, testFile, expectedWarnings);
validateWarning(extractedResult, testCaseCtx, cUnit, testFile);
break;
case "store":
// This is a query that returns the expected output of a subsequent query
@@ -1610,18 +1610,18 @@ public ExtractedResult executeQuery(OutputFormat fmt, String statement, Map<Stri

private void polldynamic(TestCaseContext testCaseCtx, TestFileContext ctx, Map<String, Object> variableCtx,
String statement, boolean isDmlRecoveryTest, ProcessBuilder pb, CompilationUnit cUnit,
MutableInt queryCount, List<TestFileContext> expectedResultFileCtxs, File testFile, String actualPath,
BitSet expectedWarnings) throws Exception {
MutableInt queryCount, List<TestFileContext> expectedResultFileCtxs, File testFile, String actualPath)
throws Exception {
IExpectedResultPoller poller = getExpectedResultPoller(statement);
final String key = getKey(statement);
poll(testCaseCtx, ctx, variableCtx, statement, isDmlRecoveryTest, pb, cUnit, queryCount, expectedResultFileCtxs,
testFile, actualPath, "validate", expectedWarnings, new IPollTask() {
testFile, actualPath, "validate", new IPollTask() {
@Override
public void execute(TestCaseContext testCaseCtx, TestFileContext ctx,
Map<String, Object> variableCtx, String statement, boolean isDmlRecoveryTest,
ProcessBuilder pb, CompilationUnit cUnit, MutableInt queryCount,
List<TestFileContext> expectedResultFileCtxs, File testFile, String actualPath,
BitSet expectedWarnings) throws Exception {
List<TestFileContext> expectedResultFileCtxs, File testFile, String actualPath)
throws Exception {
File actualResultFile = new File(actualPath, testCaseCtx.getTestCase().getFilePath()
+ File.separatorChar + cUnit.getName() + '.' + ctx.getSeqNum() + ".polled.adm");
if (actualResultFile.exists() && !actualResultFile.delete()) {
@@ -1659,7 +1659,7 @@ protected IExpectedResultPoller getExpectedResultPoller(String statement) {
private void poll(TestCaseContext testCaseCtx, TestFileContext ctx, Map<String, Object> variableCtx,
String statement, boolean isDmlRecoveryTest, ProcessBuilder pb, CompilationUnit cUnit,
MutableInt queryCount, List<TestFileContext> expectedResultFileCtxs, File testFile, String actualPath,
String newType, BitSet expectedWarnings, IPollTask pollTask) throws Exception {
String newType, IPollTask pollTask) throws Exception {
// polltimeoutsecs=nnn, polldelaysecs=nnn
int timeoutSecs = getTimeoutSecs(statement);
int retryDelaySecs = getRetryDelaySecs(statement);
@@ -1682,7 +1682,7 @@ private void poll(TestCaseContext testCaseCtx, TestFileContext ctx, Map<String,
try {
startSemaphore.release();
pollTask.execute(testCaseCtx, ctx, variableCtx, statement, isDmlRecoveryTest, pb, cUnit,
queryCount, expectedResultFileCtxs, testFile, actualPath, expectedWarnings);
queryCount, expectedResultFileCtxs, testFile, actualPath);
} finally {
endSemaphore.release();
}
@@ -2092,13 +2092,13 @@ public void executeTest(String actualPath, TestCaseContext testCaseCtx, ProcessB
public void executeTest(String actualPath, TestCaseContext testCaseCtx, ProcessBuilder pb,
boolean isDmlRecoveryTest, TestGroup failedGroup, TestGroup passedGroup) throws Exception {
MutableInt queryCount = new MutableInt(0);
int numOfErrors = 0;
testCaseCtx.numOfErrors = 0;
int numOfFiles = 0;
List<CompilationUnit> cUnits = testCaseCtx.getTestCase().getCompilationUnit();
for (CompilationUnit cUnit : cUnits) {
List<String> expectedErrors = cUnit.getExpectedError();
BitSet expectedWarnings = new BitSet(cUnit.getExpectedWarn().size());
expectedWarnings.set(0, cUnit.getExpectedWarn().size());
testCaseCtx.expectedErrors = cUnit.getExpectedError();
testCaseCtx.expectedWarnings = new BitSet(cUnit.getExpectedWarn().size());
testCaseCtx.expectedWarnings.set(0, cUnit.getExpectedWarn().size());
LOGGER.info(
"Starting [TEST]: " + testCaseCtx.getTestCase().getFilePath() + "/" + cUnit.getName() + " ... ");
Map<String, Object> variableCtx = new HashMap<>();
@@ -2120,7 +2120,7 @@ public void executeTest(String actualPath, TestCaseContext testCaseCtx, ProcessB
boolean loopCmd = testFile.getName().endsWith(".loop.cmd");
if (!testFile.getName().startsWith(DIAGNOSE)) {
executeTestFile(testCaseCtx, ctx, variableCtx, statement, isDmlRecoveryTest, pb, cUnit,
queryCount, expectedResultFileCtxs, testFile, actualPath, expectedWarnings);
queryCount, expectedResultFileCtxs, testFile, actualPath);
}
if (loopCmd) {
// this was a loop file and we have exited the loop; reset the loop iteration
@@ -2138,9 +2138,9 @@ public void executeTest(String actualPath, TestCaseContext testCaseCtx, ProcessB
}
loopIteration++;
} catch (Exception e) {
numOfErrors++;
boolean unexpected = isUnExpected(e, expectedErrors, numOfErrors, queryCount,
testCaseCtx.isSourceLocationExpected(cUnit));
testCaseCtx.numOfErrors++;
boolean unexpected = isUnExpected(e, testCaseCtx.expectedErrors, testCaseCtx.numOfErrors,
queryCount, testCaseCtx.isSourceLocationExpected(cUnit));
if (unexpected) {
LOGGER.error("testFile {} raised an unexpected exception", testFile, e);
if (failedGroup != null) {
@@ -2152,12 +2152,12 @@ public void executeTest(String actualPath, TestCaseContext testCaseCtx, ProcessB
}
}
if (numOfFiles == testFileCtxs.size()) {
if (numOfErrors < cUnit.getExpectedError().size()) {
if (testCaseCtx.numOfErrors < cUnit.getExpectedError().size()) {
LOGGER.error("Test {} failed to raise (an) expected exception(s)", cUnit.getName());
throw new Exception(
"Test \"" + cUnit.getName() + "\" FAILED; expected exception was not thrown...");
}
ensureWarnings(expectedWarnings, cUnit);
ensureWarnings(testCaseCtx.expectedWarnings, cUnit);
LOGGER.info(
"[TEST]: " + testCaseCtx.getTestCase().getFilePath() + "/" + cUnit.getName() + " PASSED ");
if (passedGroup != null) {
@@ -2416,7 +2416,7 @@ protected void fail(boolean runDiagnostics, TestCaseContext testCaseCtx, Compila
final File file = ctx.getFile();
final String statement = readTestFile(file);
executeTestFile(testCaseCtx, ctx, variableCtx, statement, false, pb, cUnit, new MutableInt(-1),
Collections.emptyList(), file, null, new BitSet());
Collections.emptyList(), file, null);
}
}
} catch (Exception diagnosticFailure) {
@@ -2794,11 +2794,11 @@ private URI getQueryServiceUri(String extension) throws URISyntaxException {
}

protected void validateWarning(ExtractedResult result, TestCaseContext testCaseCtx, CompilationUnit cUnit,
File testFile, BitSet expectedWarnings) throws Exception {
File testFile) throws Exception {
if (testCaseCtx.getTestCase().isCheckWarnings()) {
boolean expectedSourceLoc = testCaseCtx.isSourceLocationExpected(cUnit);
validateWarnings(result.getWarnings(), cUnit.getExpectedWarn(), expectedWarnings, expectedSourceLoc,
testFile);
validateWarnings(result.getWarnings(), cUnit.getExpectedWarn(), testCaseCtx.expectedWarnings,
expectedSourceLoc, testFile);
}
}

@@ -30,7 +30,6 @@
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.BitSet;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
@@ -250,8 +249,8 @@ static class AwsTestExecutor extends TestExecutor {

public void executeTestFile(TestCaseContext testCaseCtx, TestFileContext ctx, Map<String, Object> variableCtx,
String statement, boolean isDmlRecoveryTest, ProcessBuilder pb, TestCase.CompilationUnit cUnit,
MutableInt queryCount, List<TestFileContext> expectedResultFileCtxs, File testFile, String actualPath,
BitSet expectedWarnings) throws Exception {
MutableInt queryCount, List<TestFileContext> expectedResultFileCtxs, File testFile, String actualPath)
throws Exception {
String[] lines;
switch (ctx.getType()) {
case "container":
@@ -267,7 +266,7 @@ public void executeTestFile(TestCaseContext testCaseCtx, TestFileContext ctx, Ma
break;
default:
super.executeTestFile(testCaseCtx, ctx, variableCtx, statement, isDmlRecoveryTest, pb, cUnit,
queryCount, expectedResultFileCtxs, testFile, actualPath, expectedWarnings);
queryCount, expectedResultFileCtxs, testFile, actualPath);
}
}
}
@@ -31,7 +31,6 @@
import java.nio.file.Paths;
import java.time.OffsetDateTime;
import java.time.temporal.ChronoUnit;
import java.util.BitSet;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
@@ -510,8 +509,8 @@ static class AzureTestExecutor extends TestExecutor {

public void executeTestFile(TestCaseContext testCaseCtx, TestFileContext ctx, Map<String, Object> variableCtx,
String statement, boolean isDmlRecoveryTest, ProcessBuilder pb, TestCase.CompilationUnit cUnit,
MutableInt queryCount, List<TestFileContext> expectedResultFileCtxs, File testFile, String actualPath,
BitSet expectedWarnings) throws Exception {
MutableInt queryCount, List<TestFileContext> expectedResultFileCtxs, File testFile, String actualPath)
throws Exception {
String[] lines;
switch (ctx.getType()) {
case "container":
@@ -527,7 +526,7 @@ public void executeTestFile(TestCaseContext testCaseCtx, TestFileContext ctx, Ma
break;
default:
super.executeTestFile(testCaseCtx, ctx, variableCtx, statement, isDmlRecoveryTest, pb, cUnit,
queryCount, expectedResultFileCtxs, testFile, actualPath, expectedWarnings);
queryCount, expectedResultFileCtxs, testFile, actualPath);
}
}
}

0 comments on commit 803484b

Please sign in to comment.