You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by re...@apache.org on 2023/11/23 17:17:55 UTC
(jackrabbit-oak) 02/02: OAK-10562: make setClock() picky
This is an automated email from the ASF dual-hosted git repository.
reschke pushed a commit to branch OAK-10562
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
commit 81fadb4e1b7657d829bf1ffb06b0e1e265b9bbc7
Author: Julian Reschke <re...@apache.org>
AuthorDate: Thu Nov 23 18:17:35 2023 +0100
OAK-10562: make setClock() picky
---
.../jackrabbit/oak/plugins/document/ClusterNodeInfo.java | 12 ++++++++++++
.../apache/jackrabbit/oak/plugins/document/Revision.java | 15 ++++++++++++++-
2 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java
index d53e1822f9..8b503ba133 100644
--- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java
+++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java
@@ -27,6 +27,7 @@ import java.lang.management.ManagementFactory;
import java.net.NetworkInterface;
import java.util.AbstractMap;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
@@ -1163,6 +1164,9 @@ public class ClusterNodeInfo {
"invisible: " + invisible;
}
+ /** keep track of test classes that have set a custom clock */
+ static Exception lastClockSetter;
+
/**
* Specify a custom clock to be used for determining current time.
*
@@ -1170,6 +1174,13 @@ public class ClusterNodeInfo {
*/
static void setClock(Clock c) {
checkNotNull(c);
+
+ if (lastClockSetter != null) {
+ throw new RuntimeException(
+ "custom clock (" + clock + ") already in use, set by: " + Arrays.asList(lastClockSetter.getStackTrace()));
+ }
+ lastClockSetter = new Exception("call stack");
+
clock = c;
}
@@ -1178,6 +1189,7 @@ public class ClusterNodeInfo {
*/
static void resetClockToDefault() {
clock = Clock.SIMPLE;
+ lastClockSetter = null;
}
private static long getProcessId() {
diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/Revision.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/Revision.java
index 13431cd2bf..dc76c90bcd 100644
--- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/Revision.java
+++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/Revision.java
@@ -22,6 +22,8 @@ import org.apache.jackrabbit.oak.stats.Clock;
import static org.apache.jackrabbit.guava.common.base.Preconditions.checkNotNull;
+import java.util.Arrays;
+
/**
* A revision.
*/
@@ -61,6 +63,9 @@ public final class Revision implements CacheValue {
*/
private final boolean branch;
+ /** keep track of test classes that have set a custom clock */
+ static Exception lastClockSetter;
+
/** Only set for testing */
private static Clock clock;
@@ -74,6 +79,13 @@ public final class Revision implements CacheValue {
*/
static void setClock(Clock c) {
checkNotNull(c);
+
+ if (lastClockSetter != null) {
+ throw new RuntimeException(
+ "custom clock (" + clock + ") already in use, set by: " + Arrays.asList(lastClockSetter.getStackTrace()));
+ }
+ lastClockSetter = new Exception("call stack");
+
clock = c;
lastTimestamp = clock.getTime();
lastRevisionTimestamp = clock.getTime();
@@ -86,7 +98,8 @@ public final class Revision implements CacheValue {
* </b>
*/
static void resetClockToDefault() {
- setClock(Clock.SIMPLE);
+ clock = Clock.SIMPLE;
+ lastClockSetter = null;
}
public Revision(long timestamp, int counter, int clusterId) {