Skip to content

Commit

Permalink
Issue jetty#2918 restore a TestTracker with junit5 (jetty#2927)
Browse files Browse the repository at this point in the history
* add TestTracker junit5 extension jetty#2918

Signed-off-by: olivier lamy <[email protected]>
  • Loading branch information
olamy authored Sep 21, 2018
1 parent a9566d4 commit 71a1801
Show file tree
Hide file tree
Showing 15 changed files with 126 additions and 137 deletions.
4 changes: 2 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def getFullBuild(jdk, os) {
//options: [invokerPublisher(disabled: false)],
mavenOpts: mavenOpts,
mavenLocalRepo: localRepo) {
sh "mvn -V -B install -Dmaven.test.failure.ignore=true -e -Pmongodb -T3 -Dunix.socket.tmp="+env.JENKINS_HOME
sh "mvn -V -B install -Dmaven.test.failure.ignore=true -e -Pmongodb -T3 -Djetty.testtracker.log=true -Dunix.socket.tmp="+env.JENKINS_HOME
}
// withMaven doesn't label..
// Report failures in the jenkins UI
Expand Down Expand Up @@ -137,7 +137,7 @@ def getFullBuild(jdk, os) {
globalMavenSettingsConfig: settingsName,
mavenOpts: mavenOpts,
mavenLocalRepo: localRepo) {
sh "mvn -f aggregates/jetty-all-compact3 -V -B -Pcompact3 clean install -T5"
sh "mvn -f aggregates/jetty-all-compact3 -V -B -Pcompact3 clean install -T6"
}
}
} catch(Exception e) {
Expand Down
3 changes: 3 additions & 0 deletions jetty-osgi/test-jetty-osgi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,15 @@
<artifactId>pax-exam-junit4</artifactId>
<version>${exam.version}</version>
<scope>test</scope>
<!-- not anymore as others tests use junit 5 -->
<!--
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
-->
</dependency>
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.fail;


public class CookiePatternRuleTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;


import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;
Expand All @@ -38,7 +37,8 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.junit.Assert.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.*;

public class CustomResourcesMonitorTest
{
Expand Down Expand Up @@ -111,28 +111,14 @@ public void testFileOnDirectoryMonitor() throws Exception
InputStream input1 = socket1.getInputStream();

assertTrue(_fileOnDirectoryMonitor.isLowOnResources());
try
{
input1.read();
fail();
}
catch (SocketTimeoutException expected)
{
}
assertThrows(SocketTimeoutException.class, () -> input1.read());

// Wait a couple of lowResources idleTimeouts.
Thread.sleep(2 * lowResourcesIdleTimeout);

// Verify the new socket is still open.
assertTrue(_fileOnDirectoryMonitor.isLowOnResources());
try
{
input1.read();
fail();
}
catch (SocketTimeoutException expected)
{
}
assertThrows(SocketTimeoutException.class, () -> input1.read());

Files.delete( tmpFile );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.eclipse.jetty.util.thread.TimerScheduler;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
Expand All @@ -38,7 +39,6 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.*;

public class LowResourcesMonitorTest
Expand Down Expand Up @@ -248,28 +248,15 @@ public void testMaxLowResourcesTime() throws Exception
InputStream input1 = socket1.getInputStream();

assertTrue(_lowResourcesMonitor.isLowOnResources());
try
{
input1.read();
fail();
}
catch (SocketTimeoutException expected)
{
}
assertThrows( SocketTimeoutException.class, () -> input1.read());

// Wait a couple of lowResources idleTimeouts.
Thread.sleep(2 * lowResourcesIdleTimeout);

// Verify the new socket is still open.
assertTrue(_lowResourcesMonitor.isLowOnResources());
try
{
input1.read();
fail();
}
catch (SocketTimeoutException expected)
{
}
assertThrows( SocketTimeoutException.class, () -> input1.read());

// Let the maxLowResourcesTime elapse.
Thread.sleep(maxLowResourcesTime);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,26 @@

package org.eclipse.jetty.servlet;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalToIgnoringCase;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.eclipse.jetty.http.HttpTester;
import org.eclipse.jetty.server.LocalConnector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.gzip.GzipHandler;
import org.eclipse.jetty.util.IO;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import javax.servlet.DispatcherType;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
Expand All @@ -40,22 +51,9 @@
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;

import javax.servlet.*;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.eclipse.jetty.http.HttpTester;
import org.eclipse.jetty.server.Dispatcher;
import org.eclipse.jetty.server.LocalConnector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.gzip.GzipHandler;
import org.eclipse.jetty.util.IO;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.jupiter.api.Assertions.assertEquals;

@SuppressWarnings("serial")
public class GzipHandlerTest
Expand Down Expand Up @@ -616,9 +614,9 @@ public void init(FilterConfig filterConfig) throws ServletException
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
{
if (request.getParameter("X-Content-Encoding")!=null)
Assert.assertEquals(-1,request.getContentLength());
assertEquals(-1,request.getContentLength());
else if (request.getContentLength()>=0)
Assert.assertThat(request.getParameter("X-Content-Encoding"),Matchers.nullValue());
assertThat(request.getParameter("X-Content-Encoding"),Matchers.nullValue());
chain.doFilter(request,response);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assume.assumeTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assumptions.assumeTrue;

import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
import org.junit.jupiter.api.Test;

import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;



/* ------------------------------------------------------------ */
Expand Down
6 changes: 5 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
<weld.version>2.4.5.Final</weld.version>
<jetty.perf-helper.version>1.0.5</jetty.perf-helper.version>
<unix.socket.tmp></unix.socket.tmp>
<!-- enable or not TestTracker junit5 extension i.e log message when test method is starting -->
<jetty.testtracker.log>false</jetty.testtracker.log>

<!-- some maven plugins versions -->
<maven.surefire.version>2.22.0</maven.surefire.version>
Expand All @@ -49,7 +51,7 @@


<!-- testing -->
<jetty.test.version>5.0</jetty.test.version>
<jetty.test.version>5.1</jetty.test.version>
</properties>

<licenses>
Expand Down Expand Up @@ -647,6 +649,8 @@
<systemPropertyVariables>
<java.io.tmpdir>${project.build.directory}</java.io.tmpdir>
<unix.socket.tmp>${unix.socket.tmp}</unix.socket.tmp>
<junit.jupiter.extensions.autodetection.enabled>true</junit.jupiter.extensions.autodetection.enabled>
<jetty.testtracker.log>${jetty.testtracker.log}</jetty.testtracker.log>
</systemPropertyVariables>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public JettyDistro(Class<?> clazz) throws IOException
*/
public JettyDistro(Class<?> clazz, String artifact) throws IOException
{
this.jettyHomeDir = MavenTestingUtils.getTargetTestingDir(clazz,"jettyHome");
this.jettyHomeDir = MavenTestingUtils.getTargetTestingPath(clazz,"jettyHome").toFile();
if (artifact != null)
{
this.artifactName = artifact;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.eclipse.jetty.server.session.AbstractClusteredOrphanedSessionTest;
import org.eclipse.jetty.server.session.SessionDataStoreFactory;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

/**
Expand All @@ -32,10 +33,25 @@
public class ClusteredOrphanedSessionTest extends AbstractClusteredOrphanedSessionTest
{

public static GCloudSessionTestSupport __testSupport;

@BeforeAll
public static void setUp () throws Exception
{
__testSupport = new GCloudSessionTestSupport();
__testSupport.setUp();
}

@AfterAll
public static void tearDown () throws Exception
{
__testSupport.tearDown();
}

@AfterAll
public static void teardown () throws Exception
{
GCloudTestSuite.__testSupport.deleteSessions();
__testSupport.deleteSessions();
}


Expand All @@ -46,7 +62,7 @@ public static void teardown () throws Exception
@Override
public SessionDataStoreFactory createSessionDataStoreFactory()
{
return GCloudSessionTestSupport.newSessionDataStoreFactory(GCloudTestSuite.__testSupport.getDatastore());
return GCloudSessionTestSupport.newSessionDataStoreFactory(__testSupport.getDatastore());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.eclipse.jetty.server.session.AbstractClusteredSessionScavengingTest;
import org.eclipse.jetty.server.session.SessionDataStoreFactory;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;

/**
* ClusteredSessionScavengingTest
Expand All @@ -30,11 +31,26 @@
*/
public class ClusteredSessionScavengingTest extends AbstractClusteredSessionScavengingTest
{


public static GCloudSessionTestSupport __testSupport;

@BeforeAll
public static void setUp () throws Exception
{
__testSupport = new GCloudSessionTestSupport();
__testSupport.setUp();
}

@AfterAll
public static void tearDown () throws Exception
{
__testSupport.tearDown();
}

@AfterAll
public static void teardown () throws Exception
{
GCloudTestSuite.__testSupport.deleteSessions();
__testSupport.deleteSessions();
}


Expand All @@ -44,7 +60,7 @@ public static void teardown () throws Exception
@Override
public SessionDataStoreFactory createSessionDataStoreFactory()
{
return GCloudSessionTestSupport.newSessionDataStoreFactory(GCloudTestSuite.__testSupport.getDatastore());
return GCloudSessionTestSupport.newSessionDataStoreFactory(__testSupport.getDatastore());
}


Expand Down
Loading

0 comments on commit 71a1801

Please sign in to comment.