public boolean maybeCorrupt()

in harry-core/src/harry/corruptor/QueryResponseCorruptor.java [57:96]


        public boolean maybeCorrupt(Query query, SystemUnderTest sut)
        {
            List<ResultSetRow> result = new ArrayList<>();
            CompiledStatement statement = query.toSelectStatement();
            Object[][] before = sut.execute(statement.cql(), SystemUnderTest.ConsistencyLevel.ALL, statement.bindings());
            for (Object[] obj : before)
                result.add(SelectHelper.resultSetToRow(schema, clock, obj));

            // TODO: technically, we can do this just depends on corruption strategy
            // we just need to corrupt results of the current query.
            if (result.isEmpty())
                return false;

            for (ResultSetRow row : result)
            {
                if (rowCorruptor.maybeCorrupt(row, sut))
                {
                    Object[][] after = sut.execute(statement.cql(), SystemUnderTest.ConsistencyLevel.ALL, statement.bindings());
                    boolean mismatch = false;
                    for (int i = 0; i < before.length && i < after.length; i++)
                    {
                        if (!Arrays.equals(before[i], after[i]))
                        {
                            logger.info("Corrupted: \nBefore: {}\n" +
                                        "After:  {}\n",
                                        Arrays.toString(before[i]),
                                        Arrays.toString(after[i]));
                            mismatch = true;
                        }
                    }
                    assert mismatch || before.length != after.length : String.format("Could not corrupt.\n" +
                                                                                     "Before\n%s\n" +
                                                                                     "After\n%s\nkma",
                                                                                     toString(before),
                                                                                     toString(after));
                    return true;
                }
            }
            return false;
        }