MonitoringResponseOutOfOrderStrategy implements ResponseOutOfOrderStrategy { @Override public boolean isEarlyResponseDetected( final ClassicHttpRequest request, final HttpClientConnection connection, final InputStream inputStream, final long totalBytesSent, final long nextWriteSize) throws IOException { if (nextWriteStartsNewChunk(totalBytesSent, nextWriteSize)) { final boolean ssl = connection.getSSLSession() != null; return ssl ? connection.isDataAvailable(Timeout.ONE_MILLISECOND) : (inputStream.available() > 0); } return false; } MonitoringResponseOutOfOrderStrategy();  MonitoringResponseOutOfOrderStrategy(final long chunkSize);  MonitoringResponseOutOfOrderStrategy(final long chunkSize, final long maxChunksToCheck); @Override boolean isEarlyResponseDetected(
            final ClassicHttpRequest request,
            final HttpClientConnection connection,
            final InputStream inputStream,
            final long totalBytesSent,
            final long nextWriteSize); @Override String toString(); static final MonitoringResponseOutOfOrderStrategy INSTANCE; }
@Test public void testFirstByteIsNotCheckedSsl() throws IOException { final boolean earlyResponse = MonitoringResponseOutOfOrderStrategy.INSTANCE.isEarlyResponseDetected( REQUEST, connection(true, true), socketInputStream(0), 0, 1); Assert.assertFalse(earlyResponse); }
@Test public void testFirstByteIsNotCheckedPlain() throws IOException { final boolean earlyResponse = MonitoringResponseOutOfOrderStrategy.INSTANCE.isEarlyResponseDetected( REQUEST, connection(true, false), socketInputStream(1), 0, 1); Assert.assertFalse(earlyResponse); }
@Test public void testWritesWithinChunkAreNotChecked() throws IOException { final boolean earlyResponse = MonitoringResponseOutOfOrderStrategy.INSTANCE.isEarlyResponseDetected( REQUEST, connection(true, true), socketInputStream(0), 1, 8190); Assert.assertFalse( "There is data available, but checks shouldn't occur until just prior to the 8192nd byte", earlyResponse); }
@Test public void testWritesAcrossChunksAreChecked() throws IOException { final boolean earlyResponse = MonitoringResponseOutOfOrderStrategy.INSTANCE.isEarlyResponseDetected( REQUEST, connection(true, true), socketInputStream(0), 8191, 1); Assert.assertTrue(earlyResponse); }
@Test public void testMaximumChunks() throws IOException { final ResponseOutOfOrderStrategy strategy = new MonitoringResponseOutOfOrderStrategy(1, 2); Assert.assertTrue(strategy.isEarlyResponseDetected( REQUEST, connection(true, true), socketInputStream(0), 0, 1)); Assert.assertTrue(strategy.isEarlyResponseDetected( REQUEST, connection(true, true), socketInputStream(0), 1, 2)); Assert.assertFalse(strategy.isEarlyResponseDetected( REQUEST, connection(true, true), socketInputStream(0), 2, 3)); }