/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 5045306 6356004 6993490
* @library ../../httptest/
* @build HttpCallback HttpServer HttpTransaction
* @summary Http keep-alive implementation is not efficient
*/
/* Part 1:
* The http client makes a connection to a URL whos content contains a lot of
* data, more than can fit in the socket buffer. The client only reads
* 1 byte of the data from the InputStream leaving behind more data than can
* fit in the socket buffer. The client then makes a second call to the http
* server. If the connection port used by the client is the same as for the
* first call then that means that the connection is being reused.
*
* Part 2:
* Test buggy webserver that sends less data than it specifies in its
* Content-length header.
*/
public class B5045306
{
}
public static void startHttpServer() {
try {
httpTrans = new SimpleHttpTransaction();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void clientHttpCalls() {
try {
//Only read 1 byte of response data and close the stream
byte[] ba = new byte[1];
// Allow the KeepAliveStreamCleaner thread to read the data left behind and cache the connection.
throw new RuntimeException("Failed: Initial Keep Alive Connection is not being reused");
// Part 2
// Allow the KeepAliveStreamCleaner thread to try and read the data left behind and cache the connection.
if (threadMXBean.isThreadCpuTimeSupported()) {
break; // thread has died, OK
// if Keep-Alive-SocketCleaner consumes more than 50% of cpu then we
// can assume a recursive loop.
throw new RuntimeException("Failed: possible recursive loop in Keep-Alive-SocketCleaner");
}
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
}
}
}
{
static boolean failed = false;
// Need to have enough data here that is too large for the socket buffer to hold.
// Also http.KeepAlive.remainingData must be greater than this value, default is 256K.
int port1;
try {
byte[] responseBody = new byte[RESPONSE_DATA_LENGTH];
responseBody[i] = 0x41;
failed = true;
/* Force the server to not respond for more that the timeout
* set by the keepalive cleaner (5000 millis). This ensures the
* timeout is correctly resets the default read timeout,
* infinity. See 6993490. */
byte[] responseBody = new byte[RESPONSE_DATA_LENGTH];
responseBody[i] = 0x41;
// override the Content-length header to be greater than the actual response body
// now close the socket
}
} catch (Exception e) {
e.printStackTrace();
}
}
}