From 0a4b997337aafcc81396d27ac5de2a682283152f Mon Sep 17 00:00:00 2001 From: Ekaterina Dimitrova Date: Thu, 11 Mar 2021 16:02:42 -0500 Subject: [PATCH] Fix testPartitionDeletionRangeDeletionTie authored by Ekaterina Dimitrova based on solution provided by Benjamin Lerer; reviewed by Jacek Lewandowski, Benjamin Lerer and Berenguer Blasi for CASSANDRA-16512 --- .../db/SinglePartitionSliceCommandTest.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/test/unit/org/apache/cassandra/db/SinglePartitionSliceCommandTest.java b/test/unit/org/apache/cassandra/db/SinglePartitionSliceCommandTest.java index 102eb9037c..9572f28f00 100644 --- a/test/unit/org/apache/cassandra/db/SinglePartitionSliceCommandTest.java +++ b/test/unit/org/apache/cassandra/db/SinglePartitionSliceCommandTest.java @@ -344,6 +344,11 @@ public class SinglePartitionSliceCommandTest { cfs.truncateBlocking(); + // timestamp and USING TIMESTAMP have different values to ensure the correct timestamp (the one specified in the + // query) is the one being picked up. For safety reason we want to be able to ensure that further to its main goal + // the test can also detect wrongful change of the code. The current timestamp retrieved from the ClientState is + // ignored but nowInSeconds is retrieved from it and used for the DeletionTime. It shows the difference between the + // time at which the record was marked for deletion and the time at which it truly happened. final long timestamp = FBUtilities.timestampMicros(); final int nowInSec = FBUtilities.nowInSeconds(); @@ -405,10 +410,24 @@ public class SinglePartitionSliceCommandTest BiFunction> tester = (flush, multiSSTable) -> { cfs.truncateBlocking(); - QueryProcessor.executeOnceInternal("DELETE FROM ks.partition_range_deletion USING TIMESTAMP 10 WHERE k=1"); + + // timestamp and USING TIMESTAMP have different values to ensure the correct timestamp (the one specified in the + // query) is the one being picked up. For safety reason we want to be able to ensure that further to its main goal + // the test can also detect wrongful change of the code. The current timestamp retrieved from the ClientState is + // ignored but nowInSeconds is retrieved from it and used for the DeletionTime. It shows the difference between the + // time at which the record was marked for deletion and the time at which it truly happened. + + final long timestamp = FBUtilities.timestampMicros(); + final int nowInSec = FBUtilities.nowInSeconds(); + + QueryProcessor.executeOnceInternalWithNowAndTimestamp(nowInSec, + timestamp, + "DELETE FROM ks.partition_range_deletion USING TIMESTAMP 10 WHERE k=1"); if (flush && multiSSTable) cfs.forceBlockingFlush(); - QueryProcessor.executeOnceInternal("DELETE FROM ks.partition_range_deletion USING TIMESTAMP 10 WHERE k=1 and c1=1"); + QueryProcessor.executeOnceInternalWithNowAndTimestamp(nowInSec, + timestamp, + "DELETE FROM ks.partition_range_deletion USING TIMESTAMP 10 WHERE k=1 and c1=1"); if (flush) cfs.forceBlockingFlush();