From 9624e4d6b5561c70af4ec94b5d85bb043c5e7e42 Mon Sep 17 00:00:00 2001 From: Jerry Lee Date: Fri, 14 Jul 2023 16:06:50 +0800 Subject: [PATCH] build: add `enable-only-hello-agent-twice-mode` maven profile --- .github/workflows/ci.yaml | 16 +++++++ main-runner/pom.xml | 44 +++++++++++++++++++ .../foldright/study/main/StudyAgentMode.java | 3 ++ .../java/io/foldright/study/main/MainTest.kt | 16 ++++--- scripts/integration_test.sh | 6 +++ 5 files changed, 80 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index ba8fecd..8222887 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -35,6 +35,10 @@ jobs: run: ./mvnw dependency:properties surefire:test env: STUDY_AGENT_RUN_MODE: only-hello-agent + - name: test under hello agent twice + run: ./mvnw dependency:properties surefire:test + env: + STUDY_AGENT_RUN_MODE: only-hello-agent-twice - name: run Main without agents run: ./mvnw dependency:properties exec:exec -pl main-runner - name: run Main under hello and world agents @@ -45,6 +49,10 @@ jobs: run: ./mvnw dependency:properties exec:exec -pl main-runner env: STUDY_AGENT_RUN_MODE: only-hello-agent + - name: run Main under hello agent twice + run: ./mvnw dependency:properties exec:exec -pl main-runner + env: + STUDY_AGENT_RUN_MODE: only-hello-agent-twice - name: setup Java 8 uses: actions/setup-java@v3 @@ -61,6 +69,10 @@ jobs: run: ./mvnw dependency:properties surefire:test env: STUDY_AGENT_RUN_MODE: only-hello-agent + - name: test under hello agent twice + run: ./mvnw dependency:properties surefire:test + env: + STUDY_AGENT_RUN_MODE: only-hello-agent-twice - name: run Main without agents run: ./mvnw dependency:properties exec:exec -pl main-runner - name: run Main under hello and world agents @@ -71,6 +83,10 @@ jobs: run: ./mvnw dependency:properties exec:exec -pl main-runner env: STUDY_AGENT_RUN_MODE: only-hello-agent + - name: run Main under hello agent twice + run: ./mvnw dependency:properties exec:exec -pl main-runner + env: + STUDY_AGENT_RUN_MODE: only-hello-agent-twice - name: 'remove self maven install files(OS: *nix)' run: rm -rf $HOME/.m2/repository/io/foldright/study* diff --git a/main-runner/pom.xml b/main-runner/pom.xml index ca88215..b002316 100644 --- a/main-runner/pom.xml +++ b/main-runner/pom.xml @@ -137,6 +137,50 @@ -classpath + ${exec.mainClass} + + + + + + + + enable-only-hello-agent-twice-mode + + + env.STUDY_AGENT_RUN_MODE + only-hello-agent-twice + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + @{argLine} ${hello.agent.opt} ${hello.agent.opt} + + + + org.codehaus.mojo + exec-maven-plugin + + + -Xms256m + -ea + -Duser.language=en + -Duser.country=US + + + + ${hello.agent.opt} + ${hello.agent.opt} + + -classpath + + ${exec.mainClass} diff --git a/main-runner/src/main/java/io/foldright/study/main/StudyAgentMode.java b/main-runner/src/main/java/io/foldright/study/main/StudyAgentMode.java index 89c8cae..07332d9 100644 --- a/main-runner/src/main/java/io/foldright/study/main/StudyAgentMode.java +++ b/main-runner/src/main/java/io/foldright/study/main/StudyAgentMode.java @@ -4,6 +4,7 @@ public enum StudyAgentMode { NO_AGENTS, HELLO_AND_WORLD_AGENTS, ONLY_HELLO_AGENT, + ONLY_HELLO_AGENT_TWICE, ; @@ -16,6 +17,8 @@ public static StudyAgentMode getStudyAgentMode() { return HELLO_AND_WORLD_AGENTS; } else if ("only-hello-agent".equals(value)) { return ONLY_HELLO_AGENT; + } else if ("only-hello-agent-twice".equals(value)) { + return ONLY_HELLO_AGENT_TWICE; } else { throw new IllegalStateException("Illegal value of env var(" + envVarName + "): " + value); } diff --git a/main-runner/src/test/java/io/foldright/study/main/MainTest.kt b/main-runner/src/test/java/io/foldright/study/main/MainTest.kt index b5bcf02..37cefe8 100644 --- a/main-runner/src/test/java/io/foldright/study/main/MainTest.kt +++ b/main-runner/src/test/java/io/foldright/study/main/MainTest.kt @@ -1,5 +1,6 @@ package io.foldright.study.main +import io.foldright.study.main.StudyAgentMode.* import io.kotest.assertions.fail import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.string.shouldContainOnlyOnce @@ -8,28 +9,33 @@ import java.util.concurrent.Executors class MainTest : FunSpec({ - test("agent hacked toString of ThreadPoolExecutor") { + test("agent hacked toString method of ThreadPoolExecutor") { val executor = Executors.newCachedThreadPool() as java.util.concurrent.ThreadPoolExecutor val addedByHelloTransformlet = "[[[AddedByHelloTransformlet]]]" val addedByWorldTransformlet = "[[[AddedByWorldTransformlet]]]" val executorString = executor.toString() - when (val studyAgentMode = StudyAgentMode.getStudyAgentMode()) { - StudyAgentMode.NO_AGENTS -> { + when (val studyAgentMode = getStudyAgentMode()) { + NO_AGENTS -> { executorString.shouldNotContain(addedByHelloTransformlet) executorString.shouldNotContain(addedByWorldTransformlet) } - StudyAgentMode.HELLO_AND_WORLD_AGENTS -> { + HELLO_AND_WORLD_AGENTS -> { executorString.shouldContainOnlyOnce(addedByHelloTransformlet) executorString.shouldContainOnlyOnce(addedByWorldTransformlet) } - StudyAgentMode.ONLY_HELLO_AGENT -> { + ONLY_HELLO_AGENT -> { executorString.shouldContainOnlyOnce(addedByHelloTransformlet) executorString.shouldNotContain(addedByWorldTransformlet) } + ONLY_HELLO_AGENT_TWICE -> { + executorString.shouldContainOnlyOnce(addedByHelloTransformlet + addedByHelloTransformlet) + executorString.shouldNotContain(addedByWorldTransformlet) + } + else -> fail("Unknown StudyAgentMode: $studyAgentMode") } } diff --git a/scripts/integration_test.sh b/scripts/integration_test.sh index 3990bfd..303d217 100755 --- a/scripts/integration_test.sh +++ b/scripts/integration_test.sh @@ -80,6 +80,9 @@ for jdk_version in "${JDK_VERSIONS[@]}"; do cu::head_line_echo test under hello agent STUDY_AGENT_RUN_MODE=only-hello-agent jvb::mvn_cmd ${CI_MORE_BEGIN_OPTS:-} dependency:properties surefire:test ${CI_MORE_END_OPTS:-} + 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:-} + cu::head_line_echo run Main without agents jvb::mvn_cmd dependency:properties exec:exec -pl main-runner @@ -88,4 +91,7 @@ for jdk_version in "${JDK_VERSIONS[@]}"; do cu::head_line_echo run Main under hello agent STUDY_AGENT_RUN_MODE=only-hello-agent jvb::mvn_cmd dependency:properties exec:exec -pl main-runner + + cu::head_line_echo run Main under hello agent twice + STUDY_AGENT_RUN_MODE=only-hello-agent-twice jvb::mvn_cmd dependency:properties exec:exec -pl main-runner done