Skip to content

Commit

Permalink
Fixed tests.
Browse files Browse the repository at this point in the history
Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
  • Loading branch information
sbordet committed Dec 23, 2024
1 parent dbc7da7 commit 21d4dfc
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -361,12 +361,13 @@ private boolean parse(boolean notifyContentAvailable)
if (LOG.isDebugEnabled())
LOG.debug("Discarding unexpected content after response {}: {} in {}", status, BufferUtil.toDetailString(byteBuffer), this);
BufferUtil.clear(byteBuffer);
return false;
return true;
}
}

// Continue to read from the network.
return false;
// Reading the next response will
// be performed by receivedNext().
return true;
}
default -> throw new IllegalStateException("Invalid state " + state);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1401,9 +1401,12 @@ public void onClosed(Connection connection)

assertTrue(latch.await(5, TimeUnit.SECONDS));

// Client sent and server received (and viceversa) bytes may not be equal
// because upon closing the connection the TLS alert may not be read due
// to the fact that the EndPoint is closed.
assertThat(clientStats.getSentBytes(), Matchers.greaterThan(0L));
assertEquals(clientStats.getSentBytes(), serverStats.getReceivedBytes());
assertThat(serverStats.getReceivedBytes(), Matchers.greaterThan(0L));
assertThat(clientStats.getReceivedBytes(), Matchers.greaterThan(0L));
assertEquals(clientStats.getReceivedBytes(), serverStats.getSentBytes());
assertThat(serverStats.getSentBytes(), Matchers.greaterThan(0L));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public void onClosed(Connection connection)
client.newRequest(newURI(transportType))
.method(HttpMethod.POST)
.body(content)
.onResponseSuccess(r -> responseLatch.countDown())
.onResponseHeaders(r -> responseLatch.countDown())
.timeout(5, TimeUnit.SECONDS)
.send(result ->
{
Expand Down Expand Up @@ -1377,12 +1377,11 @@ public long getLength()
client.newRequest(newURI(transportType))
.method(HttpMethod.POST)
.body(content)
.onResponseSuccess(response ->
.send(result ->
{
Assertions.assertEquals(HttpStatus.REQUEST_TIMEOUT_408, response.getStatus());
Assertions.assertEquals(HttpStatus.REQUEST_TIMEOUT_408, result.getResponse().getStatus());
latch.countDown();
})
.send(null);
});

// Wait for the server to idle timeout.
Thread.sleep(2 * idleTimeout);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,21 @@ protected void service(HttpServletRequest request, HttpServletResponse response)
long idleTimeout = 1000;
setStreamIdleTimeout(idleTimeout);

CountDownLatch resultLatch = new CountDownLatch(2);
CountDownLatch resultLatch = new CountDownLatch(1);
AsyncRequestContent content = new AsyncRequestContent();
client.POST(newURI(transportType))
.body(content)
.onResponseSuccess(response ->
.onResponseHeaders(r ->
{
if (response.getStatus() == HttpStatus.INTERNAL_SERVER_ERROR_500)
resultLatch.countDown();
// For the cases where the response is not failed,
// complete the request to complete the exchange.
content.close();
})
.send(result -> resultLatch.countDown());
.send(result ->
{
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR_500, result.getResponse().getStatus());
resultLatch.countDown();
});

// The client did not send the content, the request was
// dispatched, the server should have idle timed it out.
Expand Down Expand Up @@ -339,7 +343,7 @@ protected void service(HttpServletRequest request, HttpServletResponse response)
CountDownLatch resultLatch = new CountDownLatch(1);
client.newRequest(newURI(transportType))
.body(content)
.onResponseSuccess(response ->
.onResponseHeaders(response ->
{
responseRef.set(response);
responseLatch.countDown();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public void onClosed(Connection connection)
client.newRequest(newURI(transportType))
.method(HttpMethod.POST)
.body(content)
.onResponseSuccess(r -> responseLatch.countDown())
.onResponseHeaders(r -> responseLatch.countDown())
.timeout(5, TimeUnit.SECONDS)
.send(result ->
{
Expand Down Expand Up @@ -1377,12 +1377,11 @@ public long getLength()
client.newRequest(newURI(transportType))
.method(HttpMethod.POST)
.body(content)
.onResponseSuccess(response ->
.send(result ->
{
Assertions.assertEquals(HttpStatus.REQUEST_TIMEOUT_408, response.getStatus());
Assertions.assertEquals(HttpStatus.REQUEST_TIMEOUT_408, result.getResponse().getStatus());
latch.countDown();
})
.send(null);
});

// Wait for the server to idle timeout.
Thread.sleep(2 * idleTimeout);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,21 @@ protected void service(HttpServletRequest request, HttpServletResponse response)
long idleTimeout = 1000;
setStreamIdleTimeout(idleTimeout);

CountDownLatch resultLatch = new CountDownLatch(2);
CountDownLatch resultLatch = new CountDownLatch(1);
AsyncRequestContent content = new AsyncRequestContent();
client.POST(newURI(transportType))
.body(content)
.onResponseSuccess(response ->
.onResponseHeaders(r ->
{
if (response.getStatus() == HttpStatus.INTERNAL_SERVER_ERROR_500)
resultLatch.countDown();
// For the cases where the response is not failed,
// complete the request to complete the exchange.
content.close();
})
.send(result -> resultLatch.countDown());
.send(result ->
{
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR_500, result.getResponse().getStatus());
resultLatch.countDown();
});

// The client did not send the content, the request was
// dispatched, the server should have idle timed it out.
Expand Down Expand Up @@ -339,7 +343,7 @@ protected void service(HttpServletRequest request, HttpServletResponse response)
CountDownLatch resultLatch = new CountDownLatch(1);
client.newRequest(newURI(transportType))
.body(content)
.onResponseSuccess(response ->
.onResponseHeaders(response ->
{
responseRef.set(response);
responseLatch.countDown();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public void onClosed(Connection connection)
client.newRequest(newURI(transportType))
.method(HttpMethod.POST)
.body(content)
.onResponseSuccess(r -> responseLatch.countDown())
.onResponseHeaders(r -> responseLatch.countDown())
.timeout(5, TimeUnit.SECONDS)
.send(result ->
{
Expand Down Expand Up @@ -1782,12 +1782,11 @@ public long getLength()
client.newRequest(newURI(transportType))
.method(HttpMethod.POST)
.body(content)
.onResponseSuccess(response ->
.send(result ->
{
Assertions.assertEquals(HttpStatus.REQUEST_TIMEOUT_408, response.getStatus());
Assertions.assertEquals(HttpStatus.REQUEST_TIMEOUT_408, result.getResponse().getStatus());
latch.countDown();
})
.send(null);
});

// Wait for the server to idle timeout.
Thread.sleep(2 * idleTimeout);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,21 @@ protected void service(HttpServletRequest request, HttpServletResponse response)
long idleTimeout = 1000;
setStreamIdleTimeout(idleTimeout);

CountDownLatch resultLatch = new CountDownLatch(2);
CountDownLatch resultLatch = new CountDownLatch(1);
AsyncRequestContent content = new AsyncRequestContent();
client.POST(newURI(transportType))
.body(content)
.onResponseSuccess(response ->
.onResponseHeaders(r ->
{
if (response.getStatus() == HttpStatus.INTERNAL_SERVER_ERROR_500)
resultLatch.countDown();
// For the cases where the response is not failed,
// complete the request to complete the exchange.
content.close();
})
.send(result -> resultLatch.countDown());
.send(result ->
{
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR_500, result.getResponse().getStatus());
resultLatch.countDown();
});

// The client did not send the content, the request was
// dispatched, the server should have idle timed it out.
Expand Down Expand Up @@ -340,7 +344,7 @@ protected void service(HttpServletRequest request, HttpServletResponse response)
CountDownLatch resultLatch = new CountDownLatch(1);
client.newRequest(newURI(transportType))
.body(content)
.onResponseSuccess(response ->
.onResponseHeaders(response ->
{
responseRef.set(response);
responseLatch.countDown();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#org.eclipse.jetty.LEVEL=DEBUG
org.eclipse.jetty.LEVEL=DEBUG
org.eclipse.jetty.jmx.LEVEL=INFO
#org.eclipse.jetty.client.LEVEL=DEBUG
#org.eclipse.jetty.fcgi.LEVEL=DEBUG
Expand Down

0 comments on commit 21d4dfc

Please sign in to comment.