This is an automated email from the ASF dual-hosted git repository.

reschke pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 23017ea676 OAK-11621: Reduce usage of Guava Ticker (#2202)
23017ea676 is described below

commit 23017ea6761d1e61cd3fe317211ab107d2b66044
Author: Julian Reschke <[email protected]>
AuthorDate: Fri Apr 4 15:39:16 2025 +0200

    OAK-11621: Reduce usage of Guava Ticker (#2202)
---
 oak-core/pom.xml                                   |  7 +++
 .../plugins/index/TrackingCorruptIndexHandler.java | 21 +++----
 .../oak/plugins/index/FormattingUtilsTest.java     | 72 ++++++++++------------
 .../plugins/index/lucene/BadIndexTrackerTest.java  | 13 ++--
 .../oak/plugins/index/lucene/IndexTrackerTest.java |  9 ++-
 .../oak/plugins/index/lucene/VirtualTicker.java    | 41 ------------
 .../index/elastic/ElasticIndexStatistics.java      | 18 ++++--
 .../index/elastic/ElasticIndexStatisticsTest.java  | 27 ++------
 .../oak/plugins/index/search/BadIndexTracker.java  | 24 +++++---
 9 files changed, 93 insertions(+), 139 deletions(-)

diff --git a/oak-core/pom.xml b/oak-core/pom.xml
index 09dad7d38c..187450c9a2 100644
--- a/oak-core/pom.xml
+++ b/oak-core/pom.xml
@@ -364,6 +364,13 @@
       <artifactId>logback-classic</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.apache.jackrabbit</groupId>
+      <artifactId>oak-core-spi</artifactId>
+      <version>${project.version}</version>
+      <classifier>tests</classifier>
+      <scope>test</scope>
+    </dependency>
     <dependency>
       <groupId>org.apache.jackrabbit</groupId>
       <artifactId>oak-blob-plugins</artifactId>
diff --git 
a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/TrackingCorruptIndexHandler.java
 
b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/TrackingCorruptIndexHandler.java
index 91f2e43c4a..c82fa461f3 100644
--- 
a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/TrackingCorruptIndexHandler.java
+++ 
b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/TrackingCorruptIndexHandler.java
@@ -168,7 +168,13 @@ public class TrackingCorruptIndexHandler implements 
CorruptIndexHandler {
         private final String asyncName;
         private final String path;
         private final long lastIndexerCycleCount = indexerCycleCount;
-        private final Stopwatch watch = Stopwatch.createStarted(new 
ClockTicker(clock));
+        private final Stopwatch watch = Stopwatch.createStarted(new Ticker() {
+            @Override
+            public long read() {
+                return TimeUnit.MILLISECONDS.toNanos(clock.millis());
+            }
+        });
+
         private String exception = "";
         private int failureCount;
         private int skippedCount;
@@ -312,17 +318,4 @@ public class TrackingCorruptIndexHandler implements 
CorruptIndexHandler {
             }
         }
     }
-
-    private static class ClockTicker extends Ticker {
-        private final Clock clock;
-
-        public ClockTicker(Clock clock) {
-            this.clock = clock;
-        }
-
-        @Override
-        public long read() {
-            return TimeUnit.MILLISECONDS.toNanos(clock.getTime());
-        }
-    }
 }
diff --git 
a/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/FormattingUtilsTest.java
 
b/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/FormattingUtilsTest.java
index 74155188d8..2bc0637928 100644
--- 
a/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/FormattingUtilsTest.java
+++ 
b/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/FormattingUtilsTest.java
@@ -18,71 +18,67 @@ package org.apache.jackrabbit.oak.plugins.index;
 
 import org.apache.jackrabbit.guava.common.base.Stopwatch;
 import org.apache.jackrabbit.guava.common.base.Ticker;
+import org.apache.jackrabbit.oak.stats.NonTickingTestClock;
 import org.junit.Test;
 
 import java.util.concurrent.TimeUnit;
 
 import static org.junit.Assert.assertEquals;
 
-
 public class FormattingUtilsTest {
 
-    private static class TestTicker extends Ticker {
-        private long time = 0;
+    private final NonTickingTestClock clock = new NonTickingTestClock();
+
+    private final Stopwatch sw = Stopwatch.createStarted(new Ticker() {
         @Override
         public long read() {
-            return time;
+            return TimeUnit.MILLISECONDS.toNanos(clock.millis());
         }
-        public void set(long nanos) {
-            time = nanos;
-        }
-    }
-    private final TestTicker ticker = new TestTicker();
-    private final Stopwatch sw = Stopwatch.createStarted(ticker);
+    });
 
     @Test
     public void formatToSeconds() {
         testFormatToSeconds("00:00:00", 0);
-        testFormatToSeconds("00:00:59", TimeUnit.MILLISECONDS.toNanos(59_567));
-        testFormatToSeconds("00:01:00", TimeUnit.MILLISECONDS.toNanos(60_567));
-        testFormatToSeconds("00:59:00", TimeUnit.MINUTES.toNanos(59));
-        testFormatToSeconds("01:00:00", TimeUnit.MINUTES.toNanos(60));
-        testFormatToSeconds("23:00:00", TimeUnit.HOURS.toNanos(23));
-        testFormatToSeconds("24:00:00", TimeUnit.HOURS.toNanos(24));
-        testFormatToSeconds("48:00:00", TimeUnit.HOURS.toNanos(48));
-        testFormatToSeconds("23:59:59", TimeUnit.HOURS.toNanos(23) +
-                TimeUnit.MINUTES.toNanos(59) +
-                TimeUnit.SECONDS.toNanos(59) +
-                TimeUnit.MILLISECONDS.toNanos(999)
+        testFormatToSeconds("00:00:59", 
TimeUnit.MILLISECONDS.toMillis(59_567));
+        testFormatToSeconds("00:01:00", 
TimeUnit.MILLISECONDS.toMillis(60_567));
+        testFormatToSeconds("00:59:00", TimeUnit.MINUTES.toMillis(59));
+        testFormatToSeconds("01:00:00", TimeUnit.MINUTES.toMillis(60));
+        testFormatToSeconds("23:00:00", TimeUnit.HOURS.toMillis(23));
+        testFormatToSeconds("24:00:00", TimeUnit.HOURS.toMillis(24));
+        testFormatToSeconds("48:00:00", TimeUnit.HOURS.toMillis(48));
+        testFormatToSeconds("23:59:59", TimeUnit.HOURS.toMillis(23) +
+                TimeUnit.MINUTES.toMillis(59) +
+                TimeUnit.SECONDS.toMillis(59) +
+                TimeUnit.MILLISECONDS.toMillis(999)
         );
-        testFormatToSeconds("-00:01:00", -TimeUnit.SECONDS.toNanos(60));
+        testFormatToSeconds("-00:01:00", -TimeUnit.SECONDS.toMillis(60));
     }
 
-    private void testFormatToSeconds(String expected, long nanos) {
-        ticker.set(nanos);
+    private void testFormatToSeconds(String expected, long millis) {
+        clock.setTime(millis);
         assertEquals(expected, FormattingUtils.formatToSeconds(sw));
     }
 
     @Test
     public void formatToMillis() {
         testFormatToMillis("00:00:00.000", 0);
-        testFormatToMillis("00:00:59.567", 
TimeUnit.MILLISECONDS.toNanos(59_567));
-        testFormatToMillis("00:01:00.567", 
TimeUnit.MILLISECONDS.toNanos(60_567));
-        testFormatToMillis("00:59:00.000", TimeUnit.MINUTES.toNanos(59));
-        testFormatToMillis("01:00:00.000", TimeUnit.MINUTES.toNanos(60));
-        testFormatToMillis("23:00:00.000", TimeUnit.HOURS.toNanos(23));
-        testFormatToMillis("24:00:00.000", TimeUnit.HOURS.toNanos(24));
-        testFormatToMillis("48:00:00.000", TimeUnit.HOURS.toNanos(48));
-        testFormatToMillis("23:59:59.999", TimeUnit.HOURS.toNanos(23) +
-                TimeUnit.MINUTES.toNanos(59) +
-                TimeUnit.SECONDS.toNanos(59) +
-                TimeUnit.MILLISECONDS.toNanos(999)
+        testFormatToMillis("00:00:59.567", 
TimeUnit.MILLISECONDS.toMillis(59_567));
+        testFormatToMillis("00:01:00.567", 
TimeUnit.MILLISECONDS.toMillis(60_567));
+        testFormatToMillis("00:59:00.000", TimeUnit.MINUTES.toMillis(59));
+        testFormatToMillis("01:00:00.000", TimeUnit.MINUTES.toMillis(60));
+        testFormatToMillis("23:00:00.000", TimeUnit.HOURS.toMillis(23));
+        testFormatToMillis("24:00:00.000", TimeUnit.HOURS.toMillis(24));
+        testFormatToMillis("48:00:00.000", TimeUnit.HOURS.toMillis(48));
+        testFormatToMillis("23:59:59.999", TimeUnit.HOURS.toMillis(23) +
+                TimeUnit.MINUTES.toMillis(59) +
+                TimeUnit.SECONDS.toMillis(59) +
+                TimeUnit.MILLISECONDS.toMillis(999)
         );
-        testFormatToMillis("-00:01:00.000", -TimeUnit.SECONDS.toNanos(60));
+        testFormatToMillis("-00:01:00.000", -TimeUnit.SECONDS.toMillis(60));
     }
 
-    private void testFormatToMillis(String expected, long nanos) {
-        ticker.set(nanos);
+    private void testFormatToMillis(String expected, long millis) {
+        clock.setTime(millis);
         assertEquals(expected, FormattingUtils.formatToMillis(sw));
     }
 
diff --git 
a/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/BadIndexTrackerTest.java
 
b/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/BadIndexTrackerTest.java
index 524b22ed63..e4b9c274ab 100644
--- 
a/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/BadIndexTrackerTest.java
+++ 
b/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/BadIndexTrackerTest.java
@@ -16,13 +16,12 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-
 package org.apache.jackrabbit.oak.plugins.index.lucene;
 
 import java.util.Collections;
-import java.util.concurrent.TimeUnit;
 
 import org.apache.jackrabbit.oak.plugins.index.search.BadIndexTracker;
+import org.apache.jackrabbit.oak.stats.Clock;
 import org.junit.Test;
 
 import static org.hamcrest.Matchers.hasItem;
@@ -30,7 +29,7 @@ import static org.junit.Assert.*;
 
 public class BadIndexTrackerTest {
 
-    private VirtualTicker ticker = new VirtualTicker();
+    private Clock clock = new Clock.Virtual();
     private BadIndexTracker tracker = new BadIndexTracker();
 
     @Test
@@ -56,17 +55,17 @@ public class BadIndexTrackerTest {
     @Test
     public void recheckDelay() throws Exception{
         tracker = new BadIndexTracker(100);
-        tracker.setTicker(ticker);
+        tracker.setClock(clock);
         tracker.markBadIndexForRead("foo", new Exception());
-        ticker.addTime(50, TimeUnit.MILLISECONDS);
+        clock.waitUntil(clock.millis() + 50);
 
         assertTrue(tracker.isIgnoredBadIndex("foo"));
 
-        ticker.addTime(30, TimeUnit.MILLISECONDS);
+        clock.waitUntil(clock.millis() + 30);
         assertTrue(tracker.isIgnoredBadIndex("foo"));
 
         //Now cross the threshold
-        ticker.addTime(30, TimeUnit.MILLISECONDS);
+        clock.waitUntil(clock.millis() + 30);
         assertFalse(tracker.isIgnoredBadIndex("foo"));
 
         //However index is still considered bad
diff --git 
a/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexTrackerTest.java
 
b/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexTrackerTest.java
index 872ded46e7..43e40afdce 100644
--- 
a/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexTrackerTest.java
+++ 
b/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexTrackerTest.java
@@ -16,12 +16,10 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-
 package org.apache.jackrabbit.oak.plugins.index.lucene;
 
 import java.util.Collections;
 import java.util.Set;
-import java.util.concurrent.TimeUnit;
 
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.Type;
@@ -38,6 +36,7 @@ import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
 import org.apache.jackrabbit.oak.spi.commit.EditorHook;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.apache.jackrabbit.oak.stats.Clock;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -134,8 +133,8 @@ public class IndexTrackerTest {
         tracker = new IndexTracker();
         tracker.update(indexed);
 
-        VirtualTicker ticker = new VirtualTicker();
-        tracker.getBadIndexTracker().setTicker(ticker);
+        Clock clock = new Clock.Virtual();
+        tracker.getBadIndexTracker().setClock(clock);
 
         indexNode = tracker.acquireIndexNode("/oak:index/foo");
 
@@ -157,7 +156,7 @@ public class IndexTrackerTest {
         assertEquals(0, badIdxInfo.getFailedAccessCount());
 
         //5. Move clock forward
-        ticker.addTime(tracker.getBadIndexTracker().getRecheckIntervalMillis() 
+ 1, TimeUnit.MILLISECONDS);
+        clock.waitFor(tracker.getBadIndexTracker().getRecheckIntervalMillis() 
+ 1);
 
         //Now index access must be attempted again
         indexNode = tracker.acquireIndexNode("/oak:index/foo");
diff --git 
a/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/VirtualTicker.java
 
b/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/VirtualTicker.java
deleted file mode 100644
index 612f62c6c4..0000000000
--- 
a/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/VirtualTicker.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.jackrabbit.oak.plugins.index.lucene;
-
-import java.util.concurrent.TimeUnit;
-
-import org.apache.jackrabbit.guava.common.base.Ticker;
-
-public class VirtualTicker extends Ticker {
-    private long time;
-
-    @Override
-    public long read() {
-        return time;
-    }
-
-    public void setTime(long time, TimeUnit unit){
-        this.time = unit.toNanos(time);
-    }
-
-    public void addTime(long delta, TimeUnit unit){
-        this.time += unit.toNanos(delta);
-    }
-}
diff --git 
a/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexStatistics.java
 
b/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexStatistics.java
index 4d64d77ac5..7b9dc8f12b 100644
--- 
a/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexStatistics.java
+++ 
b/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexStatistics.java
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.oak.plugins.index.elastic;
 
 import java.io.IOException;
+import java.time.Clock;
 import java.util.List;
 import java.util.Objects;
 import java.util.concurrent.ExecutorService;
@@ -26,13 +27,13 @@ import java.util.concurrent.TimeUnit;
 
 import co.elastic.clients.elasticsearch._types.query_dsl.Query;
 
+import org.apache.jackrabbit.guava.common.base.Ticker;
 import org.apache.jackrabbit.oak.plugins.index.elastic.util.ElasticIndexUtils;
 import org.apache.jackrabbit.oak.plugins.index.search.IndexStatistics;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 import org.jetbrains.annotations.TestOnly;
 
-import org.apache.jackrabbit.guava.common.base.Ticker;
 import org.apache.jackrabbit.guava.common.cache.CacheBuilder;
 import org.apache.jackrabbit.guava.common.cache.CacheLoader;
 import org.apache.jackrabbit.guava.common.cache.LoadingCache;
@@ -178,19 +179,24 @@ public class ElasticIndexStatistics implements 
IndexStatistics {
         ).luceneDocsDeleted;
     }
 
-    static LoadingCache<StatsRequestDescriptor, Integer> setupCountCache(long 
maxSize, long expireSeconds, long refreshSeconds, @Nullable Ticker ticker) {
-        return setupCache(maxSize, expireSeconds, refreshSeconds, new 
CountCacheLoader(), ticker);
+    static LoadingCache<StatsRequestDescriptor, Integer> setupCountCache(long 
maxSize, long expireSeconds, long refreshSeconds, @Nullable Clock clock) {
+        return setupCache(maxSize, expireSeconds, refreshSeconds, new 
CountCacheLoader(), clock);
     }
 
     static <K, V> LoadingCache<K, V> setupCache(long maxSize, long 
expireSeconds, long refreshSeconds,
-                                                @NotNull CacheLoader<K, V> 
cacheLoader, @Nullable Ticker ticker) {
+                                                @NotNull CacheLoader<K, V> 
cacheLoader, @Nullable Clock clock) {
         CacheBuilder<Object, Object> cacheBuilder = CacheBuilder.newBuilder()
                 .maximumSize(maxSize)
                 .expireAfterWrite(expireSeconds, TimeUnit.SECONDS)
                 // https://github.com/google/guava/wiki/CachesExplained#refresh
                 .refreshAfterWrite(refreshSeconds, TimeUnit.SECONDS);
-        if (ticker != null) {
-            cacheBuilder.ticker(ticker);
+        if (clock != null) {
+            cacheBuilder.ticker(new Ticker() {
+                @Override
+                public long read() {
+                    return TimeUnit.MILLISECONDS.toNanos(clock.millis());
+                }
+            });
         }
         return cacheBuilder.build(cacheLoader);
     }
diff --git 
a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexStatisticsTest.java
 
b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexStatisticsTest.java
index a7b4be081a..644e88ed3c 100644
--- 
a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexStatisticsTest.java
+++ 
b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexStatisticsTest.java
@@ -20,8 +20,8 @@ import co.elastic.clients.elasticsearch.ElasticsearchClient;
 import co.elastic.clients.elasticsearch._types.query_dsl.Query;
 import co.elastic.clients.elasticsearch.core.CountRequest;
 import co.elastic.clients.elasticsearch.core.CountResponse;
-import org.apache.jackrabbit.guava.common.base.Ticker;
 import org.apache.jackrabbit.guava.common.cache.LoadingCache;
+import org.apache.jackrabbit.oak.stats.Clock;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -77,9 +77,9 @@ public class ElasticIndexStatisticsTest {
 
     @Test
     public void cachedStatistics() throws Exception {
-        MutableTicker ticker = new MutableTicker();
+        Clock.Virtual clock = new Clock.Virtual();
         LoadingCache<ElasticIndexStatistics.StatsRequestDescriptor, Integer> 
cache =
-                ElasticIndexStatistics.setupCountCache(100, 10 * 60, 60, 
ticker);
+                ElasticIndexStatistics.setupCountCache(100, 10 * 60, 60, 
clock);
         ElasticIndexStatistics indexStatistics =
                 new ElasticIndexStatistics(elasticConnectionMock, 
indexDefinitionMock, cache, null);
 
@@ -102,7 +102,7 @@ public class ElasticIndexStatisticsTest {
         verifyNoMoreInteractions(elasticClientMock);
 
         // move cache time ahead of 2 minutes, cache reload time expired
-        ticker.tick(Duration.ofMinutes(2));
+        clock.waitFor(Duration.ofMinutes(2));
         // old value is returned, read fresh data from elastic in background
         assertEquals(100, indexStatistics.numDocs());
 
@@ -121,14 +121,14 @@ public class ElasticIndexStatisticsTest {
         when(countResponse.count()).thenReturn(5000L);
 
         // move cache time ahead of 15 minutes, cache value expired
-        ticker.tick(Duration.ofMinutes(15));
+        clock.waitFor(Duration.ofMinutes(15));
 
         // cache miss, read data from elastic
         assertEquals(5000, indexStatistics.numDocs());
         verify(elasticClientMock, times(3)).count(any(CountRequest.class));
 
         // move cache time ahead of 30 minutes, cache value expired
-        ticker.tick(Duration.ofMinutes(30));
+        clock.waitFor(Duration.ofMinutes(30));
 
         // cache miss, read data using an elastic query
         assertEquals(5000, indexStatistics.getDocCountFor(Query.of(qf -> 
qf.matchAll(mf -> mf))));
@@ -142,19 +142,4 @@ public class ElasticIndexStatisticsTest {
         assertEquals(5000, indexStatistics.getDocCountFor(Query.of(qf -> 
qf.matchAll(mf -> mf.boost(100F)))));
         verify(elasticClientMock, times(5)).count(any(CountRequest.class));
     }
-
-    private static class MutableTicker extends Ticker {
-
-        private long nanoOffset = 0;
-
-        @Override
-        public long read() {
-            return systemTicker().read() + nanoOffset;
-        }
-
-        public void tick(Duration duration) {
-            nanoOffset = duration.toNanos();
-        }
-    }
-
 }
diff --git 
a/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/BadIndexTracker.java
 
b/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/BadIndexTracker.java
index 2efd4881cc..1512cfa7d9 100644
--- 
a/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/BadIndexTracker.java
+++ 
b/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/BadIndexTracker.java
@@ -16,9 +16,9 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-
 package org.apache.jackrabbit.oak.plugins.index.search;
 
+import java.time.Clock;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
@@ -51,7 +51,7 @@ public class BadIndexTracker {
     private final Map<String, BadIndexInfo> badIndexesForRead = new 
ConcurrentHashMap<>();
     private final Map<String, BadIndexInfo> badPersistedIndexes = new 
ConcurrentHashMap<>();
     private final long recheckIntervalMillis;
-    private Ticker ticker = Ticker.systemTicker();
+    private Clock clock = Clock.systemUTC();
     private int indexerCycleCount;
 
     public BadIndexTracker() {
@@ -143,8 +143,8 @@ public class BadIndexTracker {
         return recheckIntervalMillis;
     }
 
-    public void setTicker(Ticker ticker) {
-        this.ticker = ticker;
+    public void setClock(Clock clock) {
+        this.clock = clock;
     }
 
     public boolean hasBadIndexes(){
@@ -154,10 +154,20 @@ public class BadIndexTracker {
     public class BadIndexInfo {
         public final String path;
         final int lastIndexerCycleCount = indexerCycleCount;
-        private final long createdTime = 
TimeUnit.NANOSECONDS.toMillis(ticker.read());
+        private final long createdTime = clock.millis();
         private final boolean persistedIndex;
-        private final Stopwatch created = Stopwatch.createStarted(ticker);
-        private final Stopwatch watch = Stopwatch.createStarted(ticker);
+        private final Stopwatch created = Stopwatch.createStarted(new Ticker() 
{
+            @Override
+            public long read() {
+                return TimeUnit.MILLISECONDS.toNanos(clock.millis());
+            }
+        });
+        private final Stopwatch watch = Stopwatch.createStarted(new Ticker() {
+            @Override
+            public long read() {
+                return TimeUnit.MILLISECONDS.toNanos(clock.millis());
+            }
+        });
         private String exception;
         private int accessCount;
         private int failedAccessCount;

Reply via email to