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

Datagram stress test hangs.

    XMLWordPrintable

Details

    • sparc
    • solaris_2.4

    Description

      Datagram stress test hangs.
      The following test case runs for about 5 minutes, then it hangs.



      import java.io.*;
      import java.net.*;


      class constant{
      static public int threadcount = 50;
              static public boolean done = false;
              static public int port = 52456;
      }
      class client_thread extends Thread{

      client_thread(){
      super();
      }
           public void run () {
      try {
               InetAddress h1 = InetAddress.getLocalHost();
                       String k1 = h1.toString();
                       int j1 = k1.lastIndexOf("/");

                       DatagramSocket y1 = new DatagramSocket();
      ByteArrayOutputStream x = new ByteArrayOutputStream();
      DataOutputStream j = new DataOutputStream(x);
      DatagramPacket y2;
      for (int i=2000 ; i >= 0 ; i--){
      j.writeInt(y1.getLocalPort());
      byte mybytes[] = x.toByteArray();
      y2 = new DatagramPacket(mybytes,mybytes.length,h1,constant.port);
      y1.send(y2);
      x.reset();
      sleep(1);
      }
      j.writeInt(0);
      byte mybytes[] = x.toByteArray();
      y2 = new DatagramPacket(mybytes,mybytes.length,h1,constant.port);
      y1.send(y2);
      x.reset();
      sleep(1);
      }
      catch(Exception e) {
      e.printStackTrace();
      System.out.print("TEST FAILED \\n");
      };
           }
      }


      class server_client extends Thread {
      Socket s;
      int i;
      server_client(){
      super();
      }
      public void run() {
      try {
      int t =0;
      int count = 1;
                       DatagramSocket y1 = new DatagramSocket(constant.port);
      System.out.print("y1.getLocalPort() " + y1.getLocalPort() + " \\n");
      ByteArrayOutputStream x = new ByteArrayOutputStream();
      DataOutputStream j = new DataOutputStream(x);
      j.writeInt(1);
      byte mybytes[] = x.toByteArray();
      DatagramPacket y2;
      ByteArrayInputStream x1;
      DataInputStream j1;
      y2 = new DatagramPacket(mybytes,mybytes.length);
      while (count <= constant.threadcount) {
      y2 = new DatagramPacket(mybytes,mybytes.length);
      y1.receive(y2);
      x1 = new ByteArrayInputStream(y2.getData());
      j1 = new DataInputStream(x1);
      t = j1.readInt();
      if (t == 0) {
      count++;
      }
      else {
      if (t != y2.getPort()) {
      System.out.print("TEST FAILED \\n");
      }
      system.out.println(t);

      }

      }

                       System.out.print("y2.getLength() " + y2.getLength() + " \\n");
                       System.out.print("y2.getAddress() " + y2.getAddress().toString() + " \\n");


      System.out.print("TEST PASSED \\n");
      }
      catch(Exception e) {
      e.printStackTrace();
      System.out.print("TEST FAILED \\n");
      };
      }

      }

      class java_net_DatagramSocket_methods {
          public static void main(String argv[]) throws Exception{
      client_thread clients[] = new client_thread[100];
      server_client server = new server_client();
      server.start();
      for (int i= 0; i<constant.threadcount ;i++){
      clients[i] = new client_thread();
      clients[i].start();
      }
          }
      }

      Attachments

        Activity

          People

            duke J. Duke
            hwilliamsunw Headley Williamson (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: