in harry-core/src/harry/model/QuiescentChecker.java [100:201]
public static void validate(SchemaSpec schema, Set<ColumnSpec<?>> selection, PartitionState partitionState, List<ResultSetRow> actualRows, Query query)
{
boolean isWildcardQuery = selection == null;
if (isWildcardQuery)
selection = new HashSet<>(schema.allColumns);
Iterator<ResultSetRow> actual = actualRows.iterator();
Collection<Reconciler.RowState> expectedRows = partitionState.rows(query.reverse);
Iterator<Reconciler.RowState> expected = expectedRows.iterator();
// It is possible that we only get a single row in response, and it is equal to static row
if (partitionState.isEmpty() && partitionState.staticRow() != null && actual.hasNext())
{
ResultSetRow actualRowState = actual.next();
if (actualRowState.cd != UNSET_DESCR && actualRowState.cd != partitionState.staticRow().cd)
throw new ValidationException(partitionState.toString(schema),
toString(actualRows),
"Found a row while model predicts statics only:" +
"\nExpected: %s" +
"\nActual: %s" +
"\nQuery: %s",
partitionState.staticRow().cd,
actualRowState, query.toSelectStatement());
for (int i = 0; i < actualRowState.vds.length; i++)
{
if (actualRowState.vds[i] != NIL_DESCR || actualRowState.lts[i] != NO_TIMESTAMP)
throw new ValidationException(partitionState.toString(schema),
toString(actualRows),
"Found a row while model predicts statics only:" +
"\nActual: %s" +
"\nQuery: %s",
actualRowState, query.toSelectStatement());
}
assertStaticRow(partitionState, actualRows,
adjustForSelection(partitionState.staticRow(), schema, selection, true),
actualRowState, query, schema, isWildcardQuery);
}
while (actual.hasNext() && expected.hasNext())
{
ResultSetRow actualRowState = actual.next();
Reconciler.RowState originalExpectedRowState = expected.next();
Reconciler.RowState expectedRowState = adjustForSelection(originalExpectedRowState, schema, selection, false);
// TODO: this is not necessarily true. It can also be that ordering is incorrect.
if (actualRowState.cd != UNSET_DESCR && actualRowState.cd != expectedRowState.cd)
throw new ValidationException(partitionState.toString(schema),
toString(actualRows),
"Found a row in the model that is not present in the resultset:" +
"\nExpected: %s" +
"\nActual: %s" +
"\nQuery: %s",
expectedRowState.toString(schema),
actualRowState, query.toSelectStatement());
if (!Arrays.equals(actualRowState.vds, expectedRowState.vds))
throw new ValidationException(partitionState.toString(schema),
toString(actualRows),
"Returned row state doesn't match the one predicted by the model:" +
"\nExpected: %s (%s)" +
"\nActual: %s (%s)." +
"\nQuery: %s",
descriptorsToString(expectedRowState.vds), expectedRowState.toString(schema),
descriptorsToString(actualRowState.vds), actualRowState,
query.toSelectStatement());
// Wildcard queries do not include timestamps
if (!isWildcardQuery && !Arrays.equals(actualRowState.lts, expectedRowState.lts))
throw new ValidationException(partitionState.toString(schema),
toString(actualRows),
"Timestamps in the row state don't match ones predicted by the model:" +
"\nExpected: %s (%s)" +
"\nActual: %s (%s)." +
"\nQuery: %s" +
"\nMax started: %d, Max finished: %d, %d reordered: %s",
Arrays.toString(expectedRowState.lts), expectedRowState.toString(schema),
Arrays.toString(actualRowState.lts), actualRowState,
query.toSelectStatement());
if (partitionState.staticRow() != null || actualRowState.sds != null || actualRowState.slts != null)
{
Reconciler.RowState expectedStaticRowState = adjustForSelection(partitionState.staticRow(), schema, selection, true);
assertStaticRow(partitionState, actualRows, expectedStaticRowState, actualRowState, query, schema, isWildcardQuery);
}
}
if (actual.hasNext() || expected.hasNext())
{
throw new ValidationException(partitionState.toString(schema),
toString(actualRows),
"Expected results to have the same number of results, but %s result iterator has more results." +
"\nExpected: %s" +
"\nActual: %s" +
"\nQuery: %s",
actual.hasNext() ? "actual" : "expected",
expectedRows,
actualRows,
query.toSelectStatement());
}
}