Skip to content

Commit

Permalink
build: add enable-only-hello-agent-twice-mode maven profile
Browse files Browse the repository at this point in the history
  • Loading branch information
oldratlee committed Jul 16, 2023
1 parent f19c1d3 commit 9624e4d
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 5 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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*
Expand Down
44 changes: 44 additions & 0 deletions main-runner/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,50 @@
<argument>-classpath</argument>
<classpath/>

<argument>${exec.mainClass}</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>enable-only-hello-agent-twice-mode</id>
<activation>
<property>
<name>env.STUDY_AGENT_RUN_MODE</name>
<value>only-hello-agent-twice</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>@{argLine} ${hello.agent.opt} ${hello.agent.opt}</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<arguments>
<argument>-Xms256m</argument>
<argument>-ea</argument>
<argument>-Duser.language=en</argument>
<argument>-Duser.country=US</argument>

<!--
<argument>-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005</argument>
-->

<argument>${hello.agent.opt}</argument>
<argument>${hello.agent.opt}</argument>

<argument>-classpath</argument>
<classpath/>

<argument>${exec.mainClass}</argument>
</arguments>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public enum StudyAgentMode {
NO_AGENTS,
HELLO_AND_WORLD_AGENTS,
ONLY_HELLO_AGENT,
ONLY_HELLO_AGENT_TWICE,

;

Expand All @@ -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);
}
Expand Down
16 changes: 11 additions & 5 deletions main-runner/src/test/java/io/foldright/study/main/MainTest.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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")
}
}
Expand Down
6 changes: 6 additions & 0 deletions scripts/integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

0 comments on commit 9624e4d

Please sign in to comment.