Spring Batch instrumentation tests: splits
MODIFY
instrumentation/spring/spring-batch-3.0/javaagent/spring-batch-3.0-javaagent.gradle
instrumentation/spring/spring-batch-3.0/javaagent/spring-batch-3.0-javaagent.gradle
@@ -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) {

MODIFY
instrumentation/spring/spring-batch-3.0/javaagent/src/test/groovy/SpringBatchApplication.groovy
instrumentation/spring/spring-batch-3.0/javaagent/src/test/groovy/SpringBatchApplication.groovy
@@ -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()
+ }
}

MODIFY
instrumentation/spring/spring-batch-3.0/javaagent/src/test/groovy/SpringBatchTest.groovy
instrumentation/spring/spring-batch-3.0/javaagent/src/test/groovy/SpringBatchTest.groovy
@@ -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 {

ADD
instrumentation/spring/spring-batch-3.0/javaagent/src/test/resources/META-INF/batch-jobs/splitJob.xml
+<?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>

MODIFY
instrumentation/spring/spring-batch-3.0/javaagent/src/test/resources/baseContext.xml
instrumentation/spring/spring-batch-3.0/javaagent/src/test/resources/baseContext.xml
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">

MODIFY
instrumentation/spring/spring-batch-3.0/javaagent/src/test/resources/spring-batch.xml
instrumentation/spring/spring-batch-3.0/javaagent/src/test/resources/spring-batch.xml
</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"/>

Spring Batch instrumentation tests: splits (#2017)