Skip to content

Commit

Permalink
Fixed timing issues in some tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
tfredrich committed May 6, 2016
1 parent 597bb85 commit 5af1eb3
Show file tree
Hide file tree
Showing 8 changed files with 340 additions and 272 deletions.
1 change: 0 additions & 1 deletion common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<name>RestExpress-Common</name>
<description>Utilities and classes common to all RESTExpress projects.</description>
<url>https://github.com/RestExpress/RestExpress-Common</url>
<groupId>com.strategicgains</groupId>
<artifactId>RestExpress-Common</artifactId>
<packaging>jar</packaging>

Expand Down
1 change: 0 additions & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<name>RestExpress</name>
<description>Internet scale, high-performance RESTful Services in Java</description>
<url>https://github.com/RestExpress/RestExpress</url>
<groupId>com.strategicgains</groupId>
<artifactId>RestExpress</artifactId>
<packaging>jar</packaging>

Expand Down
19 changes: 13 additions & 6 deletions core/src/test/java/org/restexpress/AltRestExpressServerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpResponseStatus;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -22,13 +20,13 @@
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpHead;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.BasicHttpEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.junit.After;
Expand All @@ -45,6 +43,10 @@
import org.restexpress.serialization.json.JacksonJsonProcessor;
import org.restexpress.serialization.xml.XstreamXmlProcessor;

import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpResponseStatus;

public class AltRestExpressServerTest
{
private static final int DEFAULT_PORT = 8801;
Expand Down Expand Up @@ -73,7 +75,7 @@ public class AltRestExpressServerTest
private static final String URL_EXCEPTION_LITTLE_O = SERVER_HOST + PATTERN_EXCEPTION_LITTLE_O;
private static final String URL_ECHO = SERVER_HOST + ECHO_PATTERN;

private static final HttpClient CLIENT = new DefaultHttpClient();
private static final CloseableHttpClient CLIENT = new DefaultHttpClient();
private static final AbstractSerializationProvider DEFAULT_SERIALIZER = new NullSerializationProvider();

static
Expand All @@ -94,7 +96,7 @@ public class AltRestExpressServerTest
public RestExpress createServer()
{
RestExpress server = new RestExpress();
RestExpress.setSerializationProvider(DEFAULT_SERIALIZER);
RestExpress.setDefaultSerializationProvider(DEFAULT_SERIALIZER);
StringTestController stringTestController = new StringTestController();
ObjectTestController objectTestController = new ObjectTestController();
EchoTestController echoTestController = new EchoTestController();
Expand Down Expand Up @@ -129,6 +131,7 @@ public RestExpress createServer()

@Before
public void ensureServerRunning()
throws InterruptedException
{
POSTPROCESSOR.resetCallCount();
ERROR_PREPROCESSOR.shouldThrow(false);
Expand All @@ -137,6 +140,8 @@ public void ensureServerRunning()
{
SERVER = createServer();
SERVER.bind(DEFAULT_PORT);

Thread.sleep(500L);
}
}

Expand All @@ -148,7 +153,9 @@ public void afterTest()

@AfterClass
public static void shutdownServer()
throws IOException
{
CLIENT.close();
SERVER.shutdown(true);
}

Expand Down
3 changes: 3 additions & 0 deletions core/src/test/java/org/restexpress/RestExpressServerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,14 @@ public RestExpress createServer()

@Before
public void ensureServerRunning()
throws InterruptedException
{
if (SERVER == null)
{
SERVER = createServer();
SERVER.bind(DEFAULT_PORT);

Thread.sleep(500L);
}
}

Expand Down
Loading

0 comments on commit 5af1eb3

Please sign in to comment.