Spring Batch instrumentation tests: splits (#2017)

This commit is contained in:
Mateusz Rzeszutek 2021-01-12 06:32:21 +01:00 committed by GitHub
parent 179b2257f9
commit 56dd13bfc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 108 additions and 0 deletions

View File

@ -13,6 +13,8 @@ dependencies {
library group: 'org.springframework.batch', name: 'spring-batch-core', version: '3.0.0.RELEASE'
testImplementation group: 'javax.inject', name: 'javax.inject', version: '1'
// SimpleAsyncTaskExecutor context propagation
testInstrumentation project(':instrumentation:spring:spring-core-2.0:javaagent')
}
tasks.withType(Test) {

View File

@ -17,6 +17,8 @@ import org.springframework.batch.item.ItemWriter
import org.springframework.beans.factory.annotation.Autowired
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.TestItemProcessor
import springbatch.TestItemReader
import springbatch.TestItemWriter
@ -118,4 +120,41 @@ class SpringBatchApplication {
.tasklet(new TestTasklet())
.build()
}
// split job
@Bean
Job splitJob() {
jobs.get("splitJob")
.start(splitFlowStep1())
.split(asyncTaskExecutor())
.add(splitFlow2())
.build()
.build()
}
@Bean
Step splitFlowStep1() {
steps.get("splitFlowStep1")
.tasklet(new TestTasklet())
.build()
}
@Bean
Flow splitFlow2() {
new FlowBuilder<SimpleFlow>("splitFlow2")
.start(splitFlowStep2())
.build()
}
@Bean
Step splitFlowStep2() {
steps.get("splitFlowStep2")
.tasklet(new TestTasklet())
.build()
}
@Bean
AsyncTaskExecutor asyncTaskExecutor() {
new ThreadPoolTaskExecutor()
}
}

View File

@ -147,6 +147,41 @@ abstract class SpringBatchTest extends AgentTestRunner {
}
}
}
def "should trace split flow job"() {
when:
runJob("splitJob")
then:
assertTraces(1) {
trace(0, 5) {
span(0) {
name "BatchJob splitJob"
kind INTERNAL
}
span(1) {
name ~/BatchJob splitJob\.splitFlowStep[12]/
kind INTERNAL
childOf span(0)
}
span(2) {
name ~/BatchJob splitJob\.splitFlowStep[12]\.Chunk/
kind INTERNAL
childOf span(1)
}
span(3) {
name ~/BatchJob splitJob\.splitFlowStep[12]/
kind INTERNAL
childOf span(0)
}
span(4) {
name ~/BatchJob splitJob\.splitFlowStep[12]\.Chunk/
kind INTERNAL
childOf span(3)
}
}
}
}
}
class JavaConfigBatchJobTest extends SpringBatchTest implements ApplicationConfigTrait {

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<job id="splitJob" xmlns="http://xmlns.jcp.org/xml/ns/javaee" version="1.0">
<split id="split">
<flow id="splitFlow1">
<step id="splitFlowStep1">
<batchlet ref="jsr.TestBatchlet"/>
</step>
</flow>
<flow id="splitFlow2">
<step id="splitFlowStep2">
<batchlet ref="jsr.TestBatchlet"/>
</step>
</flow>
</split>
</job>

View File

@ -3,6 +3,8 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="asyncTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor"/>
<bean id="jobRepository"
class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean"/>
<bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher">

View File

@ -37,6 +37,21 @@
</b:step>
</b:flow>
<b:job id="splitJob">
<b:split id="split" task-executor="asyncTaskExecutor">
<b:flow>
<b:step id="splitFlowStep1">
<b:tasklet ref="testTasklet"/>
</b:step>
</b:flow>
<b:flow>
<b:step id="splitFlowStep2">
<b:tasklet ref="testTasklet"/>
</b:step>
</b:flow>
</b:split>
</b:job>
<bean id="itemReader" class="springbatch.TestItemReader"/>
<bean id="itemProcessor" class="springbatch.TestItemProcessor"/>
<bean id="itemWriter" class="springbatch.TestItemWriter"/>