Updated to files to fit the Standard.
This commit is contained in:
@@ -64,8 +64,8 @@ import org.springframework.context.annotation.Lazy;
|
||||
@ConditionalOnClass(Job.class)
|
||||
@ConditionalOnBean({ Job.class, TaskLifecycleListener.class })
|
||||
// @checkstyle:off
|
||||
@ConditionalOnProperty(prefix = "spring.cloud.task.batch.events", name = "enabled",
|
||||
havingValue = "true", matchIfMissing = true)
|
||||
@ConditionalOnProperty(prefix = "spring.cloud.task.batch.events", name = "enabled", havingValue = "true",
|
||||
matchIfMissing = true)
|
||||
// @checkstyle:on
|
||||
@AutoConfigureAfter(SimpleTaskAutoConfiguration.class)
|
||||
public class BatchEventAutoConfiguration {
|
||||
@@ -121,88 +121,85 @@ public class BatchEventAutoConfiguration {
|
||||
@ConditionalOnExpression("T(org.springframework.util.StringUtils).isEmpty('${spring.batch.job.jobName:}')")
|
||||
public static class JobExecutionListenerConfiguration {
|
||||
|
||||
|
||||
@Autowired
|
||||
private TaskEventProperties taskEventProperties;
|
||||
|
||||
// @checkstyle:off
|
||||
@Bean
|
||||
@Lazy
|
||||
@ConditionalOnProperty(prefix = "spring.cloud.task.batch.events.job-execution",
|
||||
name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||
@ConditionalOnProperty(prefix = "spring.cloud.task.batch.events.job-execution", name = "enabled",
|
||||
havingValue = "true", matchIfMissing = true)
|
||||
// @checkstyle:on
|
||||
public JobExecutionListener jobExecutionEventsListener(MessagePublisher messagePublisher, TaskEventProperties properties) {
|
||||
return new EventEmittingJobExecutionListener(
|
||||
messagePublisher,
|
||||
public JobExecutionListener jobExecutionEventsListener(MessagePublisher messagePublisher,
|
||||
TaskEventProperties properties) {
|
||||
return new EventEmittingJobExecutionListener(messagePublisher,
|
||||
this.taskEventProperties.getJobExecutionOrder(), properties);
|
||||
}
|
||||
|
||||
// @checkstyle:off
|
||||
@Bean
|
||||
@ConditionalOnProperty(prefix = "spring.cloud.task.batch.events.step-execution",
|
||||
name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||
@ConditionalOnProperty(prefix = "spring.cloud.task.batch.events.step-execution", name = "enabled",
|
||||
havingValue = "true", matchIfMissing = true)
|
||||
// @checkstyle:on
|
||||
public StepExecutionListener stepExecutionEventsListener(MessagePublisher messagePublisher, TaskEventProperties properties) {
|
||||
return new EventEmittingStepExecutionListener(
|
||||
messagePublisher,
|
||||
public StepExecutionListener stepExecutionEventsListener(MessagePublisher messagePublisher,
|
||||
TaskEventProperties properties) {
|
||||
return new EventEmittingStepExecutionListener(messagePublisher,
|
||||
this.taskEventProperties.getStepExecutionOrder(), properties);
|
||||
}
|
||||
|
||||
// @checkstyle:off
|
||||
@Bean
|
||||
@Lazy
|
||||
@ConditionalOnProperty(prefix = "spring.cloud.task.batch.events.chunk",
|
||||
name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||
@ConditionalOnProperty(prefix = "spring.cloud.task.batch.events.chunk", name = "enabled", havingValue = "true",
|
||||
matchIfMissing = true)
|
||||
// @checkstyle:on
|
||||
public EventEmittingChunkListener chunkEventsListener(MessagePublisher messagePublisher, TaskEventProperties properties) {
|
||||
return new EventEmittingChunkListener(messagePublisher,
|
||||
this.taskEventProperties.getChunkOrder(), properties);
|
||||
public EventEmittingChunkListener chunkEventsListener(MessagePublisher messagePublisher,
|
||||
TaskEventProperties properties) {
|
||||
return new EventEmittingChunkListener(messagePublisher, this.taskEventProperties.getChunkOrder(),
|
||||
properties);
|
||||
}
|
||||
|
||||
// @checkstyle:off
|
||||
@Bean
|
||||
@ConditionalOnProperty(prefix = "spring.cloud.task.batch.events.item-read",
|
||||
name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||
@ConditionalOnProperty(prefix = "spring.cloud.task.batch.events.item-read", name = "enabled",
|
||||
havingValue = "true", matchIfMissing = true)
|
||||
// @checkstyle:on
|
||||
public ItemReadListener itemReadEventsListener(MessagePublisher messagePublisher, TaskEventProperties properties) {
|
||||
return new EventEmittingItemReadListener(
|
||||
messagePublisher,
|
||||
this.taskEventProperties.getItemReadOrder(), properties);
|
||||
public ItemReadListener itemReadEventsListener(MessagePublisher messagePublisher,
|
||||
TaskEventProperties properties) {
|
||||
return new EventEmittingItemReadListener(messagePublisher, this.taskEventProperties.getItemReadOrder(),
|
||||
properties);
|
||||
}
|
||||
|
||||
// @checkstyle:off
|
||||
@Bean
|
||||
@ConditionalOnProperty(prefix = "spring.cloud.task.batch.events.item-write",
|
||||
name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||
@ConditionalOnProperty(prefix = "spring.cloud.task.batch.events.item-write", name = "enabled",
|
||||
havingValue = "true", matchIfMissing = true)
|
||||
// @checkstyle:on
|
||||
public ItemWriteListener itemWriteEventsListener(MessagePublisher messagePublisher,
|
||||
TaskEventProperties properties) {
|
||||
return new EventEmittingItemWriteListener(
|
||||
messagePublisher,
|
||||
this.taskEventProperties.getItemWriteOrder(), properties);
|
||||
TaskEventProperties properties) {
|
||||
return new EventEmittingItemWriteListener(messagePublisher, this.taskEventProperties.getItemWriteOrder(),
|
||||
properties);
|
||||
}
|
||||
|
||||
// @checkstyle:off
|
||||
@Bean
|
||||
@ConditionalOnProperty(prefix = "spring.cloud.task.batch.events.item-process",
|
||||
name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||
@ConditionalOnProperty(prefix = "spring.cloud.task.batch.events.item-process", name = "enabled",
|
||||
havingValue = "true", matchIfMissing = true)
|
||||
// @checkstyle:on
|
||||
public ItemProcessListener itemProcessEventsListener(MessagePublisher messagePublisher,
|
||||
TaskEventProperties properties) {
|
||||
return new EventEmittingItemProcessListener(
|
||||
messagePublisher,
|
||||
TaskEventProperties properties) {
|
||||
return new EventEmittingItemProcessListener(messagePublisher,
|
||||
this.taskEventProperties.getItemProcessOrder(), properties);
|
||||
}
|
||||
|
||||
// @checkstyle:off
|
||||
@Bean
|
||||
@ConditionalOnProperty(prefix = "spring.cloud.task.batch.events.skip",
|
||||
name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||
@ConditionalOnProperty(prefix = "spring.cloud.task.batch.events.skip", name = "enabled", havingValue = "true",
|
||||
matchIfMissing = true)
|
||||
// @checkstyle:on
|
||||
public SkipListener skipEventsListener(MessagePublisher messagePublisher,
|
||||
TaskEventProperties properties) {
|
||||
return new EventEmittingSkipListener(messagePublisher,
|
||||
this.taskEventProperties.getItemProcessOrder(), properties);
|
||||
public SkipListener skipEventsListener(MessagePublisher messagePublisher, TaskEventProperties properties) {
|
||||
return new EventEmittingSkipListener(messagePublisher, this.taskEventProperties.getItemProcessOrder(),
|
||||
properties);
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -55,14 +55,12 @@ public class EventEmittingChunkListener implements ChunkListener, Ordered {
|
||||
|
||||
@Override
|
||||
public void beforeChunk(ChunkContext context) {
|
||||
this.messagePublisher.publish(this.properties.getChunkEventBindingName(),
|
||||
"Before Chunk Processing");
|
||||
this.messagePublisher.publish(this.properties.getChunkEventBindingName(), "Before Chunk Processing");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterChunk(ChunkContext context) {
|
||||
this.messagePublisher.publish(this.properties.getChunkEventBindingName(),
|
||||
"After Chunk Processing");
|
||||
this.messagePublisher.publish(this.properties.getChunkEventBindingName(), "After Chunk Processing");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -43,8 +43,7 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class EventEmittingItemProcessListener implements ItemProcessListener, Ordered {
|
||||
|
||||
private static final Log logger = LogFactory
|
||||
.getLog(EventEmittingItemProcessListener.class);
|
||||
private static final Log logger = LogFactory.getLog(EventEmittingItemProcessListener.class);
|
||||
|
||||
private MessagePublisher messagePublisher;
|
||||
|
||||
@@ -59,7 +58,8 @@ public class EventEmittingItemProcessListener implements ItemProcessListener, Or
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
public EventEmittingItemProcessListener(MessagePublisher messagePublisher, int order, TaskEventProperties properties) {
|
||||
public EventEmittingItemProcessListener(MessagePublisher messagePublisher, int order,
|
||||
TaskEventProperties properties) {
|
||||
this(messagePublisher, properties);
|
||||
this.order = order;
|
||||
}
|
||||
@@ -74,10 +74,12 @@ public class EventEmittingItemProcessListener implements ItemProcessListener, Or
|
||||
this.messagePublisher.publish(this.properties.getItemProcessEventBindingName(), "1 item was filtered");
|
||||
}
|
||||
else if (item.equals(result)) {
|
||||
this.messagePublisher.publish(this.properties.getItemProcessEventBindingName(), "item equaled result after processing");
|
||||
this.messagePublisher.publish(this.properties.getItemProcessEventBindingName(),
|
||||
"item equaled result after processing");
|
||||
}
|
||||
else {
|
||||
this.messagePublisher.publish(this.properties.getItemProcessEventBindingName(), "item did not equal result after processing");
|
||||
this.messagePublisher.publish(this.properties.getItemProcessEventBindingName(),
|
||||
"item did not equal result after processing");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,9 +88,8 @@ public class EventEmittingItemProcessListener implements ItemProcessListener, Or
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Executing onProcessError: " + e.getMessage(), e);
|
||||
}
|
||||
this.messagePublisher.publishWithThrowableHeader(
|
||||
this.properties.getItemProcessEventBindingName(),
|
||||
"Exception while item was being processed", e.getMessage());
|
||||
this.messagePublisher.publishWithThrowableHeader(this.properties.getItemProcessEventBindingName(),
|
||||
"Exception while item was being processed", e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -40,8 +40,7 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class EventEmittingItemReadListener implements ItemReadListener, Ordered {
|
||||
|
||||
private static final Log logger = LogFactory
|
||||
.getLog(EventEmittingItemReadListener.class);
|
||||
private static final Log logger = LogFactory.getLog(EventEmittingItemReadListener.class);
|
||||
|
||||
private int order = Ordered.LOWEST_PRECEDENCE;
|
||||
|
||||
@@ -56,8 +55,7 @@ public class EventEmittingItemReadListener implements ItemReadListener, Ordered
|
||||
this.messagePublisher = messagePublisher;
|
||||
}
|
||||
|
||||
public EventEmittingItemReadListener(MessagePublisher messagePublisher,
|
||||
int order, TaskEventProperties properties) {
|
||||
public EventEmittingItemReadListener(MessagePublisher messagePublisher, int order, TaskEventProperties properties) {
|
||||
this(messagePublisher, properties);
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
@@ -41,8 +41,7 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class EventEmittingItemWriteListener implements ItemWriteListener, Ordered {
|
||||
|
||||
private static final Log logger = LogFactory
|
||||
.getLog(EventEmittingItemWriteListener.class);
|
||||
private static final Log logger = LogFactory.getLog(EventEmittingItemWriteListener.class);
|
||||
|
||||
private int order = Ordered.LOWEST_PRECEDENCE;
|
||||
|
||||
@@ -58,7 +57,8 @@ public class EventEmittingItemWriteListener implements ItemWriteListener, Ordere
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
public EventEmittingItemWriteListener(MessagePublisher messagePublisher, int order, TaskEventProperties properties) {
|
||||
public EventEmittingItemWriteListener(MessagePublisher messagePublisher, int order,
|
||||
TaskEventProperties properties) {
|
||||
this(messagePublisher, properties);
|
||||
this.order = order;
|
||||
}
|
||||
@@ -66,7 +66,7 @@ public class EventEmittingItemWriteListener implements ItemWriteListener, Ordere
|
||||
@Override
|
||||
public void beforeWrite(List items) {
|
||||
this.messagePublisher.publish(this.properties.getItemWriteEventBindingName(),
|
||||
items.size() + " items to be written.");
|
||||
items.size() + " items to be written.");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -75,7 +75,7 @@ public class EventEmittingItemWriteListener implements ItemWriteListener, Ordere
|
||||
logger.debug("Executing afterWrite: " + items);
|
||||
}
|
||||
this.messagePublisher.publish(this.properties.getItemWriteEventBindingName(),
|
||||
items.size() + " items have been written.");
|
||||
items.size() + " items have been written.");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -83,10 +83,9 @@ public class EventEmittingItemWriteListener implements ItemWriteListener, Ordere
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Executing onWriteError: " + exception.getMessage(), exception);
|
||||
}
|
||||
String payload = "Exception while " + items.size()
|
||||
+ " items are attempted to be written.";
|
||||
this.messagePublisher.publishWithThrowableHeader(
|
||||
this.properties.getItemWriteEventBindingName(), payload, exception.getMessage());
|
||||
String payload = "Exception while " + items.size() + " items are attempted to be written.";
|
||||
this.messagePublisher.publishWithThrowableHeader(this.properties.getItemWriteEventBindingName(), payload,
|
||||
exception.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -47,19 +47,22 @@ public class EventEmittingJobExecutionListener implements JobExecutionListener,
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
public EventEmittingJobExecutionListener(MessagePublisher messagePublisher, int order, TaskEventProperties properties) {
|
||||
public EventEmittingJobExecutionListener(MessagePublisher messagePublisher, int order,
|
||||
TaskEventProperties properties) {
|
||||
this(messagePublisher, properties);
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeJob(JobExecution jobExecution) {
|
||||
this.messagePublisher.publish(properties.getJobExecutionEventBindingName(), new JobExecutionEvent(jobExecution));
|
||||
this.messagePublisher.publish(properties.getJobExecutionEventBindingName(),
|
||||
new JobExecutionEvent(jobExecution));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterJob(JobExecution jobExecution) {
|
||||
this.messagePublisher.publish(properties.getJobExecutionEventBindingName(), new JobExecutionEvent(jobExecution));
|
||||
this.messagePublisher.publish(properties.getJobExecutionEventBindingName(),
|
||||
new JobExecutionEvent(jobExecution));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -67,7 +67,8 @@ public class EventEmittingSkipListener implements SkipListener, Ordered {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Executing onSkipInRead: " + t.getMessage(), t);
|
||||
}
|
||||
this.messagePublisher.publishWithThrowableHeader(this.properties.getSkipEventBindingName(), "Skipped when reading.", t.getMessage());
|
||||
this.messagePublisher.publishWithThrowableHeader(this.properties.getSkipEventBindingName(),
|
||||
"Skipped when reading.", t.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -75,7 +76,8 @@ public class EventEmittingSkipListener implements SkipListener, Ordered {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Executing onSkipInWrite: " + t.getMessage(), t);
|
||||
}
|
||||
this.messagePublisher.publishWithThrowableHeader(this.properties.getSkipEventBindingName(), item, t.getMessage());
|
||||
this.messagePublisher.publishWithThrowableHeader(this.properties.getSkipEventBindingName(), item,
|
||||
t.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -83,7 +85,8 @@ public class EventEmittingSkipListener implements SkipListener, Ordered {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Executing onSkipInProcess: " + t.getMessage(), t);
|
||||
}
|
||||
this.messagePublisher.publishWithThrowableHeader(this.properties.getSkipEventBindingName(), item, t.getMessage());
|
||||
this.messagePublisher.publishWithThrowableHeader(this.properties.getSkipEventBindingName(), item,
|
||||
t.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -34,10 +34,10 @@ import org.springframework.util.Assert;
|
||||
* @author Glenn Renfro
|
||||
* @author Ali Shahbour
|
||||
*/
|
||||
public class EventEmittingStepExecutionListener
|
||||
implements StepExecutionListener, Ordered {
|
||||
public class EventEmittingStepExecutionListener implements StepExecutionListener, Ordered {
|
||||
|
||||
private final MessagePublisher<StepExecutionEvent> messagePublisher;
|
||||
|
||||
private int order = Ordered.LOWEST_PRECEDENCE;
|
||||
|
||||
private TaskEventProperties properties;
|
||||
@@ -50,19 +50,22 @@ public class EventEmittingStepExecutionListener
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
public EventEmittingStepExecutionListener(MessagePublisher messagePublisher, int order, TaskEventProperties properties) {
|
||||
public EventEmittingStepExecutionListener(MessagePublisher messagePublisher, int order,
|
||||
TaskEventProperties properties) {
|
||||
this(messagePublisher, properties);
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeStep(StepExecution stepExecution) {
|
||||
this.messagePublisher.publish(this.properties.getStepExecutionEventBindingName(), new StepExecutionEvent(stepExecution));
|
||||
this.messagePublisher.publish(this.properties.getStepExecutionEventBindingName(),
|
||||
new StepExecutionEvent(stepExecution));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExitStatus afterStep(StepExecution stepExecution) {
|
||||
this.messagePublisher.publish(this.properties.getStepExecutionEventBindingName(), new StepExecutionEvent(stepExecution));
|
||||
this.messagePublisher.publish(this.properties.getStepExecutionEventBindingName(),
|
||||
new StepExecutionEvent(stepExecution));
|
||||
|
||||
return stepExecution.getExitStatus();
|
||||
}
|
||||
|
||||
@@ -57,8 +57,7 @@ public class JobExecutionEvent extends Entity {
|
||||
|
||||
private Date lastUpdated = null;
|
||||
|
||||
private ExitStatus exitStatus = new ExitStatus(
|
||||
new org.springframework.batch.core.ExitStatus("UNKNOWN"));
|
||||
private ExitStatus exitStatus = new ExitStatus(new org.springframework.batch.core.ExitStatus("UNKNOWN"));
|
||||
|
||||
private ExecutionContext executionContext = new ExecutionContext();
|
||||
|
||||
@@ -73,8 +72,7 @@ public class JobExecutionEvent extends Entity {
|
||||
* @param original the StepExecution to build this DTO around.
|
||||
*/
|
||||
public JobExecutionEvent(JobExecution original) {
|
||||
this.jobParameters = new JobParametersEvent(
|
||||
original.getJobParameters().getParameters());
|
||||
this.jobParameters = new JobParametersEvent(original.getJobParameters().getParameters());
|
||||
this.jobInstance = new JobInstanceEvent(original.getJobInstance().getId(),
|
||||
original.getJobInstance().getJobName());
|
||||
for (StepExecution stepExecution : original.getStepExecutions()) {
|
||||
@@ -264,8 +262,8 @@ public class JobExecutionEvent extends Entity {
|
||||
public String toString() {
|
||||
return super.toString() + String.format(
|
||||
", startTime=%s, endTime=%s, lastUpdated=%s, status=%s, exitStatus=%s, job=[%s], jobParameters=[%s]",
|
||||
this.startTime, this.endTime, this.lastUpdated, this.status,
|
||||
this.exitStatus, this.jobInstance, this.jobParameters);
|
||||
this.startTime, this.endTime, this.lastUpdated, this.status, this.exitStatus, this.jobInstance,
|
||||
this.jobParameters);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -79,25 +79,22 @@ public class JobParameterEvent {
|
||||
}
|
||||
|
||||
JobParameterEvent rhs = (JobParameterEvent) obj;
|
||||
return this.parameter == null
|
||||
? rhs.parameter == null && this.parameterType == rhs.parameterType
|
||||
return this.parameter == null ? rhs.parameter == null && this.parameterType == rhs.parameterType
|
||||
: this.parameter.equals(rhs.parameter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.parameter == null ? null
|
||||
: (this.parameterType == JobParameterEvent.ParameterType.DATE
|
||||
? "" + ((Date) this.parameter).getTime()
|
||||
: this.parameter.toString());
|
||||
return this.parameter == null ? null : (this.parameterType == JobParameterEvent.ParameterType.DATE
|
||||
? "" + ((Date) this.parameter).getTime() : this.parameter.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int BASE_HASH = 7;
|
||||
final int MULTIPLIER_HASH = 21;
|
||||
return BASE_HASH + MULTIPLIER_HASH * (this.parameter == null
|
||||
? this.parameterType.hashCode() : this.parameter.hashCode());
|
||||
return BASE_HASH + MULTIPLIER_HASH
|
||||
* (this.parameter == null ? this.parameterType.hashCode() : this.parameter.hashCode());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -42,20 +42,16 @@ public class JobParametersEvent {
|
||||
this.parameters = new LinkedHashMap<>();
|
||||
for (Map.Entry<String, JobParameter> entry : jobParameters.entrySet()) {
|
||||
if (entry.getValue().getValue() instanceof String) {
|
||||
this.parameters.put(entry.getKey(),
|
||||
new JobParameterEvent(entry.getValue()));
|
||||
this.parameters.put(entry.getKey(), new JobParameterEvent(entry.getValue()));
|
||||
}
|
||||
else if (entry.getValue().getValue() instanceof Long) {
|
||||
this.parameters.put(entry.getKey(),
|
||||
new JobParameterEvent(entry.getValue()));
|
||||
this.parameters.put(entry.getKey(), new JobParameterEvent(entry.getValue()));
|
||||
}
|
||||
else if (entry.getValue().getValue() instanceof Date) {
|
||||
this.parameters.put(entry.getKey(),
|
||||
new JobParameterEvent(entry.getValue()));
|
||||
this.parameters.put(entry.getKey(), new JobParameterEvent(entry.getValue()));
|
||||
}
|
||||
else if (entry.getValue().getValue() instanceof Double) {
|
||||
this.parameters.put(entry.getKey(),
|
||||
new JobParameterEvent(entry.getValue()));
|
||||
this.parameters.put(entry.getKey(), new JobParameterEvent(entry.getValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class MessagePublisher<P> {
|
||||
|
||||
|
||||
private final StreamBridge streamBridge;
|
||||
|
||||
public MessagePublisher(StreamBridge streamBridge) {
|
||||
@@ -52,8 +51,8 @@ public class MessagePublisher<P> {
|
||||
}
|
||||
|
||||
public void publishWithThrowableHeader(String bindingName, P payload, String header) {
|
||||
Message<P> message = MessageBuilder.withPayload(payload)
|
||||
.setHeader(BatchJobHeaders.BATCH_EXCEPTION, header).build();
|
||||
Message<P> message = MessageBuilder.withPayload(payload).setHeader(BatchJobHeaders.BATCH_EXCEPTION, header)
|
||||
.build();
|
||||
publishMessage(bindingName, message);
|
||||
}
|
||||
|
||||
|
||||
@@ -63,8 +63,7 @@ public class StepExecutionEvent extends Entity {
|
||||
|
||||
private ExecutionContext executionContext = new ExecutionContext();
|
||||
|
||||
private ExitStatus exitStatus = new ExitStatus(
|
||||
org.springframework.batch.core.ExitStatus.EXECUTING);
|
||||
private ExitStatus exitStatus = new ExitStatus(org.springframework.batch.core.ExitStatus.EXECUTING);
|
||||
|
||||
private boolean terminateOnly;
|
||||
|
||||
@@ -82,8 +81,7 @@ public class StepExecutionEvent extends Entity {
|
||||
*/
|
||||
public StepExecutionEvent(StepExecution stepExecution) {
|
||||
super();
|
||||
Assert.notNull(stepExecution,
|
||||
"StepExecution must be provided to re-hydrate an existing StepExecutionEvent");
|
||||
Assert.notNull(stepExecution, "StepExecution must be provided to re-hydrate an existing StepExecutionEvent");
|
||||
Assert.notNull(stepExecution.getJobExecution(),
|
||||
"JobExecution must be provided to re-hydrate an existing StepExecutionEvent");
|
||||
setId(stepExecution.getId());
|
||||
@@ -393,8 +391,7 @@ public class StepExecutionEvent extends Entity {
|
||||
}
|
||||
StepExecution other = (StepExecution) obj;
|
||||
|
||||
return this.stepName.equals(other.getStepName())
|
||||
&& (this.jobExecutionId == other.getJobExecutionId())
|
||||
return this.stepName.equals(other.getStepName()) && (this.jobExecutionId == other.getJobExecutionId())
|
||||
&& getId().equals(other.getId());
|
||||
}
|
||||
|
||||
@@ -407,16 +404,13 @@ public class StepExecutionEvent extends Entity {
|
||||
public int hashCode() {
|
||||
Object jobExecutionId = getJobExecutionId();
|
||||
Long id = getId();
|
||||
return super.hashCode()
|
||||
+ 31 * (this.stepName != null ? this.stepName.hashCode() : 0)
|
||||
+ 91 * (jobExecutionId != null ? jobExecutionId.hashCode() : 0)
|
||||
+ 59 * (id != null ? id.hashCode() : 0);
|
||||
return super.hashCode() + 31 * (this.stepName != null ? this.stepName.hashCode() : 0)
|
||||
+ 91 * (jobExecutionId != null ? jobExecutionId.hashCode() : 0) + 59 * (id != null ? id.hashCode() : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format(getSummary() + ", exitDescription=%s",
|
||||
this.exitStatus.getExitDescription());
|
||||
return String.format(getSummary() + ", exitDescription=%s", this.exitStatus.getExitDescription());
|
||||
}
|
||||
|
||||
public String getSummary() {
|
||||
@@ -424,9 +418,8 @@ public class StepExecutionEvent extends Entity {
|
||||
", name=%s, status=%s, exitStatus=%s, readCount=%d, "
|
||||
+ "filterCount=%d, writeCount=%d readSkipCount=%d, writeSkipCount=%d"
|
||||
+ ", processSkipCount=%d, commitCount=%d, rollbackCount=%d",
|
||||
this.stepName, this.status, this.exitStatus.getExitCode(), this.readCount,
|
||||
this.filterCount, this.writeCount, this.readSkipCount,
|
||||
this.writeSkipCount, this.processSkipCount, this.commitCount,
|
||||
this.stepName, this.status, this.exitStatus.getExitCode(), this.readCount, this.filterCount,
|
||||
this.writeCount, this.readSkipCount, this.writeSkipCount, this.processSkipCount, this.commitCount,
|
||||
this.rollbackCount);
|
||||
}
|
||||
|
||||
|
||||
@@ -70,8 +70,7 @@ public class TaskBatchEventListenerBeanPostProcessor implements BeanPostProcesso
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Override
|
||||
public Object postProcessBeforeInitialization(Object bean, String beanName)
|
||||
throws BeansException {
|
||||
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
|
||||
|
||||
registerJobExecutionEventListener(bean);
|
||||
|
||||
@@ -83,13 +82,11 @@ public class TaskBatchEventListenerBeanPostProcessor implements BeanPostProcesso
|
||||
registerChunkEventsListener(bean);
|
||||
|
||||
if (tasklet instanceof ChunkOrientedTasklet) {
|
||||
Field chunkProviderField = ReflectionUtils
|
||||
.findField(ChunkOrientedTasklet.class, "chunkProvider");
|
||||
Field chunkProviderField = ReflectionUtils.findField(ChunkOrientedTasklet.class, "chunkProvider");
|
||||
ReflectionUtils.makeAccessible(chunkProviderField);
|
||||
SimpleChunkProvider chunkProvider = (SimpleChunkProvider) ReflectionUtils
|
||||
.getField(chunkProviderField, tasklet);
|
||||
Field chunkProcessorField = ReflectionUtils
|
||||
.findField(ChunkOrientedTasklet.class, "chunkProcessor");
|
||||
Field chunkProcessorField = ReflectionUtils.findField(ChunkOrientedTasklet.class, "chunkProcessor");
|
||||
ReflectionUtils.makeAccessible(chunkProcessorField);
|
||||
SimpleChunkProcessor chunkProcessor = (SimpleChunkProcessor) ReflectionUtils
|
||||
.getField(chunkProcessorField, tasklet);
|
||||
@@ -106,63 +103,55 @@ public class TaskBatchEventListenerBeanPostProcessor implements BeanPostProcesso
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName)
|
||||
throws BeansException {
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
|
||||
return bean;
|
||||
}
|
||||
|
||||
private void registerItemProcessEvents(SimpleChunkProcessor chunkProcessor) {
|
||||
if (this.applicationContext
|
||||
.containsBean(BatchEventAutoConfiguration.ITEM_PROCESS_EVENTS_LISTENER)) {
|
||||
if (this.applicationContext.containsBean(BatchEventAutoConfiguration.ITEM_PROCESS_EVENTS_LISTENER)) {
|
||||
chunkProcessor.registerListener((ItemProcessListener) this.applicationContext
|
||||
.getBean(BatchEventAutoConfiguration.ITEM_PROCESS_EVENTS_LISTENER));
|
||||
}
|
||||
}
|
||||
|
||||
private void registerItemReadEvents(SimpleChunkProvider chunkProvider) {
|
||||
if (this.applicationContext
|
||||
.containsBean(BatchEventAutoConfiguration.ITEM_READ_EVENTS_LISTENER)) {
|
||||
if (this.applicationContext.containsBean(BatchEventAutoConfiguration.ITEM_READ_EVENTS_LISTENER)) {
|
||||
chunkProvider.registerListener((ItemReadListener) this.applicationContext
|
||||
.getBean(BatchEventAutoConfiguration.ITEM_READ_EVENTS_LISTENER));
|
||||
}
|
||||
}
|
||||
|
||||
private void registerItemWriteEvents(SimpleChunkProcessor chunkProcessor) {
|
||||
if (this.applicationContext
|
||||
.containsBean(BatchEventAutoConfiguration.ITEM_WRITE_EVENTS_LISTENER)) {
|
||||
if (this.applicationContext.containsBean(BatchEventAutoConfiguration.ITEM_WRITE_EVENTS_LISTENER)) {
|
||||
chunkProcessor.registerListener((ItemWriteListener) this.applicationContext
|
||||
.getBean(BatchEventAutoConfiguration.ITEM_WRITE_EVENTS_LISTENER));
|
||||
}
|
||||
}
|
||||
|
||||
private void registerSkipEvents(SimpleChunkProvider chunkProvider) {
|
||||
if (this.applicationContext
|
||||
.containsBean(BatchEventAutoConfiguration.SKIP_EVENTS_LISTENER)) {
|
||||
chunkProvider.registerListener((SkipListener) this.applicationContext
|
||||
.getBean(BatchEventAutoConfiguration.SKIP_EVENTS_LISTENER));
|
||||
if (this.applicationContext.containsBean(BatchEventAutoConfiguration.SKIP_EVENTS_LISTENER)) {
|
||||
chunkProvider.registerListener(
|
||||
(SkipListener) this.applicationContext.getBean(BatchEventAutoConfiguration.SKIP_EVENTS_LISTENER));
|
||||
}
|
||||
}
|
||||
|
||||
private void registerSkipEvents(SimpleChunkProcessor chunkProcessor) {
|
||||
if (this.applicationContext
|
||||
.containsBean(BatchEventAutoConfiguration.SKIP_EVENTS_LISTENER)) {
|
||||
chunkProcessor.registerListener((SkipListener) this.applicationContext
|
||||
.getBean(BatchEventAutoConfiguration.SKIP_EVENTS_LISTENER));
|
||||
if (this.applicationContext.containsBean(BatchEventAutoConfiguration.SKIP_EVENTS_LISTENER)) {
|
||||
chunkProcessor.registerListener(
|
||||
(SkipListener) this.applicationContext.getBean(BatchEventAutoConfiguration.SKIP_EVENTS_LISTENER));
|
||||
}
|
||||
}
|
||||
|
||||
private void registerChunkEventsListener(Object bean) {
|
||||
if (this.applicationContext
|
||||
.containsBean(BatchEventAutoConfiguration.CHUNK_EVENTS_LISTENER)) {
|
||||
((TaskletStep) bean)
|
||||
.registerChunkListener((ChunkListener) this.applicationContext
|
||||
.getBean(BatchEventAutoConfiguration.CHUNK_EVENTS_LISTENER));
|
||||
if (this.applicationContext.containsBean(BatchEventAutoConfiguration.CHUNK_EVENTS_LISTENER)) {
|
||||
((TaskletStep) bean).registerChunkListener(
|
||||
(ChunkListener) this.applicationContext.getBean(BatchEventAutoConfiguration.CHUNK_EVENTS_LISTENER));
|
||||
}
|
||||
}
|
||||
|
||||
private void registerJobExecutionEventListener(Object bean) {
|
||||
if (bean instanceof AbstractJob && this.applicationContext.containsBean(
|
||||
BatchEventAutoConfiguration.JOB_EXECUTION_EVENTS_LISTENER)) {
|
||||
if (bean instanceof AbstractJob
|
||||
&& this.applicationContext.containsBean(BatchEventAutoConfiguration.JOB_EXECUTION_EVENTS_LISTENER)) {
|
||||
JobExecutionListener jobExecutionEventsListener = (JobExecutionListener) this.applicationContext
|
||||
.getBean(BatchEventAutoConfiguration.JOB_EXECUTION_EVENTS_LISTENER);
|
||||
|
||||
@@ -172,8 +161,7 @@ public class TaskBatchEventListenerBeanPostProcessor implements BeanPostProcesso
|
||||
}
|
||||
|
||||
private void registerStepExecutionEventListener(Object bean) {
|
||||
if (this.applicationContext.containsBean(
|
||||
BatchEventAutoConfiguration.STEP_EXECUTION_EVENTS_LISTENER)) {
|
||||
if (this.applicationContext.containsBean(BatchEventAutoConfiguration.STEP_EXECUTION_EVENTS_LISTENER)) {
|
||||
StepExecutionListener stepExecutionListener = (StepExecutionListener) this.applicationContext
|
||||
.getBean(BatchEventAutoConfiguration.STEP_EXECUTION_EVENTS_LISTENER);
|
||||
AbstractStep step = (AbstractStep) bean;
|
||||
|
||||
@@ -68,12 +68,19 @@ public class TaskEventProperties {
|
||||
private int skipOrder = Ordered.LOWEST_PRECEDENCE;
|
||||
|
||||
private String jobExecutionEventBindingName = "job-execution-events";
|
||||
|
||||
private String skipEventBindingName = "skip-events";
|
||||
|
||||
private String chunkEventBindingName = "chunk-events";
|
||||
|
||||
private String itemProcessEventBindingName = "item-process-events";
|
||||
|
||||
private String itemReadEventBindingName = "item-read-events";
|
||||
|
||||
private String itemWriteEventBindingName = "item-write-events";
|
||||
|
||||
private String stepExecutionEventBindingName = "step-execution-events";
|
||||
|
||||
private String taskEventBindingName = "task-events";
|
||||
|
||||
public int getJobExecutionOrder() {
|
||||
@@ -132,7 +139,6 @@ public class TaskEventProperties {
|
||||
this.skipOrder = skipOrder;
|
||||
}
|
||||
|
||||
|
||||
public String getJobExecutionEventBindingName() {
|
||||
return jobExecutionEventBindingName;
|
||||
}
|
||||
@@ -196,4 +202,5 @@ public class TaskEventProperties {
|
||||
public void setTaskEventBindingName(String taskEventBindingName) {
|
||||
this.taskEventBindingName = taskEventBindingName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -56,18 +56,14 @@ public class TaskLaunchRequest implements Serializable {
|
||||
* @param applicationName name to be applied to the launched task. If set to null then
|
||||
* the launched task name will be "Task-`hash code of the TaskLaunchRequest`.
|
||||
*/
|
||||
public TaskLaunchRequest(String uri, List<String> commandlineArguments,
|
||||
Map<String, String> environmentProperties,
|
||||
public TaskLaunchRequest(String uri, List<String> commandlineArguments, Map<String, String> environmentProperties,
|
||||
Map<String, String> deploymentProperties, String applicationName) {
|
||||
Assert.hasText(uri, "uri must not be empty nor null.");
|
||||
|
||||
this.uri = uri;
|
||||
this.commandlineArguments = (commandlineArguments == null) ? new ArrayList<>()
|
||||
: commandlineArguments;
|
||||
this.environmentProperties = environmentProperties == null ? new HashMap<>()
|
||||
: environmentProperties;
|
||||
this.deploymentProperties = deploymentProperties == null ? new HashMap<>()
|
||||
: deploymentProperties;
|
||||
this.commandlineArguments = (commandlineArguments == null) ? new ArrayList<>() : commandlineArguments;
|
||||
this.environmentProperties = environmentProperties == null ? new HashMap<>() : environmentProperties;
|
||||
this.deploymentProperties = deploymentProperties == null ? new HashMap<>() : deploymentProperties;
|
||||
setApplicationName(applicationName);
|
||||
}
|
||||
|
||||
@@ -125,16 +121,15 @@ public class TaskLaunchRequest implements Serializable {
|
||||
* @param applicationName the name to be
|
||||
*/
|
||||
public void setApplicationName(String applicationName) {
|
||||
this.applicationName = !StringUtils.hasText(applicationName)
|
||||
? "Task-" + UUID.randomUUID().toString() : applicationName;
|
||||
this.applicationName = !StringUtils.hasText(applicationName) ? "Task-" + UUID.randomUUID().toString()
|
||||
: applicationName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TaskLaunchRequest{" + "uri='" + this.uri + '\''
|
||||
+ ", commandlineArguments=" + this.commandlineArguments
|
||||
+ ", environmentProperties=" + this.environmentProperties
|
||||
+ ", deploymentProperties=" + this.deploymentProperties + '}';
|
||||
return "TaskLaunchRequest{" + "uri='" + this.uri + '\'' + ", commandlineArguments=" + this.commandlineArguments
|
||||
+ ", environmentProperties=" + this.environmentProperties + ", deploymentProperties="
|
||||
+ this.deploymentProperties + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -65,12 +65,10 @@ public class TaskLauncherSink {
|
||||
Assert.notNull(this.taskLauncher, "TaskLauncher has not been initialized");
|
||||
logger.info("Launching Task for the following uri " + taskLaunchRequest.getUri());
|
||||
Resource resource = this.resourceLoader.getResource(taskLaunchRequest.getUri());
|
||||
AppDefinition definition = new AppDefinition(
|
||||
taskLaunchRequest.getApplicationName(),
|
||||
AppDefinition definition = new AppDefinition(taskLaunchRequest.getApplicationName(),
|
||||
taskLaunchRequest.getEnvironmentProperties());
|
||||
AppDeploymentRequest request = new AppDeploymentRequest(definition, resource,
|
||||
taskLaunchRequest.getDeploymentProperties(),
|
||||
taskLaunchRequest.getCommandlineArguments());
|
||||
taskLaunchRequest.getDeploymentProperties(), taskLaunchRequest.getCommandlineArguments());
|
||||
this.taskLauncher.launch(request);
|
||||
}
|
||||
|
||||
|
||||
@@ -41,8 +41,8 @@ import org.springframework.context.annotation.PropertySource;
|
||||
@ConditionalOnBean(TaskLifecycleListener.class)
|
||||
@ConditionalOnExpression("T(org.springframework.util.StringUtils).isEmpty('${spring.batch.job.jobName:}')")
|
||||
// @checkstyle:off
|
||||
@ConditionalOnProperty(prefix = "spring.cloud.task.events", name = "enabled",
|
||||
havingValue = "true", matchIfMissing = true)
|
||||
@ConditionalOnProperty(prefix = "spring.cloud.task.events", name = "enabled", havingValue = "true",
|
||||
matchIfMissing = true)
|
||||
// @checkstyle:on
|
||||
@PropertySource("classpath:/org/springframework/cloud/task/application.properties")
|
||||
@AutoConfigureBefore(BindingServiceConfiguration.class)
|
||||
@@ -55,8 +55,10 @@ public class TaskEventAutoConfiguration {
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
public static class ListenerConfiguration {
|
||||
|
||||
@Bean
|
||||
public TaskExecutionListener taskEventEmitter(StreamBridge streamBridge, TaskEventProperties taskEventProperties) {
|
||||
public TaskExecutionListener taskEventEmitter(StreamBridge streamBridge,
|
||||
TaskEventProperties taskEventProperties) {
|
||||
return new TaskExecutionListener() {
|
||||
@Override
|
||||
public void onTaskStartup(TaskExecution taskExecution) {
|
||||
|
||||
@@ -78,27 +78,24 @@ public class EventListenerTests {
|
||||
@BeforeEach
|
||||
public void beforeTests() {
|
||||
this.applicationContext = new SpringApplicationBuilder()
|
||||
.sources(TestChannelBinderConfiguration
|
||||
.getCompleteConfiguration(BatchEventsApplication.class)).web(WebApplicationType.NONE).build()
|
||||
.run();
|
||||
.sources(TestChannelBinderConfiguration.getCompleteConfiguration(BatchEventsApplication.class))
|
||||
.web(WebApplicationType.NONE).build().run();
|
||||
StreamBridge streamBridge = this.applicationContext.getBean(StreamBridge.class);
|
||||
MessagePublisher messagePublisher = new MessagePublisher(streamBridge);
|
||||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
|
||||
this.eventEmittingSkipListener = new EventEmittingSkipListener(
|
||||
messagePublisher, this.taskEventProperties);
|
||||
this.eventEmittingItemProcessListener = new EventEmittingItemProcessListener(
|
||||
messagePublisher, this.taskEventProperties);
|
||||
this.eventEmittingItemReadListener = new EventEmittingItemReadListener(
|
||||
messagePublisher, this.taskEventProperties);
|
||||
this.eventEmittingItemWriteListener = new EventEmittingItemWriteListener(
|
||||
messagePublisher, this.taskEventProperties);
|
||||
this.eventEmittingJobExecutionListener = new EventEmittingJobExecutionListener(
|
||||
messagePublisher, this.taskEventProperties);
|
||||
this.eventEmittingStepExecutionListener = new EventEmittingStepExecutionListener(
|
||||
messagePublisher, this.taskEventProperties);
|
||||
this.eventEmittingChunkListener = new EventEmittingChunkListener(
|
||||
messagePublisher, 0, this.taskEventProperties);
|
||||
this.eventEmittingSkipListener = new EventEmittingSkipListener(messagePublisher, this.taskEventProperties);
|
||||
this.eventEmittingItemProcessListener = new EventEmittingItemProcessListener(messagePublisher,
|
||||
this.taskEventProperties);
|
||||
this.eventEmittingItemReadListener = new EventEmittingItemReadListener(messagePublisher,
|
||||
this.taskEventProperties);
|
||||
this.eventEmittingItemWriteListener = new EventEmittingItemWriteListener(messagePublisher,
|
||||
this.taskEventProperties);
|
||||
this.eventEmittingJobExecutionListener = new EventEmittingJobExecutionListener(messagePublisher,
|
||||
this.taskEventProperties);
|
||||
this.eventEmittingStepExecutionListener = new EventEmittingStepExecutionListener(messagePublisher,
|
||||
this.taskEventProperties);
|
||||
this.eventEmittingChunkListener = new EventEmittingChunkListener(messagePublisher, 0, this.taskEventProperties);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
@@ -110,25 +107,18 @@ public class EventListenerTests {
|
||||
|
||||
@Test
|
||||
public void testEventListenerOrderProperty() {
|
||||
assertThat(Ordered.LOWEST_PRECEDENCE)
|
||||
.isEqualTo(this.eventEmittingSkipListener.getOrder());
|
||||
assertThat(Ordered.LOWEST_PRECEDENCE)
|
||||
.isEqualTo(this.eventEmittingItemProcessListener.getOrder());
|
||||
assertThat(Ordered.LOWEST_PRECEDENCE)
|
||||
.isEqualTo(this.eventEmittingItemReadListener.getOrder());
|
||||
assertThat(Ordered.LOWEST_PRECEDENCE)
|
||||
.isEqualTo(this.eventEmittingItemWriteListener.getOrder());
|
||||
assertThat(Ordered.LOWEST_PRECEDENCE)
|
||||
.isEqualTo(this.eventEmittingJobExecutionListener.getOrder());
|
||||
assertThat(Ordered.LOWEST_PRECEDENCE)
|
||||
.isEqualTo(this.eventEmittingStepExecutionListener.getOrder());
|
||||
assertThat(Ordered.LOWEST_PRECEDENCE).isEqualTo(this.eventEmittingSkipListener.getOrder());
|
||||
assertThat(Ordered.LOWEST_PRECEDENCE).isEqualTo(this.eventEmittingItemProcessListener.getOrder());
|
||||
assertThat(Ordered.LOWEST_PRECEDENCE).isEqualTo(this.eventEmittingItemReadListener.getOrder());
|
||||
assertThat(Ordered.LOWEST_PRECEDENCE).isEqualTo(this.eventEmittingItemWriteListener.getOrder());
|
||||
assertThat(Ordered.LOWEST_PRECEDENCE).isEqualTo(this.eventEmittingJobExecutionListener.getOrder());
|
||||
assertThat(Ordered.LOWEST_PRECEDENCE).isEqualTo(this.eventEmittingStepExecutionListener.getOrder());
|
||||
assertThat(0).isEqualTo(this.eventEmittingChunkListener.getOrder());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testItemProcessListenerOnProcessorError() {
|
||||
this.eventEmittingItemProcessListener.onProcessError("HELLO",
|
||||
new RuntimeException("Test Exception"));
|
||||
this.eventEmittingItemProcessListener.onProcessError("HELLO", new RuntimeException("Test Exception"));
|
||||
|
||||
assertThat(getStringFromDestination(this.taskEventProperties.getItemProcessEventBindingName()))
|
||||
.isEqualTo("Exception while item was being processed");
|
||||
@@ -136,18 +126,17 @@ public class EventListenerTests {
|
||||
|
||||
@Test
|
||||
public void testItemProcessListenerAfterProcess() {
|
||||
this.eventEmittingItemProcessListener.afterProcess("HELLO_AFTER_PROCESS_EQUAL",
|
||||
"HELLO_AFTER_PROCESS_EQUAL");
|
||||
this.eventEmittingItemProcessListener.afterProcess("HELLO_AFTER_PROCESS_EQUAL", "HELLO_AFTER_PROCESS_EQUAL");
|
||||
assertThat(getStringFromDestination(this.taskEventProperties.getItemProcessEventBindingName()))
|
||||
.isEqualTo("item equaled result after processing");
|
||||
.isEqualTo("item equaled result after processing");
|
||||
|
||||
this.eventEmittingItemProcessListener.afterProcess("HELLO_NOT_EQUAL", "WORLD");
|
||||
assertThat(getStringFromDestination(this.taskEventProperties.getItemProcessEventBindingName()))
|
||||
.isEqualTo("item did not equal result after processing");
|
||||
|
||||
this.eventEmittingItemProcessListener.afterProcess("HELLO_AFTER_PROCESS", null);
|
||||
assertThat(getStringFromDestination(this.taskEventProperties.
|
||||
getItemProcessEventBindingName())).isEqualTo("1 item was filtered");
|
||||
assertThat(getStringFromDestination(this.taskEventProperties.getItemProcessEventBindingName()))
|
||||
.isEqualTo("1 item was filtered");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -159,33 +148,29 @@ public class EventListenerTests {
|
||||
@Test
|
||||
public void EventEmittingSkipListenerSkipRead() {
|
||||
this.eventEmittingSkipListener.onSkipInRead(new RuntimeException("Text Exception"));
|
||||
assertThat(getStringFromDestination(this.taskEventProperties.
|
||||
getSkipEventBindingName())).isEqualTo("Skipped when reading.");
|
||||
assertThat(getStringFromDestination(this.taskEventProperties.getSkipEventBindingName()))
|
||||
.isEqualTo("Skipped when reading.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void EventEmittingSkipListenerSkipWrite() {
|
||||
final String MESSAGE = "\"HELLO_SKIP_WRITE\"";
|
||||
this.eventEmittingSkipListener.onSkipInWrite(MESSAGE,
|
||||
new RuntimeException("Text Exception"));
|
||||
assertThat(getStringFromDestination(this.taskEventProperties.
|
||||
getSkipEventBindingName())).isEqualTo(MESSAGE);
|
||||
this.eventEmittingSkipListener.onSkipInWrite(MESSAGE, new RuntimeException("Text Exception"));
|
||||
assertThat(getStringFromDestination(this.taskEventProperties.getSkipEventBindingName())).isEqualTo(MESSAGE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void EventEmittingSkipListenerSkipProcess() {
|
||||
final String MESSAGE = "\"HELLO_SKIP_PROCESS\"";
|
||||
this.eventEmittingSkipListener.onSkipInProcess(MESSAGE,
|
||||
new RuntimeException("Text Exception"));
|
||||
assertThat(getStringFromDestination(this.taskEventProperties.
|
||||
getSkipEventBindingName())).isEqualTo(MESSAGE);
|
||||
this.eventEmittingSkipListener.onSkipInProcess(MESSAGE, new RuntimeException("Text Exception"));
|
||||
assertThat(getStringFromDestination(this.taskEventProperties.getSkipEventBindingName())).isEqualTo(MESSAGE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void EventEmittingItemReadListener() {
|
||||
this.eventEmittingItemReadListener.onReadError(new RuntimeException("Text Exception"));
|
||||
assertThat(getStringFromDestination(this.taskEventProperties.
|
||||
getItemReadEventBindingName())).isEqualTo("Exception while item was being read");
|
||||
assertThat(getStringFromDestination(this.taskEventProperties.getItemReadEventBindingName()))
|
||||
.isEqualTo("Exception while item was being read");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -204,14 +189,14 @@ public class EventListenerTests {
|
||||
public void EventEmittingItemWriteListenerBeforeWrite() {
|
||||
this.eventEmittingItemWriteListener.beforeWrite(getSampleList());
|
||||
assertThat(getStringFromDestination(this.taskEventProperties.getItemWriteEventBindingName()))
|
||||
.isEqualTo("3 items to be written.");
|
||||
.isEqualTo("3 items to be written.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void EventEmittingItemWriteListenerAfterWrite() {
|
||||
this.eventEmittingItemWriteListener.afterWrite(getSampleList());
|
||||
assertThat(getStringFromDestination(this.taskEventProperties.getItemWriteEventBindingName()))
|
||||
.isEqualTo("3 items have been written.");
|
||||
.isEqualTo("3 items have been written.");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -230,9 +215,8 @@ public class EventListenerTests {
|
||||
List<Message<byte[]>> result = testListener(this.taskEventProperties.getJobExecutionEventBindingName(), 1);
|
||||
assertThat(result.get(0)).isNotNull();
|
||||
|
||||
JobExecutionEvent jobEvent = this.objectMapper.readValue(result.get(0).getPayload(), JobExecutionEvent.class);
|
||||
assertThat(jobEvent.getJobInstance().getJobName())
|
||||
.isEqualTo(jobExecution.getJobInstance().getJobName());
|
||||
JobExecutionEvent jobEvent = this.objectMapper.readValue(result.get(0).getPayload(), JobExecutionEvent.class);
|
||||
assertThat(jobEvent.getJobInstance().getJobName()).isEqualTo(jobExecution.getJobInstance().getJobName());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -242,9 +226,8 @@ public class EventListenerTests {
|
||||
List<Message<byte[]>> result = testListener(this.taskEventProperties.getJobExecutionEventBindingName(), 1);
|
||||
assertThat(result.get(0)).isNotNull();
|
||||
|
||||
JobExecutionEvent jobEvent = this.objectMapper.readValue(result.get(0).getPayload(), JobExecutionEvent.class);
|
||||
assertThat(jobEvent.getJobInstance().getJobName())
|
||||
.isEqualTo(jobExecution.getJobInstance().getJobName());
|
||||
JobExecutionEvent jobEvent = this.objectMapper.readValue(result.get(0).getPayload(), JobExecutionEvent.class);
|
||||
assertThat(jobEvent.getJobInstance().getJobName()).isEqualTo(jobExecution.getJobInstance().getJobName());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -256,7 +239,8 @@ public class EventListenerTests {
|
||||
List<Message<byte[]>> result = testListener(this.taskEventProperties.getStepExecutionEventBindingName(), 1);
|
||||
assertThat(result.get(0)).isNotNull();
|
||||
|
||||
StepExecutionEvent stepExecutionEvent = this.objectMapper.readValue(result.get(0).getPayload(), StepExecutionEvent.class);
|
||||
StepExecutionEvent stepExecutionEvent = this.objectMapper.readValue(result.get(0).getPayload(),
|
||||
StepExecutionEvent.class);
|
||||
assertThat(stepExecutionEvent.getStepName()).isEqualTo(STEP_MESSAGE);
|
||||
}
|
||||
|
||||
@@ -268,7 +252,8 @@ public class EventListenerTests {
|
||||
List<Message<byte[]>> result = testListener(this.taskEventProperties.getStepExecutionEventBindingName(), 1);
|
||||
|
||||
assertThat(result.get(0)).isNotNull();
|
||||
StepExecutionEvent stepExecutionEvent = this.objectMapper.readValue(result.get(0).getPayload(), StepExecutionEvent.class);
|
||||
StepExecutionEvent stepExecutionEvent = this.objectMapper.readValue(result.get(0).getPayload(),
|
||||
StepExecutionEvent.class);
|
||||
assertThat(stepExecutionEvent.getStepName()).isEqualTo(STEP_MESSAGE);
|
||||
}
|
||||
|
||||
@@ -277,7 +262,7 @@ public class EventListenerTests {
|
||||
final String CHUNK_MESSAGE = "Before Chunk Processing";
|
||||
this.eventEmittingChunkListener.beforeChunk(getChunkContext());
|
||||
assertThat(getStringFromDestination(this.taskEventProperties.getChunkEventBindingName()))
|
||||
.isEqualTo(CHUNK_MESSAGE);
|
||||
.isEqualTo(CHUNK_MESSAGE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -285,7 +270,7 @@ public class EventListenerTests {
|
||||
final String CHUNK_MESSAGE = "After Chunk Processing";
|
||||
this.eventEmittingChunkListener.afterChunk(getChunkContext());
|
||||
assertThat(getStringFromDestination(this.taskEventProperties.getChunkEventBindingName()))
|
||||
.isEqualTo(CHUNK_MESSAGE);
|
||||
.isEqualTo(CHUNK_MESSAGE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -340,5 +325,7 @@ public class EventListenerTests {
|
||||
|
||||
@SpringBootApplication
|
||||
public static class BatchEventsApplication {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -60,14 +60,12 @@ public class JobExecutionEventTests {
|
||||
|
||||
private static final Long JOB_EXECUTION_ID = 2L;
|
||||
|
||||
private static final String[] LISTENER_BEAN_NAMES = {
|
||||
BatchEventAutoConfiguration.JOB_EXECUTION_EVENTS_LISTENER,
|
||||
BatchEventAutoConfiguration.STEP_EXECUTION_EVENTS_LISTENER,
|
||||
BatchEventAutoConfiguration.CHUNK_EVENTS_LISTENER,
|
||||
BatchEventAutoConfiguration.ITEM_READ_EVENTS_LISTENER,
|
||||
BatchEventAutoConfiguration.ITEM_WRITE_EVENTS_LISTENER,
|
||||
BatchEventAutoConfiguration.ITEM_PROCESS_EVENTS_LISTENER,
|
||||
BatchEventAutoConfiguration.SKIP_EVENTS_LISTENER};
|
||||
private static final String[] LISTENER_BEAN_NAMES = { BatchEventAutoConfiguration.JOB_EXECUTION_EVENTS_LISTENER,
|
||||
BatchEventAutoConfiguration.STEP_EXECUTION_EVENTS_LISTENER,
|
||||
BatchEventAutoConfiguration.CHUNK_EVENTS_LISTENER, BatchEventAutoConfiguration.ITEM_READ_EVENTS_LISTENER,
|
||||
BatchEventAutoConfiguration.ITEM_WRITE_EVENTS_LISTENER,
|
||||
BatchEventAutoConfiguration.ITEM_PROCESS_EVENTS_LISTENER,
|
||||
BatchEventAutoConfiguration.SKIP_EVENTS_LISTENER };
|
||||
|
||||
private JobParameters jobParameters;
|
||||
|
||||
@@ -83,31 +81,26 @@ public class JobExecutionEventTests {
|
||||
@Test
|
||||
public void testBasic() {
|
||||
JobExecution jobExecution;
|
||||
jobExecution = new JobExecution(this.jobInstance, JOB_EXECUTION_ID,
|
||||
this.jobParameters);
|
||||
jobExecution = new JobExecution(this.jobInstance, JOB_EXECUTION_ID, this.jobParameters);
|
||||
JobExecutionEvent jobExecutionEvent = new JobExecutionEvent(jobExecution);
|
||||
assertThat(jobExecutionEvent.getJobInstance())
|
||||
.as("jobInstance should not be null").isNotNull();
|
||||
assertThat(jobExecutionEvent.getJobParameters())
|
||||
.as("jobParameters should not be null").isNotNull();
|
||||
assertThat(jobExecutionEvent.getJobInstance()).as("jobInstance should not be null").isNotNull();
|
||||
assertThat(jobExecutionEvent.getJobParameters()).as("jobParameters should not be null").isNotNull();
|
||||
|
||||
assertThat(jobExecutionEvent.getJobParameters().getParameters().size())
|
||||
.as("jobParameters size did not match").isEqualTo(0);
|
||||
assertThat(jobExecutionEvent.getJobInstance().getJobName())
|
||||
.as("jobInstance name did not match").isEqualTo(JOB_NAME);
|
||||
assertThat(jobExecutionEvent.getStepExecutions().size())
|
||||
.as("no step executions were expected").isEqualTo(0);
|
||||
assertThat(jobExecutionEvent.getExitStatus().getExitCode())
|
||||
.as("exitStatus did not match expected").isEqualTo("UNKNOWN");
|
||||
assertThat(jobExecutionEvent.getJobParameters().getParameters().size()).as("jobParameters size did not match")
|
||||
.isEqualTo(0);
|
||||
assertThat(jobExecutionEvent.getJobInstance().getJobName()).as("jobInstance name did not match")
|
||||
.isEqualTo(JOB_NAME);
|
||||
assertThat(jobExecutionEvent.getStepExecutions().size()).as("no step executions were expected").isEqualTo(0);
|
||||
assertThat(jobExecutionEvent.getExitStatus().getExitCode()).as("exitStatus did not match expected")
|
||||
.isEqualTo("UNKNOWN");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJobParameters() {
|
||||
String[] JOB_PARAM_KEYS = {"A", "B", "C", "D"};
|
||||
String[] JOB_PARAM_KEYS = { "A", "B", "C", "D" };
|
||||
Date testDate = new Date();
|
||||
JobParameter[] PARAMETERS = {new JobParameter("FOO", true),
|
||||
new JobParameter(1L, true), new JobParameter(1D, true),
|
||||
new JobParameter(testDate, false)};
|
||||
JobParameter[] PARAMETERS = { new JobParameter("FOO", true), new JobParameter(1L, true),
|
||||
new JobParameter(1D, true), new JobParameter(testDate, false) };
|
||||
|
||||
Map<String, JobParameter> jobParamMap = new LinkedHashMap<>();
|
||||
for (int paramCount = 0; paramCount < JOB_PARAM_KEYS.length; paramCount++) {
|
||||
@@ -115,34 +108,28 @@ public class JobExecutionEventTests {
|
||||
}
|
||||
this.jobParameters = new JobParameters(jobParamMap);
|
||||
JobExecution jobExecution;
|
||||
jobExecution = new JobExecution(this.jobInstance, JOB_EXECUTION_ID,
|
||||
this.jobParameters);
|
||||
jobExecution = new JobExecution(this.jobInstance, JOB_EXECUTION_ID, this.jobParameters);
|
||||
JobExecutionEvent jobExecutionEvent = new JobExecutionEvent(jobExecution);
|
||||
|
||||
assertThat(jobExecutionEvent.getJobParameters().getString("A"))
|
||||
.as("Job Parameter A was expected").isNotNull();
|
||||
assertThat(jobExecutionEvent.getJobParameters().getLong("B"))
|
||||
.as("Job Parameter B was expected").isNotNull();
|
||||
assertThat(jobExecutionEvent.getJobParameters().getDouble("C"))
|
||||
.as("Job Parameter C was expected").isNotNull();
|
||||
assertThat(jobExecutionEvent.getJobParameters().getDate("D"))
|
||||
.as("Job Parameter D was expected").isNotNull();
|
||||
assertThat(jobExecutionEvent.getJobParameters().getString("A")).as("Job Parameter A was expected").isNotNull();
|
||||
assertThat(jobExecutionEvent.getJobParameters().getLong("B")).as("Job Parameter B was expected").isNotNull();
|
||||
assertThat(jobExecutionEvent.getJobParameters().getDouble("C")).as("Job Parameter C was expected").isNotNull();
|
||||
assertThat(jobExecutionEvent.getJobParameters().getDate("D")).as("Job Parameter D was expected").isNotNull();
|
||||
|
||||
assertThat(jobExecutionEvent.getJobParameters().getString("A"))
|
||||
.as("Job Parameter A value was not correct").isEqualTo("FOO");
|
||||
assertThat(jobExecutionEvent.getJobParameters().getLong("B"))
|
||||
.as("Job Parameter B value was not correct").isEqualTo(Long.valueOf(1));
|
||||
assertThat(jobExecutionEvent.getJobParameters().getDouble("C"))
|
||||
.as("Job Parameter C value was not correct").isEqualTo(Double.valueOf(1));
|
||||
assertThat(jobExecutionEvent.getJobParameters().getDate("D"))
|
||||
.as("Job Parameter D value was not correct").isEqualTo(testDate);
|
||||
assertThat(jobExecutionEvent.getJobParameters().getString("A")).as("Job Parameter A value was not correct")
|
||||
.isEqualTo("FOO");
|
||||
assertThat(jobExecutionEvent.getJobParameters().getLong("B")).as("Job Parameter B value was not correct")
|
||||
.isEqualTo(Long.valueOf(1));
|
||||
assertThat(jobExecutionEvent.getJobParameters().getDouble("C")).as("Job Parameter C value was not correct")
|
||||
.isEqualTo(Double.valueOf(1));
|
||||
assertThat(jobExecutionEvent.getJobParameters().getDate("D")).as("Job Parameter D value was not correct")
|
||||
.isEqualTo(testDate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStepExecutions() {
|
||||
JobExecution jobExecution;
|
||||
jobExecution = new JobExecution(this.jobInstance, JOB_EXECUTION_ID,
|
||||
this.jobParameters);
|
||||
jobExecution = new JobExecution(this.jobInstance, JOB_EXECUTION_ID, this.jobParameters);
|
||||
List<StepExecution> stepsExecutions = new ArrayList<>();
|
||||
stepsExecutions.add(new StepExecution("foo", jobExecution));
|
||||
stepsExecutions.add(new StepExecution("bar", jobExecution));
|
||||
@@ -150,16 +137,11 @@ public class JobExecutionEventTests {
|
||||
jobExecution.addStepExecutions(stepsExecutions);
|
||||
|
||||
JobExecutionEvent jobExecutionsEvent = new JobExecutionEvent(jobExecution);
|
||||
assertThat(jobExecutionsEvent.getStepExecutions().size())
|
||||
.as("stepExecutions count is incorrect").isEqualTo(3);
|
||||
Iterator<StepExecutionEvent> iter = jobExecutionsEvent.getStepExecutions()
|
||||
.iterator();
|
||||
assertThat(iter.next().getStepName()).as("foo stepExecution is not present")
|
||||
.isEqualTo("foo");
|
||||
assertThat(iter.next().getStepName()).as("bar stepExecution is not present")
|
||||
.isEqualTo("bar");
|
||||
assertThat(iter.next().getStepName()).as("baz stepExecution is not present")
|
||||
.isEqualTo("baz");
|
||||
assertThat(jobExecutionsEvent.getStepExecutions().size()).as("stepExecutions count is incorrect").isEqualTo(3);
|
||||
Iterator<StepExecutionEvent> iter = jobExecutionsEvent.getStepExecutions().iterator();
|
||||
assertThat(iter.next().getStepName()).as("foo stepExecution is not present").isEqualTo("foo");
|
||||
assertThat(iter.next().getStepName()).as("bar stepExecution is not present").isEqualTo("bar");
|
||||
assertThat(iter.next().getStepName()).as("baz stepExecution is not present").isEqualTo("baz");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -167,7 +149,6 @@ public class JobExecutionEventTests {
|
||||
testDisabledConfiguration(null, null);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDisabledJobExecutionListener() {
|
||||
testDisabledConfiguration("spring.cloud.task.batch.events.job-execution.enabled",
|
||||
@@ -177,10 +158,9 @@ public class JobExecutionEventTests {
|
||||
@Test
|
||||
public void testDisabledStepExecutionListener() {
|
||||
testDisabledConfiguration("spring.cloud.task.batch.events.step-execution.enabled",
|
||||
BatchEventAutoConfiguration.STEP_EXECUTION_EVENTS_LISTENER);
|
||||
BatchEventAutoConfiguration.STEP_EXECUTION_EVENTS_LISTENER);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDisabledChunkListener() {
|
||||
testDisabledConfiguration("spring.cloud.task.batch.events.chunk.enabled",
|
||||
@@ -222,21 +202,17 @@ public class JobExecutionEventTests {
|
||||
final String EXCEPTION_MESSAGE = "TEST EXCEPTION";
|
||||
JobExecutionEvent jobExecutionEvent = new JobExecutionEvent();
|
||||
assertThat(jobExecutionEvent.getFailureExceptions().size()).isEqualTo(0);
|
||||
jobExecutionEvent
|
||||
.addFailureException(new IllegalStateException(EXCEPTION_MESSAGE));
|
||||
jobExecutionEvent.addFailureException(new IllegalStateException(EXCEPTION_MESSAGE));
|
||||
assertThat(jobExecutionEvent.getFailureExceptions().size()).isEqualTo(1);
|
||||
assertThat(jobExecutionEvent.getAllFailureExceptions().size()).isEqualTo(1);
|
||||
assertThat(EXCEPTION_MESSAGE)
|
||||
.isEqualTo(jobExecutionEvent.getFailureExceptions().get(0).getMessage());
|
||||
assertThat(EXCEPTION_MESSAGE).isEqualTo(
|
||||
jobExecutionEvent.getAllFailureExceptions().get(0).getMessage());
|
||||
assertThat(EXCEPTION_MESSAGE).isEqualTo(jobExecutionEvent.getFailureExceptions().get(0).getMessage());
|
||||
assertThat(EXCEPTION_MESSAGE).isEqualTo(jobExecutionEvent.getAllFailureExceptions().get(0).getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
JobExecutionEvent jobExecutionEvent = new JobExecutionEvent();
|
||||
assertThat(jobExecutionEvent.toString().startsWith("JobExecutionEvent:"))
|
||||
.isTrue();
|
||||
assertThat(jobExecutionEvent.toString().startsWith("JobExecutionEvent:")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -273,10 +249,8 @@ public class JobExecutionEventTests {
|
||||
assertThat(jobExecutionEvent.getJobId()).isNull();
|
||||
JobInstanceEvent expectedJobInstanceEvent = new JobInstanceEvent(1L, JOB_NAME);
|
||||
jobExecutionEvent.setJobInstance(expectedJobInstanceEvent);
|
||||
assertThat(jobExecutionEvent.getJobInstance().getJobName())
|
||||
.isEqualTo(expectedJobInstanceEvent.getJobName());
|
||||
assertThat(jobExecutionEvent.getJobId())
|
||||
.isEqualTo(expectedJobInstanceEvent.getId());
|
||||
assertThat(jobExecutionEvent.getJobInstance().getJobName()).isEqualTo(expectedJobInstanceEvent.getJobName());
|
||||
assertThat(jobExecutionEvent.getJobId()).isEqualTo(expectedJobInstanceEvent.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -286,8 +260,7 @@ public class JobExecutionEventTests {
|
||||
JobExecutionEvent jobExecutionEvent = new JobExecutionEvent();
|
||||
assertThat(jobExecutionEvent.getExecutionContext()).isNotNull();
|
||||
jobExecutionEvent.setExecutionContext(executionContext);
|
||||
assertThat(jobExecutionEvent.getExecutionContext().getString("hello"))
|
||||
.isEqualTo("world");
|
||||
assertThat(jobExecutionEvent.getExecutionContext().getString("hello")).isEqualTo("world");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -311,15 +284,12 @@ public class JobExecutionEventTests {
|
||||
@Test
|
||||
public void testOrderConfiguration() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
|
||||
.withUserConfiguration(
|
||||
BatchEventAutoConfiguration.JobExecutionListenerConfiguration.class,
|
||||
BatchEventTestApplication.class)
|
||||
.withUserConfiguration(BatchEventAutoConfiguration.JobExecutionListenerConfiguration.class,
|
||||
BatchEventTestApplication.class)
|
||||
.withPropertyValues("--spring.cloud.task.closecontext_enabled=false",
|
||||
"--spring.main.web-environment=false",
|
||||
"--spring.cloud.task.batch.events.chunk-order=5",
|
||||
"--spring.main.web-environment=false", "--spring.cloud.task.batch.events.chunk-order=5",
|
||||
"--spring.cloud.task.batch.events.item-process-order=5",
|
||||
"--spring.cloud.task.batch.events.item-read-order=5",
|
||||
"--spring.cloud.task.batch.events.item-write-order=5",
|
||||
@@ -329,8 +299,7 @@ public class JobExecutionEventTests {
|
||||
applicationContextRunner.run((context) -> {
|
||||
for (String beanName : LISTENER_BEAN_NAMES) {
|
||||
Ordered ordered = (Ordered) context.getBean(beanName);
|
||||
assertThat(5).as("Expected order value of 5 for " + beanName)
|
||||
.isEqualTo(ordered.getOrder());
|
||||
assertThat(5).as("Expected order value of 5 for " + beanName).isEqualTo(ordered.getOrder());
|
||||
}
|
||||
|
||||
});
|
||||
@@ -339,34 +308,31 @@ public class JobExecutionEventTests {
|
||||
@Test
|
||||
public void singleStepBatchJobSkip() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
|
||||
.withUserConfiguration(
|
||||
BatchEventAutoConfiguration.JobExecutionListenerConfiguration.class,
|
||||
BatchEventTestApplication.class)
|
||||
.withPropertyValues("--spring.cloud.task.closecontext_enabled=false",
|
||||
"--spring.main.web-environment=false", "spring.batch.job.jobName=FOO");
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
|
||||
.withUserConfiguration(BatchEventAutoConfiguration.JobExecutionListenerConfiguration.class,
|
||||
BatchEventTestApplication.class)
|
||||
.withPropertyValues("--spring.cloud.task.closecontext_enabled=false",
|
||||
"--spring.main.web-environment=false", "spring.batch.job.jobName=FOO");
|
||||
applicationContextRunner.run((context) -> {
|
||||
NoSuchBeanDefinitionException exception = Assertions.assertThrows(NoSuchBeanDefinitionException.class, () -> {
|
||||
context.getBean("jobExecutionEventsListener");
|
||||
});
|
||||
assertThat(exception.getMessage()).contains(
|
||||
String.format("No bean named 'jobExecutionEventsListener' available"));
|
||||
NoSuchBeanDefinitionException exception = Assertions.assertThrows(NoSuchBeanDefinitionException.class,
|
||||
() -> {
|
||||
context.getBean("jobExecutionEventsListener");
|
||||
});
|
||||
assertThat(exception.getMessage())
|
||||
.contains(String.format("No bean named 'jobExecutionEventsListener' available"));
|
||||
});
|
||||
}
|
||||
|
||||
private void testDisabledConfiguration(String property, String disabledListener) {
|
||||
String disabledPropertyArg = (property != null) ? "--" + property + "=false" : "";
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
|
||||
.withUserConfiguration(
|
||||
BatchEventAutoConfiguration.JobExecutionListenerConfiguration.class,
|
||||
BatchEventTestApplication.class)
|
||||
.withPropertyValues("--spring.cloud.task.closecontext_enabled=false",
|
||||
"--spring.main.web-environment=false", disabledPropertyArg);
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
|
||||
.withUserConfiguration(BatchEventAutoConfiguration.JobExecutionListenerConfiguration.class,
|
||||
BatchEventTestApplication.class)
|
||||
.withPropertyValues("--spring.cloud.task.closecontext_enabled=false",
|
||||
"--spring.main.web-environment=false", disabledPropertyArg);
|
||||
applicationContextRunner.run((context) -> {
|
||||
boolean exceptionThrown = false;
|
||||
for (String beanName : LISTENER_BEAN_NAMES) {
|
||||
@@ -377,9 +343,8 @@ public class JobExecutionEventTests {
|
||||
catch (NoSuchBeanDefinitionException nsbde) {
|
||||
exceptionThrown = true;
|
||||
}
|
||||
assertThat(exceptionThrown).as(
|
||||
String.format("Did not expect %s bean in context", beanName))
|
||||
.isTrue();
|
||||
assertThat(exceptionThrown).as(String.format("Did not expect %s bean in context", beanName))
|
||||
.isTrue();
|
||||
}
|
||||
else {
|
||||
context.getBean(beanName);
|
||||
@@ -390,5 +355,7 @@ public class JobExecutionEventTests {
|
||||
|
||||
@SpringBootApplication
|
||||
public static class BatchEventTestApplication {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -53,8 +53,7 @@ public class JobInstanceEventTests {
|
||||
@Test
|
||||
public void testToString() {
|
||||
JobInstanceEvent jobInstanceEvent = new JobInstanceEvent(INSTANCE_ID, JOB_NAME);
|
||||
assertThat(jobInstanceEvent.toString())
|
||||
.isEqualTo("JobInstanceEvent: id=1, version=null, Job=[FOOBAR]");
|
||||
assertThat(jobInstanceEvent.toString()).isEqualTo("JobInstanceEvent: id=1, version=null, Job=[FOOBAR]");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -46,15 +46,13 @@ public class JobParameterEventTests {
|
||||
JobParameter jobParameter = new JobParameter(EXPECTED_VALUE, true);
|
||||
JobParameterEvent jobParameterEvent = new JobParameterEvent(jobParameter);
|
||||
assertThat(jobParameterEvent.getValue()).isEqualTo(EXPECTED_VALUE);
|
||||
assertThat(jobParameterEvent.getType())
|
||||
.isEqualTo(JobParameterEvent.ParameterType.STRING);
|
||||
assertThat(jobParameterEvent.getType()).isEqualTo(JobParameterEvent.ParameterType.STRING);
|
||||
assertThat(jobParameterEvent.isIdentifying()).isTrue();
|
||||
|
||||
jobParameter = new JobParameter(EXPECTED_DATE_VALUE, true);
|
||||
jobParameterEvent = new JobParameterEvent(jobParameter);
|
||||
assertThat(jobParameterEvent.getValue()).isEqualTo(EXPECTED_DATE_VALUE);
|
||||
assertThat(jobParameterEvent.getType())
|
||||
.isEqualTo(JobParameterEvent.ParameterType.DATE);
|
||||
assertThat(jobParameterEvent.getType()).isEqualTo(JobParameterEvent.ParameterType.DATE);
|
||||
assertThat(jobParameterEvent.isIdentifying()).isTrue();
|
||||
assertThat(new JobParameterEvent(jobParameter).equals(jobParameterEvent)).isTrue();
|
||||
}
|
||||
|
||||
@@ -59,12 +59,10 @@ public class JobParametersEventTests {
|
||||
@Test
|
||||
public void testConstructor() {
|
||||
JobParametersEvent jobParametersEvent = getPopulatedParametersEvent();
|
||||
assertThat(jobParametersEvent.getString(STRING_KEY))
|
||||
.isEqualTo(STRING_PARAM.getValue());
|
||||
assertThat(jobParametersEvent.getString(STRING_KEY)).isEqualTo(STRING_PARAM.getValue());
|
||||
assertThat(jobParametersEvent.getLong(LONG_KEY)).isEqualTo(LONG_PARAM.getValue());
|
||||
assertThat(jobParametersEvent.getDate(DATE_KEY)).isEqualTo(DATE_PARAM.getValue());
|
||||
assertThat(jobParametersEvent.getDouble(DOUBLE_KEY))
|
||||
.isEqualTo(DOUBLE_PARAM.getValue());
|
||||
assertThat(jobParametersEvent.getDouble(DOUBLE_KEY)).isEqualTo(DOUBLE_PARAM.getValue());
|
||||
|
||||
JobParametersEvent jobParametersEventNew = getPopulatedParametersEvent();
|
||||
assertThat(jobParametersEvent).isEqualTo(jobParametersEventNew);
|
||||
@@ -84,22 +82,17 @@ public class JobParametersEventTests {
|
||||
assertThat(jobParametersEvent.hashCode()).isNotNull();
|
||||
JobParametersEvent jobParametersEventPopulated = getPopulatedParametersEvent();
|
||||
assertThat(jobParametersEvent).isNotNull();
|
||||
assertThat(jobParametersEventPopulated.hashCode())
|
||||
.isNotEqualTo(jobParametersEvent.hashCode());
|
||||
assertThat(jobParametersEventPopulated.hashCode()).isNotEqualTo(jobParametersEvent.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToProperties() {
|
||||
JobParametersEvent jobParametersEvent = getPopulatedParametersEvent();
|
||||
Properties properties = jobParametersEvent.toProperties();
|
||||
assertThat(jobParametersEvent.getString(DATE_KEY))
|
||||
.isEqualTo(properties.getProperty(DATE_KEY));
|
||||
assertThat(jobParametersEvent.getString(STRING_KEY))
|
||||
.isEqualTo(properties.getProperty(STRING_KEY));
|
||||
assertThat(jobParametersEvent.getString(LONG_KEY))
|
||||
.isEqualTo(properties.getProperty(LONG_KEY));
|
||||
assertThat(jobParametersEvent.getString(DOUBLE_KEY))
|
||||
.isEqualTo(properties.getProperty(DOUBLE_KEY));
|
||||
assertThat(jobParametersEvent.getString(DATE_KEY)).isEqualTo(properties.getProperty(DATE_KEY));
|
||||
assertThat(jobParametersEvent.getString(STRING_KEY)).isEqualTo(properties.getProperty(STRING_KEY));
|
||||
assertThat(jobParametersEvent.getString(LONG_KEY)).isEqualTo(properties.getProperty(LONG_KEY));
|
||||
assertThat(jobParametersEvent.getString(DOUBLE_KEY)).isEqualTo(properties.getProperty(DOUBLE_KEY));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -114,20 +107,15 @@ public class JobParametersEventTests {
|
||||
assertThat(jobParametersEvent.getDouble("FOOBAR")).isEqualTo(Double.valueOf(0));
|
||||
assertThat(jobParametersEvent.getLong("FOOBAR")).isEqualTo(Long.valueOf(0));
|
||||
assertThat(jobParametersEvent.getDouble("FOOBAR", 5)).isEqualTo(Double.valueOf(5));
|
||||
assertThat(jobParametersEvent.getDouble(DOUBLE_KEY, 0))
|
||||
.isEqualTo(DOUBLE_PARAM.getValue());
|
||||
assertThat(jobParametersEvent.getDouble(DOUBLE_KEY, 0)).isEqualTo(DOUBLE_PARAM.getValue());
|
||||
assertThat(jobParametersEvent.getLong("FOOBAR", 5)).isEqualTo(Long.valueOf(5));
|
||||
assertThat(jobParametersEvent.getLong(LONG_KEY, 5))
|
||||
.isEqualTo(LONG_PARAM.getValue());
|
||||
assertThat(jobParametersEvent.getString("FOOBAR", "TESTVAL"))
|
||||
.isEqualTo("TESTVAL");
|
||||
assertThat(jobParametersEvent.getString(STRING_KEY, "TESTVAL"))
|
||||
.isEqualTo(STRING_PARAM.getValue());
|
||||
assertThat(jobParametersEvent.getLong(LONG_KEY, 5)).isEqualTo(LONG_PARAM.getValue());
|
||||
assertThat(jobParametersEvent.getString("FOOBAR", "TESTVAL")).isEqualTo("TESTVAL");
|
||||
assertThat(jobParametersEvent.getString(STRING_KEY, "TESTVAL")).isEqualTo(STRING_PARAM.getValue());
|
||||
|
||||
Date date = new Date();
|
||||
assertThat(jobParametersEvent.getDate("FOOBAR", date)).isEqualTo(date);
|
||||
assertThat(jobParametersEvent.getDate(DATE_KEY, date))
|
||||
.isEqualTo(DATE_PARAM.getValue());
|
||||
assertThat(jobParametersEvent.getDate(DATE_KEY, date)).isEqualTo(DATE_PARAM.getValue());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -54,34 +54,24 @@ public class StepExecutionEventTests {
|
||||
stepExecution.setWriteSkipCount(5);
|
||||
|
||||
StepExecutionEvent stepExecutionEvent = new StepExecutionEvent(stepExecution);
|
||||
assertThat(stepExecutionEvent.getStepName())
|
||||
.as("stepName result was not as expected").isEqualTo(STEP_NAME);
|
||||
assertThat(stepExecutionEvent.getStartTime())
|
||||
.as("startTime result was not as expected")
|
||||
assertThat(stepExecutionEvent.getStepName()).as("stepName result was not as expected").isEqualTo(STEP_NAME);
|
||||
assertThat(stepExecutionEvent.getStartTime()).as("startTime result was not as expected")
|
||||
.isEqualTo(stepExecution.getStartTime());
|
||||
assertThat(stepExecutionEvent.getEndTime())
|
||||
.as("endTime result was not as expected")
|
||||
assertThat(stepExecutionEvent.getEndTime()).as("endTime result was not as expected")
|
||||
.isEqualTo(stepExecution.getEndTime());
|
||||
assertThat(stepExecutionEvent.getLastUpdated())
|
||||
.as("lastUpdated result was not as expected")
|
||||
assertThat(stepExecutionEvent.getLastUpdated()).as("lastUpdated result was not as expected")
|
||||
.isEqualTo(stepExecution.getLastUpdated());
|
||||
assertThat(stepExecutionEvent.getCommitCount())
|
||||
.as("commitCount result was not as expected")
|
||||
assertThat(stepExecutionEvent.getCommitCount()).as("commitCount result was not as expected")
|
||||
.isEqualTo(stepExecution.getCommitCount());
|
||||
assertThat(stepExecutionEvent.getReadCount())
|
||||
.as("readCount result was not as expected")
|
||||
assertThat(stepExecutionEvent.getReadCount()).as("readCount result was not as expected")
|
||||
.isEqualTo(stepExecution.getReadCount());
|
||||
assertThat(stepExecutionEvent.getReadSkipCount())
|
||||
.as("readSkipCount result was not as expected")
|
||||
assertThat(stepExecutionEvent.getReadSkipCount()).as("readSkipCount result was not as expected")
|
||||
.isEqualTo(stepExecution.getReadSkipCount());
|
||||
assertThat(stepExecutionEvent.getWriteCount())
|
||||
.as("writeCount result was not as expected")
|
||||
assertThat(stepExecutionEvent.getWriteCount()).as("writeCount result was not as expected")
|
||||
.isEqualTo(stepExecution.getWriteCount());
|
||||
assertThat(stepExecutionEvent.getWriteSkipCount())
|
||||
.as("writeSkipCount result was not as expected")
|
||||
assertThat(stepExecutionEvent.getWriteSkipCount()).as("writeSkipCount result was not as expected")
|
||||
.isEqualTo(stepExecution.getWriteSkipCount());
|
||||
assertThat(stepExecutionEvent.getSkipCount())
|
||||
.as("skipCount result was not as expected")
|
||||
assertThat(stepExecutionEvent.getSkipCount()).as("skipCount result was not as expected")
|
||||
.isEqualTo(stepExecution.getSkipCount());
|
||||
}
|
||||
|
||||
@@ -99,8 +89,8 @@ public class StepExecutionEventTests {
|
||||
public void testGetSummary() {
|
||||
StepExecution stepExecution = getBasicStepExecution();
|
||||
StepExecutionEvent stepExecutionEvent = new StepExecutionEvent(stepExecution);
|
||||
assertThat(stepExecutionEvent.getSummary()).isEqualTo(
|
||||
"StepExecutionEvent: id=null, version=null, name=STEP_NAME, status=STARTING,"
|
||||
assertThat(stepExecutionEvent.getSummary())
|
||||
.isEqualTo("StepExecutionEvent: id=null, version=null, name=STEP_NAME, status=STARTING,"
|
||||
+ " exitStatus=EXECUTING, readCount=0, filterCount=0, writeCount=0 readSkipCount=0,"
|
||||
+ " writeSkipCount=0, processSkipCount=0, commitCount=0, rollbackCount=0");
|
||||
}
|
||||
@@ -109,12 +99,10 @@ public class StepExecutionEventTests {
|
||||
public void testHashCode() {
|
||||
StepExecution stepExecution = getBasicStepExecution();
|
||||
StepExecutionEvent stepExecutionEvent = new StepExecutionEvent(stepExecution);
|
||||
assertThat(stepExecutionEvent.toString())
|
||||
.isEqualTo("StepExecutionEvent: id=null, version=null, "
|
||||
+ "name=STEP_NAME, status=STARTING, exitStatus=EXECUTING, "
|
||||
+ "readCount=0, filterCount=0, writeCount=0 readSkipCount=0, "
|
||||
+ "writeSkipCount=0, processSkipCount=0, commitCount=0, "
|
||||
+ "rollbackCount=0, exitDescription=");
|
||||
assertThat(stepExecutionEvent.toString()).isEqualTo("StepExecutionEvent: id=null, version=null, "
|
||||
+ "name=STEP_NAME, status=STARTING, exitStatus=EXECUTING, "
|
||||
+ "readCount=0, filterCount=0, writeCount=0 readSkipCount=0, "
|
||||
+ "writeSkipCount=0, processSkipCount=0, commitCount=0, " + "rollbackCount=0, exitDescription=");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -135,8 +123,7 @@ public class StepExecutionEventTests {
|
||||
|
||||
@Test
|
||||
public void testSettersGetters() {
|
||||
StepExecutionEvent stepExecutionEvent = new StepExecutionEvent(
|
||||
getBasicStepExecution());
|
||||
StepExecutionEvent stepExecutionEvent = new StepExecutionEvent(getBasicStepExecution());
|
||||
Date date = new Date();
|
||||
stepExecutionEvent.setLastUpdated(date);
|
||||
assertThat(stepExecutionEvent.getLastUpdated()).isEqualTo(date);
|
||||
@@ -186,8 +173,7 @@ public class StepExecutionEventTests {
|
||||
|
||||
@Test
|
||||
public void testExitStatus() {
|
||||
StepExecutionEvent stepExecutionEvent = new StepExecutionEvent(
|
||||
getBasicStepExecution());
|
||||
StepExecutionEvent stepExecutionEvent = new StepExecutionEvent(getBasicStepExecution());
|
||||
final String EXIT_CODE = "1";
|
||||
final String EXIT_DESCRIPTION = "EXPECTED FAILURE";
|
||||
ExitStatus exitStatus = new ExitStatus();
|
||||
@@ -198,14 +184,12 @@ public class StepExecutionEventTests {
|
||||
ExitStatus actualExitStatus = stepExecutionEvent.getExitStatus();
|
||||
assertThat(actualExitStatus).isNotNull();
|
||||
assertThat(actualExitStatus.getExitCode()).isEqualTo(exitStatus.getExitCode());
|
||||
assertThat(actualExitStatus.getExitDescription())
|
||||
.isEqualTo(exitStatus.getExitDescription());
|
||||
assertThat(actualExitStatus.getExitDescription()).isEqualTo(exitStatus.getExitDescription());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBatchStatus() {
|
||||
StepExecutionEvent stepExecutionEvent = new StepExecutionEvent(
|
||||
getBasicStepExecution());
|
||||
StepExecutionEvent stepExecutionEvent = new StepExecutionEvent(getBasicStepExecution());
|
||||
assertThat(stepExecutionEvent.getStatus()).isEqualTo(BatchStatus.STARTING);
|
||||
stepExecutionEvent.setStatus(BatchStatus.ABANDONED);
|
||||
assertThat(stepExecutionEvent.getStatus()).isEqualTo(BatchStatus.ABANDONED);
|
||||
@@ -216,27 +200,23 @@ public class StepExecutionEventTests {
|
||||
StepExecutionEvent stepExecutionEvent = new StepExecutionEvent();
|
||||
assertThat(stepExecutionEvent.getStatus()).isEqualTo(BatchStatus.STARTING);
|
||||
assertThat(stepExecutionEvent.getExitStatus()).isNotNull();
|
||||
assertThat(stepExecutionEvent.getExitStatus().getExitCode())
|
||||
.isEqualTo("EXECUTING");
|
||||
assertThat(stepExecutionEvent.getExitStatus().getExitCode()).isEqualTo("EXECUTING");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecutionContext() {
|
||||
ExecutionContext executionContext = new ExecutionContext();
|
||||
executionContext.put("hello", "world");
|
||||
StepExecutionEvent stepExecutionEvent = new StepExecutionEvent(
|
||||
getBasicStepExecution());
|
||||
StepExecutionEvent stepExecutionEvent = new StepExecutionEvent(getBasicStepExecution());
|
||||
assertThat(stepExecutionEvent.getExecutionContext()).isNotNull();
|
||||
stepExecutionEvent.setExecutionContext(executionContext);
|
||||
assertThat(stepExecutionEvent.getExecutionContext().getString("hello"))
|
||||
.isEqualTo("world");
|
||||
assertThat(stepExecutionEvent.getExecutionContext().getString("hello")).isEqualTo("world");
|
||||
}
|
||||
|
||||
private StepExecution getBasicStepExecution() {
|
||||
JobInstance jobInstance = new JobInstance(JOB_INSTANCE_ID, JOB_NAME);
|
||||
JobParameters jobParameters = new JobParameters();
|
||||
JobExecution jobExecution = new JobExecution(jobInstance, JOB_EXECUTION_ID,
|
||||
jobParameters);
|
||||
JobExecution jobExecution = new JobExecution(jobInstance, JOB_EXECUTION_ID, jobParameters);
|
||||
return new StepExecution(STEP_NAME, jobExecution);
|
||||
}
|
||||
|
||||
|
||||
@@ -82,22 +82,16 @@ public class TaskBatchEventListenerBeanPostProcessorTests {
|
||||
|
||||
@BeforeEach
|
||||
public void setupMock() {
|
||||
when(this.taskletStep.getTasklet()).thenReturn(
|
||||
new ChunkOrientedTasklet(this.chunkProvider, this.chunkProcessor));
|
||||
when(this.taskletStep.getTasklet())
|
||||
.thenReturn(new ChunkOrientedTasklet(this.chunkProvider, this.chunkProcessor));
|
||||
when(this.taskletStep.getName()).thenReturn("FOOOBAR");
|
||||
|
||||
registerAlias(ItemProcessListener.class,
|
||||
BatchEventAutoConfiguration.ITEM_PROCESS_EVENTS_LISTENER);
|
||||
registerAlias(StepExecutionListener.class,
|
||||
BatchEventAutoConfiguration.STEP_EXECUTION_EVENTS_LISTENER);
|
||||
registerAlias(ChunkListener.class,
|
||||
BatchEventAutoConfiguration.CHUNK_EVENTS_LISTENER);
|
||||
registerAlias(ItemReadListener.class,
|
||||
BatchEventAutoConfiguration.ITEM_READ_EVENTS_LISTENER);
|
||||
registerAlias(ItemWriteListener.class,
|
||||
BatchEventAutoConfiguration.ITEM_WRITE_EVENTS_LISTENER);
|
||||
registerAlias(SkipListener.class,
|
||||
BatchEventAutoConfiguration.SKIP_EVENTS_LISTENER);
|
||||
registerAlias(ItemProcessListener.class, BatchEventAutoConfiguration.ITEM_PROCESS_EVENTS_LISTENER);
|
||||
registerAlias(StepExecutionListener.class, BatchEventAutoConfiguration.STEP_EXECUTION_EVENTS_LISTENER);
|
||||
registerAlias(ChunkListener.class, BatchEventAutoConfiguration.CHUNK_EVENTS_LISTENER);
|
||||
registerAlias(ItemReadListener.class, BatchEventAutoConfiguration.ITEM_READ_EVENTS_LISTENER);
|
||||
registerAlias(ItemWriteListener.class, BatchEventAutoConfiguration.ITEM_WRITE_EVENTS_LISTENER);
|
||||
registerAlias(SkipListener.class, BatchEventAutoConfiguration.SKIP_EVENTS_LISTENER);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -105,8 +99,8 @@ public class TaskBatchEventListenerBeanPostProcessorTests {
|
||||
TaskBatchEventListenerBeanPostProcessor postProcessor = this.context
|
||||
.getBean(TaskBatchEventListenerBeanPostProcessor.class);
|
||||
assertThat(postProcessor).isNotNull();
|
||||
TaskletStep updatedTaskletStep = (TaskletStep) postProcessor
|
||||
.postProcessBeforeInitialization(this.taskletStep, "FOO");
|
||||
TaskletStep updatedTaskletStep = (TaskletStep) postProcessor.postProcessBeforeInitialization(this.taskletStep,
|
||||
"FOO");
|
||||
assertThat(updatedTaskletStep).isEqualTo(this.taskletStep);
|
||||
}
|
||||
|
||||
|
||||
@@ -43,8 +43,8 @@ public class TaskLaunchConfigurationExistingTests {
|
||||
@Test
|
||||
public void testTaskLauncher() {
|
||||
try (ConfigurableApplicationContext context = new SpringApplicationBuilder(
|
||||
TaskLaunchConfigurationExistingTests.TestTaskDeployerConfiguration.class).web(WebApplicationType.NONE).run(
|
||||
"--spring.jmx.enabled=false")) {
|
||||
TaskLaunchConfigurationExistingTests.TestTaskDeployerConfiguration.class).web(WebApplicationType.NONE)
|
||||
.run("--spring.jmx.enabled=false")) {
|
||||
LocalTaskLauncher taskLauncher = context.getBean(LocalTaskLauncher.class);
|
||||
assertThat(testTaskLauncher).isNotNull();
|
||||
assertThat(taskLauncher).isNotNull();
|
||||
|
||||
@@ -42,32 +42,28 @@ public class TaskLaunchRequestTests {
|
||||
args.add("foo");
|
||||
map.put("bar", "baz");
|
||||
|
||||
TaskLaunchRequest request = new TaskLaunchRequest(URI, Collections.EMPTY_LIST,
|
||||
Collections.EMPTY_MAP, Collections.EMPTY_MAP, null);
|
||||
TaskLaunchRequest request2 = new TaskLaunchRequest(URI, Collections.EMPTY_LIST,
|
||||
Collections.EMPTY_MAP, Collections.EMPTY_MAP, null);
|
||||
TaskLaunchRequest request = new TaskLaunchRequest(URI, Collections.EMPTY_LIST, Collections.EMPTY_MAP,
|
||||
Collections.EMPTY_MAP, null);
|
||||
TaskLaunchRequest request2 = new TaskLaunchRequest(URI, Collections.EMPTY_LIST, Collections.EMPTY_MAP,
|
||||
Collections.EMPTY_MAP, null);
|
||||
assertThat(request.equals(null)).isFalse();
|
||||
assertThat(request.equals("nope")).isFalse();
|
||||
assertThat(request.equals(request)).isTrue();
|
||||
assertThat(request.equals(request2)).isTrue();
|
||||
TaskLaunchRequest requestDiff = new TaskLaunchRequest("https://oops",
|
||||
Collections.EMPTY_LIST, Collections.EMPTY_MAP, Collections.EMPTY_MAP,
|
||||
null);
|
||||
TaskLaunchRequest requestDiff = new TaskLaunchRequest("https://oops", Collections.EMPTY_LIST,
|
||||
Collections.EMPTY_MAP, Collections.EMPTY_MAP, null);
|
||||
assertThat(request.equals(requestDiff)).isFalse();
|
||||
|
||||
requestDiff = new TaskLaunchRequest(URI, args, Collections.EMPTY_MAP,
|
||||
Collections.EMPTY_MAP, null);
|
||||
requestDiff = new TaskLaunchRequest(URI, args, Collections.EMPTY_MAP, Collections.EMPTY_MAP, null);
|
||||
assertThat(request.equals(requestDiff)).isFalse();
|
||||
|
||||
requestDiff = new TaskLaunchRequest(URI, null, null, null, null);
|
||||
assertThat(request.equals(requestDiff)).isTrue();
|
||||
|
||||
requestDiff = new TaskLaunchRequest(URI, Collections.EMPTY_LIST, map,
|
||||
Collections.EMPTY_MAP, null);
|
||||
requestDiff = new TaskLaunchRequest(URI, Collections.EMPTY_LIST, map, Collections.EMPTY_MAP, null);
|
||||
assertThat(request.equals(requestDiff)).isFalse();
|
||||
|
||||
requestDiff = new TaskLaunchRequest(URI, Collections.EMPTY_LIST,
|
||||
Collections.EMPTY_MAP, map, null);
|
||||
requestDiff = new TaskLaunchRequest(URI, Collections.EMPTY_LIST, Collections.EMPTY_MAP, map, null);
|
||||
assertThat(request.equals(requestDiff)).isFalse();
|
||||
|
||||
assertThat(request.hashCode()).isEqualTo(request.hashCode());
|
||||
@@ -76,12 +72,12 @@ public class TaskLaunchRequestTests {
|
||||
|
||||
@Test
|
||||
public void testApplicationName() {
|
||||
TaskLaunchRequest request = new TaskLaunchRequest(URI, Collections.EMPTY_LIST,
|
||||
Collections.EMPTY_MAP, Collections.EMPTY_MAP, null);
|
||||
TaskLaunchRequest request = new TaskLaunchRequest(URI, Collections.EMPTY_LIST, Collections.EMPTY_MAP,
|
||||
Collections.EMPTY_MAP, null);
|
||||
assertThat(request.getApplicationName().startsWith("Task-")).isTrue();
|
||||
|
||||
request = new TaskLaunchRequest(URI, Collections.EMPTY_LIST,
|
||||
Collections.EMPTY_MAP, Collections.EMPTY_MAP, APP_NAME);
|
||||
request = new TaskLaunchRequest(URI, Collections.EMPTY_LIST, Collections.EMPTY_MAP, Collections.EMPTY_MAP,
|
||||
APP_NAME);
|
||||
assertThat(request.getApplicationName()).isEqualTo(APP_NAME);
|
||||
}
|
||||
|
||||
|
||||
@@ -48,10 +48,9 @@ public class TaskLauncherFunctionTests {
|
||||
private final static String PARAM2 = "BAR";
|
||||
|
||||
private final static String VALID_URL = "maven://org.springframework.cloud.task.app:"
|
||||
+ "timestamp-task:jar:1.0.1.RELEASE";
|
||||
+ "timestamp-task:jar:1.0.1.RELEASE";
|
||||
|
||||
private final static String INVALID_URL = "maven://not.real.group:"
|
||||
+ "invalid:jar:1.0.0.BUILD-SNAPSHOT";
|
||||
private final static String INVALID_URL = "maven://not.real.group:" + "invalid:jar:1.0.0.BUILD-SNAPSHOT";
|
||||
|
||||
private final static String DEFAULT_STATUS = "test_status";
|
||||
|
||||
@@ -60,18 +59,16 @@ public class TaskLauncherFunctionTests {
|
||||
@Test
|
||||
public void testProcessorFromFunction() {
|
||||
try (ConfigurableApplicationContext context = new SpringApplicationBuilder(
|
||||
TestChannelBinderConfiguration.getCompleteConfiguration(
|
||||
TaskLauncherSinkTestApplication.class)).web(WebApplicationType.NONE).run(
|
||||
"--spring.jmx.enabled=false")) {
|
||||
TestChannelBinderConfiguration.getCompleteConfiguration(TaskLauncherSinkTestApplication.class))
|
||||
.web(WebApplicationType.NONE).run("--spring.jmx.enabled=false")) {
|
||||
|
||||
InputDestination source = context.getBean(InputDestination.class);
|
||||
TaskLaunchRequest request = new TaskLaunchRequest(VALID_URL, Collections.emptyList(),
|
||||
Collections.emptyMap(), null, "TESTAPP1");
|
||||
Collections.emptyMap(), null, "TESTAPP1");
|
||||
GenericMessage<TaskLaunchRequest> message = new GenericMessage<>(request);
|
||||
source.send(message);
|
||||
TaskConfiguration.TestTaskLauncher target = context.getBean(TaskConfiguration.TestTaskLauncher.class);
|
||||
assertThat(target.status(DEFAULT_STATUS).getState())
|
||||
.isEqualTo(LaunchState.complete);
|
||||
assertThat(target.status(DEFAULT_STATUS).getState()).isEqualTo(LaunchState.complete);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,11 +78,10 @@ public class TaskLauncherFunctionTests {
|
||||
commandLineArgs.add(PARAM1);
|
||||
commandLineArgs.add(PARAM2);
|
||||
try (ConfigurableApplicationContext context = new SpringApplicationBuilder(
|
||||
TestChannelBinderConfiguration.getCompleteConfiguration(
|
||||
TaskLauncherSinkTestApplication.class)).web(WebApplicationType.NONE).run(
|
||||
"--spring.jmx.enabled=false")) {
|
||||
TaskConfiguration.TestTaskLauncher testTaskLauncher = launchTaskString(VALID_URL,
|
||||
commandLineArgs, null, context);
|
||||
TestChannelBinderConfiguration.getCompleteConfiguration(TaskLauncherSinkTestApplication.class))
|
||||
.web(WebApplicationType.NONE).run("--spring.jmx.enabled=false")) {
|
||||
TaskConfiguration.TestTaskLauncher testTaskLauncher = launchTaskString(VALID_URL, commandLineArgs, null,
|
||||
context);
|
||||
verifySuccessWithParams(testTaskLauncher);
|
||||
|
||||
testTaskLauncher = launchTaskByteArray(VALID_URL, commandLineArgs, null, context);
|
||||
@@ -99,11 +95,9 @@ public class TaskLauncherFunctionTests {
|
||||
@Test
|
||||
public void testSuccessWithAppName() throws Exception {
|
||||
try (ConfigurableApplicationContext context = new SpringApplicationBuilder(
|
||||
TestChannelBinderConfiguration.getCompleteConfiguration(
|
||||
TaskLauncherSinkTestApplication.class)).web(WebApplicationType.NONE).run(
|
||||
"--spring.jmx.enabled=false")) {
|
||||
TaskConfiguration.TestTaskLauncher testTaskLauncher = launchTaskString(VALID_URL,
|
||||
null, APP_NAME, context);
|
||||
TestChannelBinderConfiguration.getCompleteConfiguration(TaskLauncherSinkTestApplication.class))
|
||||
.web(WebApplicationType.NONE).run("--spring.jmx.enabled=false")) {
|
||||
TaskConfiguration.TestTaskLauncher testTaskLauncher = launchTaskString(VALID_URL, null, APP_NAME, context);
|
||||
verifySuccessWithAppName(testTaskLauncher);
|
||||
|
||||
testTaskLauncher = launchTaskByteArray(VALID_URL, null, APP_NAME, context);
|
||||
@@ -117,11 +111,10 @@ public class TaskLauncherFunctionTests {
|
||||
@Test
|
||||
public void testInvalidJar() throws Exception {
|
||||
try (ConfigurableApplicationContext context = new SpringApplicationBuilder(
|
||||
TestChannelBinderConfiguration.getCompleteConfiguration(
|
||||
TaskLauncherSinkTestApplication.class)).web(WebApplicationType.NONE).run(
|
||||
"--spring.jmx.enabled=false")) {
|
||||
TaskConfiguration.TestTaskLauncher testTaskLauncher = launchTaskTaskLaunchRequest(
|
||||
INVALID_URL, null, APP_NAME, context);
|
||||
TestChannelBinderConfiguration.getCompleteConfiguration(TaskLauncherSinkTestApplication.class))
|
||||
.web(WebApplicationType.NONE).run("--spring.jmx.enabled=false")) {
|
||||
TaskConfiguration.TestTaskLauncher testTaskLauncher = launchTaskTaskLaunchRequest(INVALID_URL, null,
|
||||
APP_NAME, context);
|
||||
verifySuccessWithAppName(testTaskLauncher);
|
||||
}
|
||||
}
|
||||
@@ -129,77 +122,62 @@ public class TaskLauncherFunctionTests {
|
||||
@Test
|
||||
public void testNoRun() {
|
||||
try (ConfigurableApplicationContext context = new SpringApplicationBuilder(
|
||||
TestChannelBinderConfiguration.getCompleteConfiguration(
|
||||
TaskLauncherSinkTestApplication.class)).web(WebApplicationType.NONE).run(
|
||||
"--spring.jmx.enabled=false")) {
|
||||
TestChannelBinderConfiguration.getCompleteConfiguration(TaskLauncherSinkTestApplication.class))
|
||||
.web(WebApplicationType.NONE).run("--spring.jmx.enabled=false")) {
|
||||
TaskConfiguration.TestTaskLauncher testTaskLauncher = context
|
||||
.getBean(TaskConfiguration.TestTaskLauncher.class);
|
||||
assertThat(testTaskLauncher.status(DEFAULT_STATUS).getState())
|
||||
.isEqualTo(LaunchState.unknown);
|
||||
.getBean(TaskConfiguration.TestTaskLauncher.class);
|
||||
assertThat(testTaskLauncher.status(DEFAULT_STATUS).getState()).isEqualTo(LaunchState.unknown);
|
||||
}
|
||||
}
|
||||
|
||||
private void verifySuccessWithAppName(
|
||||
TaskConfiguration.TestTaskLauncher testTaskLauncher) {
|
||||
assertThat(testTaskLauncher.status(DEFAULT_STATUS).getState())
|
||||
.isEqualTo(LaunchState.complete);
|
||||
private void verifySuccessWithAppName(TaskConfiguration.TestTaskLauncher testTaskLauncher) {
|
||||
assertThat(testTaskLauncher.status(DEFAULT_STATUS).getState()).isEqualTo(LaunchState.complete);
|
||||
assertThat(testTaskLauncher.getCommandlineArguments().size()).isEqualTo(0);
|
||||
assertThat(testTaskLauncher.getApplicationName()).isEqualTo(APP_NAME);
|
||||
}
|
||||
|
||||
private String getStringTaskLaunchRequest(String artifactURL,
|
||||
List<String> commandLineArgs, String applicationName) throws Exception {
|
||||
TaskLaunchRequest request = new TaskLaunchRequest(artifactURL, commandLineArgs,
|
||||
this.properties, null, applicationName);
|
||||
private String getStringTaskLaunchRequest(String artifactURL, List<String> commandLineArgs, String applicationName)
|
||||
throws Exception {
|
||||
TaskLaunchRequest request = new TaskLaunchRequest(artifactURL, commandLineArgs, this.properties, null,
|
||||
applicationName);
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
return mapper.writeValueAsString(request);
|
||||
}
|
||||
|
||||
private void verifySuccessWithParams(
|
||||
TaskConfiguration.TestTaskLauncher testTaskLauncher) {
|
||||
assertThat(testTaskLauncher.status(DEFAULT_STATUS).getState())
|
||||
.isEqualTo(LaunchState.complete);
|
||||
private void verifySuccessWithParams(TaskConfiguration.TestTaskLauncher testTaskLauncher) {
|
||||
assertThat(testTaskLauncher.status(DEFAULT_STATUS).getState()).isEqualTo(LaunchState.complete);
|
||||
assertThat(testTaskLauncher.getCommandlineArguments().size()).isEqualTo(2);
|
||||
assertThat(testTaskLauncher.getCommandlineArguments().get(0)).isEqualTo(PARAM1);
|
||||
assertThat(testTaskLauncher.getCommandlineArguments().get(1)).isEqualTo(PARAM2);
|
||||
assertThat(testTaskLauncher.getApplicationName().startsWith(TASK_NAME_PREFIX))
|
||||
.isTrue();
|
||||
assertThat(testTaskLauncher.getApplicationName().startsWith(TASK_NAME_PREFIX)).isTrue();
|
||||
}
|
||||
|
||||
private TaskConfiguration.TestTaskLauncher launchTaskString(String artifactURL,
|
||||
List<String> commandLineArgs, String applicationName,
|
||||
ConfigurableApplicationContext context) throws Exception {
|
||||
TaskConfiguration.TestTaskLauncher testTaskLauncher = context
|
||||
.getBean(TaskConfiguration.TestTaskLauncher.class);
|
||||
String stringRequest = getStringTaskLaunchRequest(artifactURL, commandLineArgs,
|
||||
applicationName);
|
||||
private TaskConfiguration.TestTaskLauncher launchTaskString(String artifactURL, List<String> commandLineArgs,
|
||||
String applicationName, ConfigurableApplicationContext context) throws Exception {
|
||||
TaskConfiguration.TestTaskLauncher testTaskLauncher = context.getBean(TaskConfiguration.TestTaskLauncher.class);
|
||||
String stringRequest = getStringTaskLaunchRequest(artifactURL, commandLineArgs, applicationName);
|
||||
GenericMessage<String> message = new GenericMessage<>(stringRequest);
|
||||
InputDestination source = context.getBean(InputDestination.class);
|
||||
source.send(message);
|
||||
return testTaskLauncher;
|
||||
}
|
||||
|
||||
private TaskConfiguration.TestTaskLauncher launchTaskByteArray(String artifactURL,
|
||||
List<String> commandLineArgs, String applicationName,
|
||||
ConfigurableApplicationContext context) throws Exception {
|
||||
TaskConfiguration.TestTaskLauncher testTaskLauncher = context
|
||||
.getBean(TaskConfiguration.TestTaskLauncher.class);
|
||||
String stringRequest = getStringTaskLaunchRequest(artifactURL, commandLineArgs,
|
||||
applicationName);
|
||||
private TaskConfiguration.TestTaskLauncher launchTaskByteArray(String artifactURL, List<String> commandLineArgs,
|
||||
String applicationName, ConfigurableApplicationContext context) throws Exception {
|
||||
TaskConfiguration.TestTaskLauncher testTaskLauncher = context.getBean(TaskConfiguration.TestTaskLauncher.class);
|
||||
String stringRequest = getStringTaskLaunchRequest(artifactURL, commandLineArgs, applicationName);
|
||||
GenericMessage<byte[]> message = new GenericMessage<>(stringRequest.getBytes());
|
||||
InputDestination source = context.getBean(InputDestination.class);
|
||||
source.send(message);
|
||||
return testTaskLauncher;
|
||||
}
|
||||
|
||||
private TaskConfiguration.TestTaskLauncher launchTaskTaskLaunchRequest(
|
||||
String artifactURL, List<String> commandLineArgs, String applicationName,
|
||||
ConfigurableApplicationContext context)
|
||||
throws Exception {
|
||||
TaskConfiguration.TestTaskLauncher testTaskLauncher = context
|
||||
.getBean(TaskConfiguration.TestTaskLauncher.class);
|
||||
TaskLaunchRequest request = new TaskLaunchRequest(artifactURL, commandLineArgs,
|
||||
this.properties, null, applicationName);
|
||||
private TaskConfiguration.TestTaskLauncher launchTaskTaskLaunchRequest(String artifactURL,
|
||||
List<String> commandLineArgs, String applicationName, ConfigurableApplicationContext context)
|
||||
throws Exception {
|
||||
TaskConfiguration.TestTaskLauncher testTaskLauncher = context.getBean(TaskConfiguration.TestTaskLauncher.class);
|
||||
TaskLaunchRequest request = new TaskLaunchRequest(artifactURL, commandLineArgs, this.properties, null,
|
||||
applicationName);
|
||||
GenericMessage<TaskLaunchRequest> message = new GenericMessage<>(request);
|
||||
InputDestination source = context.getBean(InputDestination.class);
|
||||
source.send(message);
|
||||
@@ -207,7 +185,9 @@ public class TaskLauncherFunctionTests {
|
||||
}
|
||||
|
||||
@SpringBootApplication
|
||||
@Import({TaskLauncherSink.class})
|
||||
@Import({ TaskLauncherSink.class })
|
||||
public static class TaskLauncherSinkTestApplication {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,15 +37,15 @@ public class TaskEventTests {
|
||||
@Test
|
||||
public void testDefaultConfiguration() {
|
||||
ConfigurableApplicationContext applicationContext = new SpringApplicationBuilder()
|
||||
.sources(TestChannelBinderConfiguration
|
||||
.getCompleteConfiguration(TaskEventsApplication.class)).web(WebApplicationType.NONE).build()
|
||||
.run();
|
||||
.sources(TestChannelBinderConfiguration.getCompleteConfiguration(TaskEventsApplication.class))
|
||||
.web(WebApplicationType.NONE).build().run();
|
||||
assertThat(applicationContext.getBean("taskEventEmitter")).isNotNull();
|
||||
}
|
||||
|
||||
@EnableTask
|
||||
@SpringBootApplication
|
||||
public static class TaskEventsApplication {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user