Skip to content

Commit

Permalink
Work around available tricks
Browse files Browse the repository at this point in the history
available() needs to be called even though the first read returned 0
bytes.
Going through everything it seems "normal" and there is no real
workaround.
  • Loading branch information
rmaucher committed Jan 29, 2025
1 parent 937f65c commit 0820667
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions test/org/apache/coyote/http11/filters/TestChunkedInputFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -839,22 +839,23 @@ public void onDataAvailable() throws IOException {
byte[] buf = new byte[1024];
do {
int n = is.read(buf);
if (n <= 0) {
if (n < 0) {
break;
} else if (n > 0) {
String line = new String(buf, 0, n, StandardCharsets.UTF_8);
Assert.assertTrue(line.length() > 0);
long thisRead = System.nanoTime();
if (lineCount > 0) {
/*
* After the first line, look for a pause of at least 800ms between reads.
*/
if ((thisRead - lastRead) > TimeUnit.MILLISECONDS.toNanos(800)) {
pauseCount++;
}
}
lastRead = thisRead;
lineCount++;
}
String line = new String(buf, 0, n, StandardCharsets.UTF_8);
Assert.assertTrue(line.length() > 0);
long thisRead = System.nanoTime();
if (lineCount > 0) {
/*
* After the first line, look for a pause of at least 800ms between reads.
*/
if ((thisRead - lastRead) > TimeUnit.MILLISECONDS.toNanos(800)) {
pauseCount++;
}
}
lastRead = thisRead;
lineCount++;
} while (is.isReady());
}

Expand Down Expand Up @@ -965,15 +966,15 @@ public void testChunkedSplitWithNonBlocking() throws Exception {
SimpleHttpClient.CRLF +
"7" + SimpleHttpClient.CRLF +
"DATA01\n", SimpleHttpClient.CRLF +
"7"/*, */ + SimpleHttpClient.CRLF +
"7", SimpleHttpClient.CRLF +
"DATA02\n" + SimpleHttpClient.CRLF,
"7" + SimpleHttpClient.CRLF +
// Split the CRLF between writes
"DATA03\n" + SimpleHttpClient.CR,
SimpleHttpClient.LF +
"7" + SimpleHttpClient.CRLF +
"DATA04\n", SimpleHttpClient.CRLF +
"13" + SimpleHttpClient.CRLF/*, */ +
"13" + SimpleHttpClient.CRLF,
"DATA05DATA05DATA05\n" + SimpleHttpClient.CRLF +
"0" + SimpleHttpClient.CRLF +
SimpleHttpClient.CRLF};
Expand Down

0 comments on commit 0820667

Please sign in to comment.