Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for XXL-JOB #10421

Merged
merged 16 commits into from
Mar 12, 2024
Prev Previous commit
Next Next commit
Fixed testLatestDeps job run failed
  • Loading branch information
steverao committed Feb 16, 2024
commit 265e9f540dbd01ada03c67f6b59553b15fa0821c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ dependencies {
}
testImplementation("javax.annotation:javax.annotation-api:1.3.2")
testImplementation(project(":instrumentation:xxl-job:xxl-job-common:testing"))
latestDepTestLibrary("com.xuxueli:xxl-job-core:2.1.1") {
exclude("org.codehaus.groovy", "groovy")
}
}

tasks.withType<Test>().configureEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,34 @@ dependencies {
exclude("org.codehaus.groovy", "groovy")
}
testImplementation(project(":instrumentation:xxl-job:xxl-job-common:testing"))
latestDepTestLibrary("com.xuxueli:xxl-job-core:2.2.+") {
exclude("org.codehaus.groovy", "groovy")
}
}

testing {
suites {
val version23Test by registering(JvmTestSuite::class) {
dependencies {
implementation(project(":instrumentation:xxl-job:xxl-job-common:testing"))
if (findProperty("testLatestDeps") as Boolean) {
implementation("com.xuxueli:xxl-job-core:+") {
exclude("org.codehaus.groovy", "groovy")
}
} else {
implementation("com.xuxueli:xxl-job-core:2.3.0") {
exclude("org.codehaus.groovy", "groovy")
}
}
}
}
}
}

tasks {
check {
dependsOn(testing.suites)
}
}

tasks.withType<Test>().configureEach {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.javaagent.instrumentation.xxljob.v2_3_0;

import com.xxl.job.core.handler.IJobHandler;

class SimpleCustomizedHandler extends IJobHandler {

@Override
public void execute() throws Exception {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.javaagent.instrumentation.xxljob.v2_3_0;

import static io.opentelemetry.instrumentation.xxljob.XxlJobTestingConstants.DEFAULT_GLUE_UPDATE_TIME;
import static io.opentelemetry.instrumentation.xxljob.XxlJobTestingConstants.GLUE_JOB_GROOVY_SOURCE;
import static io.opentelemetry.instrumentation.xxljob.XxlJobTestingConstants.GLUE_JOB_SHELL_SCRIPT;
import static io.opentelemetry.instrumentation.xxljob.XxlJobTestingConstants.METHOD_JOB_HANDLER_DESTROY_METHOD;
import static io.opentelemetry.instrumentation.xxljob.XxlJobTestingConstants.METHOD_JOB_HANDLER_INIT_METHOD;
import static io.opentelemetry.instrumentation.xxljob.XxlJobTestingConstants.METHOD_JOB_HANDLER_METHOD;
import static io.opentelemetry.instrumentation.xxljob.XxlJobTestingConstants.METHOD_JOB_HANDLER_OBJECT;

import com.xxl.job.core.glue.GlueFactory;
import com.xxl.job.core.glue.GlueTypeEnum;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.impl.GlueJobHandler;
import com.xxl.job.core.handler.impl.MethodJobHandler;
import com.xxl.job.core.handler.impl.ScriptJobHandler;
import io.opentelemetry.instrumentation.xxljob.AbstractXxlJobTest;

class XxlJobTest extends AbstractXxlJobTest {

private static final MethodJobHandler METHOD_JOB_HANDLER =
new MethodJobHandler(
METHOD_JOB_HANDLER_OBJECT,
METHOD_JOB_HANDLER_METHOD,
METHOD_JOB_HANDLER_INIT_METHOD,
METHOD_JOB_HANDLER_DESTROY_METHOD);

private static final IJobHandler GROOVY_HANDLER;

static {
try {
GROOVY_HANDLER = GlueFactory.getInstance().loadNewInstance(GLUE_JOB_GROOVY_SOURCE);
} catch (Exception e) {
throw new RuntimeException(e);
}
}

private static final GlueJobHandler GLUE_JOB_HANDLER =
new GlueJobHandler(GROOVY_HANDLER, DEFAULT_GLUE_UPDATE_TIME);

private static final ScriptJobHandler SCRIPT_JOB_HANDLER =
new ScriptJobHandler(
2, DEFAULT_GLUE_UPDATE_TIME, GLUE_JOB_SHELL_SCRIPT, GlueTypeEnum.GLUE_SHELL);

@Override
protected String getPackageName() {
return "io.opentelemetry.javaagent.instrumentation.xxljob.v2_3_0";
}

@Override
protected IJobHandler getGlueJobHandler() {
return GLUE_JOB_HANDLER;
}

@Override
protected IJobHandler getScriptJobHandler() {
return SCRIPT_JOB_HANDLER;
}

@Override
protected IJobHandler getCustomizeHandler() {
return new SimpleCustomizedHandler();
}

@Override
protected IJobHandler getMethodHandler() {
return METHOD_JOB_HANDLER;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,12 @@ private XxlJobTestingConstants() {}
+ " return new ReturnT<>(\"Hello World\")\n"
+ " }\n"
+ "}\n";

public static final String GLUE_JOB_GROOVY_SOURCE = "import com.xxl.job.core.handler.IJobHandler\n"
+ "\n"
+ "class CustomizedGroovyHandler extends IJobHandler {\n"
+ " @Override\n"
+ " void execute() throws Exception {\n"
+ " }\n"
+ "}\n";
}