use of org.apache.commons.lang3.mutable.MutableInt in project asterixdb by apache.
the class TestExecutor method executeTest.
public void executeTest(String actualPath, TestCaseContext testCaseCtx, ProcessBuilder pb, boolean isDmlRecoveryTest, TestGroup failedGroup) throws Exception {
MutableInt queryCount = new MutableInt(0);
int numOfErrors = 0;
int numOfFiles = 0;
List<CompilationUnit> cUnits = testCaseCtx.getTestCase().getCompilationUnit();
for (CompilationUnit cUnit : cUnits) {
List<String> expectedErrors = cUnit.getExpectedError();
LOGGER.info("Starting [TEST]: " + testCaseCtx.getTestCase().getFilePath() + "/" + cUnit.getName() + " ... ");
Map<String, Object> variableCtx = new HashMap<>();
List<TestFileContext> testFileCtxs = testCaseCtx.getTestFiles(cUnit);
List<TestFileContext> expectedResultFileCtxs = testCaseCtx.getExpectedResultFiles(cUnit);
for (TestFileContext ctx : testFileCtxs) {
numOfFiles++;
final File testFile = ctx.getFile();
final String statement = readTestFile(testFile);
try {
executeTestFile(testCaseCtx, ctx, variableCtx, statement, isDmlRecoveryTest, pb, cUnit, queryCount, expectedResultFileCtxs, testFile, actualPath);
} catch (Exception e) {
System.err.println("testFile " + testFile.toString() + " raised an exception: " + e);
numOfErrors++;
if (isUnExpected(e, expectedErrors, numOfErrors, queryCount)) {
e.printStackTrace();
System.err.println("...Unexpected!");
if (failedGroup != null) {
failedGroup.getTestCase().add(testCaseCtx.getTestCase());
}
throw new Exception("Test \"" + testFile + "\" FAILED!", e);
}
} finally {
if (numOfFiles == testFileCtxs.size()) {
if (numOfErrors < cUnit.getExpectedError().size()) {
System.err.println("...Unexpected!");
Exception e = new Exception("Test \"" + cUnit.getName() + "\" FAILED!\nExpected error was not thrown...");
System.err.println(e);
throw e;
}
LOGGER.info("[TEST]: " + testCaseCtx.getTestCase().getFilePath() + "/" + cUnit.getName() + " PASSED ");
}
}
}
}
}
use of org.apache.commons.lang3.mutable.MutableInt in project asterixdb by apache.
the class ExtractCommonOperatorsRule method computeMaterilizationFlags.
private boolean[] computeMaterilizationFlags(List<Mutable<ILogicalOperator>> group) {
for (Mutable<ILogicalOperator> root : roots) {
computeClusters(null, root, new MutableInt(++lastUsedClusterId));
}
boolean[] materializationFlags = new boolean[group.size()];
boolean worthMaterialization = worthMaterialization(group.get(0));
boolean requiresMaterialization;
// get clusterIds for each candidate in the group
List<Integer> groupClusterIds = new ArrayList<Integer>(group.size());
for (int i = 0; i < group.size(); i++) {
groupClusterIds.add(clusterMap.get(group.get(i)).getValue());
}
for (int i = group.size() - 1; i >= 0; i--) {
requiresMaterialization = requiresMaterialization(groupClusterIds, i);
if (requiresMaterialization && !worthMaterialization) {
group.remove(i);
groupClusterIds.remove(i);
}
materializationFlags[i] = requiresMaterialization;
}
if (group.size() < 2) {
group.clear();
}
// if does not worth materialization, the flags for the remaining candidates should be false
return worthMaterialization ? materializationFlags : new boolean[group.size()];
}
use of org.apache.commons.lang3.mutable.MutableInt in project asterixdb by apache.
the class ExtractCommonOperatorsRule method computeClusters.
private void computeClusters(Mutable<ILogicalOperator> parentRef, Mutable<ILogicalOperator> opRef, MutableInt currentClusterId) {
// only replicate or split operator has multiple outputs
int outputIndex = 0;
if (opRef.getValue().getOperatorTag() == LogicalOperatorTag.REPLICATE || opRef.getValue().getOperatorTag() == LogicalOperatorTag.SPLIT) {
ReplicateOperator rop = (ReplicateOperator) opRef.getValue();
List<Mutable<ILogicalOperator>> outputs = rop.getOutputs();
for (outputIndex = 0; outputIndex < outputs.size(); outputIndex++) {
if (outputs.get(outputIndex).equals(parentRef)) {
break;
}
}
}
AbstractLogicalOperator aop = (AbstractLogicalOperator) opRef.getValue();
Pair<int[], int[]> labels = aop.getPhysicalOperator().getInputOutputDependencyLabels(opRef.getValue());
List<Mutable<ILogicalOperator>> inputs = opRef.getValue().getInputs();
for (int i = 0; i < inputs.size(); i++) {
Mutable<ILogicalOperator> inputRef = inputs.get(i);
if (labels.second[outputIndex] == 1 && labels.first[i] == 0) {
// 1 -> 0
if (labels.second.length == 1) {
clusterMap.put(opRef, currentClusterId);
// start a new cluster
MutableInt newClusterId = new MutableInt(++lastUsedClusterId);
computeClusters(opRef, inputRef, newClusterId);
BitSet waitForList = clusterWaitForMap.get(currentClusterId.getValue());
if (waitForList == null) {
waitForList = new BitSet();
clusterWaitForMap.put(currentClusterId.getValue(), waitForList);
}
waitForList.set(newClusterId.getValue());
}
} else {
// 0 -> 0 and 1 -> 1
MutableInt prevClusterId = clusterMap.get(opRef);
if (prevClusterId == null || prevClusterId.getValue().equals(currentClusterId.getValue())) {
clusterMap.put(opRef, currentClusterId);
computeClusters(opRef, inputRef, currentClusterId);
} else {
// merge prevClusterId and currentClusterId: update all the map entries that has currentClusterId to prevClusterId
for (BitSet bs : clusterWaitForMap.values()) {
if (bs.get(currentClusterId.getValue())) {
bs.clear(currentClusterId.getValue());
bs.set(prevClusterId.getValue());
}
}
clusterWaitForMap.remove(currentClusterId.getValue());
currentClusterId.setValue(prevClusterId.getValue());
}
}
}
}
use of org.apache.commons.lang3.mutable.MutableInt in project sling by apache.
the class PollingTest method testCallTimeout.
@Test
public void testCallTimeout() throws Exception {
final MutableInt callCount = new MutableInt(0);
Polling p = new Polling() {
@Override
public Boolean call() throws Exception {
callCount.increment();
return false;
}
};
try {
p.poll(100, 10);
} catch (TimeoutException e) {
assertTrue("Expected to execute call() at least 4 times, got instead only " + callCount.intValue() + " calls", callCount.intValue() > 5);
return;
}
fail("Did not reach timeout");
}
use of org.apache.commons.lang3.mutable.MutableInt in project sling by apache.
the class PollingTest method testNegativeTimeout.
@Test
public void testNegativeTimeout() throws Exception {
final MutableInt callCount = new MutableInt(0);
Polling p = new Polling() {
@Override
public Boolean call() throws Exception {
callCount.increment();
return true;
}
};
p.poll(-1, 10);
assertEquals(1, callCount.intValue());
}
Aggregations