Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/jetty-9.4.x' into jetty-10.0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
gregw committed Nov 30, 2020
2 parents 20f6dc1 + 69b3c37 commit 1333bbc
Showing 1 changed file with 0 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.io.IOException;
import java.io.InterruptedIOException;
import java.nio.ByteBuffer;
import java.rmi.ServerException;
import java.util.Random;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CountDownLatch;
Expand Down Expand Up @@ -54,7 +53,6 @@
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.IO;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ArgumentsSource;

Expand Down Expand Up @@ -474,103 +472,6 @@ public void testBlockingReadHttpIdleTimeoutOverridesIdleTimeout(Transport transp
}
}

@ParameterizedTest
@ArgumentsSource(TransportProvider.class)
@Disabled // TODO #5737
public void testBlockingReadInOtherThreadThenComplete(Transport transport) throws Exception
{
init(transport);
BlockingReadAndCompleteHandler handler = new BlockingReadAndCompleteHandler();
scenario.start(handler);

try /*(StacklessLogging ignore = new StacklessLogging(HttpChannel.class))*/
{
DeferredContentProvider contentProvider = new DeferredContentProvider(ByteBuffer.allocate(1));
CountDownLatch resultLatch = new CountDownLatch(1);
scenario.client.POST(scenario.newURI())
.content(contentProvider)
.send(result ->
{
if (result.getResponse().getStatus() == 299)
resultLatch.countDown();
});

// Blocking read should error.
assertTrue(handler.readErrorLatch.await(5, TimeUnit.SECONDS));

// request should complete without waiting for content.
assertTrue(handler.readErrorLatch.await(1, TimeUnit.SECONDS));

// Complete the request.
contentProvider.close();
assertTrue(resultLatch.await(5, TimeUnit.SECONDS));
}
catch (Exception e)
{
throw e;
}
}

private static class BlockingReadAndCompleteHandler extends AbstractHandler
{
CountDownLatch readErrorLatch;
CountDownLatch completeLatch;

public BlockingReadAndCompleteHandler()
{
this.readErrorLatch = new CountDownLatch(1);
this.completeLatch = new CountDownLatch(1);
}

@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
baseRequest.setHandled(true);
AsyncContext asyncContext = baseRequest.startAsync();
ServletInputStream input = request.getInputStream();
CountDownLatch reading = new CountDownLatch(1);
new Thread(() ->
{
try
{
response.setStatus(289);
while (input.read() >= 0)
{
reading.countDown();
}
}
catch (IOException x)
{
readErrorLatch.countDown();
}
}).start();

try
{
reading.await();
}
catch (Exception e)
{
throw new ServletException(e);
}

new Thread(() ->
{
try
{
Thread.sleep(500);
response.setStatus(299);
asyncContext.complete();
completeLatch.countDown();
}
catch (InterruptedException x)
{
throw new IllegalStateException(x);
}
}).start();
}
}

@ParameterizedTest
@ArgumentsSource(TransportProvider.class)
public void testAsyncReadHttpIdleTimeoutOverridesIdleTimeout(Transport transport) throws Exception
Expand Down

0 comments on commit 1333bbc

Please sign in to comment.