Skip to content

Commit

Permalink
migrate logback-classic to Junit 5, LOGBACK-1687
Browse files Browse the repository at this point in the history
Signed-off-by: Ceki Gulcu <ceki@qos.ch>
  • Loading branch information
ceki committed Sep 27, 2022
1 parent 311cc34 commit 4ba8cc1
Show file tree
Hide file tree
Showing 99 changed files with 563 additions and 504 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,15 @@
import ch.qos.logback.access.spi.IAccessEvent;
import junit.framework.TestCase;
import ch.qos.logback.access.dummy.DummyAccessEventBuilder;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

public class SerializationPerfTest extends TestCase {
import static org.junit.jupiter.api.Assertions.fail;

@Disabled
public class SerializationPerfTest {

ObjectOutputStream oos;

Expand All @@ -29,18 +36,18 @@ public class SerializationPerfTest extends TestCase {
int pauseFrequency = 10;
long pauseLengthInMillis = 20;

@BeforeEach
public void setUp() throws Exception {
super.setUp();
oos = new ObjectOutputStream(new NOPOutputStream());

}

@AfterEach
public void tearDown() throws Exception {
super.tearDown();
oos.close();
oos = null;
}

@Test
public void test1() throws Exception {
// first run for just in time compiler
int resetCounter = 0;
Expand Down
104 changes: 54 additions & 50 deletions logback-classic/integration.xml
Original file line number Diff line number Diff line change
@@ -1,65 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="integration" default="testAll" basedir=".">

<!--
This build file is usually run indirectly via Maven.
When running this build file through Ant directly, you must
define the slf4jVersion property on the command line, e.g.:
ant -Dslf4jVersion=1.5.4-SNAPSHOT
-->
<!--
This build file is usually run indirectly via Maven.
<echo message="project.version: ${project.version}" />
<echo message="slf4j.version: ${slf4j.version}" />
<echo message="hamcrest: ${org.hamcrest:hamcrest-core:jar}" />

<path id="basicClasspath">
<!-- post junit version 4.12, we need to add hamcrest manually to the
classpath, even though the m-ant-plugin declares a dependency on hamcrest! -->
<pathelement location="${org.hamcrest:hamcrest-core:jar}" />
<pathelement location="../logback-core/target/logback-core-${project.version}.jar/" />
<pathelement location="../logback-core/target/test-classes/" />
<pathelement location="./target/classes/" />
<pathelement location="./target/test-classes/" />
<pathelement location="./lib/slf4j-api-${slf4j.version}.jar" />
<pathelement location="./src/test/input/integration/autoInit/" />
</path >
When running this build file through Ant directly, you must
define the slf4jVersion property on the command line, e.g.:
ant -Dslf4j.version=2.0.2-SNAPSHOT
-->

<target name="testAll" depends="init, testWithoutGroovy"
unless="maven.test.skip">
</target>
<echo message="project.version: ${project.version}"/>
<echo message="project.build.outputDirectory: ${project.build.outputDirectory}"/>
<echo message="project.build.testOutputDirectory: ${project.build.testOutputDirectory}"/>
<echo message="project.build.directory: ${project.build.directory}"/>

<target name="init" depends="copySLF4J_JAR">
<echo message="in init"/>
<mkdir dir="target/unit-reports" />
</target>

<target name="copySLF4J_JAR">
<echo>Making lib/ folder in case it does not already exist.</echo>
<mkdir dir="lib/"/>
<echo>Copying ${org.slf4j:slf4j-api:jar} to lib/</echo>
<!-- sneak in a cleanup procedure of the ../logback-examples/lib/ folder-->
<delete quiet="true">
<fileset dir="../logback-examples/lib/" includes="slf4j-*SNAPSHOT.jar" />
</delete>
<copy file="${org.slf4j:slf4j-api:jar}" todir="lib/" />
</target>

<echo message="slf4j.version: ${slf4j.version}"/>
<echo message="hamcrest: ${org.hamcrest:hamcrest-core:jar}"/>

<target name="testWithoutGroovy" unless="maven.test.skip">
<junit printsummary="yes" fork="no" haltonfailure="yes">
<classpath refid="basicClasspath" />
<formatter type="plain" />
<test fork="yes" todir="target/unit-reports"
outfile="TEST-NoGroovy"
name="ch.qos.logback.classic.util.InitializationIntegrationTest" />
</junit>
</target>
<path id="basicClasspath">
<!-- post junit version 4.12, we need to add hamcrest manually to the
classpath, even though the m-ant-plugin declares a dependency on hamcrest! -->
<pathelement location="${org.hamcrest:hamcrest-core:jar}"/>
<pathelement location="../logback-core/target/logback-core-${project.version}.jar/"/>
<pathelement location="../logback-core/target/test-classes/"/>
<pathelement location="${project.build.outputDirectory}"/>
<pathelement location="${project.build.testOutputDirectory}"/>
<pathelement location="./lib/slf4j-api-${slf4j.version}.jar"/>
<pathelement location="./src/test/input/integration/autoInit/"/>
</path>


<target name="testAll" depends="init, testWithoutGroovy"
unless="maven.test.skip">
</target>

<target name="init" depends="">
<echo message="in init"/>
<echo message="Making target/unit-reports folder"/>
<mkdir dir="${project.build.directory}/unit-reports"/>
</target>

<target name="copySLF4J_JAR">
<echo>Making lib/ folder in case it does not already exist.</echo>
<mkdir dir="lib/"/>
<echo>Copying ${org.slf4j:slf4j-api:jar} to lib/</echo>
<!-- sneak in a cleanup procedure of the ../logback-examples/lib/ folder-->
<delete quiet="true">
<fileset dir="../logback-examples/lib/" includes="slf4j-*SNAPSHOT.jar"/>
</delete>
<copy file="${org.slf4j:slf4j-api:jar}" todir="lib/"/>
</target>


<target name="testWithoutGroovy" unless="maven.test.skip">
<junitlauncher printsummary="yes" haltonfailure="yes">
<classpath refid="basicClasspath"/>
<listener type="legacy-plain" sendSysOut="true" sendSysErr="true"/>
<test name="ch.qos.logback.classic.util.InitializationIntegrationTest"
outputdir="${project.build.directory}/unit-reports" >
<listener type="legacy-plain"/>
</test>
</junitlauncher>
</target>


</project>
42 changes: 28 additions & 14 deletions logback-classic/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
<scope>runtime</scope>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.codehaus.janino</groupId>
<artifactId>janino</artifactId>
Expand Down Expand Up @@ -137,14 +137,14 @@
</resources>

<plugins>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<X-Compile-Source-JDK>${maven.compiler.source}</X-Compile-Source-JDK>
<X-Compile-Source-JDK>${maven.compiler.source}</X-Compile-Source-JDK>
<X-Compile-Target-JDK>${maven.compiler.target}</X-Compile-Target-JDK>
<Multi-Release>true</Multi-Release>
</manifestEntries>
Expand All @@ -167,31 +167,45 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<version>${maven-antrun-plugin.version}</version>
<dependencies>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-junit</artifactId>
<version>1.9.0</version>
<version>${ant.version}</version>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-junitlauncher</artifactId>
<version>${ant.version}</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit-jupiter-api.version}</version>
</dependency>


<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit-vintage-engine.version}</version>
</dependency>

<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>${hamcrest.version}</version>
</dependency>

</dependencies>

<executions>
<!-- Disabled osgi tests given current OSGi/ServiceLoader integration failure -->
<!--
<!--
<execution>
<id>ant-osgi-test</id>
<phase>package</phase>
<configuration>
Expand Down Expand Up @@ -305,10 +319,10 @@
</Import-Package>
<Bundle-RequiredExecutionEnvironment>JavaSE-1.6</Bundle-RequiredExecutionEnvironment>
<!-- Needed to integrate ServiceLoader mechanism with OSGi -->
<Require-Capability>osgi.extender; filter:="(osgi.extender=osgi.serviceloader.registrar)"</Require-Capability>
<Require-Capability>osgi.extender; filter:="(osgi.extender=osgi.serviceloader.registrar)"</Require-Capability>
<Provide-Capability>osgi.serviceloader;osgi.serviceloader=org.slf4j.spi.SLF4JServiceProvider</Provide-Capability>


</instructions>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import ch.qos.logback.core.read.ListAppender;
import ch.qos.logback.core.status.OnConsoleStatusListener;
import ch.qos.logback.core.testUtil.RandomUtil;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.MDC;

import static org.junit.Assert.*;
Expand All @@ -40,7 +40,7 @@ public class AsyncAppenderTest {
UnsynchronizedAppenderBase.class.getName());
int diff = RandomUtil.getPositiveInt();

@Before
@BeforeEach
public void setUp() {
onConsoleStatusListener.setContext(context);
context.getStatusManager().add(onConsoleStatusListener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
import java.util.ArrayList;
import java.util.List;

import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;

import ch.qos.logback.classic.pattern.ConverterTest;
import ch.qos.logback.classic.pattern.LineOfCallerConverter;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.AppenderBase;
import ch.qos.logback.core.pattern.DynamicConverter;
import org.junit.jupiter.api.Test;

public class FluentAPILocationExtractionTest {
static public class WithLocationInfoListAppender extends AppenderBase<ILoggingEvent> {
Expand All @@ -43,15 +43,15 @@ protected void append(ILoggingEvent e) {
Logger logger = lc.getLogger(ConverterTest.class);
WithLocationInfoListAppender wlila = new WithLocationInfoListAppender();

@Before
@BeforeEach
public void setUp() {
wlila.setContext(lc);
wlila.start();

logger.addAppender(wlila);
}

@Test
@Test
public void smoke() {
logger.addAppender(wlila);
// line number to retain is the next line's number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static org.junit.Assert.assertEquals;

import org.junit.Test;
import org.junit.jupiter.api.Test;

public class LevelTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
package ch.qos.logback.classic;

import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.TimeUnit;

import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import ch.qos.logback.core.contention.AbstractMultiThreadedHarness;
import ch.qos.logback.core.contention.RunnableWithCounterAndDone;
import ch.qos.logback.core.testUtil.StatusChecker;
import org.junit.jupiter.api.Timeout;

@Ignore
@Disabled
public class LoggerContextConcurrentResetTest {
static int CONCURRENT_RESET_THREAD_COUNT = 10;

// see http://jira.qos.ch/browse/LOGBACK-397
@Test(timeout = 1000)
@Test
@Timeout(value = 1)
public void concurrentReset() throws InterruptedException {
LoggerContext loggerContext = new LoggerContext();
CyclicBarrier cyclicBarrier = new CyclicBarrier(CONCURRENT_RESET_THREAD_COUNT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,33 @@
package ch.qos.logback.classic;

import java.io.ByteArrayInputStream;
import java.util.concurrent.TimeUnit;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import ch.qos.logback.classic.joran.JoranConfigurator;
import ch.qos.logback.core.joran.spi.JoranException;
import org.junit.jupiter.api.Timeout;

public class LoggerContextDeadlockTest {

LoggerContext loggerContext = new LoggerContext();
JoranConfigurator jc = new JoranConfigurator();
GetLoggerThread getLoggerThread = new GetLoggerThread(loggerContext);

@Before
@BeforeEach
public void setUp() throws Exception {
jc.setContext(loggerContext);
}

@After
@AfterEach
public void tearDown() throws Exception {
}

@Test(timeout = 20000)
@Test
@Timeout(value = 20, unit= TimeUnit.SECONDS)
public void testLBCLASSIC_81() throws JoranException {

getLoggerThread.start();
Expand Down

0 comments on commit 4ba8cc1

Please sign in to comment.