-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added tests for scheduler/quartz OTel integration.
- Loading branch information
Showing
23 changed files
with
1,012 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>quarkus-integration-tests-parent</artifactId> | ||
<groupId>io.quarkus</groupId> | ||
<version>999-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>quarkus-integration-test-opentelemetry-quartz</artifactId> | ||
<name>Quarkus - Integration Tests - OpenTelemetry Quartz</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-arc</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-resteasy-reactive</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-quartz</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-opentelemetry</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-resteasy-reactive-jackson</artifactId> | ||
</dependency> | ||
|
||
<!-- Needed for InMemorySpanExporter to verify captured traces --> | ||
<dependency> | ||
<groupId>io.opentelemetry</groupId> | ||
<artifactId>opentelemetry-sdk-testing</artifactId> | ||
</dependency> | ||
|
||
<!-- test dependencies --> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-junit5</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.rest-assured</groupId> | ||
<artifactId>rest-assured</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.awaitility</groupId> | ||
<artifactId>awaitility</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<!-- Minimal test dependencies to *-deployment artifacts for consistent build order --> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-arc-deployment</artifactId> | ||
<version>${project.version}</version> | ||
<type>pom</type> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>*</groupId> | ||
<artifactId>*</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-quartz-deployment</artifactId> | ||
<version>${project.version}</version> | ||
<type>pom</type> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>*</groupId> | ||
<artifactId>*</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-resteasy-reactive-deployment</artifactId> | ||
<version>${project.version}</version> | ||
<type>pom</type> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>*</groupId> | ||
<artifactId>*</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-opentelemetry-deployment</artifactId> | ||
<version>${project.version}</version> | ||
<type>pom</type> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>*</groupId> | ||
<artifactId>*</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-resteasy-reactive-jackson-deployment</artifactId> | ||
<version>${project.version}</version> | ||
<type>pom</type> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>*</groupId> | ||
<artifactId>*</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>build</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
|
||
</project> |
40 changes: 40 additions & 0 deletions
40
.../opentelemetry-quartz/src/main/java/io/quarkus/it/opentelemetry/quartz/CountResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package io.quarkus.it.opentelemetry.quartz; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.core.MediaType; | ||
|
||
@Path("/scheduler/count") | ||
public class CountResource { | ||
|
||
@Inject | ||
Counter counter; | ||
|
||
@Inject | ||
ManualScheduledCounter manualScheduledCounter; | ||
|
||
@Inject | ||
JobDefinitionCounter jobDefinitionCounter; | ||
|
||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public Integer getCount() { | ||
return counter.get(); | ||
} | ||
|
||
@GET | ||
@Path("manual") | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public Integer getManualCount() { | ||
return manualScheduledCounter.get(); | ||
} | ||
|
||
@GET | ||
@Path("job-definition") | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public Integer getJobDefinitionCount() { | ||
return jobDefinitionCounter.get(); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...-tests/opentelemetry-quartz/src/main/java/io/quarkus/it/opentelemetry/quartz/Counter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package io.quarkus.it.opentelemetry.quartz; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import jakarta.annotation.PostConstruct; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
import io.quarkus.scheduler.Scheduled; | ||
|
||
@ApplicationScoped | ||
public class Counter { | ||
|
||
AtomicInteger counter; | ||
|
||
@PostConstruct | ||
void init() { | ||
counter = new AtomicInteger(); | ||
} | ||
|
||
public int get() { | ||
return counter.get(); | ||
} | ||
|
||
@Scheduled(cron = "*/1 * * * * ?", identity = "myCounter") | ||
void increment() throws InterruptedException { | ||
Thread.sleep(100l); | ||
counter.incrementAndGet(); | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
...entelemetry-quartz/src/main/java/io/quarkus/it/opentelemetry/quartz/ExporterResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package io.quarkus.it.opentelemetry.quartz; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.inject.Produces; | ||
import jakarta.inject.Inject; | ||
import jakarta.inject.Singleton; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
|
||
import io.opentelemetry.sdk.testing.exporter.InMemorySpanExporter; | ||
import io.opentelemetry.sdk.trace.data.SpanData; | ||
|
||
@Path("") | ||
public class ExporterResource { | ||
@Inject | ||
InMemorySpanExporter inMemorySpanExporter; | ||
|
||
@GET | ||
@Path("/export") | ||
public List<SpanData> export() { // only export scheduled spans | ||
return inMemorySpanExporter.getFinishedSpanItems() | ||
.stream() | ||
.filter(sd -> !sd.getName().contains("export") && !sd.getName().contains("GET")) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
@ApplicationScoped | ||
static class InMemorySpanExporterProducer { | ||
@Produces | ||
@Singleton | ||
InMemorySpanExporter inMemorySpanExporter() { | ||
return InMemorySpanExporter.create(); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...lemetry-quartz/src/main/java/io/quarkus/it/opentelemetry/quartz/FailedBasicScheduler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.quarkus.it.opentelemetry.quartz; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
import io.quarkus.scheduler.Scheduled; | ||
|
||
@ApplicationScoped | ||
public class FailedBasicScheduler { | ||
|
||
@Scheduled(cron = "*/1 * * * * ?", identity = "myFailedBasicScheduler") | ||
void init() throws InterruptedException { | ||
Thread.sleep(100l); | ||
throw new RuntimeException("error occurred in myFailedBasicScheduler."); | ||
|
||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
...quartz/src/main/java/io/quarkus/it/opentelemetry/quartz/FailedJobDefinitionScheduler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.quarkus.it.opentelemetry.quartz; | ||
|
||
import jakarta.annotation.PostConstruct; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
|
||
import io.quarkus.quartz.QuartzScheduler; | ||
import io.quarkus.runtime.Startup; | ||
|
||
@ApplicationScoped | ||
@Startup | ||
public class FailedJobDefinitionScheduler { | ||
|
||
@Inject | ||
QuartzScheduler scheduler; | ||
|
||
@PostConstruct | ||
void init() { | ||
scheduler.newJob("myFailedJobDefinition").setCron("*/1 * * * * ?").setTask(ex -> { | ||
try { | ||
Thread.sleep(100l); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
throw new RuntimeException("error occurred in myFailedJobDefinition."); | ||
}).schedule(); | ||
} | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
...emetry-quartz/src/main/java/io/quarkus/it/opentelemetry/quartz/FailedManualScheduler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package io.quarkus.it.opentelemetry.quartz; | ||
|
||
import jakarta.annotation.PostConstruct; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
|
||
import org.quartz.Job; | ||
import org.quartz.JobBuilder; | ||
import org.quartz.JobDetail; | ||
import org.quartz.JobExecutionContext; | ||
import org.quartz.SchedulerException; | ||
import org.quartz.SimpleScheduleBuilder; | ||
import org.quartz.Trigger; | ||
import org.quartz.TriggerBuilder; | ||
|
||
import io.quarkus.runtime.Startup; | ||
import io.quarkus.runtime.annotations.RegisterForReflection; | ||
|
||
@Startup | ||
@ApplicationScoped | ||
public class FailedManualScheduler { | ||
@Inject | ||
org.quartz.Scheduler quartz; | ||
|
||
@PostConstruct | ||
void init() throws SchedulerException { | ||
JobDetail job = JobBuilder.newJob(CountingJob.class).withIdentity("myFailedManualJob", "myFailedGroup").build(); | ||
Trigger trigger = TriggerBuilder | ||
.newTrigger() | ||
.withIdentity("myFailedTrigger", "myFailedGroup") | ||
.startNow() | ||
.withSchedule(SimpleScheduleBuilder | ||
.simpleSchedule() | ||
.repeatForever() | ||
.withIntervalInSeconds(1)) | ||
.build(); | ||
quartz.scheduleJob(job, trigger); | ||
} | ||
|
||
@RegisterForReflection | ||
public static class CountingJob implements Job { | ||
@Override | ||
public void execute(JobExecutionContext jobExecutionContext) { | ||
try { | ||
Thread.sleep(100l); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
throw new RuntimeException("error occurred in myFailedManualJob."); | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...lemetry-quartz/src/main/java/io/quarkus/it/opentelemetry/quartz/JobDefinitionCounter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package io.quarkus.it.opentelemetry.quartz; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import jakarta.annotation.PostConstruct; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
|
||
import io.quarkus.quartz.QuartzScheduler; | ||
import io.quarkus.runtime.Startup; | ||
|
||
@ApplicationScoped | ||
@Startup | ||
public class JobDefinitionCounter { | ||
|
||
@Inject | ||
QuartzScheduler scheduler; | ||
|
||
AtomicInteger counter; | ||
|
||
@PostConstruct | ||
void init() { | ||
counter = new AtomicInteger(); | ||
scheduler.newJob("myJobDefinition").setCron("*/1 * * * * ?").setTask(ex -> { | ||
try { | ||
Thread.sleep(100l); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
counter.incrementAndGet(); | ||
}).schedule(); | ||
} | ||
|
||
public int get() { | ||
return counter.get(); | ||
} | ||
} |
Oops, something went wrong.