Skip to content

Commit

Permalink
Merge pull request #398 from scalecube/bring-back-slf4j
Browse files Browse the repository at this point in the history
Set back slf4j, + added LoggingExtension
  • Loading branch information
artem-v authored Jan 25, 2025
2 parents b31e47e + 8cbd4fe commit ac03cb8
Show file tree
Hide file tree
Showing 28 changed files with 406 additions and 616 deletions.
53 changes: 52 additions & 1 deletion cluster-testlib/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>scalecube-cluster-parent</artifactId>
<groupId>io.scalecube</groupId>
Expand All @@ -21,6 +23,55 @@
<artifactId>scalecube-cluster-api</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit-jupiter.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit-jupiter.version}</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>${mockito-junit.version}</version>
<exclusions>
<exclusion>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>${hamcrest.version}</version>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package io.scalecube.cluster.utils;

import java.lang.reflect.Method;
import org.junit.jupiter.api.extension.AfterAllCallback;
import org.junit.jupiter.api.extension.AfterEachCallback;
import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class LoggingExtension
implements AfterEachCallback, BeforeEachCallback, AfterAllCallback, BeforeAllCallback {

private static final Logger LOGGER = LoggerFactory.getLogger(LoggingExtension.class);

@Override
public void beforeAll(ExtensionContext context) {
LOGGER.info(
"***** Setup: " + context.getTestClass().map(Class::getSimpleName).orElse("") + " *****");
}

@Override
public void afterEach(ExtensionContext context) {
LOGGER.info(
"***** Test finished: "
+ context.getTestClass().map(Class::getSimpleName).orElse("")
+ "."
+ context.getTestMethod().map(Method::getName).orElse("")
+ "."
+ context.getDisplayName()
+ " *****");
}

@Override
public void beforeEach(ExtensionContext context) {
LOGGER.info(
"***** Test started: "
+ context.getTestClass().map(Class::getSimpleName).orElse("")
+ "."
+ context.getTestMethod().map(Method::getName).orElse("")
+ "."
+ context.getDisplayName()
+ " *****");
}

@Override
public void afterAll(ExtensionContext context) {
LOGGER.info(
"***** TearDown: "
+ context.getTestClass().map(Class::getSimpleName).orElse("")
+ " *****");
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package io.scalecube.cluster.utils;

import io.scalecube.cluster.transport.api.Message;
import java.lang.System.Logger;
import java.lang.System.Logger.Level;
import java.time.Duration;
import java.util.Arrays;
import java.util.Collection;
Expand All @@ -11,6 +9,8 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicLong;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Mono;

/**
Expand All @@ -24,7 +24,7 @@
*/
public final class NetworkEmulator {

private static final Logger LOGGER = System.getLogger(NetworkEmulator.class.getName());
private static final Logger LOGGER = LoggerFactory.getLogger(NetworkEmulator.class);

private volatile OutboundSettings defaultOutboundSettings = new OutboundSettings(0, 0);
private volatile InboundSettings defaultInboundSettings = new InboundSettings(true);
Expand Down Expand Up @@ -69,8 +69,7 @@ public OutboundSettings outboundSettings(String destination) {
public void outboundSettings(String destination, int lossPercent, int meanDelay) {
OutboundSettings settings = new OutboundSettings(lossPercent, meanDelay);
outboundSettings.put(destination, settings);
LOGGER.log(
Level.DEBUG, "[{0}] Set outbound settings {1} to {2}", address, settings, destination);
LOGGER.debug("[{}] Set outbound settings {} to {}", address, settings, destination);
}

/**
Expand All @@ -81,22 +80,21 @@ public void outboundSettings(String destination, int lossPercent, int meanDelay)
*/
public void setDefaultOutboundSettings(int lossPercent, int meanDelay) {
defaultOutboundSettings = new OutboundSettings(lossPercent, meanDelay);
LOGGER.log(
Level.DEBUG, "[{0}] Set default outbound settings {1}", address, defaultOutboundSettings);
LOGGER.debug("[{}] Set default outbound settings {}", address, defaultOutboundSettings);
}

/** Blocks outbound messages to all destinations. */
public void blockAllOutbound() {
outboundSettings.clear();
setDefaultOutboundSettings(100, 0);
LOGGER.log(Level.DEBUG, "[{0}] Blocked outbound to all destinations", address);
LOGGER.debug("[{}] Blocked outbound to all destinations", address);
}

/** Unblocks outbound messages to all destinations. */
public void unblockAllOutbound() {
outboundSettings.clear();
setDefaultOutboundSettings(0, 0);
LOGGER.log(Level.DEBUG, "[{0}] Unblocked outbound to all destinations", address);
LOGGER.debug("[{}] Unblocked outbound to all destinations", address);
}

/**
Expand All @@ -117,7 +115,7 @@ public void blockOutbound(Collection<String> destinations) {
for (String destination : destinations) {
outboundSettings.put(destination, new OutboundSettings(100, 0));
}
LOGGER.log(Level.DEBUG, "[{0}] Blocked outbound to {1}", address, destinations);
LOGGER.debug("[{}] Blocked outbound to {}", address, destinations);
}

/**
Expand All @@ -136,7 +134,7 @@ public void unblockOutbound(String... destinations) {
*/
public void unblockOutbound(Collection<String> destinations) {
destinations.forEach(outboundSettings::remove);
LOGGER.log(Level.DEBUG, "[{0}] Unblocked outbound {1}", address, destinations);
LOGGER.debug("[{}] Unblocked outbound {}", address, destinations);
}

/**
Expand Down Expand Up @@ -222,8 +220,7 @@ public InboundSettings inboundSettings(String destination) {
public void inboundSettings(String destination, boolean shallPass) {
InboundSettings settings = new InboundSettings(shallPass);
inboundSettings.put(destination, settings);
LOGGER.log(
Level.DEBUG, "[{0}] Set inbound settings {1} to {2}", address, settings, destination);
LOGGER.debug("[{}] Set inbound settings {} to {}", address, settings, destination);
}

/**
Expand All @@ -233,22 +230,21 @@ public void inboundSettings(String destination, boolean shallPass) {
*/
public void setDefaultInboundSettings(boolean shallPass) {
defaultInboundSettings = new InboundSettings(shallPass);
LOGGER.log(
Level.DEBUG, "[{0}] Set default inbound settings {1}", address, defaultInboundSettings);
LOGGER.debug("[{}] Set default inbound settings {}", address, defaultInboundSettings);
}

/** Blocks inbound messages from all destinations. */
public void blockAllInbound() {
inboundSettings.clear();
setDefaultInboundSettings(false);
LOGGER.log(Level.DEBUG, "[{0}] Blocked inbound from all destinations", address);
LOGGER.debug("[{}] Blocked inbound from all destinations", address);
}

/** Unblocks inbound messages to all destinations. */
public void unblockAllInbound() {
inboundSettings.clear();
setDefaultInboundSettings(true);
LOGGER.log(Level.DEBUG, "[{0}] Unblocked inbound from all destinations", address);
LOGGER.debug("[{}] Unblocked inbound from all destinations", address);
}

/**
Expand All @@ -269,7 +265,7 @@ public void blockInbound(Collection<String> destinations) {
for (String destination : destinations) {
inboundSettings.put(destination, new InboundSettings(false));
}
LOGGER.log(Level.DEBUG, "[{0}] Blocked inbound from {1}", address, destinations);
LOGGER.debug("[{}] Blocked inbound from {}", address, destinations);
}

/**
Expand All @@ -288,7 +284,7 @@ public void unblockInbound(String... destinations) {
*/
public void unblockInbound(Collection<String> destinations) {
destinations.forEach(inboundSettings::remove);
LOGGER.log(Level.DEBUG, "[{0}] Unblocked inbound from {1}", address, destinations);
LOGGER.debug("[{}] Unblocked inbound from {}", address, destinations);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.scalecube.cluster.utils.LoggingExtension
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
junit.jupiter.extensions.autodetection.enabled=true
File renamed without changes.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class NetworkEmulatorTest extends BaseTest {
public class NetworkEmulatorTest {

@Test
public void testResolveLinkSettingsBySocketAddress() {
Expand Down
4 changes: 4 additions & 0 deletions cluster/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
<artifactId>scalecube-cluster-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>

<!-- Test dependencies -->
<dependency>
Expand Down
Loading

0 comments on commit ac03cb8

Please sign in to comment.