test.sh 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #!/usr/bin/env bash
  2. # Cause the script to exit if a single command fails.
  3. set -e
  4. # Show explicitly which commands are currently running.
  5. set -x
  6. ROOT_DIR=$(cd "$(dirname "${BASH_SOURCE:-$0}")"; pwd)
  7. java -version
  8. pushd "$ROOT_DIR"
  9. echo "Check java code format."
  10. # check google java style
  11. mvn -T16 spotless:check
  12. # check naming and others
  13. mvn -T16 checkstyle:check
  14. popd
  15. run_testng() {
  16. local pid
  17. local exit_code
  18. "$@" &
  19. pid=$!
  20. if wait $pid; then
  21. exit_code=0
  22. else
  23. exit_code=$?
  24. fi
  25. # exit_code == 2 means there are skipped tests.
  26. if [ $exit_code -ne 2 ] && [ $exit_code -ne 0 ] ; then
  27. # Only print log files if it ran in cluster mode
  28. if [[ ! "$*" =~ LOCAL ]]; then
  29. if [ $exit_code -gt 128 ] ; then
  30. # Test crashed. Print the driver log for diagnosis.
  31. cat /tmp/ray/session_latest/logs/java-core-driver-*$pid*
  32. fi
  33. fi
  34. # Only print the hs_err_pid file of TestNG process
  35. find . -name "hs_err_pid$pid.log" -exec cat {} +
  36. exit $exit_code
  37. fi
  38. }
  39. run_timeout() {
  40. local pid
  41. timeout=$1
  42. shift 1
  43. "$@" &
  44. pid=$!
  45. sleep "$timeout"
  46. if ps -p $pid > /dev/null
  47. then
  48. echo "run_timeout process exists, kill it."
  49. kill -9 $pid
  50. else
  51. echo "run_timeout process not exist."
  52. cat /tmp/ray/session_latest/logs/java-core-driver-*$pid*
  53. exit 1
  54. fi
  55. }
  56. pushd "$ROOT_DIR"/..
  57. echo "Build java maven deps."
  58. bazel build //java:gen_maven_deps
  59. echo "Build test jar."
  60. bazel build //java:all_tests_shaded.jar
  61. java/generate_jni_header_files.sh
  62. if ! git diff --exit-code -- java src/ray/core_worker/lib/java; then
  63. echo "Files are changed after build. Common cases are:"
  64. echo " * Java native methods doesn't match JNI files. You need to either update Java code or JNI code."
  65. echo " * pom_template.xml and pom.xml doesn't match. You need to either update pom_template.xml or pom.xml."
  66. exit 1
  67. fi
  68. # NOTE(kfstrom): Java test troubleshooting only.
  69. # Set MAX_ROUNDS to a big number (e.g. 1000) to run Java tests repeatedly.
  70. # You may also want to modify java/testng.xml to run only a subset of test cases.
  71. MAX_ROUNDS=1
  72. if [ $MAX_ROUNDS -gt 1 ]; then
  73. export RAY_BACKEND_LOG_LEVEL=debug
  74. fi
  75. export RAY_ENABLE_WINDOWS_OR_OSX_CLUSTER=1
  76. round=1
  77. while true; do
  78. echo Starting cluster mode test round $round
  79. echo "Running tests under cluster mode."
  80. # TODO(hchen): Ideally, we should use the following bazel command to run Java tests. However, if there're skipped tests,
  81. # TestNG will exit with code 2. And bazel treats it as test failure.
  82. # bazel test //java:all_tests --config=ci || cluster_exit_code=$?
  83. run_testng java -cp "$ROOT_DIR"/../bazel-bin/java/all_tests_shaded.jar org.testng.TestNG -d /tmp/ray_java_test_output "$ROOT_DIR"/testng.xml
  84. echo Finished cluster mode test round $round
  85. date
  86. round=$((round+1))
  87. if (( round > MAX_ROUNDS )); then
  88. break
  89. fi
  90. done
  91. echo "Running tests under local mode."
  92. run_testng java -Dray.run-mode="LOCAL" -cp "$ROOT_DIR"/../bazel-bin/java/all_tests_shaded.jar org.testng.TestNG -d /tmp/ray_java_test_output "$ROOT_DIR"/testng.xml
  93. echo "Running connecting existing cluster tests."
  94. case "${OSTYPE}" in
  95. linux*) ip=$(hostname -I | awk '{print $1}');;
  96. darwin*) ip=$(ipconfig getifaddr en0);;
  97. *) echo "Can't get ip address for ${OSTYPE}"; exit 1;;
  98. esac
  99. RAY_BACKEND_LOG_LEVEL=debug ray start --head --port=6379 --redis-password=123456 --node-ip-address="$ip"
  100. RAY_BACKEND_LOG_LEVEL=debug java -cp bazel-bin/java/all_tests_shaded.jar -Dray.address="$ip:6379"\
  101. -Dray.redis.password='123456' -Dray.job.code-search-path="$PWD/bazel-bin/java/all_tests_shaded.jar" io.ray.test.MultiDriverTest
  102. ray stop
  103. echo "Running documentation demo code."
  104. docdemo_path="java/test/src/main/java/io/ray/docdemo/"
  105. for file in "$docdemo_path"*.java; do
  106. file=${file#"$docdemo_path"}
  107. class=${file%".java"}
  108. echo "Running $class"
  109. java -cp bazel-bin/java/all_tests_shaded.jar -Dray.raylet.startup-token=0 "io.ray.docdemo.$class"
  110. done
  111. popd
  112. pushd "$ROOT_DIR"
  113. echo "Testing maven install."
  114. mvn -Dorg.slf4j.simpleLogger.defaultLogLevel=WARN clean install -DskipTests -Dcheckstyle.skip
  115. # Ensure mvn test works
  116. mvn test -pl test -Dtest="io.ray.test.HelloWorldTest"
  117. popd
  118. pushd "$ROOT_DIR"
  119. echo "Running performance test."
  120. run_timeout 60 java -cp "$ROOT_DIR"/../bazel-bin/java/all_tests_shaded.jar io.ray.performancetest.test.ActorPerformanceTestCase1
  121. # The performance process may be killed by run_timeout, so clear ray here.
  122. ray stop
  123. popd