test/sun/tools/jstatd/jstatdPort.sh
Print this page
@@ -40,11 +40,15 @@
JSTATD="${TESTJAVA}/bin/jstatd"
JPS="${TESTJAVA}/bin/jps"
JSTAT="${TESTJAVA}/bin/jstat"
HOSTNAME=`uname -n`
-PORT=2099
+PORT=`freePort`
+if [ "${PORT}" = "0" ] ; then
+ echo "Cannot get free port"
+ exit 1
+fi
JSTATD_OUT="jstatd_$$.out"
${JSTATD} -J-Djava.security.policy=${TESTSRC}/all.policy -p ${PORT} 2>&1 > ${JSTATD_OUT} &
JSTATD_PID=$!
@@ -55,16 +59,15 @@
${JPS} ${HOSTNAME}:${PORT} 2>&1 | awk -f ${TESTSRC}/jpsOutput1.awk
if [ $? -ne 0 ]
then
echo "Output of jps differs from expected output. Failed."
+ cleanup
exit 1
fi
-TARGET_PID=`${JPS} | grep "Jstatd" | cut -d" " -f1`
-
-${JSTAT} -gcutil ${TARGET_PID}@${HOSTNAME}:${PORT} 250 5 2>&1 | awk -f ${TESTSRC}/jstatGcutilOutput1.awk
+${JSTAT} -gcutil ${JSTATD_PID}@${HOSTNAME}:${PORT} 250 5 2>&1 | awk -f ${TESTSRC}/jstatGcutilOutput1.awk
RC=$?
if [ ${RC} -ne 0 ]
then
echo "jstat output differs from expected output"
@@ -74,6 +77,8 @@
then
echo "jstatd generated the following, unexpected output:"
RC=1
fi
+cleanup
+
exit ${RC}