From 0a1eee1c28820265d6bfacf7273af4d628c84ba9 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Fri, 3 Feb 2017 06:25:23 -0700 Subject: [PATCH] Fixing surefire breaking HttpManyWayToCommitTest + Reverting change to HttpTester.parseResponse(Input) + Providing new HttpTester.parsePartialResponse(Input) + InsufficientBytes tests no longer assert content strings with invalid characters (this was breaks the surefire report xml) --- .../org/eclipse/jetty/http/HttpTester.java | 19 ++++++++++++------- .../eclipse/jetty/http/HttpTesterTest.java | 7 +------ .../jetty/server/AbstractHttpTest.java | 2 +- .../server/HttpManyWaysToCommitTest.java | 15 +++++++++------ 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpTester.java b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpTester.java index b33c16c72b6..47206e27746 100644 --- a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpTester.java +++ b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpTester.java @@ -25,7 +25,6 @@ import java.nio.ByteBuffer; import java.nio.channels.ReadableByteChannel; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; -import java.util.Locale; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.IO; @@ -194,7 +193,17 @@ public class HttpTester } public static Response parseResponse(Input in) throws IOException - { + { + return parseResponse(in, false); + } + + public static Response parsePartialResponse(Input in) throws IOException + { + return parseResponse(in, true); + } + + private static Response parseResponse(Input in, boolean allowIncomplete) throws IOException + { Response r; HttpParser parser=in.takeHttpParser(); if (parser==null) @@ -217,13 +226,9 @@ public class HttpTester break; } - if (r.isComplete()) + if (allowIncomplete || r.isComplete()) return r; - String te = r.get(HttpHeader.TRANSFER_ENCODING); - if(te != null && te.toLowerCase(Locale.ENGLISH).contains("chunked")) - return r; - LOG.info("Incomplete Response: (parser={}) {}", parser, r); in.setHttpParser(parser); diff --git a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpTesterTest.java b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpTesterTest.java index c0e642ae887..4ecfaf277ba 100644 --- a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpTesterTest.java +++ b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpTesterTest.java @@ -20,7 +20,7 @@ package org.eclipse.jetty.http; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.*; +import static org.junit.Assert.assertThat; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -30,14 +30,11 @@ import java.net.Socket; import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; -import org.junit.Ignore; import org.junit.Test; public class HttpTesterTest { - @Test - @Ignore public void testExampleUsage() throws Exception { try(Socket socket = new Socket("www.google.com",80)) @@ -59,10 +56,8 @@ public class HttpTesterTest System.err.printf("%s: %s%n",field.getName(),field.getValue()); System.err.printf("%n%s%n",response.getContent()); } - } - @Test public void testGetRequestBuffer10() { diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/AbstractHttpTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/AbstractHttpTest.java index b350d58bfe9..a544816252a 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/AbstractHttpTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/AbstractHttpTest.java @@ -93,7 +93,7 @@ public abstract class AbstractHttpTest writer.flush(); HttpTester.Input input = HttpTester.from(socket.getInputStream()); - HttpTester.Response response = HttpTester.parseResponse(input); + HttpTester.Response response = HttpTester.parsePartialResponse(input); if ("HTTP/1.1".equals(httpVersion) && response.get("content-length") == null && response.get("transfer-encoding") == null diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToCommitTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToCommitTest.java index c5e60c4b34a..f4595070355 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToCommitTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToCommitTest.java @@ -23,6 +23,7 @@ import static org.hamcrest.Matchers.not; import static org.junit.Assert.assertThat; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Collection; @@ -425,11 +426,12 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest try { HttpTester.Response response = executeRequest(); - char badChar = (char) -1; - String failed_body = "" + badChar + badChar + badChar; assertThat("response code", response.getStatus(), is(200)); assertHeader(response, "content-length", "6"); - assertThat(response.getContent(), endsWith(failed_body)); + byte content[] = response.getContentBytes(); + assertThat("content bytes", content.length, is(6)); + String contentStr = new String(content, StandardCharsets.UTF_8); + assertThat("content bytes as string", contentStr, is("foo")); } catch(EOFException e) { @@ -446,11 +448,12 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest try { HttpTester.Response response = executeRequest(); - char badChar = (char) -1; - String failed_body = "" + badChar + badChar + badChar; assertThat("response code is 200", response.getStatus(), is(200)); assertHeader(response, "content-length", "6"); - assertThat(response.getContent(), endsWith(failed_body)); + byte content[] = response.getContentBytes(); + assertThat("content bytes", content.length, is(3)); + String contentStr = new String(content, StandardCharsets.UTF_8); + assertThat("content bytes as string", contentStr, is("foo")); } catch(EOFException e) {