Skip to content

Commit c3fa3da

Browse files
author
Jeff Bornemann
committed
Set input stream right after connection is made, so that even failed calls can properly clean up input streams
1 parent 0db905b commit c3fa3da

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/main/groovy/com/twcable/grabbit/client/batch/steps/http/CreateHttpConnectionTasklet.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,15 @@ class CreateHttpConnectionTasklet implements Tasklet {
6666

6767
final Connection connection = createConnection(request, username, password)
6868

69+
ClientBatchJobContext.setInputStream(connection.inputStream)
70+
6971
if(connection.status != SC_OK) {
7072
log.warn "Received a status of ${connection.status} when attempting to create a connection to ${jobParameters.get(ClientBatchJob.HOST)}. Bailing out. See debug log for more details."
7173
log.debug "Request to start a connection with ${jobParameters.get(ClientBatchJob.HOST)} resulted in: ${connection.networkResponse}."
7274
contribution.setExitStatus(ExitStatus.FAILED)
7375
return RepeatStatus.FINISHED
7476
}
7577

76-
ClientBatchJobContext.setInputStream(connection.inputStream)
7778
return RepeatStatus.FINISHED
7879
}
7980

src/test/groovy/com/twcable/grabbit/client/batch/steps/http/CreateHttpConnectionTaskletSpec.groovy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,17 @@ class CreateHttpConnectionTaskletSpec extends Specification {
8181
final StepContribution stepContribution = Mock(StepContribution) {
8282
1 * setExitStatus(ExitStatus.FAILED)
8383
}
84+
final InputStream inputStream = Mock(InputStream)
8485
final CreateHttpConnectionTasklet tasklet = Spy(CreateHttpConnectionTasklet) {
8586
createConnection(_, 'username', 'password') >> Mock(Connection) {
8687
getStatus() >> SC_BAD_GATEWAY
88+
getInputStream() >> inputStream
8789
}
8890
}
8991

9092
then:
9193
tasklet.execute(stepContribution, chunkContext) == RepeatStatus.FINISHED
94+
ClientBatchJobContext.inputStream != null
9295
}
9396

9497

0 commit comments

Comments
 (0)