Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apm-agent-builds/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,12 @@
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>apm-quartz-1-plugin</artifactId>
<artifactId>apm-quartz-plugin-1</artifactId>

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[for reviewer] using same naming convention as grpc

<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>apm-quartz-2-plugin</artifactId>
<artifactId>apm-quartz-plugin-2</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>apm-quartz-job-plugin</artifactId>
<artifactId>apm-quartz</artifactId>

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[for reviewer] using apm-quartz as module name for all the other sub-modules, the -plugin sufix is kept for the instrumentation plugins (with an extra per-version suffix to fit the naming conventions).

<groupId>co.elastic.apm</groupId>
<version>1.38.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>quartz-common</artifactId>
<artifactId>apm-quartz-common</artifactId>
<name>${project.groupId}:${project.artifactId}</name>

<properties>
<version.quartz>2.3.1</version.quartz>

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[for reviewer] the common part was compiled with quartz 2.x and contained some code that was only used with 2.x plugin, however making sure the common part is compiled with 1.x only is safer.

<version.quartz>1.7.3</version.quartz>
<apm-agent-parent.base.dir>${project.basedir}/../../..</apm-agent-parent.base.dir>
</properties>

Expand All @@ -22,19 +22,6 @@
<version>${version.quartz}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${version.spring}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz-jobs</artifactId>
<version>${version.quartz}</version>
<scope>test</scope>
</dependency>
Comment on lines -25 to -37

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[for reviewer] those were only required for quartz 2.x

</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,25 @@
import co.elastic.apm.agent.AbstractInstrumentationTest;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.impl.TracerInternalApiUtils;
import co.elastic.apm.agent.tracer.Outcome;
import co.elastic.apm.agent.impl.transaction.Span;
import co.elastic.apm.agent.impl.transaction.Transaction;
import co.elastic.apm.agent.tracer.Outcome;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.JobExecutionException;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SimpleTrigger;
import org.quartz.impl.StdSchedulerFactory;
import org.quartz.jobs.DirectoryScanJob;
import org.quartz.jobs.DirectoryScanListener;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

import static org.assertj.core.api.Assertions.assertThat;


abstract class AbstractJobTransactionNameInstrumentationTest extends AbstractInstrumentationTest {

private Scheduler scheduler;
protected Scheduler scheduler;

@BeforeEach
void prepare() throws SchedulerException {
Expand Down Expand Up @@ -105,15 +96,7 @@ public void testAgentPaused() throws SchedulerException {
assertThat(objectPoolFactory.getSpanPool().getRequestedObjectCount()).isEqualTo(spanCount);
}

@Test
void testSpringJob() throws SchedulerException {
Assumptions.assumeFalse(ignoreTestSpringJob());

JobDetail job = buildJobDetailTestSpringJob("dummyJobName", "group1");
scheduler.scheduleJob(job, createTrigger());

verifyTransactionFromJobDetails(job, Outcome.SUCCESS);
}

@Test
void testJobWithResult() throws SchedulerException {
Expand All @@ -124,24 +107,6 @@ void testJobWithResult() throws SchedulerException {
assertThat(transaction.getResult()).isEqualTo("this is the result");
}

@Test
void testDirectoryScan() throws SchedulerException, IOException {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[for reviewer] this was only relevant for quartz 2.x (hence the Assumptions call at start of test method.

Assumptions.assumeFalse(ignoreDirectoryScanTest());

Path directoryScanTest = Files.createTempDirectory("DirectoryScanTest");

final JobDetail job = JobBuilder.newJob(DirectoryScanJob.class)
.withIdentity("dummyJobName")
.usingJobData(DirectoryScanJob.DIRECTORY_NAME, directoryScanTest.toAbsolutePath().toString())
.usingJobData(DirectoryScanJob.DIRECTORY_SCAN_LISTENER_NAME, TestDirectoryScanListener.class.getSimpleName())
.build();

scheduler.getContext().put(TestDirectoryScanListener.class.getSimpleName(), new TestDirectoryScanListener());
scheduler.scheduleJob(job, createTrigger());

verifyTransactionFromJobDetails(job, Outcome.SUCCESS);
}

@Test
void testJobWithException() throws SchedulerException {
JobDetail job = buildJobDetailTestJobWithException("dummyJobName");
Expand Down Expand Up @@ -174,16 +139,4 @@ public Transaction verifyTransaction(Transaction transaction, String expectedNam

abstract JobDetail buildJobDetailTestJobWithException(String name);

abstract JobDetail buildJobDetailTestSpringJob(String name, String groupName);

abstract boolean ignoreTestSpringJob();

abstract boolean ignoreDirectoryScanTest();

public static class TestDirectoryScanListener implements DirectoryScanListener {

@Override
public void filesUpdatedOrAdded(File[] files) {
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>apm-quartz-job-plugin</artifactId>
<artifactId>apm-quartz</artifactId>
<groupId>co.elastic.apm</groupId>
<version>1.38.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>apm-quartz-1-plugin</artifactId>
<artifactId>apm-quartz-plugin-1</artifactId>
<name>${project.groupId}:${project.artifactId}</name>

<properties>
Expand All @@ -18,7 +18,7 @@
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>quartz-common</artifactId>
<artifactId>apm-quartz-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
Expand All @@ -29,7 +29,7 @@
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>quartz-common</artifactId>
<artifactId>apm-quartz-common</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
package co.elastic.apm.agent.quartzjob;

import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.tracer.Outcome;
import co.elastic.apm.agent.impl.transaction.Transaction;
import co.elastic.apm.agent.tracer.Outcome;
import org.quartz.Job;
import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
Expand Down Expand Up @@ -79,23 +79,6 @@ JobDetail buildJobDetailTestJobWithException(String name) {
return buildJobDetail(TestJobWithException.class, name);
}

@Override
JobDetail buildJobDetailTestSpringJob(String name, String groupName) {
throw new UnsupportedOperationException("Spring scheduling work with updated version of quartz.");
}

@Override
boolean ignoreTestSpringJob() {
// Spring scheduling work with updated version of quartz(2.*.*).
return true;
}

@Override
boolean ignoreDirectoryScanTest() {
// DirectoryScanJob not present at this version
return true;
}

private JobDetail buildJobDetail(Class jobClass, String name) {
JobDetail job = new JobDetail();
job.setName(name);
Expand Down Expand Up @@ -153,5 +136,4 @@ public void execute(JobExecutionContext context) throws JobExecutionException {
}
}


}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>apm-quartz-job-plugin</artifactId>
<artifactId>apm-quartz</artifactId>
<groupId>co.elastic.apm</groupId>
<version>1.38.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>apm-quartz-2-plugin</artifactId>
<artifactId>apm-quartz-plugin-2</artifactId>
<name>${project.groupId}:${project.artifactId}</name>

<properties>
Expand All @@ -18,7 +18,7 @@
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>quartz-common</artifactId>
<artifactId>apm-quartz-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
Expand All @@ -41,7 +41,7 @@
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>quartz-common</artifactId>
<artifactId>apm-quartz-common</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,27 @@
package co.elastic.apm.agent.quartzjob;

import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.tracer.Outcome;
import co.elastic.apm.agent.impl.transaction.Transaction;
import co.elastic.apm.agent.tracer.Outcome;
import org.junit.jupiter.api.Test;
import org.quartz.Job;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.SchedulerException;
import org.quartz.SimpleScheduleBuilder;
import org.quartz.SimpleTrigger;
import org.quartz.TriggerBuilder;
import org.quartz.jobs.DirectoryScanJob;
import org.quartz.jobs.DirectoryScanListener;
import org.springframework.scheduling.quartz.QuartzJobBean;

import javax.annotation.Nullable;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
Expand Down Expand Up @@ -88,28 +96,13 @@ JobDetail buildJobDetailTestJobWithException(String name) {
return buildJobDetail(TestJobWithException.class, name);
}

@Override
JobDetail buildJobDetailTestSpringJob(String name, String groupName) {
return buildJobDetail(TestSpringJob.class, name, groupName);
}

@Override
boolean ignoreTestSpringJob() {
return false;
}

@Override
boolean ignoreDirectoryScanTest() {
return false;
}

private JobDetail buildJobDetail(Class jobClass, String name) {
return JobBuilder.newJob(jobClass)
.withIdentity(name)
.build();
}

private JobDetail buildJobDetail(Class jobClass, String name, String groupName) {
private JobDetail buildJobDetail(Class jobClass, String name, @Nullable String groupName) {
if (groupName == null) {
return buildJobDetail(jobClass, name);
}
Expand Down Expand Up @@ -167,4 +160,35 @@ protected void executeInternal(JobExecutionContext context) throws JobExecutionE
}
}

@Test
void testSpringJob() throws SchedulerException {
JobDetail job = buildJobDetail(TestSpringJob.class, "dummyJobName", "group1");
scheduler.scheduleJob(job, createTrigger());

verifyTransactionFromJobDetails(job, Outcome.SUCCESS);
}

@Test
void testDirectoryScan() throws SchedulerException, IOException {
Path directoryScanTest = Files.createTempDirectory("DirectoryScanTest");

final JobDetail job = JobBuilder.newJob(DirectoryScanJob.class)
.withIdentity("dummyJobName")
.usingJobData(DirectoryScanJob.DIRECTORY_NAME, directoryScanTest.toAbsolutePath().toString())
.usingJobData(DirectoryScanJob.DIRECTORY_SCAN_LISTENER_NAME, TestDirectoryScanListener.class.getSimpleName())
.build();

scheduler.getContext().put(TestDirectoryScanListener.class.getSimpleName(), new TestDirectoryScanListener());
scheduler.scheduleJob(job, createTrigger());

verifyTransactionFromJobDetails(job, Outcome.SUCCESS);
}

public static class TestDirectoryScanListener implements DirectoryScanListener {

@Override
public void filesUpdatedOrAdded(File[] files) {
}
}

}
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
<modules>
<module>quartz-common</module>
<module>apm-quartz-1-plugin</module>
<module>apm-quartz-2-plugin</module>
</modules>

<parent>
<artifactId>apm-agent-plugins</artifactId>
<groupId>co.elastic.apm</groupId>
<version>1.38.1-SNAPSHOT</version>
</parent>

<artifactId>apm-quartz-job-plugin</artifactId>
<artifactId>apm-quartz</artifactId>
<name>${project.groupId}:${project.artifactId}</name>
<packaging>pom</packaging>

<properties>
<apm-agent-parent.base.dir>${project.basedir}/../..</apm-agent-parent.base.dir>
</properties>

<modules>
<module>apm-quartz-common</module>
<module>apm-quartz-plugin-1</module>
<module>apm-quartz-plugin-2</module>
</modules>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!-- explicit version required as bom will not cover plugins, only dependencies -->
<version>${version.spring-boot}</version>

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[for reviewer] the global spring-boot version property was removed because only used here in test application, thus in test code.

<version>2.2.2.RELEASE</version>
<configuration>
<mainClass>co.elastic.apm.agent.springwebflux.testapp.WebFluxApplication</mainClass>
<!-- by default original jar is replaced, which makes impossible to reuse as dependency -->
Expand Down
Loading