test/sun/management/jmxremote/startstop/JMXStartStopTest.sh

Print this page




  34 _port_one=50234
  35 _port_two=50235
  36 
  37 
  38 _testclasses=".classes"
  39 _testsrc=`pwd`
  40 
  41 _logname=".classes/output.txt"
  42 _lockFileName="JMXStartStop.lck"
  43 
  44 _compile(){
  45 
  46     if [ ! -d ${_testclasses} ]
  47     then
  48       mkdir -p ${_testclasses} 
  49     fi   
  50 
  51     rm -f ${_testclasses}/JMXStartStopTest.class
  52 
  53     # Compile testcase
  54     ${TESTJAVA}/bin/javac -d ${_testclasses} JMXStartStopDoSomething.java JMXStartStopTest.java 

  55 
  56     if [ ! -f ${_testclasses}/JMXStartStopTest.class ]
  57     then
  58       echo "ERROR: Can't compile"
  59       exit -1
  60     fi
  61 }
  62 
  63 _app_start(){
  64   ${TESTJAVA}/bin/java ${TESTVMOPTS} $* -cp ${_testclasses} JMXStartStopDoSomething  >> ${_logname} 2>&1 &
  65 
  66   x=0
  67   while [ ! -f ${_lockFileName} ]
  68   do
  69      if [ $x -gt 20 ]
  70      then
  71         echo "ERROR: Test app not started"
  72         if [ "${_jtreg}" = "yes" ]
  73         then
  74            exit -1
  75         fi   
  76      fi    
  77         
  78      echo "Waiting JMXStartStopDoSomething to start: $x"
  79      x=`expr $x + 1`
  80      sleep 1
  81   done
  82 }
  83 
  84 _get_pid(){
  85     ${TESTJAVA}/bin/jps | sed -n "/JMXStartStopDoSomething/s/ .*//p"
  86 }
  87 
  88 _app_stop(){
  89   rm ${_lockFileName}
  90 
  91   # wait until VM is actually shuts down
  92   while true 
  93   do
  94     npid=`_get_pid`
  95     if [ "${npid}" = "" ] 
  96     then
  97       break
  98     fi
  99     sleep 1
 100   done 
 101 }
 102 
 103 _exit_on_jtreg(){
 104   # Stop on first failed test under jtreg
 105   if [ "${_jtreg}" = "yes" ]
 106   then
 107       _app_stop
 108       exit -1
 109   fi
 110 }
 111 
 112 _testme(){
 113   ${TESTJAVA}/bin/java ${TESTVMOPTS} -cp ${_testclasses} JMXStartStopTest $*
 114 }   
 115 
 116   
 117 _jcmd(){
 118   ${TESTJAVA}/bin/jcmd JMXStartStopDoSomething $* > /dev/null 2>/dev/null
 119 } 
 120 
 121 _echo(){
 122     echo "$*"
 123     echo "$*" >> ${_logname}
 124 }
 125    
 126 # ============= TESTS ======================================
 127    
 128 test_01(){
 129 # Run an app with JMX enabled stop it and 
 130 # restart on other port
 131         
 132     _echo "**** Test one ****"      
 133 
 134     _app_start  -Dcom.sun.management.jmxremote.port=$1 \
 135                 -Dcom.sun.management.jmxremote.authenticate=false \
 136                 -Dcom.sun.management.jmxremote.ssl=false 
 137 
 138     res1=`_testme $1`


 428     fi
 429  
 430     _app_stop
 431 }   
 432 
 433 test_11(){
 434 # Run an app with JMX enabled 
 435 # stop remote agent 
 436 # make sure local agent is not affected
 437 
 438     _echo "**** Test eleven ****"       
 439 
 440     _app_start  -Dcom.sun.management.jmxremote.port=$2 \
 441                 -Dcom.sun.management.jmxremote.authenticate=false \
 442                 -Dcom.sun.management.jmxremote.ssl=false 
 443       
 444     res1=`_testme $2`
 445 
 446     _jcmd ManagementAgent.stop
 447 
 448     pid=`${TESTJAVA}/bin/jps | sed -n "/JMXStartStopDoSomething/s/ .*//p"`
 449     res2=`_testme local ${pid}`
 450 
 451     if [ "${res1}" = "OK_CONN" -a "${res2}" = "OK_CONN" ] 
 452     then
 453         _echo "Passed"
 454     else
 455         _echo "Failed r1(OK):${res1} r2(OK):${res2}"
 456         _exit_on_jtreg
 457     fi
 458  
 459     _app_stop
 460 }   
 461 
 462 test_12(){
 463 # Run an app with JMX disabled 
 464 # start local agent only
 465 
 466     _echo "**** Test twelve ****"       
 467 
 468     _app_start 


 511     else
 512         _echo "Failed r1(NO):${res1}"
 513         _exit_on_jtreg
 514     fi
 515  
 516     _app_stop
 517 }   
 518 
 519 # ============= MAIN =======================================
 520 
 521 if [ "x${TESTJAVA}" = "x" ]
 522 then
 523   echo "TESTJAVA env have to be set"
 524   exit
 525 fi
 526 
 527 if [ ! -x "${TESTJAVA}/bin/jcmd" ]
 528 then
 529   echo "${TESTJAVA}/bin/jcmd"
 530   echo "Doesn't exist or not an executable"

 531 fi
 532 
 533 
 534 #------------------------------------------------------------------------------
 535 # reading parameters 
 536 
 537 for parm in "$@"  
 538 do
 539    case $parm in
 540   --jtreg)        _jtreg=yes    ;;
 541   --no-compile)   _compile=no   ;;
 542   --testsuite=*)  _testsuite=`_echo $parm | sed "s,^--.*=\(.*\),\1,"`  ;;
 543   --port-one=*)   _port_one=`_echo $parm | sed "s,^--.*=\(.*\),\1,"`  ;;
 544   --port-two=*)   _port_two=`_echo $parm | sed "s,^--.*=\(.*\),\1,"`  ;;
 545   *) 
 546      echo "Undefined parameter $parm. Try --help for help" 
 547      exit 
 548    ;;
 549  esac 
 550 done




  34 _port_one=50234
  35 _port_two=50235
  36 
  37 
  38 _testclasses=".classes"
  39 _testsrc=`pwd`
  40 
  41 _logname=".classes/output.txt"
  42 _lockFileName="JMXStartStop.lck"
  43 
  44 _compile(){
  45 
  46     if [ ! -d ${_testclasses} ]
  47     then
  48       mkdir -p ${_testclasses} 
  49     fi   
  50 
  51     rm -f ${_testclasses}/JMXStartStopTest.class
  52 
  53     # Compile testcase
  54     ${COMPILEJAVA}/bin/javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -d ${_testclasses} \
  55         JMXStartStopDoSomething.java JMXStartStopTest.java 
  56 
  57     if [ ! -f ${_testclasses}/JMXStartStopTest.class ]
  58     then
  59       echo "ERROR: Can't compile"
  60       exit -1
  61     fi
  62 }
  63 
  64 _app_start(){
  65   ${TESTJAVA}/bin/java ${TESTVMOPTS} $* -cp ${_testclasses} JMXStartStopDoSomething  >> ${_logname} 2>&1 &
  66 
  67   x=0
  68   while [ ! -f ${_lockFileName} ]
  69   do
  70      if [ $x -gt 20 ]
  71      then
  72         echo "ERROR: Test app not started"
  73         if [ "${_jtreg}" = "yes" ]
  74         then
  75            exit -1
  76         fi   
  77      fi    
  78         
  79      echo "Waiting JMXStartStopDoSomething to start: $x"
  80      x=`expr $x + 1`
  81      sleep 1
  82   done
  83 }
  84 
  85 _get_pid(){
  86     ${COMPILEJAVA}/bin/jps ${TESTTOOLVMOPTS} | sed -n "/JMXStartStopDoSomething/s/ .*//p"
  87 }
  88 
  89 _app_stop(){
  90   rm ${_lockFileName}
  91 
  92   # wait until VM is actually shuts down
  93   while true 
  94   do
  95     npid=`_get_pid`
  96     if [ "${npid}" = "" ] 
  97     then
  98       break
  99     fi
 100     sleep 1
 101   done 
 102 }
 103 
 104 _exit_on_jtreg(){
 105   # Stop on first failed test under jtreg
 106   if [ "${_jtreg}" = "yes" ]
 107   then
 108       _app_stop
 109       exit -1
 110   fi
 111 }
 112 
 113 _testme(){
 114   ${TESTJAVA}/bin/java ${TESTVMOPTS} -cp ${_testclasses} JMXStartStopTest $*
 115 }   
 116 
 117   
 118 _jcmd(){
 119   ${TESTJAVA}/bin/jcmd ${TESTTOOLVMOPTS} JMXStartStopDoSomething $* > /dev/null 2>/dev/null
 120 } 
 121 
 122 _echo(){
 123     echo "$*"
 124     echo "$*" >> ${_logname}
 125 }
 126    
 127 # ============= TESTS ======================================
 128    
 129 test_01(){
 130 # Run an app with JMX enabled stop it and 
 131 # restart on other port
 132         
 133     _echo "**** Test one ****"      
 134 
 135     _app_start  -Dcom.sun.management.jmxremote.port=$1 \
 136                 -Dcom.sun.management.jmxremote.authenticate=false \
 137                 -Dcom.sun.management.jmxremote.ssl=false 
 138 
 139     res1=`_testme $1`


 429     fi
 430  
 431     _app_stop
 432 }   
 433 
 434 test_11(){
 435 # Run an app with JMX enabled 
 436 # stop remote agent 
 437 # make sure local agent is not affected
 438 
 439     _echo "**** Test eleven ****"       
 440 
 441     _app_start  -Dcom.sun.management.jmxremote.port=$2 \
 442                 -Dcom.sun.management.jmxremote.authenticate=false \
 443                 -Dcom.sun.management.jmxremote.ssl=false 
 444       
 445     res1=`_testme $2`
 446 
 447     _jcmd ManagementAgent.stop
 448 
 449     pid=`${COMPILEJAVA}/bin/jps ${TESTTOOLVMOPTS} | sed -n "/JMXStartStopDoSomething/s/ .*//p"`
 450     res2=`_testme local ${pid}`
 451 
 452     if [ "${res1}" = "OK_CONN" -a "${res2}" = "OK_CONN" ] 
 453     then
 454         _echo "Passed"
 455     else
 456         _echo "Failed r1(OK):${res1} r2(OK):${res2}"
 457         _exit_on_jtreg
 458     fi
 459  
 460     _app_stop
 461 }   
 462 
 463 test_12(){
 464 # Run an app with JMX disabled 
 465 # start local agent only
 466 
 467     _echo "**** Test twelve ****"       
 468 
 469     _app_start 


 512     else
 513         _echo "Failed r1(NO):${res1}"
 514         _exit_on_jtreg
 515     fi
 516  
 517     _app_stop
 518 }   
 519 
 520 # ============= MAIN =======================================
 521 
 522 if [ "x${TESTJAVA}" = "x" ]
 523 then
 524   echo "TESTJAVA env have to be set"
 525   exit
 526 fi
 527 
 528 if [ ! -x "${TESTJAVA}/bin/jcmd" ]
 529 then
 530   echo "${TESTJAVA}/bin/jcmd"
 531   echo "Doesn't exist or not an executable"
 532   exit
 533 fi
 534 
 535 
 536 #------------------------------------------------------------------------------
 537 # reading parameters 
 538 
 539 for parm in "$@"  
 540 do
 541    case $parm in
 542   --jtreg)        _jtreg=yes    ;;
 543   --no-compile)   _compile=no   ;;
 544   --testsuite=*)  _testsuite=`_echo $parm | sed "s,^--.*=\(.*\),\1,"`  ;;
 545   --port-one=*)   _port_one=`_echo $parm | sed "s,^--.*=\(.*\),\1,"`  ;;
 546   --port-two=*)   _port_two=`_echo $parm | sed "s,^--.*=\(.*\),\1,"`  ;;
 547   *) 
 548      echo "Undefined parameter $parm. Try --help for help" 
 549      exit 
 550    ;;
 551  esac 
 552 done