Skip to content

Commit 2196e70

Browse files
authored
Fix xxljob latest dep tests (#15490)
1 parent 23b6953 commit 2196e70

File tree

7 files changed

+253
-27
lines changed

7 files changed

+253
-27
lines changed

instrumentation/xxl-job/xxl-job-2.3.0/javaagent/build.gradle.kts

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,46 @@ dependencies {
2727
testInstrumentation(project(":instrumentation:xxl-job:xxl-job-2.3.0:javaagent"))
2828

2929
testImplementation(project(":instrumentation:xxl-job:xxl-job-common:testing"))
30+
31+
// latest version is tested in a separate test suite
32+
latestDepTestLibrary("com.xuxueli:xxl-job-core:3.2.+") // documented limitation
33+
}
34+
35+
val testLatestDeps = findProperty("testLatestDeps") as Boolean
36+
37+
testing {
38+
suites {
39+
val xxlJob33Test by registering(JvmTestSuite::class) {
40+
dependencies {
41+
val version = if (testLatestDeps) "latest.release" else "3.3.0"
42+
implementation("com.xuxueli:xxl-job-core:$version")
43+
implementation(project(":instrumentation:xxl-job:xxl-job-common:testing"))
44+
}
45+
}
46+
}
3047
}
3148

32-
tasks.withType<Test>().configureEach {
33-
// required on jdk17
34-
jvmArgs("--add-opens=java.base/java.lang=ALL-UNNAMED")
35-
jvmArgs("-XX:+IgnoreUnrecognizedVMOptions")
36-
jvmArgs("-Dotel.instrumentation.xxl-job.experimental-span-attributes=true")
49+
tasks {
50+
withType<Test>().configureEach {
51+
// required on jdk17
52+
jvmArgs("--add-opens=java.base/java.lang=ALL-UNNAMED")
53+
jvmArgs("-XX:+IgnoreUnrecognizedVMOptions")
54+
jvmArgs("-Dotel.instrumentation.xxl-job.experimental-span-attributes=true")
55+
}
56+
57+
named("compileXxlJob33TestJava", JavaCompile::class).configure {
58+
options.release.set(17)
59+
}
60+
val testJavaVersion =
61+
gradle.startParameter.projectProperties.get("testJavaVersion")?.let(JavaVersion::toVersion)
62+
?: JavaVersion.current()
63+
if (!testJavaVersion.isCompatibleWith(JavaVersion.VERSION_17)) {
64+
named("xxlJob33Test", Test::class).configure {
65+
enabled = false
66+
}
67+
}
68+
69+
check {
70+
dependsOn(testing.suites)
71+
}
3772
}

instrumentation/xxl-job/xxl-job-2.3.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/xxljob/v2_3_0/CustomizedFailedHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
class CustomizedFailedHandler extends IJobHandler {
1212

1313
@Override
14-
public void execute() throws Exception {
14+
public void execute() {
1515
XxlJobHelper.handleFail();
1616
}
1717
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.javaagent.instrumentation.xxljob.v3_3_0;
7+
8+
import com.xxl.job.core.context.XxlJobHelper;
9+
import com.xxl.job.core.handler.IJobHandler;
10+
11+
class CustomizedFailedHandler extends IJobHandler {
12+
13+
@Override
14+
public void execute() {
15+
XxlJobHelper.handleFail();
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.javaagent.instrumentation.xxljob.v3_3_0;
7+
8+
import com.xxl.tool.response.Response;
9+
import java.lang.reflect.Method;
10+
11+
class ReflectiveMethodsFactory {
12+
13+
private ReflectiveMethodsFactory() {}
14+
15+
public static class ReflectObject {
16+
17+
private ReflectObject() {}
18+
19+
public void initMethod() {}
20+
21+
public void destroyMethod() {}
22+
23+
public Response<String> echo(String param) {
24+
Response<String> result = new Response<>();
25+
result.setData("echo: " + param);
26+
return result;
27+
}
28+
}
29+
30+
private static final Object SINGLETON_OBJECT = new ReflectObject();
31+
32+
static Object getTarget() {
33+
return SINGLETON_OBJECT;
34+
}
35+
36+
static Method getMethod() {
37+
try {
38+
return SINGLETON_OBJECT.getClass().getMethod("echo", String.class);
39+
} catch (Throwable t) {
40+
// Ignore
41+
}
42+
return null;
43+
}
44+
45+
static Method getInitMethod() {
46+
try {
47+
return SINGLETON_OBJECT.getClass().getMethod("initMethod");
48+
} catch (Throwable t) {
49+
// Ignore
50+
}
51+
return null;
52+
}
53+
54+
static Method getDestroyMethod() {
55+
try {
56+
return SINGLETON_OBJECT.getClass().getMethod("destroyMethod");
57+
} catch (Throwable t) {
58+
// Ignore
59+
}
60+
return null;
61+
}
62+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.javaagent.instrumentation.xxljob.v3_3_0;
7+
8+
import com.xxl.job.core.context.XxlJobHelper;
9+
import com.xxl.job.core.handler.IJobHandler;
10+
11+
class SimpleCustomizedHandler extends IJobHandler {
12+
13+
@Override
14+
public void execute() {
15+
XxlJobHelper.handleSuccess();
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.javaagent.instrumentation.xxljob.v3_3_0;
7+
8+
import static io.opentelemetry.instrumentation.xxljob.XxlJobTestingConstants.DEFAULT_GLUE_UPDATE_TIME;
9+
import static io.opentelemetry.instrumentation.xxljob.XxlJobTestingConstants.GLUE_JOB_GROOVY_SOURCE;
10+
import static io.opentelemetry.instrumentation.xxljob.XxlJobTestingConstants.GLUE_JOB_SHELL_SCRIPT;
11+
12+
import com.xxl.job.core.glue.GlueFactory;
13+
import com.xxl.job.core.glue.GlueTypeEnum;
14+
import com.xxl.job.core.handler.IJobHandler;
15+
import com.xxl.job.core.handler.impl.GlueJobHandler;
16+
import com.xxl.job.core.handler.impl.MethodJobHandler;
17+
import com.xxl.job.core.handler.impl.ScriptJobHandler;
18+
import com.xxl.job.core.openapi.model.TriggerRequest;
19+
import com.xxl.job.core.thread.JobThread;
20+
import io.opentelemetry.instrumentation.xxljob.AbstractXxlJobTest;
21+
22+
class XxlJobTest extends AbstractXxlJobTest {
23+
24+
private static final MethodJobHandler METHOD_JOB_HANDLER =
25+
new MethodJobHandler(
26+
ReflectiveMethodsFactory.getTarget(),
27+
ReflectiveMethodsFactory.getMethod(),
28+
ReflectiveMethodsFactory.getInitMethod(),
29+
ReflectiveMethodsFactory.getDestroyMethod());
30+
31+
private static final IJobHandler GROOVY_HANDLER;
32+
33+
static {
34+
try {
35+
GROOVY_HANDLER = GlueFactory.getInstance().loadNewInstance(GLUE_JOB_GROOVY_SOURCE);
36+
} catch (Exception e) {
37+
throw new IllegalStateException(e);
38+
}
39+
}
40+
41+
private static final GlueJobHandler GLUE_JOB_HANDLER =
42+
new GlueJobHandler(GROOVY_HANDLER, DEFAULT_GLUE_UPDATE_TIME);
43+
44+
private static final ScriptJobHandler SCRIPT_JOB_HANDLER =
45+
new ScriptJobHandler(
46+
2, DEFAULT_GLUE_UPDATE_TIME, GLUE_JOB_SHELL_SCRIPT, GlueTypeEnum.GLUE_SHELL);
47+
48+
@Override
49+
protected String getPackageName() {
50+
return "io.opentelemetry.javaagent.instrumentation.xxljob.v3_3_0";
51+
}
52+
53+
@Override
54+
protected IJobHandler getGlueJobHandler() {
55+
return GLUE_JOB_HANDLER;
56+
}
57+
58+
@Override
59+
protected IJobHandler getScriptJobHandler() {
60+
return SCRIPT_JOB_HANDLER;
61+
}
62+
63+
@Override
64+
protected IJobHandler getCustomizeHandler() {
65+
return new SimpleCustomizedHandler();
66+
}
67+
68+
@Override
69+
protected IJobHandler getCustomizeFailedHandler() {
70+
return new CustomizedFailedHandler();
71+
}
72+
73+
@Override
74+
protected IJobHandler getMethodHandler() {
75+
return METHOD_JOB_HANDLER;
76+
}
77+
78+
@Override
79+
protected void trigger(JobThread jobThread, String executorParams) {
80+
TriggerRequest triggerParam = new TriggerRequest();
81+
triggerParam.setExecutorTimeout(0);
82+
if (executorParams != null) {
83+
triggerParam.setExecutorParams(executorParams);
84+
}
85+
jobThread.pushTriggerQueue(triggerParam);
86+
jobThread.start();
87+
}
88+
89+
@Override
90+
protected Class<?> getReflectObjectClass() {
91+
return ReflectiveMethodsFactory.ReflectObject.class;
92+
}
93+
}

instrumentation/xxl-job/xxl-job-common/testing/src/main/java/io/opentelemetry/instrumentation/xxljob/AbstractXxlJobTest.java

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,24 @@ static void setUp() {
3939
XxlJobFileAppender.initLogPath("build/xxljob/log");
4040
}
4141

42-
@Test
43-
void testGlueJob() {
44-
JobThread jobThread = new JobThread(1, getGlueJobHandler());
42+
private void trigger(JobThread jobThread) {
43+
trigger(jobThread, null);
44+
}
45+
46+
protected void trigger(JobThread jobThread, String executorParams) {
4547
TriggerParam triggerParam = new TriggerParam();
4648
triggerParam.setExecutorTimeout(0);
49+
if (executorParams != null) {
50+
triggerParam.setExecutorParams(executorParams);
51+
}
4752
jobThread.pushTriggerQueue(triggerParam);
4853
jobThread.start();
54+
}
55+
56+
@Test
57+
void testGlueJob() {
58+
JobThread jobThread = new JobThread(1, getGlueJobHandler());
59+
trigger(jobThread);
4960
checkXxlJob(
5061
"CustomizedGroovyHandler.execute",
5162
StatusData.unset(),
@@ -59,22 +70,15 @@ void testGlueJob() {
5970
@Test
6071
void testScriptJob() {
6172
JobThread jobThread = new JobThread(2, getScriptJobHandler());
62-
TriggerParam triggerParam = new TriggerParam();
63-
triggerParam.setExecutorParams("");
64-
triggerParam.setExecutorTimeout(0);
65-
jobThread.pushTriggerQueue(triggerParam);
66-
jobThread.start();
73+
trigger(jobThread, "");
6774
checkXxlJobWithoutCodeAttributes("GLUE(Shell)", StatusData.unset(), GlueTypeEnum.GLUE_SHELL, 2);
6875
jobThread.toStop("Test finish");
6976
}
7077

7178
@Test
7279
void testSimpleJob() {
7380
JobThread jobThread = new JobThread(3, getCustomizeHandler());
74-
TriggerParam triggerParam = new TriggerParam();
75-
triggerParam.setExecutorTimeout(0);
76-
jobThread.pushTriggerQueue(triggerParam);
77-
jobThread.start();
81+
trigger(jobThread);
7882
checkXxlJob(
7983
"SimpleCustomizedHandler.execute",
8084
StatusData.unset(),
@@ -84,32 +88,30 @@ void testSimpleJob() {
8488
jobThread.toStop("Test finish");
8589
}
8690

91+
protected Class<?> getReflectObjectClass() {
92+
return ReflectiveMethodsFactory.ReflectObject.class;
93+
}
94+
8795
@Test
8896
public void testMethodJob() {
8997
// method handle is null if test is not supported by tested version of the library
9098
Assumptions.assumeTrue(getMethodHandler() != null);
9199

92100
JobThread jobThread = new JobThread(4, getMethodHandler());
93-
TriggerParam triggerParam = new TriggerParam();
94-
triggerParam.setExecutorTimeout(0);
95-
jobThread.pushTriggerQueue(triggerParam);
96-
jobThread.start();
101+
trigger(jobThread);
97102
checkXxlJob(
98103
"ReflectObject.echo",
99104
StatusData.unset(),
100105
GlueTypeEnum.BEAN,
101-
"io.opentelemetry.instrumentation.xxljob.ReflectiveMethodsFactory$ReflectObject",
106+
getReflectObjectClass().getName(),
102107
"echo");
103108
jobThread.toStop("Test finish");
104109
}
105110

106111
@Test
107112
void testFailedJob() {
108113
JobThread jobThread = new JobThread(5, getCustomizeFailedHandler());
109-
TriggerParam triggerParam = new TriggerParam();
110-
triggerParam.setExecutorTimeout(0);
111-
jobThread.pushTriggerQueue(triggerParam);
112-
jobThread.start();
114+
trigger(jobThread);
113115
checkXxlJob(
114116
"CustomizedFailedHandler.execute",
115117
StatusData.error(),

0 commit comments

Comments
 (0)