Skip to content

Commit

Permalink
upgrade slf4j-test to next major version
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-manes committed Jul 14, 2023
1 parent b2dc82d commit c6434e3
Show file tree
Hide file tree
Showing 21 changed files with 44 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import static uk.org.lidalia.slf4jext.Level.ERROR;
import static uk.org.lidalia.slf4jext.Level.WARN;
import static org.slf4j.event.Level.ERROR;
import static org.slf4j.event.Level.WARN;

import java.util.AbstractMap;
import java.util.Arrays;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import static uk.org.lidalia.slf4jext.Level.ERROR;
import static uk.org.lidalia.slf4jext.Level.WARN;
import static org.slf4j.event.Level.ERROR;
import static org.slf4j.event.Level.WARN;

import java.util.AbstractMap;
import java.util.Arrays;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static uk.org.lidalia.slf4jext.Level.WARN;
import static org.slf4j.event.Level.WARN;

import java.util.ArrayList;
import java.util.Collections;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import static com.google.common.truth.Truth.assertThat;
import static java.util.function.Function.identity;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static uk.org.lidalia.slf4jext.Level.WARN;
import static org.slf4j.event.Level.WARN;

import java.time.Duration;
import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,8 @@
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import static uk.org.lidalia.slf4jext.ConventionalLevelHierarchy.WARN_LEVELS;
import static uk.org.lidalia.slf4jext.Level.ERROR;
import static uk.org.lidalia.slf4jext.Level.WARN;
import static org.slf4j.event.Level.ERROR;
import static org.slf4j.event.Level.WARN;

import java.io.IOException;
import java.lang.ref.Reference;
Expand Down Expand Up @@ -95,6 +94,7 @@
import org.apache.commons.lang3.mutable.MutableInt;
import org.mockito.Mockito;
import org.mockito.stubbing.Answer;
import org.slf4j.event.Level;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;

Expand Down Expand Up @@ -1892,7 +1892,7 @@ public void put_warnIfEvictionBlocked(BoundedLocalCache<Int, Int> cache, CacheCo
try {
ConcurrentTestHarness.execute(() -> {
var logger = TestLoggerFactory.getTestLogger(BoundedLocalCache.class);
logger.setEnabledLevels(WARN_LEVELS);
logger.setEnabledLevels(Level.WARN, Level.ERROR);
thread.set(Thread.currentThread());
testLogger.set(logger);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
import static org.junit.Assert.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static uk.org.lidalia.slf4jext.Level.ERROR;
import static uk.org.lidalia.slf4jext.Level.WARN;
import static org.slf4j.event.Level.ERROR;
import static org.slf4j.event.Level.WARN;

import java.io.InvalidObjectException;
import java.io.ObjectInputStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static uk.org.lidalia.slf4jext.Level.WARN;
import static org.slf4j.event.Level.WARN;

import java.time.Duration;
import java.util.ConcurrentModificationException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import static uk.org.lidalia.slf4jext.Level.WARN;
import static org.slf4j.event.Level.WARN;

import java.time.Duration;
import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static org.junit.Assert.assertThrows;
import static uk.org.lidalia.slf4jext.Level.WARN;
import static org.slf4j.event.Level.WARN;

import java.time.Duration;
import java.time.temporal.ChronoUnit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import static uk.org.lidalia.slf4jext.Level.WARN;
import static org.slf4j.event.Level.WARN;

import java.time.Duration;
import java.time.temporal.ChronoUnit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static org.junit.Assert.assertThrows;
import static uk.org.lidalia.slf4jext.Level.WARN;
import static org.slf4j.event.Level.WARN;

import java.time.Duration;
import java.time.temporal.ChronoUnit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
import static com.google.common.truth.Truth.assertThat;
import static java.util.function.Function.identity;
import static org.junit.Assert.assertThrows;
import static uk.org.lidalia.slf4jext.Level.TRACE;
import static uk.org.lidalia.slf4jext.Level.WARN;
import static org.slf4j.event.Level.TRACE;
import static org.slf4j.event.Level.WARN;

import java.time.Duration;
import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import static com.google.common.base.Preconditions.checkState;
import static java.util.function.Function.identity;
import static uk.org.lidalia.slf4jext.Level.WARN;
import static org.slf4j.event.Level.WARN;

import java.util.List;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static uk.org.lidalia.slf4jext.Level.WARN;
import static org.slf4j.event.Level.WARN;

import java.util.AbstractMap;
import java.util.AbstractMap.SimpleEntry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import static java.util.function.Function.identity;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThrows;
import static uk.org.lidalia.slf4jext.Level.WARN;
import static org.slf4j.event.Level.WARN;

import java.time.Duration;
import java.time.temporal.ChronoUnit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package com.github.benmanes.caffeine.cache;

import static com.google.common.truth.Truth8.assertThat;
import static uk.org.lidalia.slf4jext.Level.TRACE;
import static org.slf4j.event.Level.TRACE;

import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static org.testng.ITestResult.FAILURE;
import static uk.org.lidalia.slf4jext.ConventionalLevelHierarchy.TRACE_LEVELS;

import java.util.Arrays;
import java.util.Collection;
Expand All @@ -36,6 +35,7 @@
import org.apache.commons.lang3.StringUtils;
import org.joor.Reflect;
import org.mockito.Mockito;
import org.slf4j.event.Level;
import org.testng.Assert;
import org.testng.IInvokedMethod;
import org.testng.IInvokedMethodListener;
Expand All @@ -60,17 +60,20 @@
import com.github.benmanes.caffeine.cache.testing.CacheSpec.CacheScheduler;
import com.github.benmanes.caffeine.cache.testing.CacheSpec.ExecutorFailure;
import com.github.valfirst.slf4jtest.TestLoggerFactory;
import com.google.common.collect.ImmutableList;

/**
* A listener that validates the internal structure after a successful test execution.
*
* @author ben.manes@gmail.com (Ben Manes)
*/
public final class CacheValidationListener implements ISuiteListener, IInvokedMethodListener {
private static final ImmutableList<Level> TRACE_LEVELS = ImmutableList.copyOf(Level.values());
private static final Object[] EMPTY_PARAMS = {};

private static final Cache<Object, String> simpleNames = Caffeine.newBuilder().build();
private static final AtomicBoolean detailedParams = new AtomicBoolean(false);
private static final ITestContext testngContext = Mockito.mock();
private static final Object[] EMPTY_PARAMS = {};

private final List<Collection<?>> resultQueues = new CopyOnWriteArrayList<>();
private final AtomicBoolean beforeCleanup = new AtomicBoolean();
Expand Down Expand Up @@ -229,7 +232,7 @@ private static void checkLogger(ITestResult testResult) {
.getRealClass().getAnnotation(CheckMaxLogLevel.class));
if (checkMaxLogLevel != null) {
var events = TestLoggerFactory.getLoggingEvents().stream()
.filter(event -> event.getLevel().ordinal() > checkMaxLogLevel.value().ordinal())
.filter(event -> event.getLevel().toInt() > checkMaxLogLevel.value().toInt())
.collect(toImmutableList());
assertWithMessage("maxLevel=%s", checkMaxLogLevel.value()).that(events).isEmpty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import uk.org.lidalia.slf4jext.Level;
import org.slf4j.event.Level;

/**
* A test class or method with this annotation has indicated that logging should not exceed the
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ picocli = "4.7.4"
pmd = "7.0.0-rc3"
protobuf = "3.23.4"
slf4j = "2.0.7"
slf4j-test = "2.9.0"
slf4j-test = "3.0.1"
snakeyaml = "2.0"
sonarqube = "4.2.1.3168"
spotbugs-contrib = "7.6.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,22 +91,22 @@ private void broadcast(TraceReader trace, List<PolicyActor> policies) {
events.forEach(event -> {
batch.add(event);
if (batch.size() == batchSize) {
var accessEvents = List.copyOf(batch);
var accessEvents = ImmutableList.copyOf(batch);
for (var policy : policies) {
policy.send(accessEvents);
}
batch.clear();
}
});

var remainder = List.copyOf(batch);
var remainder = ImmutableList.copyOf(batch);
for (var policy : policies) {
policy.send(remainder);
policy.finish();
}

var futures = policies.stream()
.map(PolicyActor::future)
.map(PolicyActor::completed)
.toArray(CompletableFuture<?>[]::new);
CompletableFuture.allOf(futures).join();
}
Expand Down Expand Up @@ -142,9 +142,9 @@ private void throwError(RuntimeException error, Iterable<PolicyActor> policies)
throw error;
}
for (var policy : policies) {
if (policy.future().isCompletedExceptionally()) {
if (policy.completed().isCompletedExceptionally()) {
try {
policy.future().join();
policy.completed().join();
} catch (CompletionException e) {
Throwables.throwIfUnchecked(e.getCause());
e.addSuppressed(error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
import java.util.concurrent.Semaphore;

import com.github.benmanes.caffeine.cache.simulator.BasicSettings;
import com.google.common.collect.ImmutableList;

/**
* An actor that proxies to the page replacement policy.
*
* @author ben.manes@gmail.com (Ben Manes)
*/
public final class PolicyActor {
private final CompletableFuture<Void> completed;
private final Semaphore semaphore;
private final Policy policy;
private final Thread parent;
Expand All @@ -45,12 +47,13 @@ public final class PolicyActor {
public PolicyActor(Thread parent, Policy policy, BasicSettings settings) {
this.semaphore = new Semaphore(settings.actor().mailboxSize());
this.future = CompletableFuture.completedFuture(null);
this.completed = new CompletableFuture<>();
this.policy = requireNonNull(policy);
this.parent = requireNonNull(parent);
}

/** Sends the access events for async processing and blocks until accepted into the mailbox. */
public void send(List<AccessEvent> events) {
public void send(ImmutableList<AccessEvent> events) {
submit(new Execute(events));
}

Expand All @@ -60,8 +63,8 @@ public void finish() {
}

/** Return the future that signals the policy's completion. */
public CompletableFuture<Void> future() {
return future;
public CompletableFuture<Void> completed() {
return completed;
}

/** Submits the command to the mailbox and blocks until accepted. */
Expand Down Expand Up @@ -108,6 +111,7 @@ private final class Execute extends Command {
private final class Finish extends Command {
@Override public void execute() {
policy.finished();
completed.complete(null);
}
}

Expand All @@ -118,6 +122,7 @@ private abstract class Command implements Runnable {
try {
execute();
} catch (Throwable t) {
completed.completeExceptionally(t);
parent.interrupt();
throw t;
} finally {
Expand Down

0 comments on commit c6434e3

Please sign in to comment.