From 599294c919df10a4aea592d78364af565d8ff1ed Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Mon, 8 Nov 2021 11:52:54 -0600 Subject: [PATCH] Replace System.currentTimeMillis with Clock.Global.currentTimeMillis Patch by brandonwilliams; reviewed by bereng for CASSANDRA-17123 --- src/java/org/apache/cassandra/cql3/Lists.java | 2 +- .../org/apache/cassandra/hints/HintsBuffer.java | 2 +- .../cassandra/io/sstable/format/SSTableReader.java | 2 +- .../cassandra/concurrent/LongOpOrderTest.java | 7 ++++--- .../org/apache/cassandra/utils/LongBTreeTest.java | 3 ++- .../cassandra/distributed/action/GossipHelper.java | 5 +++-- .../distributed/test/IncRepairAdminTest.java | 3 ++- .../cassandra/distributed/test/ReadRepairTest.java | 7 ++++--- .../distributed/test/RepairDigestTrackingTest.java | 3 ++- .../ring/CommunicationDuringDecommissionTest.java | 5 +++-- .../org/apache/cassandra/cql3/CachingBench.java | 13 +++++++------ .../apache/cassandra/cql3/GcCompactionBench.java | 13 +++++++------ .../cassandra/db/commitlog/CommitLogStressTest.java | 7 ++++--- .../db/compaction/LongCompactionsTest.java | 3 ++- .../LongLeveledCompactionStrategyCQLTest.java | 6 ++++-- .../AbstractReplicationAwareTokenAllocatorTest.java | 6 ++++-- .../NoReplicationTokenAllocatorTest.java | 6 ++++-- .../cassandra/hints/HintsWriteThenReadTest.java | 4 +++- .../StreamingTombstoneHistogramBuilderBench.java | 4 +++- .../cassandra/CassandraXMLJUnitResultFormatter.java | 5 +++-- test/unit/org/apache/cassandra/SchemaLoader.java | 4 +++- .../cassandra/batchlog/BatchlogManagerTest.java | 13 +++++++------ .../apache/cassandra/cache/AutoSavingCacheTest.java | 4 +++- .../apache/cassandra/cache/CacheProviderTest.java | 7 ++++--- .../apache/cassandra/cql3/CQL3TypeLiteralTest.java | 3 ++- test/unit/org/apache/cassandra/cql3/CQLTester.java | 9 +++++---- 26 files changed, 88 insertions(+), 58 deletions(-) diff --git a/src/java/org/apache/cassandra/cql3/Lists.java b/src/java/org/apache/cassandra/cql3/Lists.java index ece822dd12..a2c26084f2 100644 --- a/src/java/org/apache/cassandra/cql3/Lists.java +++ b/src/java/org/apache/cassandra/cql3/Lists.java @@ -360,7 +360,7 @@ public abstract class Lists else { // in addition to being at the same millisecond, we handle the unexpected case of the millis parameter - // being in the past. That could happen if the System.currentTimeMillis() not operating montonically + // being in the past. That could happen if the Global.currentTimeMillis() not operating montonically // or if one thread is just a really big loser in the compareAndSet game of life. long millisToUse = millis <= current.millis ? millis : current.millis; diff --git a/src/java/org/apache/cassandra/hints/HintsBuffer.java b/src/java/org/apache/cassandra/hints/HintsBuffer.java index e86ce26f45..d6dcfb3fae 100644 --- a/src/java/org/apache/cassandra/hints/HintsBuffer.java +++ b/src/java/org/apache/cassandra/hints/HintsBuffer.java @@ -148,7 +148,7 @@ final class HintsBuffer /** * Retrieve the time of the earliest hint in the buffer for a specific node * @param hostId UUID of the node - * @return timestamp for the earliest hint in the buffer, or {@link System#currentTimeMillis()} + * @return timestamp for the earliest hint in the buffer, or {@link Global#currentTimeMillis()} */ long getEarliestHintTime(UUID hostId) { diff --git a/src/java/org/apache/cassandra/io/sstable/format/SSTableReader.java b/src/java/org/apache/cassandra/io/sstable/format/SSTableReader.java index 771974d1f3..804a59ab63 100644 --- a/src/java/org/apache/cassandra/io/sstable/format/SSTableReader.java +++ b/src/java/org/apache/cassandra/io/sstable/format/SSTableReader.java @@ -184,7 +184,7 @@ public abstract class SSTableReader extends SSTable implements SelfRefCounted until) break; if (now > lastReport + REPORT_INTERVAL) diff --git a/test/burn/org/apache/cassandra/utils/LongBTreeTest.java b/test/burn/org/apache/cassandra/utils/LongBTreeTest.java index d21f7b34ac..362b7974ed 100644 --- a/test/burn/org/apache/cassandra/utils/LongBTreeTest.java +++ b/test/burn/org/apache/cassandra/utils/LongBTreeTest.java @@ -52,6 +52,7 @@ import static com.google.common.collect.Iterables.transform; import static java.util.Comparator.naturalOrder; import static java.util.Comparator.reverseOrder; import static org.apache.cassandra.utils.btree.BTree.iterable; +import static org.apache.cassandra.utils.Clock.Global.currentTimeMillis; import static org.junit.Assert.assertTrue; public class LongBTreeTest @@ -1073,7 +1074,7 @@ public class LongBTreeTest { args = Arrays.copyOf(args, args.length + 1); System.arraycopy(args, 0, args, 1, args.length - 1); - args[0] = System.currentTimeMillis(); + args[0] = currentTimeMillis(); System.out.printf("%tT: " + formatstr + "\n", args); } } diff --git a/test/distributed/org/apache/cassandra/distributed/action/GossipHelper.java b/test/distributed/org/apache/cassandra/distributed/action/GossipHelper.java index dc4f89cef8..431583492d 100644 --- a/test/distributed/org/apache/cassandra/distributed/action/GossipHelper.java +++ b/test/distributed/org/apache/cassandra/distributed/action/GossipHelper.java @@ -50,6 +50,7 @@ import org.apache.cassandra.service.StorageService; import org.apache.cassandra.utils.FBUtilities; import static org.apache.cassandra.distributed.impl.DistributedTestSnitch.toCassandraInetAddressAndPort; +import static org.apache.cassandra.utils.Clock.Global.currentTimeMillis; public class GossipHelper { @@ -329,14 +330,14 @@ public class GossipHelper public static VersionedApplicationState statusLeft(IInvokableInstance instance) { return versionedToken(instance, ApplicationState.STATUS, (partitioner, tokens) -> { - return new VersionedValue.VersionedValueFactory(partitioner).left(tokens, System.currentTimeMillis() + Gossiper.aVeryLongTime); + return new VersionedValue.VersionedValueFactory(partitioner).left(tokens, currentTimeMillis() + Gossiper.aVeryLongTime); }); } public static VersionedApplicationState statusWithPortLeft(IInvokableInstance instance) { return versionedToken(instance, ApplicationState.STATUS_WITH_PORT, (partitioner, tokens) -> { - return new VersionedValue.VersionedValueFactory(partitioner).left(tokens, System.currentTimeMillis() + Gossiper.aVeryLongTime); + return new VersionedValue.VersionedValueFactory(partitioner).left(tokens, currentTimeMillis() + Gossiper.aVeryLongTime); }); } diff --git a/test/distributed/org/apache/cassandra/distributed/test/IncRepairAdminTest.java b/test/distributed/org/apache/cassandra/distributed/test/IncRepairAdminTest.java index 236c8193b0..c807087a16 100644 --- a/test/distributed/org/apache/cassandra/distributed/test/IncRepairAdminTest.java +++ b/test/distributed/org/apache/cassandra/distributed/test/IncRepairAdminTest.java @@ -46,6 +46,7 @@ import org.apache.cassandra.utils.UUIDGen; import static org.apache.cassandra.distributed.api.Feature.GOSSIP; import static org.apache.cassandra.distributed.api.Feature.NETWORK; import static org.apache.cassandra.repair.consistent.ConsistentSession.State.REPAIRING; +import static org.apache.cassandra.utils.Clock.Global.currentTimeMillis; import static org.junit.Assert.assertTrue; public class IncRepairAdminTest extends TestBaseImpl @@ -153,7 +154,7 @@ public class IncRepairAdminTest extends TestBaseImpl Lists.newArrayList(cfs), Sets.newHashSet(range), true, - System.currentTimeMillis(), + currentTimeMillis(), true, PreviewKind.NONE); LocalSessionAccessor.prepareUnsafe(sessionId, diff --git a/test/distributed/org/apache/cassandra/distributed/test/ReadRepairTest.java b/test/distributed/org/apache/cassandra/distributed/test/ReadRepairTest.java index 2718609493..c5e3a71c9c 100644 --- a/test/distributed/org/apache/cassandra/distributed/test/ReadRepairTest.java +++ b/test/distributed/org/apache/cassandra/distributed/test/ReadRepairTest.java @@ -68,6 +68,7 @@ import static org.apache.cassandra.distributed.shared.AssertUtils.row; import static org.apache.cassandra.net.Verb.READ_REPAIR_REQ; import static org.apache.cassandra.net.Verb.READ_REPAIR_RSP; import static org.apache.cassandra.net.Verb.READ_REQ; +import static org.apache.cassandra.utils.Clock.Global.currentTimeMillis; import static org.apache.cassandra.utils.concurrent.Condition.newOneTimeCondition; import static org.junit.Assert.fail; @@ -132,7 +133,7 @@ public class ReadRepairTest extends TestBaseImpl cluster.get(2).executeInternal("INSERT INTO " + KEYSPACE + ".tbl (pk, ck, v) VALUES (1, 1, 1)"); assertRows(cluster.get(3).executeInternal("SELECT * FROM " + KEYSPACE + ".tbl WHERE pk = 1")); cluster.verbs(READ_REPAIR_RSP).to(1).drop(); - final long start = System.currentTimeMillis(); + final long start = currentTimeMillis(); try { cluster.coordinator(1).execute("SELECT * FROM " + KEYSPACE + ".tbl WHERE pk = 1", ConsistencyLevel.ALL); @@ -142,7 +143,7 @@ public class ReadRepairTest extends TestBaseImpl { // the containing exception class was loaded by another class loader. Comparing the message as a workaround to assert the exception Assert.assertTrue(ex.getClass().toString().contains("ReadTimeoutException")); - long actualTimeTaken = System.currentTimeMillis() - start; + long actualTimeTaken = currentTimeMillis() - start; long magicDelayAmount = 100L; // it might not be the best way to check if the time taken is around the timeout value. // Due to the delays, the actual time taken from client perspective is slighly more than the timeout value Assert.assertTrue(actualTimeTaken > reducedReadTimeout); @@ -506,4 +507,4 @@ public class ReadRepairTest extends TestBaseImpl return r.call(); } } -} \ No newline at end of file +} diff --git a/test/distributed/org/apache/cassandra/distributed/test/RepairDigestTrackingTest.java b/test/distributed/org/apache/cassandra/distributed/test/RepairDigestTrackingTest.java index e293dd51b4..f6da888cfa 100644 --- a/test/distributed/org/apache/cassandra/distributed/test/RepairDigestTrackingTest.java +++ b/test/distributed/org/apache/cassandra/distributed/test/RepairDigestTrackingTest.java @@ -67,6 +67,7 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArguments; import static org.apache.cassandra.distributed.api.Feature.GOSSIP; import static org.apache.cassandra.distributed.api.Feature.NETWORK; import static org.apache.cassandra.distributed.shared.AssertUtils.assertRows; +import static org.apache.cassandra.utils.Clock.Global.currentTimeMillis; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -544,7 +545,7 @@ public class RepairDigestTrackingTest extends TestBaseImpl SSTableReader sstable = sstables.next(); Descriptor descriptor = sstable.descriptor; descriptor.getMetadataSerializer() - .mutateRepairMetadata(descriptor, System.currentTimeMillis(), null, false); + .mutateRepairMetadata(descriptor, currentTimeMillis(), null, false); sstable.reloadSSTableMetadata(); } } catch (IOException e) { diff --git a/test/distributed/org/apache/cassandra/distributed/test/ring/CommunicationDuringDecommissionTest.java b/test/distributed/org/apache/cassandra/distributed/test/ring/CommunicationDuringDecommissionTest.java index 848318c95d..631ea9113a 100644 --- a/test/distributed/org/apache/cassandra/distributed/test/ring/CommunicationDuringDecommissionTest.java +++ b/test/distributed/org/apache/cassandra/distributed/test/ring/CommunicationDuringDecommissionTest.java @@ -33,6 +33,7 @@ import static org.apache.cassandra.distributed.action.GossipHelper.decommission; import static org.apache.cassandra.distributed.api.Feature.GOSSIP; import static org.apache.cassandra.distributed.api.Feature.NATIVE_PROTOCOL; import static org.apache.cassandra.distributed.api.Feature.NETWORK; +import static org.apache.cassandra.utils.Clock.Global.currentTimeMillis; public class CommunicationDuringDecommissionTest extends TestBaseImpl { @@ -53,10 +54,10 @@ public class CommunicationDuringDecommissionTest extends TestBaseImpl Map connectionAttempts = new HashMap<>(); - long deadline = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(10); + long deadline = currentTimeMillis() + TimeUnit.SECONDS.toMillis(10); // Wait 10 seconds and check if there are any new connection attempts to the decomissioned node - while (System.currentTimeMillis() <= deadline) + while (currentTimeMillis() <= deadline) { for (int i = 2; i <= cluster.size(); i++) { diff --git a/test/long/org/apache/cassandra/cql3/CachingBench.java b/test/long/org/apache/cassandra/cql3/CachingBench.java index 92b63b6bfd..11d90b7bfb 100644 --- a/test/long/org/apache/cassandra/cql3/CachingBench.java +++ b/test/long/org/apache/cassandra/cql3/CachingBench.java @@ -48,6 +48,7 @@ import org.apache.cassandra.io.sstable.format.SSTableReader; import org.apache.cassandra.io.util.FileUtils; import org.apache.cassandra.utils.FBUtilities; +import static org.apache.cassandra.utils.Clock.Global.currentTimeMillis; import static org.apache.cassandra.utils.Clock.Global.nanoTime; import static org.assertj.core.api.Assertions.assertThat; @@ -204,7 +205,7 @@ public class CachingBench extends CQLTester ColumnFamilyStore cfs = getCurrentColumnFamilyStore(); cfs.disableAutoCompaction(); - long onStartTime = System.currentTimeMillis(); + long onStartTime = currentTimeMillis(); ExecutorService es = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); List> tasks = new ArrayList<>(); for (int ti = 0; ti < 1; ++ti) @@ -228,7 +229,7 @@ public class CachingBench extends CQLTester task.get(); flush(); - long onEndTime = System.currentTimeMillis(); + long onEndTime = currentTimeMillis(); int startRowCount = countRows(cfs); int startTombCount = countTombstoneMarkers(cfs); int startRowDeletions = countRowDeletions(cfs); @@ -258,9 +259,9 @@ public class CachingBench extends CQLTester System.out.println(); String hashesBefore = getHashes(); - long startTime = System.currentTimeMillis(); + long startTime = currentTimeMillis(); CompactionManager.instance.performMaximal(cfs, true); - long endTime = System.currentTimeMillis(); + long endTime = currentTimeMillis(); int endRowCount = countRows(cfs); int endTombCount = countTombstoneMarkers(cfs); @@ -281,9 +282,9 @@ public class CachingBench extends CQLTester private String getHashes() throws Throwable { - long startTime = System.currentTimeMillis(); + long startTime = currentTimeMillis(); String hashes = Arrays.toString(getRows(execute(hashQuery))[0]); - long endTime = System.currentTimeMillis(); + long endTime = currentTimeMillis(); System.out.println(String.format("Hashes: %s, retrieved in %.3fs", hashes, (endTime - startTime) * 1e-3)); return hashes; } diff --git a/test/long/org/apache/cassandra/cql3/GcCompactionBench.java b/test/long/org/apache/cassandra/cql3/GcCompactionBench.java index 155335e6f5..c6f1bb6cb1 100644 --- a/test/long/org/apache/cassandra/cql3/GcCompactionBench.java +++ b/test/long/org/apache/cassandra/cql3/GcCompactionBench.java @@ -46,6 +46,7 @@ import org.apache.cassandra.io.sstable.format.SSTableReader; import org.apache.cassandra.schema.CompactionParams.TombstoneOption; import org.apache.cassandra.utils.FBUtilities; +import static org.apache.cassandra.utils.Clock.Global.currentTimeMillis; import static org.apache.cassandra.utils.Clock.Global.nanoTime; public class GcCompactionBench extends CQLTester @@ -202,7 +203,7 @@ public class GcCompactionBench extends CQLTester ColumnFamilyStore cfs = getCurrentColumnFamilyStore(); cfs.disableAutoCompaction(); - long onStartTime = System.currentTimeMillis(); + long onStartTime = currentTimeMillis(); ExecutorService es = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); List> tasks = new ArrayList<>(); for (int ti = 0; ti < 1; ++ti) @@ -226,7 +227,7 @@ public class GcCompactionBench extends CQLTester task.get(); flush(); - long onEndTime = System.currentTimeMillis(); + long onEndTime = currentTimeMillis(); int startRowCount = countRows(cfs); int startTombCount = countTombstoneMarkers(cfs); int startRowDeletions = countRowDeletions(cfs); @@ -237,9 +238,9 @@ public class GcCompactionBench extends CQLTester String hashesBefore = getHashes(); - long startTime = System.currentTimeMillis(); + long startTime = currentTimeMillis(); CompactionManager.instance.performGarbageCollection(cfs, tombstoneOption, 0); - long endTime = System.currentTimeMillis(); + long endTime = currentTimeMillis(); int endRowCount = countRows(cfs); int endTombCount = countTombstoneMarkers(cfs); @@ -266,9 +267,9 @@ public class GcCompactionBench extends CQLTester private String getHashes() throws Throwable { - long startTime = System.currentTimeMillis(); + long startTime = currentTimeMillis(); String hashes = Arrays.toString(getRows(execute(hashQuery))[0]); - long endTime = System.currentTimeMillis(); + long endTime = currentTimeMillis(); System.out.println(String.format("Hashes: %s, retrieved in %.3fs", hashes, (endTime - startTime) * 1e-3)); return hashes; } diff --git a/test/long/org/apache/cassandra/db/commitlog/CommitLogStressTest.java b/test/long/org/apache/cassandra/db/commitlog/CommitLogStressTest.java index 93faf252e1..493f33edf2 100644 --- a/test/long/org/apache/cassandra/db/commitlog/CommitLogStressTest.java +++ b/test/long/org/apache/cassandra/db/commitlog/CommitLogStressTest.java @@ -57,6 +57,7 @@ import org.apache.cassandra.schema.Schema; import org.apache.cassandra.security.EncryptionContext; import org.apache.cassandra.security.EncryptionContextGenerator; +import static org.apache.cassandra.utils.Clock.Global.currentTimeMillis; @Ignore public abstract class CommitLogStressTest @@ -309,7 +310,7 @@ public abstract class CommitLogStressTest t.start(); } - final long start = System.currentTimeMillis(); + final long start = currentTimeMillis(); Runnable printRunnable = new Runnable() { long lastUpdate = 0; @@ -327,11 +328,11 @@ public abstract class CommitLogStressTest temp += clt.counter.get(); sz += clt.dataSize; } - double time = (System.currentTimeMillis() - start) / 1000.0; + double time = (currentTimeMillis() - start) / 1000.0; double avg = (temp / time); System.out.println( String.format("second %d mem max %.0fmb allocated %.0fmb free %.0fmb mutations %d since start %d avg %.3f content %.1fmb ondisk %.1fmb transfer %.3fmb", - ((System.currentTimeMillis() - start) / 1000), + ((currentTimeMillis() - start) / 1000), mb(maxMemory), mb(allocatedMemory), mb(freeMemory), diff --git a/test/long/org/apache/cassandra/db/compaction/LongCompactionsTest.java b/test/long/org/apache/cassandra/db/compaction/LongCompactionsTest.java index 9b4fe73bf6..58ad585fcb 100644 --- a/test/long/org/apache/cassandra/db/compaction/LongCompactionsTest.java +++ b/test/long/org/apache/cassandra/db/compaction/LongCompactionsTest.java @@ -41,6 +41,7 @@ import org.apache.cassandra.schema.KeyspaceParams; import org.apache.cassandra.utils.ByteBufferUtil; import org.apache.cassandra.utils.FBUtilities; +import static org.apache.cassandra.utils.Clock.Global.currentTimeMillis; import static org.apache.cassandra.utils.Clock.Global.nanoTime; import static org.junit.Assert.assertEquals; @@ -125,7 +126,7 @@ public class LongCompactionsTest Thread.sleep(1000); long start = nanoTime(); - final int gcBefore = (int) (System.currentTimeMillis() / 1000) - Schema.instance.getTableMetadata(KEYSPACE1, "Standard1").params.gcGraceSeconds; + final int gcBefore = (int) (currentTimeMillis() / 1000) - Schema.instance.getTableMetadata(KEYSPACE1, "Standard1").params.gcGraceSeconds; try (LifecycleTransaction txn = store.getTracker().tryModify(sstables, OperationType.COMPACTION)) { assert txn != null : "Cannot markCompacting all sstables"; diff --git a/test/long/org/apache/cassandra/db/compaction/LongLeveledCompactionStrategyCQLTest.java b/test/long/org/apache/cassandra/db/compaction/LongLeveledCompactionStrategyCQLTest.java index 9bfa3808b8..c8a86e1099 100644 --- a/test/long/org/apache/cassandra/db/compaction/LongLeveledCompactionStrategyCQLTest.java +++ b/test/long/org/apache/cassandra/db/compaction/LongLeveledCompactionStrategyCQLTest.java @@ -35,6 +35,8 @@ import org.apache.cassandra.cql3.CQLTester; import org.apache.cassandra.service.StorageService; import org.apache.cassandra.utils.Hex; +import static org.apache.cassandra.utils.Clock.Global.currentTimeMillis; + public class LongLeveledCompactionStrategyCQLTest extends CQLTester { @@ -47,7 +49,7 @@ public class LongLeveledCompactionStrategyCQLTest extends CQLTester ExecutorService es = Executors.newSingleThreadExecutor(); DatabaseDescriptor.setConcurrentCompactors(8); AtomicBoolean stop = new AtomicBoolean(false); - long start = System.currentTimeMillis(); + long start = currentTimeMillis(); try { Random r = new Random(); @@ -75,7 +77,7 @@ public class LongLeveledCompactionStrategyCQLTest extends CQLTester } }); - while(System.currentTimeMillis() - start < TimeUnit.MILLISECONDS.convert(5, TimeUnit.MINUTES)) + while(currentTimeMillis() - start < TimeUnit.MILLISECONDS.convert(5, TimeUnit.MINUTES)) { StorageService.instance.getTokenMetadata().invalidateCachedRings(); Uninterruptibles.sleepUninterruptibly(r.nextInt(1000), TimeUnit.MILLISECONDS); diff --git a/test/long/org/apache/cassandra/dht/tokenallocator/AbstractReplicationAwareTokenAllocatorTest.java b/test/long/org/apache/cassandra/dht/tokenallocator/AbstractReplicationAwareTokenAllocatorTest.java index 420981d19d..26d454df96 100644 --- a/test/long/org/apache/cassandra/dht/tokenallocator/AbstractReplicationAwareTokenAllocatorTest.java +++ b/test/long/org/apache/cassandra/dht/tokenallocator/AbstractReplicationAwareTokenAllocatorTest.java @@ -31,6 +31,8 @@ import org.junit.Ignore; import org.apache.cassandra.dht.IPartitioner; import org.apache.cassandra.dht.Token; +import static org.apache.cassandra.utils.Clock.Global.currentTimeMillis; + /** * Base class for {@link Murmur3ReplicationAwareTokenAllocatorTest} and {@link RandomReplicationAwareTokenAllocatorTest}, * we need to separate classes to avoid timeous in case flaky tests need to be repeated, see CASSANDRA-12784. @@ -489,7 +491,7 @@ abstract class AbstractReplicationAwareTokenAllocatorTest extends TokenAllocator if (size < targetClusterSize) { System.out.format("Adding %d unit(s) using %s...", targetClusterSize - size, t.toString()); - long time = System.currentTimeMillis(); + long time = currentTimeMillis(); while (size < targetClusterSize) { int tokens = tc.tokenCount(perUnitCount, rand); @@ -500,7 +502,7 @@ abstract class AbstractReplicationAwareTokenAllocatorTest extends TokenAllocator if (verifyMetrics) updateSummary(t, su, st, false); } - System.out.format(" Done in %.3fs\n", (System.currentTimeMillis() - time) / 1000.0); + System.out.format(" Done in %.3fs\n", (currentTimeMillis() - time) / 1000.0); if (verifyMetrics) { updateSummary(t, su, st, true); diff --git a/test/long/org/apache/cassandra/dht/tokenallocator/NoReplicationTokenAllocatorTest.java b/test/long/org/apache/cassandra/dht/tokenallocator/NoReplicationTokenAllocatorTest.java index ee38a28d53..5e13519fcd 100644 --- a/test/long/org/apache/cassandra/dht/tokenallocator/NoReplicationTokenAllocatorTest.java +++ b/test/long/org/apache/cassandra/dht/tokenallocator/NoReplicationTokenAllocatorTest.java @@ -34,6 +34,8 @@ import org.apache.cassandra.dht.Murmur3Partitioner; import org.apache.cassandra.dht.RandomPartitioner; import org.apache.cassandra.dht.Token; +import static org.apache.cassandra.utils.Clock.Global.currentTimeMillis; + public class NoReplicationTokenAllocatorTest extends TokenAllocatorTestBase { @@ -149,7 +151,7 @@ public class NoReplicationTokenAllocatorTest extends TokenAllocatorTestBase if (size < targetClusterSize) { System.out.format("Adding %d unit(s) using %s...", targetClusterSize - size, t.toString()); - long time = System.currentTimeMillis(); + long time = currentTimeMillis(); while (size < targetClusterSize) { @@ -160,7 +162,7 @@ public class NoReplicationTokenAllocatorTest extends TokenAllocatorTestBase if (verifyMetrics) updateSummary(t, su, st, false); } - System.out.format(" Done in %.3fs\n", (System.currentTimeMillis() - time) / 1000.0); + System.out.format(" Done in %.3fs\n", (currentTimeMillis() - time) / 1000.0); if (verifyMetrics) { diff --git a/test/long/org/apache/cassandra/hints/HintsWriteThenReadTest.java b/test/long/org/apache/cassandra/hints/HintsWriteThenReadTest.java index 8b43c8e076..e6a6478c68 100644 --- a/test/long/org/apache/cassandra/hints/HintsWriteThenReadTest.java +++ b/test/long/org/apache/cassandra/hints/HintsWriteThenReadTest.java @@ -48,6 +48,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import static org.apache.cassandra.utils.Clock.Global.currentTimeMillis; + public class HintsWriteThenReadTest { private static final String KEYSPACE = "hints_write_then_read_test"; @@ -61,7 +63,7 @@ public class HintsWriteThenReadTest SchemaLoader.prepareServer(); SchemaLoader.createKeyspace(KEYSPACE, KeyspaceParams.simple(1), SchemaLoader.standardCFMD(KEYSPACE, TABLE)); - HintsDescriptor descriptor = new HintsDescriptor(UUID.randomUUID(), System.currentTimeMillis()); + HintsDescriptor descriptor = new HintsDescriptor(UUID.randomUUID(), currentTimeMillis()); File directory = new File(Files.createTempDirectory(null)); try diff --git a/test/microbench/org/apache/cassandra/test/microbench/StreamingTombstoneHistogramBuilderBench.java b/test/microbench/org/apache/cassandra/test/microbench/StreamingTombstoneHistogramBuilderBench.java index f3df8c1e50..0dd51f268e 100644 --- a/test/microbench/org/apache/cassandra/test/microbench/StreamingTombstoneHistogramBuilderBench.java +++ b/test/microbench/org/apache/cassandra/test/microbench/StreamingTombstoneHistogramBuilderBench.java @@ -28,6 +28,8 @@ import org.openjdk.jmh.profile.*; import org.openjdk.jmh.runner.*; import org.openjdk.jmh.runner.options.*; +import static org.apache.cassandra.utils.Clock.Global.currentTimeMillis; + @BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.MILLISECONDS) @Warmup(iterations = 3, time = 1, timeUnit = TimeUnit.SECONDS) @@ -45,7 +47,7 @@ public class StreamingTombstoneHistogramBuilderBench static { - final int now = (int) (System.currentTimeMillis() / 1000L); + final int now = (int) (currentTimeMillis() / 1000L); Random random = new Random(); for(int i = 0 ; i < 10000000; i++) { diff --git a/test/unit/org/apache/cassandra/CassandraXMLJUnitResultFormatter.java b/test/unit/org/apache/cassandra/CassandraXMLJUnitResultFormatter.java index da8e4077f3..df0ce7f327 100644 --- a/test/unit/org/apache/cassandra/CassandraXMLJUnitResultFormatter.java +++ b/test/unit/org/apache/cassandra/CassandraXMLJUnitResultFormatter.java @@ -50,6 +50,7 @@ import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Text; +import static org.apache.cassandra.utils.Clock.Global.currentTimeMillis; /** * Prints XML output of the test to a specified Writer. @@ -240,7 +241,7 @@ public class CassandraXMLJUnitResultFormatter implements JUnitResultFormatter, X * @param t the test. */ public void startTest(final Test t) { - testStarts.put(createDescription(t), System.currentTimeMillis()); + testStarts.put(createDescription(t), currentTimeMillis()); } private static String createDescription(final Test test) throws BuildException { @@ -284,7 +285,7 @@ public class CassandraXMLJUnitResultFormatter implements JUnitResultFormatter, X final Long l = testStarts.get(createDescription(test)); currentTest.setAttribute(ATTR_TIME, - "" + ((System.currentTimeMillis() - l) / ONE_SECOND)); + "" + ((currentTimeMillis() - l) / ONE_SECOND)); } /** diff --git a/test/unit/org/apache/cassandra/SchemaLoader.java b/test/unit/org/apache/cassandra/SchemaLoader.java index 62fcebf5f1..c5016970aa 100644 --- a/test/unit/org/apache/cassandra/SchemaLoader.java +++ b/test/unit/org/apache/cassandra/SchemaLoader.java @@ -50,6 +50,8 @@ import org.apache.cassandra.utils.FBUtilities; import org.junit.After; import org.junit.BeforeClass; +import static org.apache.cassandra.utils.Clock.Global.currentTimeMillis; + public class SchemaLoader { @BeforeClass @@ -82,7 +84,7 @@ public class SchemaLoader // skip shadow round and endpoint collision check in tests System.setProperty("cassandra.allow_unsafe_join", "true"); if (!Gossiper.instance.isEnabled()) - Gossiper.instance.start((int) (System.currentTimeMillis() / 1000)); + Gossiper.instance.start((int) (currentTimeMillis() / 1000)); } public static void schemaDefinition(String testName) throws ConfigurationException diff --git a/test/unit/org/apache/cassandra/batchlog/BatchlogManagerTest.java b/test/unit/org/apache/cassandra/batchlog/BatchlogManagerTest.java index b86b0d34df..b2420eafc6 100644 --- a/test/unit/org/apache/cassandra/batchlog/BatchlogManagerTest.java +++ b/test/unit/org/apache/cassandra/batchlog/BatchlogManagerTest.java @@ -55,6 +55,7 @@ import org.apache.cassandra.utils.UUIDGen; import static java.util.concurrent.TimeUnit.MILLISECONDS; import static org.apache.cassandra.cql3.QueryProcessor.executeInternal; +import static org.apache.cassandra.utils.Clock.Global.currentTimeMillis; import static org.junit.Assert.*; public class BatchlogManagerTest @@ -146,8 +147,8 @@ public class BatchlogManagerTest } long timestamp = i < 50 - ? (System.currentTimeMillis() - BatchlogManager.getBatchlogTimeout()) - : (System.currentTimeMillis() + BatchlogManager.getBatchlogTimeout()); + ? (currentTimeMillis() - BatchlogManager.getBatchlogTimeout()) + : (currentTimeMillis() + BatchlogManager.getBatchlogTimeout()); BatchlogManager.store(Batch.createLocal(UUIDGen.getTimeUUID(timestamp, i), timestamp * 1000, mutations)); } @@ -220,7 +221,7 @@ public class BatchlogManagerTest List mutations = Lists.newArrayList(mutation1, mutation2); // Make sure it's ready to be replayed, so adjust the timestamp. - long timestamp = System.currentTimeMillis() - BatchlogManager.getBatchlogTimeout(); + long timestamp = currentTimeMillis() - BatchlogManager.getBatchlogTimeout(); if (i == 500) SystemKeyspace.saveTruncationRecord(Keyspace.open(KEYSPACE1).getColumnFamilyStore(CF_STANDARD2), @@ -275,7 +276,7 @@ public class BatchlogManagerTest long initialAllBatches = BatchlogManager.instance.countAllBatches(); TableMetadata cfm = Keyspace.open(KEYSPACE1).getColumnFamilyStore(CF_STANDARD5).metadata(); - long timestamp = (System.currentTimeMillis() - DatabaseDescriptor.getWriteRpcTimeout(MILLISECONDS) * 2) * 1000; + long timestamp = (currentTimeMillis() - DatabaseDescriptor.getWriteRpcTimeout(MILLISECONDS) * 2) * 1000; UUID uuid = UUIDGen.getTimeUUID(); // Add a batch with 10 mutations @@ -307,7 +308,7 @@ public class BatchlogManagerTest long initialAllBatches = BatchlogManager.instance.countAllBatches(); TableMetadata cfm = Keyspace.open(KEYSPACE1).getColumnFamilyStore(CF_STANDARD5).metadata(); - long timestamp = (System.currentTimeMillis() - DatabaseDescriptor.getWriteRpcTimeout(MILLISECONDS) * 2) * 1000; + long timestamp = (currentTimeMillis() - DatabaseDescriptor.getWriteRpcTimeout(MILLISECONDS) * 2) * 1000; UUID uuid = UUIDGen.getTimeUUID(); // Add a batch with 10 mutations @@ -349,7 +350,7 @@ public class BatchlogManagerTest TableMetadata cfm = Keyspace.open(KEYSPACE1).getColumnFamilyStore(CF_STANDARD1).metadata(); - long timestamp = (System.currentTimeMillis() - DatabaseDescriptor.getWriteRpcTimeout(MILLISECONDS) * 2) * 1000; + long timestamp = (currentTimeMillis() - DatabaseDescriptor.getWriteRpcTimeout(MILLISECONDS) * 2) * 1000; UUID uuid = UUIDGen.getTimeUUID(); // Add a batch with 10 mutations diff --git a/test/unit/org/apache/cassandra/cache/AutoSavingCacheTest.java b/test/unit/org/apache/cassandra/cache/AutoSavingCacheTest.java index bb5129af9a..865ae1f69f 100644 --- a/test/unit/org/apache/cassandra/cache/AutoSavingCacheTest.java +++ b/test/unit/org/apache/cassandra/cache/AutoSavingCacheTest.java @@ -34,6 +34,8 @@ import org.apache.cassandra.schema.KeyspaceParams; import org.apache.cassandra.service.CacheService; import org.apache.cassandra.utils.ByteBufferUtil; +import static org.apache.cassandra.utils.Clock.Global.currentTimeMillis; + public class AutoSavingCacheTest { private static final String KEYSPACE1 = "AutoSavingCacheTest1"; @@ -71,7 +73,7 @@ public class AutoSavingCacheTest for (int i = 0; i < 2; i++) { ColumnMetadata colDef = ColumnMetadata.regularColumn(cfs.metadata(), ByteBufferUtil.bytes("col1"), AsciiType.instance); - RowUpdateBuilder rowBuilder = new RowUpdateBuilder(cfs.metadata(), System.currentTimeMillis(), "key1"); + RowUpdateBuilder rowBuilder = new RowUpdateBuilder(cfs.metadata(), currentTimeMillis(), "key1"); rowBuilder.add(colDef, "val1"); rowBuilder.build().apply(); cfs.forceBlockingFlush(); diff --git a/test/unit/org/apache/cassandra/cache/CacheProviderTest.java b/test/unit/org/apache/cassandra/cache/CacheProviderTest.java index 0355d51376..8ec536b759 100644 --- a/test/unit/org/apache/cassandra/cache/CacheProviderTest.java +++ b/test/unit/org/apache/cassandra/cache/CacheProviderTest.java @@ -45,6 +45,7 @@ import org.apache.cassandra.schema.TableId; import org.apache.cassandra.schema.TableMetadata; import org.apache.cassandra.utils.FBUtilities; +import static org.apache.cassandra.utils.Clock.Global.currentTimeMillis; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -80,7 +81,7 @@ public class CacheProviderTest private CachedBTreePartition createPartition() { - PartitionUpdate update = new RowUpdateBuilder(cfm, System.currentTimeMillis(), "key1") + PartitionUpdate update = new RowUpdateBuilder(cfm, currentTimeMillis(), "key1") .add("col1", "val1") .buildUpdate(); @@ -113,12 +114,12 @@ public class CacheProviderTest private void concurrentCase(final CachedBTreePartition partition, final ICache cache) throws InterruptedException { - final long startTime = System.currentTimeMillis() + 500; + final long startTime = currentTimeMillis() + 500; Runnable runnable = new Runnable() { public void run() { - while (System.currentTimeMillis() < startTime) {} + while (currentTimeMillis() < startTime) {} for (int j = 0; j < 1000; j++) { cache.put(key1, partition); diff --git a/test/unit/org/apache/cassandra/cql3/CQL3TypeLiteralTest.java b/test/unit/org/apache/cassandra/cql3/CQL3TypeLiteralTest.java index 8e6b76125d..48fefcaadb 100644 --- a/test/unit/org/apache/cassandra/cql3/CQL3TypeLiteralTest.java +++ b/test/unit/org/apache/cassandra/cql3/CQL3TypeLiteralTest.java @@ -34,6 +34,7 @@ import org.apache.cassandra.transport.ProtocolVersion; import org.apache.cassandra.utils.ByteBufferUtil; import org.apache.cassandra.utils.UUIDGen; +import static org.apache.cassandra.utils.Clock.Global.currentTimeMillis; import static org.junit.Assert.assertEquals; /** @@ -225,7 +226,7 @@ public class CQL3TypeLiteralTest for (int i = 0; i < 20; i++) { - UUID v = UUIDGen.getTimeUUID(randLong(System.currentTimeMillis())); + UUID v = UUIDGen.getTimeUUID(randLong(currentTimeMillis())); addNativeValue(v.toString(), CQL3Type.Native.TIMEUUID, TimeUUIDType.instance.decompose(v)); } addNativeValue("null", CQL3Type.Native.TIMEUUID, ByteBufferUtil.EMPTY_BYTE_BUFFER); diff --git a/test/unit/org/apache/cassandra/cql3/CQLTester.java b/test/unit/org/apache/cassandra/cql3/CQLTester.java index 2ed4e26739..ea3c971321 100644 --- a/test/unit/org/apache/cassandra/cql3/CQLTester.java +++ b/test/unit/org/apache/cassandra/cql3/CQLTester.java @@ -103,6 +103,7 @@ import org.apache.cassandra.utils.Pair; import static com.datastax.driver.core.SocketOptions.DEFAULT_CONNECT_TIMEOUT_MILLIS; import static com.datastax.driver.core.SocketOptions.DEFAULT_READ_TIMEOUT_MILLIS; +import static org.apache.cassandra.utils.Clock.Global.currentTimeMillis; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -940,7 +941,7 @@ public abstract class CQLTester */ protected boolean waitForIndex(String keyspace, String table, String index) throws Throwable { - long start = System.currentTimeMillis(); + long start = currentTimeMillis(); boolean indexCreated = false; while (!indexCreated) { @@ -954,7 +955,7 @@ public abstract class CQLTester } } - if (System.currentTimeMillis() - start > 5000) + if (currentTimeMillis() - start > 5000) break; Thread.sleep(10); @@ -975,7 +976,7 @@ public abstract class CQLTester */ protected boolean waitForIndexBuilds(String keyspace, String indexName) throws InterruptedException { - long start = System.currentTimeMillis(); + long start = currentTimeMillis(); SecondaryIndexManager indexManager = getCurrentColumnFamilyStore(keyspace).indexManager; while (true) @@ -984,7 +985,7 @@ public abstract class CQLTester { return true; } - else if (System.currentTimeMillis() - start > 5000) + else if (currentTimeMillis() - start > 5000) { return false; }