Introduced Error Message to Task Execution

To provide the ability to control task orchestration via the exit
message, we moved the stack trace storage to a new field.  This means
that exit message is now a field we can use similar to how exit code is
in batch, and still have the stack trace of an unsuccessful task
execution stored.

Resolves spring-cloud/spring-cloud-task#186

Disabled integration tests by default

Just some cleanup on merge
This commit is contained in:
Michael Minella
2016-08-11 14:25:10 -05:00
committed by Glenn Renfro
parent 551a4bc53a
commit db0565b7cf
28 changed files with 225 additions and 64 deletions

View File

@@ -28,8 +28,8 @@ public class TaskCoreTests {
private static final String UPDATE_TASK_MESSAGE = "Updating: TaskExecution with executionId=";
private static final String SUCCESS_EXIT_CODE_MESSAGE = "with the following {exitCode=0";
private static final String EXCEPTION_EXIT_CODE_MESSAGE = "with the following {exitCode=1";
private static final String EXIT_MESSAGE =
"exitMessage='java.lang.IllegalStateException: Failed to execute CommandLineRunner";
private static final String ERROR_MESSAGE =
"errorMessage='java.lang.IllegalStateException: Failed to execute CommandLineRunner";
private ConfigurableApplicationContext applicationContext;
@@ -83,7 +83,7 @@ public class TaskCoreTests {
assertTrue("Test results have incorrect exit code: " + output,
output.contains(EXCEPTION_EXIT_CODE_MESSAGE));
assertTrue("Test results have incorrect exit message: " + output,
output.contains(EXIT_MESSAGE));
output.contains(ERROR_MESSAGE));
assertTrue("Test results have exception message: " + output,
output.contains(EXCEPTION_MESSAGE));
}

View File

@@ -71,7 +71,7 @@ public class TaskExecutionListenerTests {
DefaultTaskListenerConfiguration.TestTaskExecutionListener taskExecutionListener =
context.getBean(DefaultTaskListenerConfiguration.TestTaskExecutionListener.class);
TaskExecution taskExecution = new TaskExecution(0, null, "wombat",
new Date(), new Date(), null, new ArrayList<String>());
new Date(), new Date(), null, new ArrayList<String>(), null);
verifyListenerResults(true, false, false, taskExecution,taskExecutionListener);
}
@@ -87,7 +87,7 @@ public class TaskExecutionListenerTests {
context.publishEvent(new ApplicationReadyEvent(new SpringApplication(), new String[0], context));
TaskExecution taskExecution = new TaskExecution(0, 0, "wombat",
new Date(), new Date(), null, new ArrayList<String>());
new Date(), new Date(), null, new ArrayList<String>(), null);
verifyListenerResults(true, true, false, taskExecution,taskExecutionListener);
}
@@ -106,7 +106,7 @@ public class TaskExecutionListenerTests {
context.publishEvent(new ApplicationReadyEvent(application, new String[0], context));
TaskExecution taskExecution = new TaskExecution(0, 1, "wombat", new Date(),
new Date(), null, new ArrayList<String>());
new Date(), null, new ArrayList<String>(), null);
verifyListenerResults(true, true, true, taskExecution,taskExecutionListener);
}
@@ -120,7 +120,7 @@ public class TaskExecutionListenerTests {
DefaultAnnotationConfiguration.AnnotatedTaskListener annotatedListener =
context.getBean(DefaultAnnotationConfiguration.AnnotatedTaskListener.class);
TaskExecution taskExecution = new TaskExecution(0, null, "wombat",
new Date(), new Date(), null, new ArrayList<String>());
new Date(), new Date(), null, new ArrayList<String>(), null);
verifyListenerResults(true, false, false, taskExecution,annotatedListener);
}
@@ -136,7 +136,7 @@ public class TaskExecutionListenerTests {
context.publishEvent(new ApplicationReadyEvent(new SpringApplication(), new String[0], context));
TaskExecution taskExecution = new TaskExecution(0, 0, "wombat",
new Date(), new Date(), null, new ArrayList<String>());
new Date(), new Date(), null, new ArrayList<String>(), null);
verifyListenerResults(true, true, false, taskExecution,annotatedListener);
}
@@ -155,7 +155,7 @@ public class TaskExecutionListenerTests {
context.publishEvent(new ApplicationReadyEvent(application, new String[0], context));
TaskExecution taskExecution = new TaskExecution(0, 1, "wombat", new Date(),
new Date(), null, new ArrayList<String>());
new Date(), null, new ArrayList<String>(), null);
verifyListenerResults(true, true, true, taskExecution,annotatedListener);
}
@@ -169,13 +169,16 @@ public class TaskExecutionListenerTests {
assertEquals(TestListener.END_MESSAGE, actualListener.getTaskExecution().getExitMessage());
assertNotNull(actualListener.getThrowable());
assertTrue(actualListener.getThrowable() instanceof RuntimeException);
assertTrue(actualListener.getTaskExecution().getErrorMessage().startsWith("java.lang.RuntimeException: This was expected"));
}
else if(isTaskEnd){
assertEquals(TestListener.END_MESSAGE, actualListener.getTaskExecution().getExitMessage());
assertNull(actualListener.getTaskExecution().getErrorMessage());
assertNull(actualListener.getThrowable());
}
else {
assertEquals(TestListener.START_MESSAGE, actualListener.getTaskExecution().getExitMessage());
assertNull(actualListener.getTaskExecution().getErrorMessage());
assertNull(actualListener.getThrowable());
}

View File

@@ -139,7 +139,7 @@ public class TaskLifecycleListenerTests {
assertEquals(exitCode, taskExecution.getExitCode());
if(exception != null) {
assertTrue(taskExecution.getExitMessage().length() > exception.getStackTrace().length);
assertTrue(taskExecution.getErrorMessage().length() > exception.getStackTrace().length);
}
else {
assertNull(taskExecution.getExitMessage());

View File

@@ -16,18 +16,19 @@
package org.springframework.cloud.task.repository.database.support;
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
import java.util.Collection;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.springframework.cloud.task.util.TestDBUtils;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import static org.junit.Assert.assertEquals;
/**
* @author Glenn Renfro
*/
@@ -42,30 +43,30 @@ public class FindAllPagingQueryProviderTests {
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][]{
{"Oracle", "SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, TASK_NAME, "
+ "EXIT_CODE, EXIT_MESSAGE, LAST_UPDATED FROM "
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED FROM "
+ "(SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, TASK_NAME, "
+ "EXIT_CODE, EXIT_MESSAGE, LAST_UPDATED, ROWNUM as "
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, ROWNUM as "
+ "TMP_ROW_NUM FROM (SELECT TASK_EXECUTION_ID, START_TIME, "
+ "END_TIME, TASK_NAME, EXIT_CODE, EXIT_MESSAGE, LAST_UPDATED "
+ "END_TIME, TASK_NAME, EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED "
+ "FROM %PREFIX%EXECUTION ORDER BY START_TIME DESC, "
+ "TASK_EXECUTION_ID DESC)) WHERE TMP_ROW_NUM >= 1 AND "
+ "TMP_ROW_NUM < 11"},
{"HSQL Database Engine","SELECT LIMIT 0 10 TASK_EXECUTION_ID, "
+ "START_TIME, END_TIME, TASK_NAME, EXIT_CODE, EXIT_MESSAGE, "
+ "LAST_UPDATED FROM %PREFIX%EXECUTION ORDER BY "
+ "ERROR_MESSAGE, LAST_UPDATED FROM %PREFIX%EXECUTION ORDER BY "
+ "START_TIME DESC, TASK_EXECUTION_ID DESC"},
{"PostgreSQL","SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, "
+ "TASK_NAME, EXIT_CODE, EXIT_MESSAGE, LAST_UPDATED "
+ "TASK_NAME, EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED "
+ "FROM %PREFIX%EXECUTION ORDER BY START_TIME DESC, "
+ "TASK_EXECUTION_ID DESC LIMIT 10 OFFSET 0"},
{"MySQL","SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, TASK_NAME, "
+ "EXIT_CODE, EXIT_MESSAGE, LAST_UPDATED FROM "
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED FROM "
+ "%PREFIX%EXECUTION ORDER BY START_TIME DESC, "
+ "TASK_EXECUTION_ID DESC LIMIT 0, 10"},
{"Microsoft SQL Server","SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, "
+ "TASK_NAME, EXIT_CODE, EXIT_MESSAGE, LAST_UPDATED FROM "
+ "TASK_NAME, EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED FROM "
+ "(SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, TASK_NAME, "
+ "EXIT_CODE, EXIT_MESSAGE, LAST_UPDATED, ROW_NUMBER() "
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, ROW_NUMBER() "
+ "OVER (ORDER BY START_TIME DESC, TASK_EXECUTION_ID DESC) AS "
+ "TMP_ROW_NUM FROM %PREFIX%EXECUTION) TASK_EXECUTION_PAGE "
+ "WHERE TMP_ROW_NUM >= 1 AND TMP_ROW_NUM < 11 ORDER BY START_TIME DESC, "

View File

@@ -16,19 +16,20 @@
package org.springframework.cloud.task.repository.database.support;
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
import java.util.Collection;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.springframework.cloud.task.repository.database.PagingQueryProvider;
import org.springframework.cloud.task.util.TestDBUtils;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import static org.junit.Assert.assertEquals;
/**
* @author Glenn Renfro
*/
@@ -43,34 +44,34 @@ public class WhereClausePagingQueryProviderTests {
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][]{
{"Oracle", "SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, TASK_NAME, "
+ "EXIT_CODE, EXIT_MESSAGE, LAST_UPDATED FROM "
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED FROM "
+ "(SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, TASK_NAME, "
+ "EXIT_CODE, EXIT_MESSAGE, LAST_UPDATED, ROWNUM as "
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, ROWNUM as "
+ "TMP_ROW_NUM FROM (SELECT TASK_EXECUTION_ID, START_TIME, "
+ "END_TIME, TASK_NAME, EXIT_CODE, EXIT_MESSAGE, LAST_UPDATED "
+ "FROM %PREFIX%EXECUTION "
+ "END_TIME, TASK_NAME, EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, "
+ "LAST_UPDATED FROM %PREFIX%EXECUTION "
+ "WHERE TASK_EXECUTION_ID = '0000' ORDER BY START_TIME DESC, "
+ "TASK_EXECUTION_ID DESC)) WHERE TMP_ROW_NUM >= 1 AND "
+ "TMP_ROW_NUM < 11"},
{"HSQL Database Engine","SELECT LIMIT 0 10 TASK_EXECUTION_ID, "
+ "START_TIME, END_TIME, TASK_NAME, EXIT_CODE, EXIT_MESSAGE, "
+ "LAST_UPDATED FROM %PREFIX%EXECUTION "
+ "ERROR_MESSAGE, LAST_UPDATED FROM %PREFIX%EXECUTION "
+ "WHERE TASK_EXECUTION_ID = '0000' ORDER BY "
+ "START_TIME DESC, TASK_EXECUTION_ID DESC"},
{"PostgreSQL","SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, "
+ "TASK_NAME, EXIT_CODE, EXIT_MESSAGE, LAST_UPDATED "
+ "TASK_NAME, EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED "
+ "FROM %PREFIX%EXECUTION WHERE TASK_EXECUTION_ID = '0000' "
+ "ORDER BY START_TIME DESC, "
+ "TASK_EXECUTION_ID DESC LIMIT 10 OFFSET 0"},
{"MySQL","SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, TASK_NAME, "
+ "EXIT_CODE, EXIT_MESSAGE, LAST_UPDATED FROM "
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED FROM "
+ "%PREFIX%EXECUTION WHERE TASK_EXECUTION_ID = '0000' "
+ "ORDER BY START_TIME DESC, "
+ "TASK_EXECUTION_ID DESC LIMIT 0, 10"},
{"Microsoft SQL Server","SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, "
+ "TASK_NAME, EXIT_CODE, EXIT_MESSAGE, LAST_UPDATED FROM "
+ "TASK_NAME, EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED FROM "
+ "(SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, TASK_NAME, "
+ "EXIT_CODE, EXIT_MESSAGE, LAST_UPDATED, ROW_NUMBER() "
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, ROW_NUMBER() "
+ "OVER (ORDER BY START_TIME DESC, TASK_EXECUTION_ID DESC) AS "
+ "TMP_ROW_NUM FROM %PREFIX%EXECUTION WHERE TASK_EXECUTION_ID = "
+ "'0000') TASK_EXECUTION_PAGE WHERE TMP_ROW_NUM >= 1 "

View File

@@ -70,6 +70,6 @@ public class TaskExecutionCreator {
TaskExecution expectedTaskExecution) {
return taskRepository.completeTaskExecution(expectedTaskExecution.getExecutionId(),
expectedTaskExecution.getExitCode(), expectedTaskExecution.getEndTime(),
expectedTaskExecution.getExitMessage());
expectedTaskExecution.getExitMessage(), expectedTaskExecution.getErrorMessage());
}
}

View File

@@ -73,7 +73,8 @@ public class TestDBUtils {
rs.getTimestamp("START_TIME"),
rs.getTimestamp("END_TIME"),
rs.getString("EXIT_MESSAGE"),
new ArrayList<String>(0));
new ArrayList<String>(0),
rs.getString("ERROR_MESSAGE"));
return taskExecution;
}
});

View File

@@ -90,7 +90,7 @@ public class TestVerifierUtils {
String taskName = UUID.randomUUID().toString();
return new TaskExecution(executionId, 0, taskName,
startTime, null, null, new ArrayList<String>());
startTime, null, null, new ArrayList<String>(), null);
}
/**
@@ -108,7 +108,7 @@ public class TestVerifierUtils {
String exitMessage = UUID.randomUUID().toString();
return new TaskExecution(executionId, exitCode, taskName,
startTime, endTime, exitMessage, new ArrayList<String>());
startTime, endTime, exitMessage, new ArrayList<String>(), null);
}
/**
@@ -117,7 +117,6 @@ public class TestVerifierUtils {
* @return
*/
public static TaskExecution createSampleTaskExecution(long executionId) {
Random randomGenerator = new Random();
Date startTime = new Date();
String taskName = UUID.randomUUID().toString();
List<String> args = new ArrayList<>(ARG_SIZE);
@@ -125,7 +124,7 @@ public class TestVerifierUtils {
args.add(UUID.randomUUID().toString());
}
return new TaskExecution(executionId, null, taskName,
startTime, null, null, args);
startTime, null, null, args, null);
}
/**
@@ -153,6 +152,9 @@ public class TestVerifierUtils {
assertEquals("exitMessage must be equal",
expectedTaskExecution.getExitMessage(),
actualTaskExecution.getExitMessage());
assertEquals("errorMessage must be equal",
expectedTaskExecution.getErrorMessage(),
actualTaskExecution.getErrorMessage());
if (expectedTaskExecution.getArguments() != null) {
assertNotNull("arguments should not be null",
actualTaskExecution.getArguments());