Skip to content

Commit

Permalink
Remove log4j1 from bk test code
Browse files Browse the repository at this point in the history
### Motivation
this is a part work of remove log4j1 from bookeeper, first remove it from our test code, unit test and integrate test

### Changes
- remove log4j1 scope test dependency
- use log4j2.xml instread of log4j.properties
- introduce testtools module to reduce duplication,  if a module needs particular configuration (very unlikely) we can add a log4j2-test.xml file which has precedence over log4j2.xml one. idea from [nicoloboschi](https://github.com/nicoloboschi)

Reviewers: Andrey Yegorov <None>, Enrico Olivelli <eolivelli@gmail.com>, Nicolò Boschi <boschi1997@gmail.com>

This closes apache#3208 from Shoothzj/remove-log4j1-from-bk-test-code2
  • Loading branch information
ZhangJian He authored Apr 19, 2022
1 parent 7c89303 commit 760b9e0
Show file tree
Hide file tree
Showing 70 changed files with 276 additions and 935 deletions.
17 changes: 11 additions & 6 deletions bookkeeper-benchmark/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.bookkeeper</groupId>
<artifactId>bookkeeper-server</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.bookkeeper</groupId>
<artifactId>testtools</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
Expand All @@ -61,12 +72,6 @@
<artifactId>metrics-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.bookkeeper</groupId>
<artifactId>bookkeeper-server</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.bookkeeper</groupId>
<artifactId>bookkeeper-common</artifactId>
Expand Down
72 changes: 0 additions & 72 deletions bookkeeper-benchmark/src/test/resources/log4j.properties

This file was deleted.

1 change: 0 additions & 1 deletion bookkeeper-common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ dependencies {
testImplementation depLibs.hamcrest
testImplementation depLibs.junit
testImplementation depLibs.log4jSlf4jImpl
testImplementation depLibs.log4j12api
testImplementation depLibs.log4jCore
testImplementation depLibs.mockito

Expand Down
17 changes: 6 additions & 11 deletions bookkeeper-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,15 @@
<artifactId>rxjava</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<groupId>org.apache.bookkeeper</groupId>
<artifactId>testtools</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-1.2-api</artifactId>
<version>${log4j.version}</version>
<scope>test</scope> <!-- There are tests that rely on this binding in their test logic -->
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.TimeUnit;

import org.apache.log4j.MDC;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.ThreadContext;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.appender.NullAppender;
Expand All @@ -62,7 +62,7 @@ public static String mdcFormat(Object mdc, String message) {

@Before
public void setUp() throws Exception {
MDC.clear();
ThreadContext.clearMap();
LoggerContext lc = (LoggerContext) org.apache.logging.log4j.LogManager.getContext(false);
mockAppender = spy(NullAppender.createAppender(UUID.randomUUID().toString()));
mockAppender.start();
Expand All @@ -83,7 +83,7 @@ public void tearDown() throws Exception {
lc.getRootLogger().removeAppender(lc.getConfiguration().getAppender(mockAppender.getName()));
lc.updateLoggers();
capturedEvents.clear();
MDC.clear();
ThreadContext.clearMap();
}

@Test
Expand All @@ -92,7 +92,7 @@ public void testMDCInvokeOrdered() throws Exception {
.name("test").numThreads(20).preserveMdcForTaskExecution(true).build();

try {
MDC.put(MDC_KEY, "testMDCInvokeOrdered");
ThreadContext.put(MDC_KEY, "testMDCInvokeOrdered");
executor.submitOrdered(10, () -> {
log.info("foobar");
return 10;
Expand All @@ -110,7 +110,7 @@ public void testMDCInvokeDirectOnChosen() throws Exception {
.name("test").numThreads(20).preserveMdcForTaskExecution(true).build();

try {
MDC.put(MDC_KEY, "testMDCInvokeOrdered");
ThreadContext.put(MDC_KEY, "testMDCInvokeOrdered");
executor.chooseThread(10).submit(() -> {
log.info("foobar");
return 10;
Expand All @@ -130,7 +130,7 @@ public void testMDCScheduleOrdered() throws Exception {
.name("test").numThreads(20).preserveMdcForTaskExecution(true).build();

try {
MDC.put(MDC_KEY, "testMDCInvokeOrdered");
ThreadContext.put(MDC_KEY, "testMDCInvokeOrdered");
scheduler.scheduleOrdered(10, safeRun(() -> {
log.info("foobar");
}), 0, TimeUnit.DAYS).get();
Expand All @@ -147,7 +147,7 @@ public void testMDCScheduleDirectOnChosen() throws Exception {
.name("test").numThreads(20).preserveMdcForTaskExecution(true).build();

try {
MDC.put(MDC_KEY, "testMDCInvokeOrdered");
ThreadContext.put(MDC_KEY, "testMDCInvokeOrdered");
scheduler.chooseThread(10).schedule(safeRun(() -> {
log.info("foobar");
}), 0, TimeUnit.DAYS).get();
Expand Down
42 changes: 0 additions & 42 deletions bookkeeper-common/src/test/resources/log4j.properties

This file was deleted.

4 changes: 2 additions & 2 deletions bookkeeper-dist/src/main/resources/LICENSE-all.bin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ Apache Software License, Version 2.
- lib/io.dropwizard.metrics-metrics-jvm-3.2.5.jar [47]
- lib/io.perfmark-perfmark-api-0.23.0.jar [48]
- lib/org.conscrypt-conscrypt-openjdk-uber-2.5.1.jar [49]
- lib/org.xerial.snappy-snappy-java-1.1.7.jar [50]
- lib/org.xerial.snappy-snappy-java-1.1.7.7.jar [50]
- lib/io.reactivex.rxjava3-rxjava-3.0.1.jar [51]

[1] Source available at https://github.com/FasterXML/jackson-annotations/tree/jackson-annotations-2.11.0
Expand Down Expand Up @@ -360,7 +360,7 @@ Apache Software License, Version 2.
[47] Source available at https://github.com/dropwizard/metrics/releases/tag/v3.2.5
[48] Source available at https://github.com/perfmark/perfmark/releases/tag/v0.23.0
[49] Source available at https://github.com/google/conscrypt/releases/tag/2.5.1
[50] Source available at https://github.com/google/snappy/releases/tag/1.1.7
[50] Source available at https://github.com/google/snappy/releases/tag/1.1.7.7
[51] Source available at https://github.com/ReactiveX/RxJava/tree/v3.0.1

------------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions bookkeeper-dist/src/main/resources/LICENSE-bkctl.bin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ Apache Software License, Version 2.
- lib/io.dropwizard.metrics-metrics-core-3.2.5.jar [46]
- lib/io.perfmark-perfmark-api-0.23.0.jar [47]
- lib/org.conscrypt-conscrypt-openjdk-uber-2.5.1.jar [49]
- lib/org.xerial.snappy-snappy-java-1.1.7.jar [50]
- lib/org.xerial.snappy-snappy-java-1.1.7.7.jar [50]
- lib/io.reactivex.rxjava3-rxjava-3.0.1.jar [51]

[1] Source available at https://github.com/FasterXML/jackson-annotations/tree/jackson-annotations-2.11.0
Expand Down Expand Up @@ -329,7 +329,7 @@ Apache Software License, Version 2.
[46] Source available at https://github.com/dropwizard/metrics/releases/tag/v3.1.0
[47] Source available at https://github.com/perfmark/perfmark/releases/tag/v0.23.0
[49] Source available at https://github.com/google/conscrypt/releases/tag/2.5.1
[50] Source available at https://github.com/google/snappy/releases/tag/1.1.7
[50] Source available at https://github.com/google/snappy/releases/tag/1.1.7.7
[51] Source available at https://github.com/ReactiveX/RxJava/tree/v3.0.1

------------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions bookkeeper-dist/src/main/resources/LICENSE-server.bin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ Apache Software License, Version 2.
- lib/io.dropwizard.metrics-metrics-core-3.2.5.jar [47]
- lib/io.perfmark-perfmark-api-0.23.0.jar [48]
- lib/org.conscrypt-conscrypt-openjdk-uber-2.5.1.jar [49]
- lib/org.xerial.snappy-snappy-java-1.1.7.jar [50]
- lib/org.xerial.snappy-snappy-java-1.1.7.7.jar [50]
- lib/io.reactivex.rxjava3-rxjava-3.0.1.jar [51]

[1] Source available at https://github.com/FasterXML/jackson-annotations/tree/jackson-annotations-2.11.0
Expand Down Expand Up @@ -358,7 +358,7 @@ Apache Software License, Version 2.
[47] Source available at https://github.com/dropwizard/metrics/releases/tag/v3.2.5
[48] Source available at https://github.com/perfmark/perfmark/releases/tag/v0.23.0
[49] Source available at https://github.com/google/conscrypt/releases/tag/2.5.1
[50] Source available at https://github.com/google/snappy/releases/tag/1.1.7
[50] Source available at https://github.com/google/snappy/releases/tag/1.1.7.7
[51] Source available at https://github.com/ReactiveX/RxJava/tree/v3.0.1

------------------------------------------------------------------------------------
Expand Down
4 changes: 0 additions & 4 deletions bookkeeper-http/http-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@
<name>Apache BookKeeper :: Http :: Http Server</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion bookkeeper-server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ dependencies {
runtimeOnly depLibs.metricsCore
runtimeOnly depLibs.snappy

testImplementation project(':testtools')
testImplementation project(':bookkeeper-stats-providers:prometheus-metrics-provider')
testImplementation project(':bookkeeper-http:vertx-http-server')
testImplementation project(path: ':bookkeeper-common', configuration: 'testArtifacts')
Expand All @@ -76,7 +77,6 @@ dependencies {
annotationProcessor depLibs.lombok
testAnnotationProcessor depLibs.lombok
testImplementation depLibs.log4jSlf4jImpl
testImplementation depLibs.log4j12api
testImplementation depLibs.log4jCore
}

Expand Down
8 changes: 4 additions & 4 deletions bookkeeper-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@
<artifactId>rocksdbjni</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-1.2-api</artifactId>
<version>${log4j.version}</version>
<scope>test</scope> <!-- There are tests that rely on this binding in their test logic -->
<groupId>org.apache.bookkeeper</groupId>
<artifactId>testtools</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest(SyncThread.class)
@PowerMockIgnore("javax.*")
@PowerMockIgnore({"java.*", "javax.*", "org.slf4j.*"})
public class LedgerStorageCheckpointTest {
private static final Logger LOG = LoggerFactory
.getLogger(LedgerStorageCheckpointTest.class);
Expand Down
Loading

0 comments on commit 760b9e0

Please sign in to comment.