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

api/java_awt/InetAddress/serial/complement.html#isReachable

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 6u31
    • core-libs
    • x86
    • windows_xp

      FULL PRODUCT VERSION :
      java version "1.6.0_20"
      Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
      Java HotSpot(TM) Client VM (build 16.3-b01, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      isReachable001: Passed. OKAY
      isReachable002: Passed. OKAY
      isReachable003: Failed. Fail: external host 'javasoft.sqe.jck.lib.InetAddressValue$Parameter@109a4c' is reachable via loopback 'name:lo (MS TCP Loopback interface) index: 1 addresses: /127.0.0.1; '!
      isReachableIf002: Passed. OKAY
      STATUS:Failed.test cases: 4; passed: 3; failed: 1; first test case failure: isReachable003



      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      sReachable003: Failed. Fail: external host 'javasoft.sqe.jck.lib.InetAddressValue$Parameter@109a4c' is reachable via loopback 'name:lo (MS TCP Loopback interface) index: 1 addresses: /127.0.0.1; '!

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      /*
       * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
       * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
       */


      /*
       * @(#)isReachable.test.xml 1.10 07/12/11 Arzhan Kinzhalin
       * Generated from : api/java_net/InetAddress/isReachable.test.xml
       *
       * Tests for InetAddress.isReachable(*) methods.
       */

      package javasoft.sqe.tests.api.java.net.InetAddress;

      import java.io.IOException;
      import java.io.PrintWriter;
      import java.net.*;
      import java.util.Enumeration;
      import javasoft.sqe.javatest.Status;
      import javasoft.sqe.jck.lib.FileValue;
      import javasoft.sqe.jck.lib.InetAddressValue;
      import javasoft.sqe.jck.lib.IntegersRangeValue;
      import javasoft.sqe.jck.lib.MultiTestExt;
      import javasoft.sqe.jck.lib.PortsRangeValue;
      import javasoft.sqe.jck.lib.StringValue;
      import javasoft.sqe.jck.lib.TestDirValue;
      import javasoft.sqe.jck.lib.URIFileValue;
      import javasoft.sqe.jck.lib.URIValue;


      public class isReachableTests extends MultiTestExt {

          public InetAddressValue.Parameter testHost1 =
                  new InetAddressValue.Parameter("network.testHost1");

          /* declare the timeout value. 60 seconds is more than enough to access a host in a local network */
          private int HUGE_TIMEOUT = 60000;

          /* standalone interface */
          public static void main(String argv[]) {
              isReachableTests test = new isReachableTests();
              test.run(argv, System.err, System.out).exit();
          }

          /**
           * Boundary value analysis
           * with input and output values orientation
           * for public boolean isReachable(int timeout),
           * <br><b>timeout</b>: 1, 2, 3, 10
           * <br><b>output</b>: Will return true..
           */
          public Status isReachable001() {
              String testCaseID = "isReachable001";

              int errors = 0;

              /* STEP 1: get an instance of InetAddress for localhost */
              InetAddress ia = null;
              try {
                  ia = InetAddress.getByName("localhost");
              } catch (UnknownHostException uhe) {
                  return Status.failed("Cannot resolve 'localhost'");
              } catch (IOException ioe) {
                  ref.println(testCaseID + ": " + ioe);
                  return Status.failed("Unexpected IOException");
              }

              /* STEP 2: test the reachability of the host */
              try {
                  if ( ! ia.isReachable(HUGE_TIMEOUT) ) {
                      ref.println(testCaseID + ": false returned with timeout value "
                             + HUGE_TIMEOUT + " for host " + ia);
                      errors++;
                  }
              } catch (IOException ioe) {
                  ref.println(testCaseID + ": " + ioe);
                  errors++;
              }

              if ( errors > 0 ) {
                  return Status.failed(errors + " errors during the test.");
              }
              return Status.passed("OKAY");
          }

          /**
           * Boundary value analysis
           * with input and output values orientation
           * for public boolean isReachable(int timeout),
           * <br><b>timeout</b>: 5000
           * <br><b>output</b>: Will return true..
           */
          public Status isReachable002() {
              String testCaseID = "isReachable002";

              int errors = 0;

              /* STEP 1: get the testhosts */
              InetAddress ia[] = new InetAddress[] { testHost1.get() };
              ref.println(testCaseID + ": testHost1 " + ia[0]);

              /* STEP 2: for each host test the reachability of the host */
              for (int i=0; i < ia.length; i++) {
                  try {
                      if ( ! ia[i].isReachable(HUGE_TIMEOUT) ) {
                          ref.println(testCaseID + ": false returned with timeout value "
                                  + HUGE_TIMEOUT + " for host " + ia[i]);
                          errors++;
                      }
                  } catch (IOException ioe) {
                      ref.println(testCaseID + ": " + ioe);
                      errors++;
                  }
              }

              if ( errors > 0 ) {
                  return Status.failed(errors + " errors during the test.");
              }
              return Status.passed("OKAY");
          }

          /**
           * Assertion testing
           * for public boolean isReachable(NetworkInterface if, int ttl, int timeout),
           * Will return true if the host is reachable, false otherwise.
           */
          public Status isReachable003() {
              String testCaseID = "isReachable003";

              try {
                  NetworkInterface loopbackNi = null;
                  Enumeration<NetworkInterface> list = NetworkInterface.getNetworkInterfaces();
                  boolean loopbackFound = false;
                  while( list.hasMoreElements() && !loopbackFound){
                      loopbackNi = list.nextElement();
                      if( loopbackNi.isLoopback() && loopbackNi.isUp() ) {
                          loopbackFound = true;
                      }
                  }
                  if( !loopbackFound )
                      return Status.passed( "The test skipped: Loopback interface isn't found." );
                  int ttl = 10;
                  if( testHost1.get().isReachable( loopbackNi, ttl, HUGE_TIMEOUT ) )
                      return Status.failed( String.format("Fail: external host '%s' is reachable via loopback '%s'!",
                                                              testHost1, loopbackNi) );
              } catch( Exception x ){
                  x.printStackTrace( ref );
                  return Status.failed( x.toString() );
              }
              return Status.passed("OK");
          }

          /**
           * Boundary value analysis
           * with input and output values orientation
           * for public boolean isReachable(NetworkInterface if, int ttl, int timeout),
           * <br><b>if</b>: a valid network interface
           * <br><b>ttl</b>: a valid value
           * <br><b>timeout</b>: 1, 2, 3, 10
           * <br><b>output</b>: Will return true..
           */
          public Status isReachableIf002() {
              String testCaseID = "isReachableIf002";

              /* STEP 1: get inet addresses to test */
              InetAddress ia1 = testHost1.get();

              final int ttl = 10; // 10 hops is quite away
              try {
                  /* STEP 2: get network interfaces . */
                  Enumeration ifs = NetworkInterface.getNetworkInterfaces();

                  /* STEP 3: test reachability of the host */
                  boolean done = false;
                  while( !done && ifs.hasMoreElements() ) {
                      NetworkInterface netif = (NetworkInterface)ifs.nextElement();
                      try {
                          ref.println( String.format("%s: netIntf '%s', isUp() = %s",
                                          testCaseID, netif, netif.isUp()) );
                          if( netif.isUp() ){
                              done = ia1.isReachable(netif, ttl, HUGE_TIMEOUT);
                          }
                      } catch( IOException x ){}
                  } // while
                  if( !done )
                      return Status.failed("hosts are not reachable");
              } catch (SocketException se) {
                  ref.println(testCaseID + ": " + se);
                  return Status.failed("Unexpected SocketException");
              }
              return Status.passed("OKAY");
          }
      }

      ---------- END SOURCE ----------

      SUPPORT :
      YES

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: