Refactored task end event to be Spring Boot's ApplicationReadyEvent

In testing and other use cases, the ability to keep a context open
beyond the end of a task can be useful.  This change provides the
ability to keep the context alive once a task has completed while also
explicitly shutting the context down (by default) once a task has ended.

Resolves spring-cloud/spring-cloud-task#102
This commit is contained in:
Michael Minella
2016-04-05 11:44:09 -05:00
parent 3d3b90812e
commit 0a56672171
9 changed files with 88 additions and 107 deletions

View File

@@ -44,9 +44,9 @@ public class BatchJobApplicationTests {
final String CREATE_TASK_MESSAGE = "Creating: TaskExecution{executionId=";
final String UPDATE_TASK_MESSAGE = "Updating: TaskExecution with executionId=";
final String JOB_ASSOCIATION_MESSAGE = "The job execution id ";
final String EXIT_CODE_MESSAGE = "with the following {exitCode=0";
assertEquals(0, SpringApplication.exit(SpringApplication
.run(BatchJobApplication.class)));
SpringApplication.run(BatchJobApplication.class);
String output = this.outputCapture.toString();
assertTrue("Unable to find the timestamp: " + output,
@@ -55,6 +55,8 @@ public class BatchJobApplicationTests {
output.contains(CREATE_TASK_MESSAGE));
assertTrue("Test results do not show success message: " + output,
output.contains(UPDATE_TASK_MESSAGE));
assertTrue("Test results do not show success message: " + output,
output.contains(EXIT_CODE_MESSAGE));
int i = output.indexOf(JOB_ASSOCIATION_MESSAGE);

View File

@@ -16,17 +16,18 @@
package org.springframework.cloud.task.timestamp;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.junit.Rule;
import org.junit.Test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.test.OutputCapture;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* Verifies that the Task Application outputs the correct task log entries.
*
@@ -42,10 +43,10 @@ public class TaskApplicationTests {
final String TEST_DATE_DOTS = ".......";
final String CREATE_TASK_MESSAGE = "Creating: TaskExecution{executionId=";
final String UPDATE_TASK_MESSAGE = "Updating: TaskExecution with executionId=";
final String EXIT_CODE_MESSAGE = "with the following {exitCode=0";
String[] args = { "--format=yyyy" + TEST_DATE_DOTS };
assertEquals(0, SpringApplication.exit(SpringApplication
.run(TaskApplication.class, args)));
SpringApplication.run(TaskApplication.class, args);
String output = this.outputCapture.toString();
assertTrue("Unable to find the timestamp: " + output,
@@ -54,6 +55,8 @@ public class TaskApplicationTests {
output.contains(CREATE_TASK_MESSAGE));
assertTrue("Test results do not show success message: " + output,
output.contains(UPDATE_TASK_MESSAGE));
assertTrue("Test results have incorrect exit code: " + output,
output.contains(EXIT_CODE_MESSAGE));
String taskTitle = "Demo Timestamp Task";
Pattern pattern = Pattern.compile(taskTitle);
@@ -62,7 +65,6 @@ public class TaskApplicationTests {
while (matcher.find()) {
count++;
}
assertEquals("The number of task titles did not match expected: ", 3, count);
assertEquals("The number of task titles did not match expected: ", 1, count);
}
}

View File

@@ -14,5 +14,5 @@
# limitations under the License.
#
logging.level.root=DEBUG
logging.level.org.springframework.cloud.task=DEBUG
spring.application.name=Demo Timestamp Task