diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/ConnectionPoolTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/ConnectionPoolTest.java index dd8479061a6e..c296014e0060 100644 --- a/jetty-client/src/test/java/org/eclipse/jetty/client/ConnectionPoolTest.java +++ b/jetty-client/src/test/java/org/eclipse/jetty/client/ConnectionPoolTest.java @@ -379,7 +379,7 @@ public void resolve(String host, int port, Promise> prom @MethodSource("pools") public void testConcurrentRequestsAllBlockedOnServerWithLargeConnectionPool(ConnectionPoolFactory factory) throws Exception { - int count = 50; + int count = 10; testConcurrentRequestsAllBlockedOnServer(factory, count, 2 * count); } @@ -387,7 +387,7 @@ public void testConcurrentRequestsAllBlockedOnServerWithLargeConnectionPool(Conn @MethodSource("pools") public void testConcurrentRequestsAllBlockedOnServerWithExactConnectionPool(ConnectionPoolFactory factory) throws Exception { - int count = 50; + int count = 10; testConcurrentRequestsAllBlockedOnServer(factory, count, count); } @@ -441,10 +441,12 @@ protected void service(String target, org.eclipse.jetty.server.Request jettyRequ { if (result.isSucceeded()) latch.countDown(); + else + result.getFailure().printStackTrace(); })); } - assertTrue(latch.await(5, TimeUnit.SECONDS), "server requests " + barrier.getNumberWaiting() + "<" + count + " - client: " + client.dump()); + assertTrue(latch.await(15, TimeUnit.SECONDS), "server requests " + barrier.getNumberWaiting() + "<" + count + " - client: " + client.dump()); List destinations = client.getDestinations(); assertEquals(1, destinations.size()); // The max duration connection pool aggressively closes expired connections upon release, which interferes with this assertion. diff --git a/jetty-http2/http2-client/src/test/java/org/eclipse/jetty/http2/client/StreamCloseTest.java b/jetty-http2/http2-client/src/test/java/org/eclipse/jetty/http2/client/StreamCloseTest.java index 5dc0beb00c91..1cd02492f09b 100644 --- a/jetty-http2/http2-client/src/test/java/org/eclipse/jetty/http2/client/StreamCloseTest.java +++ b/jetty-http2/http2-client/src/test/java/org/eclipse/jetty/http2/client/StreamCloseTest.java @@ -14,6 +14,7 @@ package org.eclipse.jetty.http2.client; import java.nio.ByteBuffer; +import java.time.Duration; import java.util.ArrayList; import java.util.List; import java.util.concurrent.CountDownLatch; @@ -38,6 +39,8 @@ import org.eclipse.jetty.util.Promise; import org.junit.jupiter.api.Test; +import static org.awaitility.Awaitility.await; +import static org.hamcrest.Matchers.equalTo; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -179,7 +182,7 @@ public void succeeded() assertTrue(serverDataLatch.await(5, TimeUnit.SECONDS)); assertTrue(completeLatch.await(5, TimeUnit.SECONDS)); assertTrue(stream.isClosed()); - assertEquals(0, stream.getSession().getStreams().size()); + await().atMost(Duration.ofSeconds(5)).until(() -> stream.getSession().getStreams().size(), equalTo(0)); } @Test diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/MultiPartInputStreamParser.java b/jetty-server/src/main/java/org/eclipse/jetty/server/MultiPartInputStreamParser.java index a66df1cef9b3..c070f2cf479d 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/MultiPartInputStreamParser.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/MultiPartInputStreamParser.java @@ -941,7 +941,7 @@ else if (_line.length() == 0) _pos = 0; } - return _buffer[_pos++]; + return _buffer[_pos++] & 0xFF; } } } diff --git a/jetty-websocket/websocket-core-common/src/main/java/org/eclipse/jetty/websocket/core/internal/messages/MessageInputStream.java b/jetty-websocket/websocket-core-common/src/main/java/org/eclipse/jetty/websocket/core/internal/messages/MessageInputStream.java index 12b20ce350f0..d670440c87fd 100644 --- a/jetty-websocket/websocket-core-common/src/main/java/org/eclipse/jetty/websocket/core/internal/messages/MessageInputStream.java +++ b/jetty-websocket/websocket-core-common/src/main/java/org/eclipse/jetty/websocket/core/internal/messages/MessageInputStream.java @@ -87,7 +87,7 @@ public int read() throws IOException if (len < 0) // EOF return -1; if (len > 0) // did read something - return buf[0]; + return buf[0] & 0xFF; // reading nothing (len == 0) tries again } } diff --git a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/MessageInputStreamTest.java b/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/MessageInputStreamTest.java index 74929abe8b5a..e22965db5edc 100644 --- a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/MessageInputStreamTest.java +++ b/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/MessageInputStreamTest.java @@ -33,6 +33,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTimeout; @@ -279,4 +280,23 @@ public void testAppendNullPayloadRead() throws IOException } }); } + + @Test + public void testReadSingleByteIsNotSigned() throws Exception + { + try (MessageInputStream stream = new MessageInputStream()) + { + // Byte must be greater than 127. + int theByte = 200; + // Append a single message (simple, short) + Frame frame = new Frame(OpCode.BINARY); + frame.setPayload(new byte[]{(byte)theByte}); + frame.setFin(true); + stream.accept(frame, Callback.NOOP); + + // Single byte read must not return a signed byte. + int read = stream.read(); + assertEquals(theByte, read); + } + } }