Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
}

dependencies {
classpath 'com.palantir.baseline:gradle-baseline-java:5.3.0'
classpath 'com.palantir.baseline:gradle-baseline-java:5.5.0'
classpath 'com.palantir.gradle.consistentversions:gradle-consistent-versions:2.12.0'
classpath 'com.palantir.gradle.externalpublish:gradle-external-publish-plugin:1.12.0'
classpath 'com.palantir.gradle.gitversion:gradle-git-version:3.0.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ private final class TaggedMetricsRunnable implements Runnable {
}

@Override
@SuppressWarnings("PreferJavaTimeOverload") // performance sensitive
public void run() {
stopQueueTimer();
running.inc();
Expand Down Expand Up @@ -168,6 +169,7 @@ private final class TaggedMetricsCallable<T> implements Callable<T> {
}

@Override
@SuppressWarnings("PreferJavaTimeOverload") // performance sensitive
public T call() throws Exception {
stopQueueTimer();
running.inc();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ private final class TaggedMetricsRunnable implements Runnable {
}

@Override
@SuppressWarnings("PreferJavaTimeOverload") // performance sensitive
public void run() {
running.inc();
long startNanos = System.nanoTime();
Expand All @@ -153,6 +154,7 @@ private final class TaggedMetricsScheduledRunnable implements Runnable {
}

@Override
@SuppressWarnings("PreferJavaTimeOverload") // performance sensitive
public void run() {
running.inc();
long startNanos = System.nanoTime();
Expand All @@ -178,6 +180,7 @@ private final class TaggedMetricsCallable<T> implements Callable<T> {
}

@Override
@SuppressWarnings("PreferJavaTimeOverload") // performance sensitive
public T call() throws Exception {
running.inc();
long startNanos = System.nanoTime();
Expand Down
1 change: 1 addition & 0 deletions tritium-slf4j/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dependencies {
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.junit.jupiter:junit-jupiter'
testImplementation 'org.junit.jupiter:junit-jupiter-api'
testImplementation 'org.junit.jupiter:junit-jupiter-params'
testImplementation 'org.slf4j:slf4j-simple'
}

Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
import com.palantir.tritium.event.InvocationContext;
import com.palantir.tritium.event.InvocationEventHandler;
import java.lang.reflect.Method;
import java.time.Duration;
import java.util.Collection;
import java.util.concurrent.TimeUnit;
import java.util.function.BiConsumer;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand All @@ -44,10 +42,10 @@ public class LoggingInvocationEventHandler extends AbstractInvocationEventHandle
public static final com.palantir.tritium.api.functions.LongPredicate LOG_ALL_DURATIONS = _input -> true;

public static final com.palantir.tritium.api.functions.LongPredicate LOG_DURATIONS_GREATER_THAN_1_MICROSECOND =
nanos -> TimeUnit.MICROSECONDS.convert(Duration.ofNanos(nanos)) > 1;
nanos -> nanos > 1000;

public static final com.palantir.tritium.api.functions.LongPredicate LOG_DURATIONS_GREATER_THAN_0_MILLIS =
nanos -> TimeUnit.MILLISECONDS.convert(Duration.ofNanos(nanos)) > 0;
nanos -> nanos >= 1_000_000;

public static final com.palantir.tritium.api.functions.LongPredicate NEVER_LOG = _input -> false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.helpers.MessageFormatter;
Expand Down Expand Up @@ -160,4 +162,32 @@ public void testBackwardCompatibility() {
assertThat(new LoggingInvocationEventHandler(getLogger(), LoggingLevel.TRACE, legacyPredicate))
.isNotNull();
}

@ParameterizedTest
@ValueSource(longs = {Long.MIN_VALUE, -1, 0, 1, 100, 1_000})
void testLogDurationsLessThanOrEqualToOneMicrosecond(long nanoseconds) {
assertThat(LoggingInvocationEventHandler.LOG_DURATIONS_GREATER_THAN_1_MICROSECOND.test(nanoseconds))
.isFalse();
}

@ParameterizedTest
@ValueSource(longs = {1_001, 1_000_000, Long.MAX_VALUE})
void testLogDurationsGreaterThanOneMicrosecond(long nanoseconds) {
assertThat(LoggingInvocationEventHandler.LOG_DURATIONS_GREATER_THAN_1_MICROSECOND.test(nanoseconds))
.isTrue();
}

@ParameterizedTest
@ValueSource(longs = {Long.MIN_VALUE, -1, 0, 1, 100, 1_000, 999_999})
void testLogDurationsLessThanOrEqualToZeroMilliseconds(long nanoseconds) {
assertThat(LoggingInvocationEventHandler.LOG_DURATIONS_GREATER_THAN_0_MILLIS.test(nanoseconds))
.isFalse();
}

@ParameterizedTest
@ValueSource(longs = {1_000_000, 1_000_001, 1_000_000_000, Long.MAX_VALUE})
void testLogDurationsGreaterThanZeroMilliseconds(long nanoseconds) {
assertThat(LoggingInvocationEventHandler.LOG_DURATIONS_GREATER_THAN_0_MILLIS.test(nanoseconds))
.isTrue();
}
}