Spring Batch instrumentation tests: decisions (#2024)

* Spring Batch instrumentation tests: decisions

* spotless
This commit is contained in:
Mateusz Rzeszutek 2021-01-13 08:17:15 +01:00 committed by GitHub
parent f3334c3990
commit 269378e929
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 136 additions and 0 deletions

View File

@ -19,6 +19,7 @@ import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.core.task.AsyncTaskExecutor
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
import springbatch.TestDecider
import springbatch.TestItemProcessor
import springbatch.TestItemReader
import springbatch.TestItemWriter
@ -157,4 +158,37 @@ class SpringBatchApplication {
AsyncTaskExecutor asyncTaskExecutor() {
new ThreadPoolTaskExecutor()
}
// job with decisions
@Bean
Job decisionJob() {
jobs.get("decisionJob")
.start(decisionStepStart())
.next(new TestDecider())
.on("LEFT").to(decisionStepLeft())
.on("RIGHT").to(decisionStepRight())
.end()
.build()
}
@Bean
Step decisionStepStart() {
steps.get("decisionStepStart")
.tasklet(new TestTasklet())
.build()
}
@Bean
Step decisionStepLeft() {
steps.get("decisionStepLeft")
.tasklet(new TestTasklet())
.build()
}
@Bean
Step decisionStepRight() {
steps.get("decisionStepRight")
.tasklet(new TestTasklet())
.build()
}
}

View File

@ -182,6 +182,41 @@ abstract class SpringBatchTest extends AgentTestRunner {
}
}
}
def "should trace job with decision"() {
when:
runJob("decisionJob")
then:
assertTraces(1) {
trace(0, 5) {
span(0) {
name "BatchJob decisionJob"
kind INTERNAL
}
span(1) {
name "BatchJob decisionJob.decisionStepStart"
kind INTERNAL
childOf span(0)
}
span(2) {
name "BatchJob decisionJob.decisionStepStart.Chunk"
kind INTERNAL
childOf span(1)
}
span(3) {
name "BatchJob decisionJob.decisionStepLeft"
kind INTERNAL
childOf span(0)
}
span(4) {
name "BatchJob decisionJob.decisionStepLeft.Chunk"
kind INTERNAL
childOf span(3)
}
}
}
}
}
class JavaConfigBatchJobTest extends SpringBatchTest implements ApplicationConfigTrait {

View File

@ -0,0 +1,16 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package jsr
import javax.batch.api.Decider
import javax.batch.runtime.StepExecution
class TestDecider implements Decider {
@Override
String decide(StepExecution[] stepExecutions) throws Exception {
"LEFT"
}
}

View File

@ -0,0 +1,18 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package springbatch
import org.springframework.batch.core.JobExecution
import org.springframework.batch.core.StepExecution
import org.springframework.batch.core.job.flow.FlowExecutionStatus
import org.springframework.batch.core.job.flow.JobExecutionDecider
class TestDecider implements JobExecutionDecider {
@Override
FlowExecutionStatus decide(JobExecution jobExecution, StepExecution stepExecution) {
new FlowExecutionStatus("LEFT")
}
}

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<job id="decisionJob" xmlns="http://xmlns.jcp.org/xml/ns/javaee" version="1.0">
<step id="decisionStepStart" next="decision">
<batchlet ref="jsr.TestBatchlet"/>
</step>
<decision id="decision" ref="jsr.TestDecider">
<next on="LEFT" to="decisionStepLeft"/>
<next on="LEFT" to="decisionStepRight"/>
</decision>
<step id="decisionStepLeft">
<batchlet ref="jsr.TestBatchlet"/>
</step>
<step id="decisionStepRight">
<batchlet ref="jsr.TestBatchlet"/>
</step>
</job>

View File

@ -52,8 +52,25 @@
</b:split>
</b:job>
<b:job id="decisionJob">
<b:step id="decisionStepStart" next="decision">
<b:tasklet ref="testTasklet"/>
</b:step>
<b:decision id="decision" decider="testDecider">
<b:next on="LEFT" to="decisionStepLeft"/>
<b:next on="RIGHT" to="decisionStepRight"/>
</b:decision>
<b:step id="decisionStepLeft">
<b:tasklet ref="testTasklet"/>
</b:step>
<b:step id="decisionStepRight">
<b:tasklet ref="testTasklet"/>
</b:step>
</b:job>
<bean id="itemReader" class="springbatch.TestItemReader"/>
<bean id="itemProcessor" class="springbatch.TestItemProcessor"/>
<bean id="itemWriter" class="springbatch.TestItemWriter"/>
<bean id="testTasklet" class="springbatch.TestTasklet"/>
<bean id="testDecider" class="springbatch.TestDecider"/>
</beans>