Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7005016

pit jdk7 b121 sqe test jhttp/HttpServer150013/HttpServer150013.java fails on all platforms.

XMLWordPrintable

    • b123
    • sparc
    • solaris_10
    • Verified

      pit jdk7 b121 sqe test jhttp/HttpServer150013/HttpServer150013.java fails on platforms.


      /net/sqenfs-1/export1/comp/jsn/all_workspace/7_int/networking/src/jhttp/HttpServer150013

      fails on solaris/win/linux
      tests hangs.

      jdk7 pit b121

      how to test, test output, test src are given below.

      solaris output:
      ==============

      machine used solaris: jsn-sfv245-1.sfbay.sun.com

      how to test:

      1. set jdk path.
      2. javac HttpServer150013.java
      3. java -Dsun.http.clockTick=2 -Dsun.http.idleInterval=4 HttpServer150013 jsn-sfv245-1

      below are output of testing jdk7b119 promotion
                                
      and jdk7 b121 pit


      =========jdk7 pit b121 output fail========================

      jsn-sfv245-1:/net/sqenfs-1/export1/comp/jsn/users/shantaram/testjhttp/jhttp/Http
      Server150013 205 % uname -a
      SunOS jsn-sfv245-1 5.10 Generic_127127-11 sun4u sparc SUNW,Sun-Fire-V245
      jsn-sfv245-1:/net/sqenfs-1/export1/comp/jsn/users/shantaram/testjhttp/jhttp/Http
      Server150013 206 % java -version
      java version "1.7.0-internal"
      Java(TM) SE Runtime Environment (build 1.7.0-internal-jprtadm_2010_11_30_17_00-b
      00)
      Java HotSpot(TM) Server VM (build 20.0-b03-201011302309.ss145989.tl-pit-2d-awt-s
      win, mixed mode)
      jsn-sfv245-1:/net/sqenfs-1/export1/comp/jsn/users/shantaram/testjhttp/jhttp/Http
      Server150013 207 % java -Dsun.http.clockTick=2 -Dsun.http.idleInterval=4 HttpSer
      ver150013 jsn-sfv245-1
      Total tests for HttpServer150013 : 1
      server started in HttpServer150013Test01() of HttpServer150013.java
      write over in HttpServer150013Test01() of HttpServer150013.java
      before is.read()
      I am in handle() of class Handler150013
      expected method PUT actual method received = PUT
      read over in handle() of class Handler150013
      methodTestOK = true



      Note: test hangs at this point.


      =========================jdk7 b119 promotion build pass===============

      jsn-sfv245-1:/net/sqenfs-1/export1/comp/jsn/users/shantaram/testjhttp/jhttp/Http
      Server150013 136 % uname -a
      SunOS jsn-sfv245-1 5.10 Generic_127127-11 sun4u sparc SUNW,Sun-Fire-V245

      jsn-sfv245-1:/net/sqenfs-1/export1/comp/jsn/users/shantaram/testjhttp/jhttp/Http
      Server150013 137 % java -version
      java version "1.7.0-ea"
      Java(TM) SE Runtime Environment (build 1.7.0-ea-b119)
      Java HotSpot(TM) Server VM (build 20.0-b03, mixed mode)




      jsn-sfv245-1:/net/sqenfs-1/export1/comp/jsn/users/shantaram/testjhttp/jhttp/Http
      Server150013 138 % !132
      java -Dsun.http.clockTick=2 -Dsun.http.idleInterval=4 HttpServer150013 jsn-sfv24
      5-1
      Total tests for HttpServer150013 : 1
      server started in HttpServer150013Test01() of HttpServer150013.java
      write over in HttpServer150013Test01() of HttpServer150013.java
      I am in handle() of class Handler150013
      expected method PUT actual method received = PUT
      read over in handle() of class Handler150013
      read over in HttpServer150013Test01() of HttpServer150013.java
      gotResponse = HTTP/1.1 200 OK
      Content-length: 0
      Date: Thu, 02 Dec 2010 06:21:20 GMT


      responseCodeGotInt = 200
      Pass count: 1
      Fail count: 0
      Test for HttpServer150013.java Passed

      ====================test src================================================

      import com.sun.net.httpserver.*;
      import java.util.*;
      import java.util.concurrent.*;
      import java.io.*;
      import java.net.*;
      import java.security.*;
      import javax.security.auth.callback.*;
      import javax.net.ssl.*;

      /**
       *Test ID JHttp015
       *HttpServer150013: Testing of com.sun.net.httpserver
       *HttpServer testing:
       *server and client are both in same machine: local testing
       * 1. set javapath jdk under test (1.6 for internal use b53 onwards)
       * 2. java -Dsun.http.clockTick=2 -Dsun.http.idleInterval=4 HttpServer150013 servername(or localhost)
       * Note : it takes time apprx.1 mint.
       *
       */
      public class HttpServer150013 {

          private static ExecutorService exec = null;
          private static HttpServer server = null;
          private static final int DEF_PORT = 5050;
          private static final int DEF_BACKLOG = 10;
          private static final int SIZE = 99999;
          private static final int TEST_RESPONSE_CODE = 200;
          private static final int TEST_RESPONSE_CODE_NOTOK = 400;
          private static final int EXPECTED_RESPONSE_CODE = 200;
          private static final int TEST_RESPONSE_BODY_LEN = -1;
          static String body1 = "12345abcde";
          private static String servername = "localhost";

          public static void main(String[] args) throws Exception {
              if (args.length == 1) {
                  servername = args[0];
              }

              boolean status[];
              int passcount = 0, failcount = 0;
              int numTests = 1;
              int i, j = 0;
              int testNumber;
              status = new boolean[numTests];
              System.out.println("Total tests for HttpServer150013 : "+numTests);
              for (i = 0; i < numTests; ++i) {
                  // Put all tests in try... catch block
                  try {
                      ++j;
                      switch (j) {
                          case 1:
                                status[i] = HttpServer150013Test01();
                                break;
                      }
                  } catch (Exception e) {
                          status[i] = false;
                          System.out.println ("main main main main Exception in test "+j+": "+e.getMessage());
                          e.printStackTrace();
                  }
              } // end for

              // Get pass and fail totals
              for (i = 0; i < numTests; ++i) {
                  if (status[i] == true) {
                      passcount++;
                  }else{
                      failcount++;
                  }
              }

              System.out.println("Pass count: " + passcount);
              System.out.println("Fail count: " + failcount);

              // check if tests passed
              if (failcount < 1) {
                 System.out.println("Test for HttpServer150013.java Passed");
                 System.exit(0);
              } else {
                 System.out.println("Test for HttpServer150013.java Failed");
                 System.exit(1);
              }

          } // end main
          /**
           *Test ID JHttp150013
           *HttpServer testing:
           *Check for the request method PUT is reeived correctly.
           *If ok then test pass.
           *
          */
          public static boolean HttpServer150013Test01() { //throws IOException {
               boolean bReturn = true;
               try {
                    Handler150013 handler = new Handler150013();
                    InetSocketAddress addr = new InetSocketAddress(servername,DEF_PORT);
                    server = HttpServer.create(addr, 0);
                    int port = server.getAddress().getPort();
                    HttpContext c2 = server.createContext("/testHandler150013", handler);
                    c2.getAttributes().put("name", "This is the http handler");
                    exec = Executors.newCachedThreadPool();
                    server.setExecutor(exec);
                    server.start();
                    System.out.println("server started in HttpServer150013Test01() of HttpServer150013.java");
                    String s = "PUT /testHandler150013/foo.html HTTP/1.1\r\n\r\n";
                    Socket socket = new Socket(servername, port);
                    OutputStream os = socket.getOutputStream();
                    os.write(s.getBytes());
                    System.out.println("write over in HttpServer150013Test01() of HttpServer150013.java");
                    InputStream is = socket.getInputStream();
                   //check for response code is ok
                    byte [] b01 = new byte [2024];
                    int count01 = 0, c01;
                    while ((c01=is.read(b01, count01, b01.length-count01)) != -1) {
                        count01+=c01;
                    }
                    is.close();
                    System.out.println("read over in HttpServer150013Test01() of HttpServer150013.java");
                    String gotResponse = new String(b01, 0, count01, "ISO8859_1");
                    System.out.println("gotResponse = " + gotResponse);
                    Thread.sleep(200);
                    is.close();
                    socket.close();
                    String responseCodeGot = gotResponse.substring(9,12);
                    int responseCodeGotInt = Integer.parseInt(responseCodeGot);
                    System.out.println("responseCodeGotInt = " + responseCodeGotInt);
                    //if responsecode is not ok then throw exception
                    if (responseCodeGotInt != EXPECTED_RESPONSE_CODE) {
                       throw new Exception("responseCodeGotInt != EXPECTED_RESPONSE_CODE not ok in HttpServer15003Test01() HttpServer150013.java");
                    }

                    bReturn = true;
               } catch (Exception e) {
                   System.out.println("Exception thrown:********* " + e);
                   e.printStackTrace();
                   bReturn = false;
               } finally {
                  // delay();
                   server.stop(2);
                   exec.shutdown();
               }
               return bReturn;
          }

          static class Handler150013 implements HttpHandler {

              public void handle(HttpExchange t) throws IOException {
                  System.out.println("I am in handle() of class Handler150013");
                  boolean methodTestOK = true;
                  String checkMethod = t.getRequestMethod();

                  if (!checkMethod.equals("PUT")) {
                     methodTestOK = false;
                  }
                  System.out.println("expected method PUT actual method received = " + checkMethod);
                  InputStream is = t.getRequestBody();
                  int c;
                  while ((c=is.read()) != -1) {
                  }
                  is.close();
                  System.out.println("read over in handle() of class Handler150013");
                  if (methodTestOK) {
                     t.sendResponseHeaders (TEST_RESPONSE_CODE, TEST_RESPONSE_BODY_LEN);
                  } else {
                     t.sendResponseHeaders (TEST_RESPONSE_CODE_NOTOK, TEST_RESPONSE_BODY_LEN);
                  }
                  t.close();
              }
          }
      }

      =====================================================================================

            michaelm Michael McMahon
            spandeorcl Shantaram Pande (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: