#
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#
# @test
# @bug 4212439 5102289 6272156
# @summary Tests for expiration control and reloading expired resource bundles.
# @build ExpirationTest
# @run shell/timeout=300 ExpirationTest.sh
#
# Timings of the test sequence
#
# 0 5 7 10 20 40 [seconds]
# +---------+----+------+------//------+------//------+--
# g X g X U g [event]
#
# 0 g - java starts; the first getBundle call gets "German";
# sleep for 7 sec
# 5 X - the bundle expires (every 5 seconds)
# 7 g - java wakes up; the second getBundle call still gets "German";
# sleep for 33 sec
# 10 X - the bundle expires in the cache
# 20 U - shell script updates DE and add AT
# 40 g - java wakes up; third getBundle call; gets "Deutsch"
#
# event: g - getBundle, X - eXpire, U - Update
#
#
# ExpirationTest.java uses 3 exit values.
# 0 - passed
# 1 - failed
# 2 - can't proceed due to slow platform
#
# Check environment variables
if [ "x$TESTJAVA" = "x" ]; then
1>&2 echo "No TESTJAVA defined. exiting..."
exit 1
fi
# Make sure that this test is run in C locale
LANG=C
export LANG
export LC_ALL
: ${TESTCLASSES:=.}
# YES if the platform has %s support in date
DEL=";"
;;
DEL=":"
;;
DEL=":"
;;
esac
# Interval until resources are updated
INTERVAL=20
rm -f ${DATA}*.properties
}
F="${DATA}*.properties"
else
F="-C classes ${ROOT}.class -C classes ${JA}.class -C classes ${DE}.class"
fi
rm -f ${DATA}*.properties
}
}
(echo "
import java.util.*;
public class $1 extends ListResourceBundle {
public Object[][] getContents() {
return new Object[][] {
{ \"data\", \"$2\" },"
if [ "x$3" != "x" ]; then
echo " { \"january\", \"$3\" },"
fi
echo " };
}
}
# add de_AT
}
createJava $AT Deutsch "J\\u00e4nner"
}
else
F="-C classes ${DE}.class -C classes ${AT}.class"
fi
}
date '+%s'
else
# Returns an approximation of the offset from the Epoch in
# seconds.
awk '{d=($1-1970)*365.2425; print int(((((((d+$2-1)*24)+$3)*60)+$3)*60)+$5);}'
fi
}
#
# Execute $1 and check how long it takes
#
S=`getSeconds`
eval $1
E=`getSeconds`
D=`expr $E - $S`
#
# If this machine is too slow, give up the further testing.
#
1>&2 echo "This machine took $D seconds to prepare test data," \
"which is too slow to proceed. Exiting..."
exit 0
fi
unset S
unset E
unset D
}
if [ $1 = 0 ]; then
echo "$2: PASSED"
elif [ $1 != 2 ]; then
echo "$2: FAILED"
exit 1
else
# Just we should't proceed to avoid timing issues.
exit 0
fi
}
#
# Before starting tests, check the latency with Thread.sleep().
#
STATUS=$?
if [ $STATUS = 2 ]; then
exit 0
fi
#
# Tests for properties
#
#
# Test with plain files (properties)
#
#
# Creates properties files
#
#
# Execute a child process which will update files in $INTERVAL seconds.
#
(sleep $INTERVAL; updateDEaddAT; exit 0) &
STATUS=$?
wait
#
# Test with jar file if jar is available (properties)
#
else
fi
echo ""
#
# Create a jar files with properties
#
STATUS=$?
wait
fi
#
# Test for classes
#
# Note: class-based resource bundles can't be reloaded due to the
# cache support in class loaders. So the results of the test cases
# below are not checked. (Test cases always pass.)
# If there's no javac available, then give up the test with
# class-based properties.
exit 0
fi
JA=`basename $JA .properties`
DE=`basename $DE .properties`
AT=`basename $AT .properties`
echo ""
#
# Create class files
#
(sleep $INTERVAL; updateClassDEaddClassAT; exit 0) &
STATUS=$?
wait
echo ""
#
# Create a jar file with class files
#
STATUS=$?
wait
fi
exit 0