diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 8222887..96ffd46 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -7,7 +7,7 @@ jobs: test: # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#choosing-github-hosted-runners runs-on: ${{ matrix.os }} - timeout-minutes: 5 + timeout-minutes: 10 name: fast test on OS ${{ matrix.os }} strategy: matrix: diff --git a/.github/workflows/strong_ci.yaml b/.github/workflows/strong_ci.yaml index abaa06d..91b54cf 100644 --- a/.github/workflows/strong_ci.yaml +++ b/.github/workflows/strong_ci.yaml @@ -7,7 +7,7 @@ jobs: test: # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#choosing-github-hosted-runners runs-on: ubuntu-latest - timeout-minutes: 10 + timeout-minutes: 15 name: test by multiply java versions steps: diff --git a/hello-agent/src/main/java/io/foldright/study/hello/agent/HelloAgent.java b/hello-agent/src/main/java/io/foldright/study/hello/agent/HelloAgent.java index a8a9909..5b9bfde 100644 --- a/hello-agent/src/main/java/io/foldright/study/hello/agent/HelloAgent.java +++ b/hello-agent/src/main/java/io/foldright/study/hello/agent/HelloAgent.java @@ -8,8 +8,8 @@ import java.util.Collections; import java.util.List; -import static io.foldright.study.agent.utils.transform.ThreadPoolExecutorTransformlet.THREAD_POOL_EXECUTOR_CLASS_NAME; import static io.foldright.study.agent.utils.Utils.isClassLoaded; +import static io.foldright.study.agent.utils.transform.ThreadPoolExecutorTransformlet.THREAD_POOL_EXECUTOR_CLASS_NAME; /** @@ -21,6 +21,10 @@ public class HelloAgent { public static void premain(final String agentArgs, @NonNull final Instrumentation inst) { System.out.println("[" + NAME + "Agent] Enter premain!"); + if (System.getenv().containsKey("STUDY_HELLO_AGENT_THROW_EXCEPTION")) { + throw new IllegalStateException("throw exception for jvm start failure test by setting HELLO_AGENT_THROW_EXCEPTION env var!"); + } + if (isClassLoaded(inst, THREAD_POOL_EXECUTOR_CLASS_NAME)) throw new IllegalStateException("class " + THREAD_POOL_EXECUTOR_CLASS_NAME + " already loaded"); diff --git a/scripts/integration_test.sh b/scripts/integration_test.sh index 303d217..c839b40 100755 --- a/scripts/integration_test.sh +++ b/scripts/integration_test.sh @@ -67,6 +67,10 @@ for jdk_version in "${JDK_VERSIONS[@]}"; do # just test without build cu::head_line_echo "test with Java $jdk_version: $JAVA_HOME" + ############################## + # run unit test + ############################## + # skip default jdk, already tested above if [ "$jdk_version" != "$default_build_jdk_version" ]; then # just test without build @@ -83,9 +87,21 @@ for jdk_version in "${JDK_VERSIONS[@]}"; do cu::head_line_echo test under hello agent twice STUDY_AGENT_RUN_MODE=only-hello-agent-twice jvb::mvn_cmd ${CI_MORE_BEGIN_OPTS:-} dependency:properties surefire:test ${CI_MORE_END_OPTS:-} + ############################## + # run main test + ############################## + cu::head_line_echo run Main without agents jvb::mvn_cmd dependency:properties exec:exec -pl main-runner + cu::head_line_echo "test jvm should fail if throw exception in agent premain" + tmp_output_file="target/study_hello_agent_throw_exception_$$_$RANDOM.tmp" + STUDY_HELLO_AGENT_THROW_EXCEPTION= STUDY_AGENT_RUN_MODE=only-hello-agent jvb::mvn_cmd dependency:properties exec:exec -pl main-runner 2>&1 | + tee "$tmp_output_file" && + cu::die "jvm should fail if throw exception in agent premain!" + cu::log_then_run grep "IllegalStateException.*throw exception for jvm start failure test by setting HELLO_AGENT_THROW_EXCEPTION env var!" "$tmp_output_file" || + cu::die "should contains exception message!" + cu::head_line_echo run Main under hello and world agents STUDY_AGENT_RUN_MODE=hello-and-world-agents jvb::mvn_cmd dependency:properties exec:exec -pl main-runner diff --git a/world-agent/src/main/java/io/foldright/study/world/agent/WorldAgent.java b/world-agent/src/main/java/io/foldright/study/world/agent/WorldAgent.java index 4548613..d0c7927 100644 --- a/world-agent/src/main/java/io/foldright/study/world/agent/WorldAgent.java +++ b/world-agent/src/main/java/io/foldright/study/world/agent/WorldAgent.java @@ -8,8 +8,8 @@ import java.util.Collections; import java.util.List; -import static io.foldright.study.agent.utils.transform.ThreadPoolExecutorTransformlet.THREAD_POOL_EXECUTOR_CLASS_NAME; import static io.foldright.study.agent.utils.Utils.isClassLoaded; +import static io.foldright.study.agent.utils.transform.ThreadPoolExecutorTransformlet.THREAD_POOL_EXECUTOR_CLASS_NAME; /**