Skip to content

Commit

Permalink
fix some deprecation warnings (#1111)
Browse files Browse the repository at this point in the history
  • Loading branch information
brharrington committed Jan 29, 2024
1 parent f3dfdbb commit 184f017
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void testRecord() {
public void testRecordCallable() throws Exception {
Timer t = newTimer();
clock.setMonotonicTime(100L);
int v = t.record(() -> {
int v = t.recordCallable(() -> {
clock.setMonotonicTime(500L);
return 42;
});
Expand All @@ -106,7 +106,7 @@ public void testRecordCallableException() throws Exception {
clock.setMonotonicTime(100L);
boolean seen = false;
try {
t.record((Callable<Integer>) () -> {
t.recordCallable((Callable<Integer>) () -> {
clock.setMonotonicTime(500L);
throw new RuntimeException("foo");
});
Expand All @@ -122,7 +122,7 @@ public void testRecordCallableException() throws Exception {
public void testRecordRunnable() throws Exception {
Timer t = newTimer();
clock.setMonotonicTime(100L);
t.record(() -> clock.setMonotonicTime(500L));
t.recordRunnable(() -> clock.setMonotonicTime(500L));
assertCountEquals(t, 1L);
assertTotalEquals(t, 400L);
}
Expand All @@ -133,7 +133,7 @@ public void testRecordRunnableException() throws Exception {
clock.setMonotonicTime(100L);
boolean seen = false;
try {
t.record((Runnable) () -> {
t.recordRunnable(() -> {
clock.setMonotonicTime(500L);
throw new RuntimeException("foo");
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void testRecordCallableException() throws Exception {
NoopTimer t = NoopTimer.INSTANCE;
boolean seen = false;
try {
t.record(() -> {
t.recordCallable(() -> {
throw new Exception("foo");
});
} catch (Exception e) {
Expand All @@ -55,7 +55,7 @@ public void testRecordRunnable() throws Exception {
NoopTimer t = NoopTimer.INSTANCE;
AtomicBoolean run = new AtomicBoolean();

t.record(() -> run.set(true));
t.recordRunnable(() -> run.set(true));
Assertions.assertTrue(run.get());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ public void resurrectUsingLambda() {
ExpiringRegistry registry = new ExpiringRegistry(clock);
Timer t = registry.timer("test");

t.record(() -> {
t.recordRunnable(() -> {
// Force expiration in the body of the lambda
clock.setWallTime(60000 * 30);
registry.removeExpiredMeters();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
*/
package com.netflix.spectator.placeholders;

import com.netflix.spectator.api.Clock;
import com.netflix.spectator.api.Registry;
import com.netflix.spectator.api.Timer;

import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;

/**
Expand All @@ -27,6 +27,7 @@
* interface methods are called.
*/
class DefaultPlaceholderTimer extends AbstractDefaultPlaceholderMeter<Timer> implements Timer {

/**
* Constructs a new timer with the specified dynamic id.
*
Expand All @@ -38,18 +39,13 @@ class DefaultPlaceholderTimer extends AbstractDefaultPlaceholderMeter<Timer> imp
}

@Override
public void record(long amount, TimeUnit unit) {
resolveToCurrentMeter().record(amount, unit);
}

@Override
public <T> T record(Callable<T> f) throws Exception {
return resolveToCurrentMeter().record(f);
public Clock clock() {
return resolveToCurrentMeter().clock();
}

@Override
public void record(Runnable f) {
resolveToCurrentMeter().record(f);
public void record(long amount, TimeUnit unit) {
resolveToCurrentMeter().record(amount, unit);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void testRecordCallable() throws Exception {
int expected = 42;
Timer timer = factory.timer(factory.createId("testRecordCallable"));
clock.setMonotonicTime(100L);
int actual = timer.record(() -> {
int actual = timer.recordCallable(() -> {
clock.setMonotonicTime(500L);
return expected;
});
Expand All @@ -96,7 +96,7 @@ public void testRecordCallableException() throws Exception {
clock.setMonotonicTime(100L);
boolean seen = false;
try {
timer.record(() -> {
timer.recordCallable(() -> {
clock.setMonotonicTime(500L);
throw new Exception("foo");
});
Expand All @@ -112,7 +112,7 @@ public void testRecordCallableException() throws Exception {
public void testRecordRunnable() throws Exception {
Timer timer = factory.timer(factory.createId("testRecordRunnable"));
clock.setMonotonicTime(100L);
timer.record(() -> clock.setMonotonicTime(500L));
timer.recordRunnable(() -> clock.setMonotonicTime(500L));
Assertions.assertEquals(1L, timer.count());
Assertions.assertEquals(timer.totalTime(), 400L);
}
Expand All @@ -121,10 +121,10 @@ public void testRecordRunnable() throws Exception {
public void testRecordRunnableException() throws Exception {
Timer timer = factory.timer(factory.createId("testRecordRunnableException"));
clock.setMonotonicTime(100L);
Exception expectedExc = new RuntimeException("foo");
RuntimeException expectedExc = new RuntimeException("foo");
Exception actualExc = null;
try {
timer.record(() -> {
timer.recordRunnable(() -> {
clock.setMonotonicTime(500L);
throw expectedExc;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ private void timePublishTask(String id, Runnable task) {
}

private void timePublishTask(String id, String lockName, Runnable task) {
publishTaskTimer(id).record(() -> {
publishTaskTimer(id).recordRunnable(() -> {
Lock lock = publishTaskLocks.computeIfAbsent(lockName, n -> new ReentrantLock());
lock.lock();
try {
Expand Down Expand Up @@ -341,7 +341,7 @@ void pollMeters(long t) {
evaluator.update(id, timestamp, value);
};
logger.debug("collecting measurements for time: {}", t);
publishTaskTimer("pollMeasurements").record(() -> StreamSupport
publishTaskTimer("pollMeasurements").recordRunnable(() -> StreamSupport
.stream(spliterator(), parallelPolling)
.forEach(meter -> ((AtlasMeter) meter).measure(t, consumer)));
lastPollTimestamp = t;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,14 +272,14 @@ public void recordBatchPollsClockOnce() {

@Test
public void recordRunnable() {
dist.record(() -> clock.setMonotonicTime(clock.monotonicTime() + 2));
dist.recordRunnable(() -> clock.setMonotonicTime(clock.monotonicTime() + 2));
clock.setWallTime(step + 1);
checkValue(1, 2, 4, 2);
}

@Test
public void recordCallable() throws Exception {
String s = dist.record(() -> {
String s = dist.recordCallable(() -> {
clock.setMonotonicTime(clock.monotonicTime() + 2);
return "foo";
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,15 @@ public void timerRecord() {
@Test
public void timerRecordRunnable() {
Timer t = registry.timer("foo");
t.record((Runnable) () -> clock.add(42, TimeUnit.SECONDS));
t.recordRunnable(() -> clock.add(42, TimeUnit.SECONDS));
Assertions.assertEquals(1, t.count());
Assertions.assertEquals(TimeUnit.SECONDS.toNanos(42), t.totalTime());
}

@Test
public void timerRecordCallable() throws Exception {
Timer t = registry.timer("foo");
t.record(() -> clock.add(42, TimeUnit.SECONDS));
t.recordCallable(() -> clock.add(42, TimeUnit.SECONDS));
Assertions.assertEquals(1, t.count());
Assertions.assertEquals(TimeUnit.SECONDS.toNanos(42), t.totalTime());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void testRecordZero() {
public void testRecordCallable() throws Exception {
Timer t = newTimer("foo");
clock.setMonotonicTime(100L);
int v = t.record(() -> {
int v = t.recordCallable(() -> {
clock.setMonotonicTime(500L);
return 42;
});
Expand All @@ -94,7 +94,7 @@ public void testRecordCallableException() throws Exception {
clock.setMonotonicTime(100L);
boolean seen = false;
try {
t.record((Callable<Integer>) () -> {
t.recordCallable(() -> {
clock.setMonotonicTime(500L);
throw new RuntimeException("foo");
});
Expand All @@ -110,7 +110,7 @@ public void testRecordCallableException() throws Exception {
public void testRecordRunnable() throws Exception {
Timer t = newTimer("foo");
clock.setMonotonicTime(100L);
t.record(() -> clock.setMonotonicTime(500L));
t.recordRunnable(() -> clock.setMonotonicTime(500L));
Assertions.assertEquals(t.count(), 1L);
Assertions.assertEquals(t.totalTime(), 400L);
}
Expand All @@ -121,7 +121,7 @@ public void testRecordRunnableException() throws Exception {
clock.setMonotonicTime(100L);
boolean seen = false;
try {
t.record((Runnable) () -> {
t.recordRunnable(() -> {
clock.setMonotonicTime(500L);
throw new RuntimeException("foo");
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public void timerZero() {
@Test
public void timerRecordCallable() throws Exception {
Timer t = registry.timer("test");
long v = t.record(() -> {
long v = t.recordCallable(() -> {
clock.setMonotonicTime(100_000_000);
return registry.clock().monotonicTime();
});
Expand All @@ -191,7 +191,7 @@ public void timerRecordCallable() throws Exception {
@Test
public void timerRecordRunnable() {
Timer t = registry.timer("test");
t.record(() -> {
t.recordRunnable(() -> {
clock.setMonotonicTime(100_000_000);
});
assertSingleMessage("t:test:0.1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.LongToDoubleFunction;
Expand Down Expand Up @@ -68,24 +67,6 @@ class StatelessTimer extends StatelessMeter implements Timer {
}
}

@Override public <T> T record(Callable<T> f) throws Exception {
final long start = clock.monotonicTime();
try {
return f.call();
} finally {
record(clock.monotonicTime() - start, TimeUnit.NANOSECONDS);
}
}

@Override public void record(Runnable f) {
final long start = clock.monotonicTime();
try {
f.run();
} finally {
record(clock.monotonicTime() - start, TimeUnit.NANOSECONDS);
}
}

@Override public long count() {
return count.get();
}
Expand Down

0 comments on commit 184f017

Please sign in to comment.