Print this page


Split Close
Expand all
Collapse all
          --- old/test/sun/net/www/http/KeepAliveCache/B5045306.java
          +++ new/test/sun/net/www/http/KeepAliveCache/B5045306.java
↓ open down ↓ 15 lines elided ↑ open up ↑
  16   16   * 2 along with this work; if not, write to the Free Software Foundation,
  17   17   * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18   18   *
  19   19   * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20   20   * or visit www.oracle.com if you need additional information or have any
  21   21   * questions.
  22   22   */
  23   23  
  24   24  /*
  25   25   * @test
  26      - * @bug 5045306 6356004
       26 + * @bug 5045306 6356004 6993490
  27   27   * @library ../../httptest/
  28   28   * @build HttpCallback HttpServer HttpTransaction
  29   29   * @run main/othervm B5045306
  30   30   * @summary Http keep-alive implementation is not efficient
  31   31   */
  32   32  
  33   33  import java.net.*;
  34   34  import java.io.*;
  35      -import java.nio.channels.*;
  36   35  import java.lang.management.*;
  37   36  
  38   37  /* Part 1:
  39   38   * The http client makes a connection to a URL whos content contains a lot of
  40   39   * data, more than can fit in the socket buffer. The client only reads
  41   40   * 1 byte of the data from the InputStream leaving behind more data than can
  42   41   * fit in the socket buffer. The client then makes a second call to the http
  43   42   * server. If the connection port used by the client is the same as for the
  44   43   * first call then that means that the connection is being reused.
  45   44   *
↓ open down ↓ 111 lines elided ↑ open up ↑
 157  156                  trans.setResponseEntityBody (responseBody, responseBody.length);
 158  157                  trans.sendResponse(200, "OK");
 159  158              } else if (path.equals("/secondCall")) {
 160  159                  int port2 = trans.channel().socket().getPort();
 161  160                  System.out.println("Second connection on client port = " + port2);
 162  161  
 163  162                  if (port1 != port2)
 164  163                      failed = true;
 165  164  
 166  165                  trans.setResponseHeader ("Content-length", Integer.toString(0));
      166 +
      167 +                 /* Force the server to not respond for more that the timeout
      168 +                  * set by the keepalive cleaner (5000 millis). This ensures the
      169 +                  * timeout is correctly resets the default read timeout,
      170 +                  * infinity. See 6993490. */
      171 +                System.out.println("server sleeping...");
      172 +                try {Thread.sleep(6000); } catch (InterruptedException e) {}
      173 +
 167  174                  trans.sendResponse(200, "OK");
 168  175              } else if(path.equals("/part2")) {
 169  176                  System.out.println("Call to /part2");
 170  177                  byte[] responseBody = new byte[RESPONSE_DATA_LENGTH];
 171  178                  for (int i=0; i<responseBody.length; i++)
 172  179                      responseBody[i] = 0x41;
 173  180                  trans.setResponseEntityBody (responseBody, responseBody.length);
 174  181  
 175  182                  // override the Content-length header to be greater than the actual response body
 176  183                  trans.setResponseHeader("Content-length", Integer.toString(responseBody.length+1));
 177  184                  trans.sendResponse(200, "OK");
 178  185  
 179  186                  // now close the socket
 180  187                  trans.channel().socket().close();
 181  188              }
 182  189          } catch (Exception e) {
 183  190              e.printStackTrace();
 184  191          }
 185  192      }
 186  193  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX