From 1f130b551fe504d8c9eac288dd00b16ef1a8e977 Mon Sep 17 00:00:00 2001 From: Phu Dinh Date: Sun, 10 Nov 2024 19:41:30 -0500 Subject: [PATCH 1/2] Revert PR 680 and also Ignore the challenged test --- .../HttpServletResponseTests.java | 48 +++------------ .../httpservletresponse/HttpTestServlet.java | 58 ++++--------------- 2 files changed, 18 insertions(+), 88 deletions(-) diff --git a/tck/tck-runtime/src/main/java/servlet/tck/spec/httpservletresponse/HttpServletResponseTests.java b/tck/tck-runtime/src/main/java/servlet/tck/spec/httpservletresponse/HttpServletResponseTests.java index ec85295d3..94c503141 100644 --- a/tck/tck-runtime/src/main/java/servlet/tck/spec/httpservletresponse/HttpServletResponseTests.java +++ b/tck/tck-runtime/src/main/java/servlet/tck/spec/httpservletresponse/HttpServletResponseTests.java @@ -26,6 +26,7 @@ import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; public class HttpServletResponseTests extends AbstractTckTest { @@ -70,55 +71,20 @@ public void intHeaderTest() throws Exception { } /* - * @testName: flushBufferOnContentLengthTest + * @testName: flushBufferTest * * @assertion_ids: Servlet:SPEC:32; Servlet:SPEC:33; Servlet:SPEC:42.2; * * @test_Strategy: 1. First call setContentLength to set the length of - * content; 2. Write bytes to the expected content length; 3. Call - * setIntHeader to set header; 4. Attempt to write - * additional bytes, expecting an exception to confirm the output stream - * is closed; 5. Verify a 200 response without the header value set. - * 6. Repeat the test to check that the expected exception was thrown - * after the first request. + * content; 2. Then write to the buffer to fill up the buffer. 2. Call + * setIntHeader to set header 3. Verify that the header value is not set, */ + @Disabled @Test - public void flushBufferOnContentLengthTest() throws Exception { - TEST_PROPS.get().setProperty(SAVE_STATE, "true"); + public void flushBufferTest() throws Exception { TEST_PROPS.get().setProperty(UNEXPECTED_HEADERS, "header1: 12345"); TEST_PROPS.get().setProperty(REQUEST, "GET " + getContextRoot() + "/" - + getServletName() + "?testname=" + "flushBufferOnContentLengthTest" + " HTTP/1.1"); - invoke(); - - TEST_PROPS.get().setProperty(USE_SAVED_STATE, "true"); - TEST_PROPS.get().setProperty(UNEXPECTED_HEADERS, "header1: 12345"); - TEST_PROPS.get().setProperty(REQUEST, "GET " + getContextRoot() + "/" - + getServletName() + "?testname=" + "flushBufferOnContentLengthTest" + " HTTP/1.1"); - invoke(); - } - - /* - * @testName: flushBufferOnContentLengthCommittedTest - * - * @assertion_ids: Servlet:SPEC:32; Servlet:SPEC:33; Servlet:SPEC:42.2; - * - * @test_Strategy: 1. First call setContentLength to set the length of - * content; 2. Write some bytes and flush the response; 3. Write - * remaining bytes to the expected content length; 4. Attempt to write - * additional bytes, expecting an exception to confirm the output stream - * is closed; 5. Verify a 200 response; 6. Repeat the test to check that - * the expected exception was thrown after the first request. - */ - @Test - public void flushBufferOnContentLengthCommittedTest() throws Exception { - TEST_PROPS.get().setProperty(SAVE_STATE, "true"); - TEST_PROPS.get().setProperty(REQUEST, "GET " + getContextRoot() + "/" - + getServletName() + "?testname=" + "flushBufferOnContentLengthCommittedTest" + " HTTP/1.1"); - invoke(); - - TEST_PROPS.get().setProperty(USE_SAVED_STATE, "true"); - TEST_PROPS.get().setProperty(REQUEST, "GET " + getContextRoot() + "/" - + getServletName() + "?testname=" + "flushBufferOnContentLengthCommittedTest" + " HTTP/1.1"); + + getServletName() + "?testname=" + "flushBufferTest" + " HTTP/1.1"); invoke(); } diff --git a/tck/tck-runtime/src/main/java/servlet/tck/spec/httpservletresponse/HttpTestServlet.java b/tck/tck-runtime/src/main/java/servlet/tck/spec/httpservletresponse/HttpTestServlet.java index 36b5bc5ab..c8511a91b 100644 --- a/tck/tck-runtime/src/main/java/servlet/tck/spec/httpservletresponse/HttpTestServlet.java +++ b/tck/tck-runtime/src/main/java/servlet/tck/spec/httpservletresponse/HttpTestServlet.java @@ -25,12 +25,8 @@ package servlet.tck.spec.httpservletresponse; import java.io.IOException; -import java.io.OutputStream; import java.io.PrintWriter; -import java.nio.charset.StandardCharsets; -import java.util.Arrays; -import jakarta.servlet.http.HttpSession; import servlet.tck.common.servlets.HttpTCKServlet; import jakarta.servlet.ServletException; @@ -46,54 +42,22 @@ public void intHeaderTest(HttpServletRequest request, response.addIntHeader("header2", 56789); } - public void flushBufferOnContentLengthTest(HttpServletRequest request, + public void flushBufferTest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - HttpSession session = request.getSession(true); - Object illegalStateException = session.getAttribute("IllegalStateException"); - if (illegalStateException instanceof IllegalStateException) - throw (IllegalStateException)illegalStateException; - int size = 40; response.setContentLength(size); - OutputStream out = response.getOutputStream(); - byte[] passed = "Test PASSED\n".getBytes(StandardCharsets.ISO_8859_1); - out.write(passed); - - byte[] fill = new byte[size - passed.length]; - Arrays.fill(fill, (byte) 'x'); - out.write(fill); + PrintWriter pw = response.getWriter(); + pw.println("Test PASSED"); + StringBuffer tmp = new StringBuffer(2 * size); + int i = 0; + + while (i < 8) { + tmp = tmp.append("111111111x"); + i = i + 1; + } + pw.println(tmp); response.addIntHeader("header1", 12345); - - try { - out.write(fill); - session.setAttribute("IllegalStateException", new IllegalStateException("write did not fail")); - } catch (IOException ignored) {} - } - - public void flushBufferOnContentLengthCommittedTest(HttpServletRequest request, - HttpServletResponse response) throws ServletException, IOException { - HttpSession session = request.getSession(true); - Object illegalStateException = session.getAttribute("IllegalStateException"); - if (illegalStateException instanceof IllegalStateException) - throw (IllegalStateException)illegalStateException; - - int size = 40; - response.setContentLength(size); - - OutputStream out = response.getOutputStream(); - byte[] passed = "Test PASSED\n".getBytes(StandardCharsets.ISO_8859_1); - out.write(passed); - response.flushBuffer(); - - byte[] fill = new byte[size - passed.length]; - Arrays.fill(fill, (byte) 'x'); - out.write(fill); - - try { - out.write(fill); - session.setAttribute("IllegalStateException", new IllegalStateException("write did not fail")); - } catch (IOException ignored) {} } public void sendErrorCommitTest(HttpServletRequest request, From 9706b792a8f2f3605db24e524fbdfb78bac8003c Mon Sep 17 00:00:00 2001 From: Phu Dinh Date: Fri, 15 Nov 2024 11:01:28 -0500 Subject: [PATCH 2/2] Update TCK-Exclude-List for doc purpose --- tck/tck-docs/TCK-Exclude-List.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/tck/tck-docs/TCK-Exclude-List.txt b/tck/tck-docs/TCK-Exclude-List.txt index 607e0385e..f3f4302e8 100644 --- a/tck/tck-docs/TCK-Exclude-List.txt +++ b/tck/tck-docs/TCK-Exclude-List.txt @@ -18,3 +18,4 @@ # This is intended only for documentation purpose and is not used to exclude any tests. # The tests are excluded from the test source using @Disabled tag in JUnit framework. # +#servlet/tck/tck-runtime/src/main/java/servlet/tck/spec/httpservletresponse/HttpServletResponseTests.flushBufferTest()