Updated to files to fit the Standard.
This commit is contained in:
@@ -40,19 +40,15 @@ public class SimpleSingleTaskAutoConfigurationTests {
|
||||
public void testConfiguration() {
|
||||
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
|
||||
.withPropertyValues("spring.cloud.task.singleInstanceEnabled=true");
|
||||
applicationContextRunner.run((context) -> {
|
||||
SingleInstanceTaskListener singleInstanceTaskListener = context
|
||||
.getBean(SingleInstanceTaskListener.class);
|
||||
SingleInstanceTaskListener singleInstanceTaskListener = context.getBean(SingleInstanceTaskListener.class);
|
||||
|
||||
assertThat(singleInstanceTaskListener)
|
||||
.as("singleInstanceTaskListener should not be null").isNotNull();
|
||||
assertThat(singleInstanceTaskListener).as("singleInstanceTaskListener should not be null").isNotNull();
|
||||
|
||||
assertThat(SingleInstanceTaskListener.class)
|
||||
.isEqualTo(singleInstanceTaskListener.getClass());
|
||||
assertThat(SingleInstanceTaskListener.class).isEqualTo(singleInstanceTaskListener.getClass());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -41,20 +41,16 @@ public class SimpleSingleTaskAutoConfigurationWithDataSourceTests {
|
||||
public void testConfiguration() {
|
||||
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class,
|
||||
EmbeddedDataSourceConfiguration.class))
|
||||
.withPropertyValues("spring.cloud.task.singleInstanceEnabled=true");
|
||||
applicationContextRunner.run((context) -> {
|
||||
SingleInstanceTaskListener singleInstanceTaskListener = context
|
||||
.getBean(SingleInstanceTaskListener.class);
|
||||
SingleInstanceTaskListener singleInstanceTaskListener = context.getBean(SingleInstanceTaskListener.class);
|
||||
|
||||
assertThat(singleInstanceTaskListener)
|
||||
.as("singleInstanceTaskListener should not be null").isNotNull();
|
||||
assertThat(singleInstanceTaskListener).as("singleInstanceTaskListener should not be null").isNotNull();
|
||||
|
||||
assertThat(SingleInstanceTaskListener.class)
|
||||
.isEqualTo(singleInstanceTaskListener.getClass());
|
||||
assertThat(SingleInstanceTaskListener.class).isEqualTo(singleInstanceTaskListener.getClass());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -62,10 +62,8 @@ public class SimpleTaskAutoConfigurationTests {
|
||||
@Test
|
||||
public void testRepository() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class,
|
||||
SingleTaskConfiguration.class));
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class));
|
||||
applicationContextRunner.run((context) -> {
|
||||
|
||||
TaskRepository taskRepository = context.getBean(TaskRepository.class);
|
||||
@@ -78,8 +76,7 @@ public class SimpleTaskAutoConfigurationTests {
|
||||
@Test
|
||||
public void testAutoConfigurationDisabled() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
|
||||
.withPropertyValues("spring.cloud.task.autoconfiguration.enabled=false");
|
||||
Executable executable = () -> {
|
||||
@@ -87,17 +84,16 @@ public class SimpleTaskAutoConfigurationTests {
|
||||
context.getBean(TaskRepository.class);
|
||||
});
|
||||
};
|
||||
verifyExceptionThrown(NoSuchBeanDefinitionException.class, "No qualifying "
|
||||
+ "bean of type 'org.springframework.cloud.task.repository.TaskRepository' "
|
||||
+ "available", executable);
|
||||
verifyExceptionThrown(
|
||||
NoSuchBeanDefinitionException.class, "No qualifying "
|
||||
+ "bean of type 'org.springframework.cloud.task.repository.TaskRepository' " + "available",
|
||||
executable);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRepositoryInitialized() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
EmbeddedDataSourceConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner().withConfiguration(
|
||||
AutoConfigurations.of(EmbeddedDataSourceConfiguration.class, PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
|
||||
.withUserConfiguration(TaskLifecycleListenerConfiguration.class);
|
||||
applicationContextRunner.run((context) -> {
|
||||
@@ -108,14 +104,12 @@ public class SimpleTaskAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void testRepositoryInitializedWithLazyInitialization() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withInitializer((context) -> context
|
||||
.addBeanFactoryPostProcessor(new LazyInitializationBeanFactoryPostProcessor()))
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
EmbeddedDataSourceConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
|
||||
.withUserConfiguration(TaskLifecycleListenerConfiguration.class);
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner().withInitializer(
|
||||
(context) -> context.addBeanFactoryPostProcessor(new LazyInitializationBeanFactoryPostProcessor()))
|
||||
.withConfiguration(AutoConfigurations.of(EmbeddedDataSourceConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class, SimpleTaskAutoConfiguration.class,
|
||||
SingleTaskConfiguration.class))
|
||||
.withUserConfiguration(TaskLifecycleListenerConfiguration.class);
|
||||
applicationContextRunner.run((context) -> {
|
||||
TaskExplorer taskExplorer = context.getBean(TaskExplorer.class);
|
||||
assertThat(taskExplorer.getTaskExecutionCount()).isEqualTo(1L);
|
||||
@@ -125,47 +119,42 @@ public class SimpleTaskAutoConfigurationTests {
|
||||
@Test
|
||||
public void testRepositoryNotInitialized() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
EmbeddedDataSourceConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
|
||||
.withConfiguration(AutoConfigurations.of(EmbeddedDataSourceConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class, SimpleTaskAutoConfiguration.class,
|
||||
SingleTaskConfiguration.class))
|
||||
.withUserConfiguration(TaskLifecycleListenerConfiguration.class)
|
||||
.withPropertyValues("spring.cloud.task.tablePrefix=foobarless");
|
||||
|
||||
verifyExceptionThrownDefaultExecutable(ApplicationContextException.class,
|
||||
applicationContextRunner);
|
||||
verifyExceptionThrownDefaultExecutable(ApplicationContextException.class, applicationContextRunner);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleConfigurers() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
|
||||
.withUserConfiguration(MultipleConfigurers.class);
|
||||
|
||||
verifyExceptionThrownDefaultExecutable(BeanCreationException.class,
|
||||
"Error creating bean "
|
||||
+ "with name 'simpleTaskAutoConfiguration': Invocation of init method failed",
|
||||
"Error creating bean " + "with name 'simpleTaskAutoConfiguration': Invocation of init method failed",
|
||||
applicationContextRunner);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleDataSources() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
|
||||
.withUserConfiguration(MultipleDataSources.class);
|
||||
|
||||
verifyExceptionThrownDefaultExecutable(BeanCreationException.class,
|
||||
"Error creating bean "
|
||||
+ "with name 'simpleTaskAutoConfiguration': Invocation of init method failed",
|
||||
"Error creating bean " + "with name 'simpleTaskAutoConfiguration': Invocation of init method failed",
|
||||
applicationContextRunner);
|
||||
|
||||
}
|
||||
|
||||
public void verifyExceptionThrownDefaultExecutable(Class classToCheck, ApplicationContextRunner applicationContextRunner) {
|
||||
public void verifyExceptionThrownDefaultExecutable(Class classToCheck,
|
||||
ApplicationContextRunner applicationContextRunner) {
|
||||
Executable executable = () -> {
|
||||
applicationContextRunner.run((context) -> {
|
||||
Throwable expectedException = context.getStartupFailure();
|
||||
@@ -188,10 +177,8 @@ public class SimpleTaskAutoConfigurationTests {
|
||||
verifyExceptionThrown(classToCheck, message, executable);
|
||||
}
|
||||
|
||||
public void verifyExceptionThrown(Class classToCheck, String message,
|
||||
Executable executable) {
|
||||
assertThatExceptionOfType(classToCheck).isThrownBy(executable::execute)
|
||||
.withMessage(message);
|
||||
public void verifyExceptionThrown(Class classToCheck, String message, Executable executable) {
|
||||
assertThatExceptionOfType(classToCheck).isThrownBy(executable::execute).withMessage(message);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -200,16 +187,13 @@ public class SimpleTaskAutoConfigurationTests {
|
||||
*/
|
||||
@Test
|
||||
public void testWithDataSourceProxy() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
EmbeddedDataSourceConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner().withConfiguration(
|
||||
AutoConfigurations.of(EmbeddedDataSourceConfiguration.class, PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
|
||||
.withUserConfiguration(DataSourceProxyConfiguration.class);
|
||||
applicationContextRunner.run((context) -> {
|
||||
assertThat(context.getBeanNamesForType(DataSource.class).length).isEqualTo(2);
|
||||
SimpleTaskAutoConfiguration taskConfiguration = context
|
||||
.getBean(SimpleTaskAutoConfiguration.class);
|
||||
SimpleTaskAutoConfiguration taskConfiguration = context.getBean(SimpleTaskAutoConfiguration.class);
|
||||
assertThat(taskConfiguration).isNotNull();
|
||||
assertThat(taskConfiguration.taskExplorer()).isNotNull();
|
||||
});
|
||||
@@ -255,10 +239,9 @@ public class SimpleTaskAutoConfigurationTests {
|
||||
public BeanDefinitionHolder proxyDataSource() {
|
||||
GenericBeanDefinition proxyBeanDefinition = new GenericBeanDefinition();
|
||||
proxyBeanDefinition.setBeanClassName("javax.sql.DataSource");
|
||||
BeanDefinitionHolder myDataSource = new BeanDefinitionHolder(
|
||||
proxyBeanDefinition, "dataSource2");
|
||||
ScopedProxyUtils.createScopedProxy(myDataSource,
|
||||
(BeanDefinitionRegistry) this.context.getBeanFactory(), true);
|
||||
BeanDefinitionHolder myDataSource = new BeanDefinitionHolder(proxyBeanDefinition, "dataSource2");
|
||||
ScopedProxyUtils.createScopedProxy(myDataSource, (BeanDefinitionRegistry) this.context.getBeanFactory(),
|
||||
true);
|
||||
return myDataSource;
|
||||
}
|
||||
|
||||
|
||||
@@ -72,17 +72,16 @@ public class TaskCoreTests {
|
||||
@Test
|
||||
public void successfulTaskTest(CapturedOutput capturedOutput) {
|
||||
this.applicationContext = SpringApplication.run(TaskConfiguration.class,
|
||||
"--spring.cloud.task.closecontext.enable=false",
|
||||
"--spring.cloud.task.name=" + TASK_NAME,
|
||||
"--spring.cloud.task.closecontext.enable=false", "--spring.cloud.task.name=" + TASK_NAME,
|
||||
"--spring.main.web-environment=false");
|
||||
|
||||
String output = capturedOutput.toString();
|
||||
assertThat(output.contains(CREATE_TASK_MESSAGE))
|
||||
.as("Test results do not show create task message: " + output).isTrue();
|
||||
assertThat(output.contains(UPDATE_TASK_MESSAGE))
|
||||
.as("Test results do not show success message: " + output).isTrue();
|
||||
assertThat(output.contains(SUCCESS_EXIT_CODE_MESSAGE))
|
||||
.as("Test results have incorrect exit code: " + output).isTrue();
|
||||
assertThat(output.contains(CREATE_TASK_MESSAGE)).as("Test results do not show create task message: " + output)
|
||||
.isTrue();
|
||||
assertThat(output.contains(UPDATE_TASK_MESSAGE)).as("Test results do not show success message: " + output)
|
||||
.isTrue();
|
||||
assertThat(output.contains(SUCCESS_EXIT_CODE_MESSAGE)).as("Test results have incorrect exit code: " + output)
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,76 +89,63 @@ public class TaskCoreTests {
|
||||
*/
|
||||
@Test
|
||||
public void successfulTaskTestWithAnnotation(CapturedOutput capturedOutput) {
|
||||
this.applicationContext = SpringApplication.run(
|
||||
TaskConfigurationWithAnotation.class,
|
||||
"--spring.cloud.task.closecontext.enable=false",
|
||||
"--spring.cloud.task.name=" + TASK_NAME,
|
||||
this.applicationContext = SpringApplication.run(TaskConfigurationWithAnotation.class,
|
||||
"--spring.cloud.task.closecontext.enable=false", "--spring.cloud.task.name=" + TASK_NAME,
|
||||
"--spring.main.web-environment=false");
|
||||
|
||||
String output = capturedOutput.toString();
|
||||
assertThat(output.contains(CREATE_TASK_MESSAGE))
|
||||
.as("Test results do not show create task message: " + output).isTrue();
|
||||
assertThat(output.contains(UPDATE_TASK_MESSAGE))
|
||||
.as("Test results do not show success message: " + output).isTrue();
|
||||
assertThat(output.contains(SUCCESS_EXIT_CODE_MESSAGE))
|
||||
.as("Test results have incorrect exit code: " + output).isTrue();
|
||||
assertThat(output.contains(CREATE_TASK_MESSAGE)).as("Test results do not show create task message: " + output)
|
||||
.isTrue();
|
||||
assertThat(output.contains(UPDATE_TASK_MESSAGE)).as("Test results do not show success message: " + output)
|
||||
.isTrue();
|
||||
assertThat(output.contains(SUCCESS_EXIT_CODE_MESSAGE)).as("Test results have incorrect exit code: " + output)
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exceptionTaskTest(CapturedOutput capturedOutput) {
|
||||
boolean exceptionFired = false;
|
||||
try {
|
||||
this.applicationContext = SpringApplication.run(
|
||||
TaskExceptionConfiguration.class,
|
||||
"--spring.cloud.task.closecontext.enable=false",
|
||||
"--spring.cloud.task.name=" + TASK_NAME,
|
||||
this.applicationContext = SpringApplication.run(TaskExceptionConfiguration.class,
|
||||
"--spring.cloud.task.closecontext.enable=false", "--spring.cloud.task.name=" + TASK_NAME,
|
||||
"--spring.main.web-environment=false");
|
||||
}
|
||||
catch (IllegalStateException exception) {
|
||||
exceptionFired = true;
|
||||
}
|
||||
assertThat(exceptionFired).as("An IllegalStateException should have been thrown")
|
||||
.isTrue();
|
||||
assertThat(exceptionFired).as("An IllegalStateException should have been thrown").isTrue();
|
||||
|
||||
String output = capturedOutput.toString();
|
||||
assertThat(output.contains(CREATE_TASK_MESSAGE))
|
||||
.as("Test results do not show create task message: " + output).isTrue();
|
||||
assertThat(output.contains(UPDATE_TASK_MESSAGE))
|
||||
.as("Test results do not show success message: " + output).isTrue();
|
||||
assertThat(output.contains(EXCEPTION_EXIT_CODE_MESSAGE))
|
||||
.as("Test results have incorrect exit code: " + output).isTrue();
|
||||
assertThat(output.contains(ERROR_MESSAGE))
|
||||
.as("Test results have incorrect exit message: " + output).isTrue();
|
||||
assertThat(output.contains(EXCEPTION_MESSAGE))
|
||||
.as("Test results have exception message: " + output).isTrue();
|
||||
assertThat(output.contains(CREATE_TASK_MESSAGE)).as("Test results do not show create task message: " + output)
|
||||
.isTrue();
|
||||
assertThat(output.contains(UPDATE_TASK_MESSAGE)).as("Test results do not show success message: " + output)
|
||||
.isTrue();
|
||||
assertThat(output.contains(EXCEPTION_EXIT_CODE_MESSAGE)).as("Test results have incorrect exit code: " + output)
|
||||
.isTrue();
|
||||
assertThat(output.contains(ERROR_MESSAGE)).as("Test results have incorrect exit message: " + output).isTrue();
|
||||
assertThat(output.contains(EXCEPTION_MESSAGE)).as("Test results have exception message: " + output).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invalidExecutionId(CapturedOutput capturedOutput) {
|
||||
boolean exceptionFired = false;
|
||||
try {
|
||||
this.applicationContext = SpringApplication.run(
|
||||
TaskExceptionConfiguration.class,
|
||||
"--spring.cloud.task.closecontext.enable=false",
|
||||
"--spring.cloud.task.name=" + TASK_NAME,
|
||||
"--spring.main.web-environment=false",
|
||||
"--spring.cloud.task.executionid=55");
|
||||
this.applicationContext = SpringApplication.run(TaskExceptionConfiguration.class,
|
||||
"--spring.cloud.task.closecontext.enable=false", "--spring.cloud.task.name=" + TASK_NAME,
|
||||
"--spring.main.web-environment=false", "--spring.cloud.task.executionid=55");
|
||||
}
|
||||
catch (ApplicationContextException exception) {
|
||||
exceptionFired = true;
|
||||
}
|
||||
assertThat(exceptionFired)
|
||||
.as("An ApplicationContextException should have been thrown").isTrue();
|
||||
assertThat(exceptionFired).as("An ApplicationContextException should have been thrown").isTrue();
|
||||
|
||||
String output = capturedOutput.toString();
|
||||
assertThat(output.contains(EXCEPTION_INVALID_TASK_EXECUTION_ID))
|
||||
.as("Test results do not show the correct exception message: " + output)
|
||||
.isTrue();
|
||||
.as("Test results do not show the correct exception message: " + output).isTrue();
|
||||
}
|
||||
|
||||
@EnableTask
|
||||
@ImportAutoConfiguration({ SimpleTaskAutoConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class })
|
||||
@ImportAutoConfiguration({ SimpleTaskAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class })
|
||||
public static class TaskConfiguration {
|
||||
|
||||
@Bean
|
||||
@@ -174,8 +160,7 @@ public class TaskCoreTests {
|
||||
}
|
||||
|
||||
@EnableTask
|
||||
@ImportAutoConfiguration({ SimpleTaskAutoConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class })
|
||||
@ImportAutoConfiguration({ SimpleTaskAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class })
|
||||
public static class TaskConfigurationWithAnotation {
|
||||
|
||||
@Bean
|
||||
@@ -190,8 +175,7 @@ public class TaskCoreTests {
|
||||
}
|
||||
|
||||
@EnableTask
|
||||
@ImportAutoConfiguration({ SimpleTaskAutoConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class })
|
||||
@ImportAutoConfiguration({ SimpleTaskAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class })
|
||||
public static class TaskExceptionConfiguration {
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -43,8 +43,7 @@ import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(classes = { SimpleTaskAutoConfiguration.class,
|
||||
EmbeddedDataSourceConfiguration.class })
|
||||
@ContextConfiguration(classes = { SimpleTaskAutoConfiguration.class, EmbeddedDataSourceConfiguration.class })
|
||||
@DirtiesContext
|
||||
public class TaskRepositoryInitializerDefaultTaskConfigurerTests {
|
||||
|
||||
|
||||
@@ -44,9 +44,8 @@ import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(
|
||||
classes = { SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class,
|
||||
EmbeddedDataSourceConfiguration.class, DefaultTaskConfigurer.class })
|
||||
@ContextConfiguration(classes = { SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class,
|
||||
EmbeddedDataSourceConfiguration.class, DefaultTaskConfigurer.class })
|
||||
public class TaskRepositoryInitializerNoDataSourceTaskConfigurerTests {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -51,48 +51,39 @@ public class DefaultTaskConfigurerTests {
|
||||
public void resourcelessTransactionManagerTest() {
|
||||
DefaultTaskConfigurer defaultTaskConfigurer = new DefaultTaskConfigurer();
|
||||
assertThat(defaultTaskConfigurer.getTransactionManager().getClass().getName())
|
||||
.isEqualTo(
|
||||
"org.springframework.batch.support.transaction.ResourcelessTransactionManager");
|
||||
.isEqualTo("org.springframework.batch.support.transaction.ResourcelessTransactionManager");
|
||||
defaultTaskConfigurer = new DefaultTaskConfigurer("foo");
|
||||
assertThat(defaultTaskConfigurer.getTransactionManager().getClass().getName())
|
||||
.isEqualTo(
|
||||
"org.springframework.batch.support.transaction.ResourcelessTransactionManager");
|
||||
.isEqualTo("org.springframework.batch.support.transaction.ResourcelessTransactionManager");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultContext() throws Exception {
|
||||
AnnotationConfigApplicationContext localContext = new AnnotationConfigApplicationContext();
|
||||
localContext.register(EmbeddedDataSourceConfiguration.class,
|
||||
EntityManagerConfiguration.class);
|
||||
localContext.register(EmbeddedDataSourceConfiguration.class, EntityManagerConfiguration.class);
|
||||
localContext.refresh();
|
||||
DefaultTaskConfigurer defaultTaskConfigurer = new DefaultTaskConfigurer(
|
||||
this.dataSource, TaskProperties.DEFAULT_TABLE_PREFIX, localContext);
|
||||
DefaultTaskConfigurer defaultTaskConfigurer = new DefaultTaskConfigurer(this.dataSource,
|
||||
TaskProperties.DEFAULT_TABLE_PREFIX, localContext);
|
||||
assertThat(defaultTaskConfigurer.getTransactionManager().getClass().getName())
|
||||
.isEqualTo("org.springframework.jdbc.datasource.DataSourceTransactionManager");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dataSourceTransactionManagerTest() {
|
||||
DefaultTaskConfigurer defaultTaskConfigurer = new DefaultTaskConfigurer(
|
||||
this.dataSource);
|
||||
DefaultTaskConfigurer defaultTaskConfigurer = new DefaultTaskConfigurer(this.dataSource);
|
||||
assertThat(defaultTaskConfigurer.getTransactionManager().getClass().getName())
|
||||
.isEqualTo(
|
||||
"org.springframework.jdbc.datasource.DataSourceTransactionManager");
|
||||
.isEqualTo("org.springframework.jdbc.datasource.DataSourceTransactionManager");
|
||||
defaultTaskConfigurer = new DefaultTaskConfigurer(this.dataSource, "FOO", null);
|
||||
assertThat(defaultTaskConfigurer.getTransactionManager().getClass().getName())
|
||||
.isEqualTo(
|
||||
"org.springframework.jdbc.datasource.DataSourceTransactionManager");
|
||||
defaultTaskConfigurer = new DefaultTaskConfigurer(this.dataSource, "FOO",
|
||||
this.context);
|
||||
.isEqualTo("org.springframework.jdbc.datasource.DataSourceTransactionManager");
|
||||
defaultTaskConfigurer = new DefaultTaskConfigurer(this.dataSource, "FOO", this.context);
|
||||
assertThat(defaultTaskConfigurer.getTransactionManager().getClass().getName())
|
||||
.isEqualTo(
|
||||
"org.springframework.jdbc.datasource.DataSourceTransactionManager");
|
||||
.isEqualTo("org.springframework.jdbc.datasource.DataSourceTransactionManager");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void taskExplorerTest() {
|
||||
DefaultTaskConfigurer defaultTaskConfigurer = new DefaultTaskConfigurer(
|
||||
this.dataSource);
|
||||
DefaultTaskConfigurer defaultTaskConfigurer = new DefaultTaskConfigurer(this.dataSource);
|
||||
assertThat(defaultTaskConfigurer.getTaskExplorer()).isNotNull();
|
||||
defaultTaskConfigurer = new DefaultTaskConfigurer();
|
||||
assertThat(defaultTaskConfigurer.getTaskExplorer()).isNotNull();
|
||||
@@ -100,8 +91,7 @@ public class DefaultTaskConfigurerTests {
|
||||
|
||||
@Test
|
||||
public void taskRepositoryTest() {
|
||||
DefaultTaskConfigurer defaultTaskConfigurer = new DefaultTaskConfigurer(
|
||||
this.dataSource);
|
||||
DefaultTaskConfigurer defaultTaskConfigurer = new DefaultTaskConfigurer(this.dataSource);
|
||||
assertThat(defaultTaskConfigurer.getTaskRepository()).isNotNull();
|
||||
defaultTaskConfigurer = new DefaultTaskConfigurer();
|
||||
assertThat(defaultTaskConfigurer.getTaskRepository()).isNotNull();
|
||||
@@ -109,8 +99,7 @@ public class DefaultTaskConfigurerTests {
|
||||
|
||||
@Test
|
||||
public void taskDataSource() {
|
||||
DefaultTaskConfigurer defaultTaskConfigurer = new DefaultTaskConfigurer(
|
||||
this.dataSource);
|
||||
DefaultTaskConfigurer defaultTaskConfigurer = new DefaultTaskConfigurer(this.dataSource);
|
||||
assertThat(defaultTaskConfigurer.getTaskDataSource()).isNotNull();
|
||||
defaultTaskConfigurer = new DefaultTaskConfigurer();
|
||||
assertThat(defaultTaskConfigurer.getTaskDataSource()).isNull();
|
||||
|
||||
@@ -50,17 +50,14 @@ public class RepositoryTransactionManagerConfigurationTests {
|
||||
@Test
|
||||
public void testZeroCustomTransactionManagerConfiguration() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class,
|
||||
ZeroTransactionManagerConfiguration.class))
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, ZeroTransactionManagerConfiguration.class))
|
||||
.withPropertyValues("application.name=transactionManagerTask");
|
||||
|
||||
applicationContextRunner.run((context) -> {
|
||||
DataSource dataSource = context.getBean("dataSource", DataSource.class);
|
||||
|
||||
int taskExecutionCount = JdbcTestUtils
|
||||
.countRowsInTable(new JdbcTemplate(dataSource), "TASK_EXECUTION");
|
||||
int taskExecutionCount = JdbcTestUtils.countRowsInTable(new JdbcTemplate(dataSource), "TASK_EXECUTION");
|
||||
|
||||
assertThat(taskExecutionCount).isEqualTo(1);
|
||||
});
|
||||
@@ -78,29 +75,24 @@ public class RepositoryTransactionManagerConfigurationTests {
|
||||
|
||||
private void testConfiguration(Class configurationClass) {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, configurationClass))
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, configurationClass))
|
||||
.withPropertyValues("application.name=transactionManagerTask");
|
||||
|
||||
applicationContextRunner.run((context) -> {
|
||||
DataSource dataSource = context.getBean("dataSource", DataSource.class);
|
||||
|
||||
int taskExecutionCount = JdbcTestUtils
|
||||
.countRowsInTable(new JdbcTemplate(dataSource), "TASK_EXECUTION");
|
||||
int taskExecutionCount = JdbcTestUtils.countRowsInTable(new JdbcTemplate(dataSource), "TASK_EXECUTION");
|
||||
|
||||
// Verify that the create call was rolled back
|
||||
assertThat(taskExecutionCount).isEqualTo(0);
|
||||
|
||||
// Execute a new create call so that things close cleanly
|
||||
TaskRepository taskRepository = context.getBean("taskRepository",
|
||||
TaskRepository.class);
|
||||
TaskRepository taskRepository = context.getBean("taskRepository", TaskRepository.class);
|
||||
|
||||
TaskExecution taskExecution = taskRepository
|
||||
.createTaskExecution("transactionManagerTask");
|
||||
taskExecution = taskRepository.startTaskExecution(
|
||||
taskExecution.getExecutionId(), taskExecution.getTaskName(),
|
||||
new Date(), new ArrayList<>(0), null);
|
||||
TaskExecution taskExecution = taskRepository.createTaskExecution("transactionManagerTask");
|
||||
taskExecution = taskRepository.startTaskExecution(taskExecution.getExecutionId(),
|
||||
taskExecution.getTaskName(), new Date(), new ArrayList<>(0), null);
|
||||
|
||||
TaskLifecycleListener listener = context.getBean(TaskLifecycleListener.class);
|
||||
|
||||
@@ -129,8 +121,7 @@ public class RepositoryTransactionManagerConfigurationTests {
|
||||
public static class SingleTransactionManagerConfiguration {
|
||||
|
||||
@Bean
|
||||
public TaskConfigurer taskConfigurer(DataSource dataSource,
|
||||
PlatformTransactionManager transactionManager) {
|
||||
public TaskConfigurer taskConfigurer(DataSource dataSource, PlatformTransactionManager transactionManager) {
|
||||
return new DefaultTaskConfigurer(dataSource) {
|
||||
@Override
|
||||
public PlatformTransactionManager getTransactionManager() {
|
||||
@@ -156,8 +147,7 @@ public class RepositoryTransactionManagerConfigurationTests {
|
||||
public static class MultipleTransactionManagerConfiguration {
|
||||
|
||||
@Bean
|
||||
public TaskConfigurer taskConfigurer(DataSource dataSource,
|
||||
PlatformTransactionManager transactionManager) {
|
||||
public TaskConfigurer taskConfigurer(DataSource dataSource, PlatformTransactionManager transactionManager) {
|
||||
return new DefaultTaskConfigurer(dataSource) {
|
||||
@Override
|
||||
public PlatformTransactionManager getTransactionManager() {
|
||||
@@ -188,8 +178,7 @@ public class RepositoryTransactionManagerConfigurationTests {
|
||||
|
||||
}
|
||||
|
||||
private static class TestDataSourceTransactionManager
|
||||
extends DataSourceTransactionManager {
|
||||
private static class TestDataSourceTransactionManager extends DataSourceTransactionManager {
|
||||
|
||||
protected TestDataSourceTransactionManager(DataSource dataSource) {
|
||||
super(dataSource);
|
||||
|
||||
@@ -28,10 +28,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@DirtiesContext
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(
|
||||
classes = { SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class },
|
||||
properties = { "spring.cloud.task.closecontextEnabled=false",
|
||||
"spring.cloud.task.initialize-enabled=false" })
|
||||
@SpringBootTest(classes = { SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class },
|
||||
properties = { "spring.cloud.task.closecontextEnabled=false", "spring.cloud.task.initialize-enabled=false" })
|
||||
public class TaskPropertiesTests {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -50,8 +50,7 @@ public class TestConfiguration implements InitializingBean {
|
||||
|
||||
@Bean
|
||||
public TaskRepositoryInitializer taskRepositoryInitializer() throws Exception {
|
||||
TaskRepositoryInitializer taskRepositoryInitializer = new TaskRepositoryInitializer(
|
||||
new TaskProperties());
|
||||
TaskRepositoryInitializer taskRepositoryInitializer = new TaskRepositoryInitializer(new TaskProperties());
|
||||
taskRepositoryInitializer.setDataSource(this.dataSource);
|
||||
taskRepositoryInitializer.setResourceLoader(this.resourceLoader);
|
||||
taskRepositoryInitializer.afterPropertiesSet();
|
||||
@@ -82,8 +81,7 @@ public class TestConfiguration implements InitializingBean {
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
if (this.dataSource != null) {
|
||||
this.taskExecutionDaoFactoryBean = new TaskExecutionDaoFactoryBean(
|
||||
this.dataSource);
|
||||
this.taskExecutionDaoFactoryBean = new TaskExecutionDaoFactoryBean(this.dataSource);
|
||||
}
|
||||
else {
|
||||
this.taskExecutionDaoFactoryBean = new TaskExecutionDaoFactoryBean();
|
||||
|
||||
@@ -63,15 +63,15 @@ class ObservationIntegrationTests {
|
||||
void testSuccessfulObservation() {
|
||||
List<FinishedSpan> finishedSpans = finishedSpans();
|
||||
|
||||
SpansAssert.then(finishedSpans)
|
||||
.thenASpanWithNameEqualTo("my-command-line-runner")
|
||||
.hasTag("spring.cloud.task.runner.bean-name", "myCommandLineRunner")
|
||||
.backToSpans()
|
||||
.thenASpanWithNameEqualTo("my-application-runner")
|
||||
.hasTag("spring.cloud.task.runner.bean-name", "myApplicationRunner");
|
||||
SpansAssert.then(finishedSpans).thenASpanWithNameEqualTo("my-command-line-runner")
|
||||
.hasTag("spring.cloud.task.runner.bean-name", "myCommandLineRunner").backToSpans()
|
||||
.thenASpanWithNameEqualTo("my-application-runner")
|
||||
.hasTag("spring.cloud.task.runner.bean-name", "myApplicationRunner");
|
||||
MeterRegistryAssert.then(this.meterRegistry)
|
||||
.hasTimerWithNameAndTags("spring.cloud.task.runner", KeyValues.of("spring.cloud.task.runner.bean-name", "myCommandLineRunner"))
|
||||
.hasTimerWithNameAndTags("spring.cloud.task.runner", KeyValues.of("spring.cloud.task.runner.bean-name", "myApplicationRunner"));
|
||||
.hasTimerWithNameAndTags("spring.cloud.task.runner",
|
||||
KeyValues.of("spring.cloud.task.runner.bean-name", "myCommandLineRunner"))
|
||||
.hasTimerWithNameAndTags("spring.cloud.task.runner",
|
||||
KeyValues.of("spring.cloud.task.runner.bean-name", "myApplicationRunner"));
|
||||
}
|
||||
|
||||
private List<FinishedSpan> finishedSpans() {
|
||||
@@ -80,8 +80,12 @@ class ObservationIntegrationTests {
|
||||
|
||||
@Configuration
|
||||
@EnableTask
|
||||
@ImportAutoConfiguration({SimpleTaskAutoConfiguration.class, ObservationAutoConfiguration.class, ObservationTaskAutoConfiguration.class, BraveAutoConfiguration.class, MicrometerTracingAutoConfiguration.class, MetricsAutoConfiguration.class, CompositeMeterRegistryAutoConfiguration.class, ZipkinAutoConfiguration.class})
|
||||
@ImportAutoConfiguration({ SimpleTaskAutoConfiguration.class, ObservationAutoConfiguration.class,
|
||||
ObservationTaskAutoConfiguration.class, BraveAutoConfiguration.class,
|
||||
MicrometerTracingAutoConfiguration.class, MetricsAutoConfiguration.class,
|
||||
CompositeMeterRegistryAutoConfiguration.class, ZipkinAutoConfiguration.class })
|
||||
static class Config {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(Config.class);
|
||||
|
||||
@Bean
|
||||
@@ -96,12 +100,16 @@ class ObservationIntegrationTests {
|
||||
|
||||
@Bean
|
||||
CommandLineRunner myCommandLineRunner(Tracer tracer) {
|
||||
return args -> log.info("<TRACE:{}> Hello from command line runner", tracer.currentSpan().context().traceId());
|
||||
return args -> log.info("<TRACE:{}> Hello from command line runner",
|
||||
tracer.currentSpan().context().traceId());
|
||||
}
|
||||
|
||||
@Bean
|
||||
ApplicationRunner myApplicationRunner(Tracer tracer) {
|
||||
return args -> log.info("<TRACE:{}> Hello from application runner", tracer.currentSpan().context().traceId());
|
||||
return args -> log.info("<TRACE:{}> Hello from application runner",
|
||||
tracer.currentSpan().context().traceId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,8 +32,7 @@ public class TaskExceptionTests {
|
||||
TaskException taskException = new TaskException(ERROR_MESSAGE);
|
||||
assertThat(taskException.getMessage()).isEqualTo(ERROR_MESSAGE);
|
||||
|
||||
taskException = new TaskException(ERROR_MESSAGE,
|
||||
new IllegalStateException(ERROR_MESSAGE));
|
||||
taskException = new TaskException(ERROR_MESSAGE, new IllegalStateException(ERROR_MESSAGE));
|
||||
assertThat(taskException.getMessage()).isEqualTo(ERROR_MESSAGE);
|
||||
assertThat(taskException.getCause()).isNotNull();
|
||||
assertThat(taskException.getCause().getMessage()).isEqualTo(ERROR_MESSAGE);
|
||||
@@ -44,8 +43,7 @@ public class TaskExceptionTests {
|
||||
TaskExecutionException taskException = new TaskExecutionException(ERROR_MESSAGE);
|
||||
assertThat(taskException.getMessage()).isEqualTo(ERROR_MESSAGE);
|
||||
|
||||
taskException = new TaskExecutionException(ERROR_MESSAGE,
|
||||
new IllegalStateException(ERROR_MESSAGE));
|
||||
taskException = new TaskExecutionException(ERROR_MESSAGE, new IllegalStateException(ERROR_MESSAGE));
|
||||
assertThat(taskException.getMessage()).isEqualTo(ERROR_MESSAGE);
|
||||
assertThat(taskException.getCause()).isNotNull();
|
||||
assertThat(taskException.getCause().getMessage()).isEqualTo(ERROR_MESSAGE);
|
||||
|
||||
@@ -80,10 +80,9 @@ public class TaskExecutionListenerTests {
|
||||
public void testTaskCreate() {
|
||||
setupContextForTaskExecutionListener();
|
||||
DefaultTaskListenerConfiguration.TestTaskExecutionListener taskExecutionListener = this.context
|
||||
.getBean(
|
||||
DefaultTaskListenerConfiguration.TestTaskExecutionListener.class);
|
||||
TaskExecution taskExecution = new TaskExecution(0, null, "wombat", new Date(),
|
||||
new Date(), null, new ArrayList<>(), null, null);
|
||||
.getBean(DefaultTaskListenerConfiguration.TestTaskExecutionListener.class);
|
||||
TaskExecution taskExecution = new TaskExecution(0, null, "wombat", new Date(), new Date(), null,
|
||||
new ArrayList<>(), null, null);
|
||||
verifyListenerResults(false, false, taskExecution, taskExecutionListener);
|
||||
}
|
||||
|
||||
@@ -101,12 +100,9 @@ public class TaskExecutionListenerTests {
|
||||
exceptionFired = true;
|
||||
}
|
||||
assertThat(exceptionFired).as("Exception should have fired").isTrue();
|
||||
assertThat(beforeTaskDidFireOnError)
|
||||
.as("BeforeTask Listener should have executed").isTrue();
|
||||
assertThat(endTaskDidFireOnError).as("EndTask Listener should have executed")
|
||||
.isTrue();
|
||||
assertThat(failedTaskDidFireOnError)
|
||||
.as("FailedTask Listener should have executed").isTrue();
|
||||
assertThat(beforeTaskDidFireOnError).as("BeforeTask Listener should have executed").isTrue();
|
||||
assertThat(endTaskDidFireOnError).as("EndTask Listener should have executed").isTrue();
|
||||
assertThat(failedTaskDidFireOnError).as("FailedTask Listener should have executed").isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -123,10 +119,8 @@ public class TaskExecutionListenerTests {
|
||||
exceptionFired = true;
|
||||
}
|
||||
assertThat(exceptionFired).as("Exception should have fired").isTrue();
|
||||
assertThat(endTaskDidFireOnError).as("EndTask Listener should have executed")
|
||||
.isTrue();
|
||||
assertThat(failedTaskDidFireOnError)
|
||||
.as("FailedTask Listener should not have executed").isTrue();
|
||||
assertThat(endTaskDidFireOnError).as("EndTask Listener should have executed").isTrue();
|
||||
assertThat(failedTaskDidFireOnError).as("FailedTask Listener should not have executed").isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -137,18 +131,15 @@ public class TaskExecutionListenerTests {
|
||||
public void testAfterTaskErrorCreate() {
|
||||
setupContextForAfterTaskErrorAnnotatedListener();
|
||||
AfterTaskErrorAnnotationConfiguration.AnnotatedTaskListener taskExecutionListener = this.context
|
||||
.getBean(
|
||||
AfterTaskErrorAnnotationConfiguration.AnnotatedTaskListener.class);
|
||||
this.context.publishEvent(new ApplicationReadyEvent(new SpringApplication(),
|
||||
new String[0], this.context, Duration.ofSeconds(50)));
|
||||
.getBean(AfterTaskErrorAnnotationConfiguration.AnnotatedTaskListener.class);
|
||||
this.context.publishEvent(new ApplicationReadyEvent(new SpringApplication(), new String[0], this.context,
|
||||
Duration.ofSeconds(50)));
|
||||
|
||||
assertThat(taskExecutionListener.isTaskStartup()).isTrue();
|
||||
assertThat(taskExecutionListener.isTaskEnd()).isTrue();
|
||||
assertThat(taskExecutionListener.getTaskExecution().getExitMessage())
|
||||
.isEqualTo(TestListener.END_MESSAGE);
|
||||
assertThat(taskExecutionListener.getTaskExecution().getErrorMessage().contains(
|
||||
"Failed to process @BeforeTask or @AfterTask annotation because: AfterTaskFailure"))
|
||||
.isTrue();
|
||||
assertThat(taskExecutionListener.getTaskExecution().getExitMessage()).isEqualTo(TestListener.END_MESSAGE);
|
||||
assertThat(taskExecutionListener.getTaskExecution().getErrorMessage()
|
||||
.contains("Failed to process @BeforeTask or @AfterTask annotation because: AfterTaskFailure")).isTrue();
|
||||
assertThat(taskExecutionListener.getThrowable()).isNull();
|
||||
}
|
||||
|
||||
@@ -160,13 +151,12 @@ public class TaskExecutionListenerTests {
|
||||
public void testTaskUpdate() {
|
||||
setupContextForTaskExecutionListener();
|
||||
DefaultTaskListenerConfiguration.TestTaskExecutionListener taskExecutionListener = this.context
|
||||
.getBean(
|
||||
DefaultTaskListenerConfiguration.TestTaskExecutionListener.class);
|
||||
this.context.publishEvent(new ApplicationReadyEvent(new SpringApplication(),
|
||||
new String[0], this.context, Duration.ofSeconds(50)));
|
||||
.getBean(DefaultTaskListenerConfiguration.TestTaskExecutionListener.class);
|
||||
this.context.publishEvent(new ApplicationReadyEvent(new SpringApplication(), new String[0], this.context,
|
||||
Duration.ofSeconds(50)));
|
||||
|
||||
TaskExecution taskExecution = new TaskExecution(0, 0, "wombat", new Date(),
|
||||
new Date(), null, new ArrayList<>(), null, null);
|
||||
TaskExecution taskExecution = new TaskExecution(0, 0, "wombat", new Date(), new Date(), null, new ArrayList<>(),
|
||||
null, null);
|
||||
verifyListenerResults(true, false, taskExecution, taskExecutionListener);
|
||||
}
|
||||
|
||||
@@ -180,15 +170,13 @@ public class TaskExecutionListenerTests {
|
||||
setupContextForTaskExecutionListener();
|
||||
SpringApplication application = new SpringApplication();
|
||||
DefaultTaskListenerConfiguration.TestTaskExecutionListener taskExecutionListener = this.context
|
||||
.getBean(
|
||||
DefaultTaskListenerConfiguration.TestTaskExecutionListener.class);
|
||||
this.context.publishEvent(new ApplicationFailedEvent(application, new String[0],
|
||||
this.context, exception));
|
||||
.getBean(DefaultTaskListenerConfiguration.TestTaskExecutionListener.class);
|
||||
this.context.publishEvent(new ApplicationFailedEvent(application, new String[0], this.context, exception));
|
||||
this.context.publishEvent(
|
||||
new ApplicationReadyEvent(application, new String[0], this.context, Duration.ofSeconds(50)));
|
||||
|
||||
TaskExecution taskExecution = new TaskExecution(0, 1, "wombat", new Date(),
|
||||
new Date(), null, new ArrayList<>(), null, null);
|
||||
TaskExecution taskExecution = new TaskExecution(0, 1, "wombat", new Date(), new Date(), null, new ArrayList<>(),
|
||||
null, null);
|
||||
verifyListenerResults(true, true, taskExecution, taskExecutionListener);
|
||||
}
|
||||
|
||||
@@ -201,8 +189,8 @@ public class TaskExecutionListenerTests {
|
||||
setupContextForAnnotatedListener();
|
||||
DefaultAnnotationConfiguration.AnnotatedTaskListener annotatedListener = this.context
|
||||
.getBean(DefaultAnnotationConfiguration.AnnotatedTaskListener.class);
|
||||
TaskExecution taskExecution = new TaskExecution(0, null, "wombat", new Date(),
|
||||
new Date(), null, new ArrayList<>(), null, null);
|
||||
TaskExecution taskExecution = new TaskExecution(0, null, "wombat", new Date(), new Date(), null,
|
||||
new ArrayList<>(), null, null);
|
||||
verifyListenerResults(false, false, taskExecution, annotatedListener);
|
||||
}
|
||||
|
||||
@@ -215,11 +203,11 @@ public class TaskExecutionListenerTests {
|
||||
setupContextForAnnotatedListener();
|
||||
DefaultAnnotationConfiguration.AnnotatedTaskListener annotatedListener = this.context
|
||||
.getBean(DefaultAnnotationConfiguration.AnnotatedTaskListener.class);
|
||||
this.context.publishEvent(new ApplicationReadyEvent(new SpringApplication(),
|
||||
new String[0], this.context, Duration.ofSeconds(50)));
|
||||
this.context.publishEvent(new ApplicationReadyEvent(new SpringApplication(), new String[0], this.context,
|
||||
Duration.ofSeconds(50)));
|
||||
|
||||
TaskExecution taskExecution = new TaskExecution(0, 0, "wombat", new Date(),
|
||||
new Date(), null, new ArrayList<>(), null, null);
|
||||
TaskExecution taskExecution = new TaskExecution(0, 0, "wombat", new Date(), new Date(), null, new ArrayList<>(),
|
||||
null, null);
|
||||
verifyListenerResults(true, false, taskExecution, annotatedListener);
|
||||
}
|
||||
|
||||
@@ -234,88 +222,71 @@ public class TaskExecutionListenerTests {
|
||||
SpringApplication application = new SpringApplication();
|
||||
DefaultAnnotationConfiguration.AnnotatedTaskListener annotatedListener = this.context
|
||||
.getBean(DefaultAnnotationConfiguration.AnnotatedTaskListener.class);
|
||||
this.context.publishEvent(new ApplicationFailedEvent(application, new String[0],
|
||||
this.context, exception));
|
||||
this.context.publishEvent(new ApplicationFailedEvent(application, new String[0], this.context, exception));
|
||||
this.context.publishEvent(
|
||||
new ApplicationReadyEvent(application, new String[0], this.context, Duration.ofSeconds(50)));
|
||||
|
||||
TaskExecution taskExecution = new TaskExecution(0, 1, "wombat", new Date(),
|
||||
new Date(), null, new ArrayList<>(), null, null);
|
||||
TaskExecution taskExecution = new TaskExecution(0, 1, "wombat", new Date(), new Date(), null, new ArrayList<>(),
|
||||
null, null);
|
||||
verifyListenerResults(true, true, taskExecution, annotatedListener);
|
||||
}
|
||||
|
||||
private void verifyListenerResults(boolean isTaskEnd, boolean isTaskFailed,
|
||||
TaskExecution taskExecution, TestListener actualListener) {
|
||||
private void verifyListenerResults(boolean isTaskEnd, boolean isTaskFailed, TaskExecution taskExecution,
|
||||
TestListener actualListener) {
|
||||
assertThat(actualListener.isTaskStartup()).isTrue();
|
||||
assertThat(actualListener.isTaskEnd()).isEqualTo(isTaskEnd);
|
||||
assertThat(actualListener.isTaskFailed()).isEqualTo(isTaskFailed);
|
||||
if (isTaskFailed) {
|
||||
assertThat(actualListener.getTaskExecution().getExitMessage())
|
||||
.isEqualTo(TestListener.END_MESSAGE);
|
||||
assertThat(actualListener.getTaskExecution().getExitMessage()).isEqualTo(TestListener.END_MESSAGE);
|
||||
assertThat(actualListener.getThrowable()).isNotNull();
|
||||
assertThat(actualListener.getThrowable() instanceof RuntimeException)
|
||||
.isTrue();
|
||||
assertThat(actualListener.getThrowable() instanceof RuntimeException).isTrue();
|
||||
assertThat(actualListener.getTaskExecution().getErrorMessage()
|
||||
.startsWith("java.lang.RuntimeException: This was expected"))
|
||||
.isTrue();
|
||||
.startsWith("java.lang.RuntimeException: This was expected")).isTrue();
|
||||
}
|
||||
else if (isTaskEnd) {
|
||||
assertThat(actualListener.getTaskExecution().getExitMessage())
|
||||
.isEqualTo(TestListener.END_MESSAGE);
|
||||
assertThat(actualListener.getTaskExecution().getErrorMessage())
|
||||
.isEqualTo(taskExecution.getErrorMessage());
|
||||
assertThat(actualListener.getTaskExecution().getExitMessage()).isEqualTo(TestListener.END_MESSAGE);
|
||||
assertThat(actualListener.getTaskExecution().getErrorMessage()).isEqualTo(taskExecution.getErrorMessage());
|
||||
assertThat(actualListener.getThrowable()).isNull();
|
||||
}
|
||||
else {
|
||||
assertThat(actualListener.getTaskExecution().getExitMessage())
|
||||
.isEqualTo(TestListener.START_MESSAGE);
|
||||
assertThat(actualListener.getTaskExecution().getExitMessage()).isEqualTo(TestListener.START_MESSAGE);
|
||||
assertThat(actualListener.getTaskExecution().getErrorMessage()).isNull();
|
||||
assertThat(actualListener.getThrowable()).isNull();
|
||||
}
|
||||
|
||||
assertThat(actualListener.getTaskExecution().getExecutionId())
|
||||
.isEqualTo(taskExecution.getExecutionId());
|
||||
assertThat(actualListener.getTaskExecution().getExitCode())
|
||||
.isEqualTo(taskExecution.getExitCode());
|
||||
assertThat(actualListener.getTaskExecution().getExecutionId()).isEqualTo(taskExecution.getExecutionId());
|
||||
assertThat(actualListener.getTaskExecution().getExitCode()).isEqualTo(taskExecution.getExitCode());
|
||||
assertThat(actualListener.getTaskExecution().getExternalExecutionId())
|
||||
.isEqualTo(taskExecution.getExternalExecutionId());
|
||||
}
|
||||
|
||||
private void setupContextForTaskExecutionListener() {
|
||||
this.context = new AnnotationConfigApplicationContext(
|
||||
DefaultTaskListenerConfiguration.class, TestDefaultConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
this.context = new AnnotationConfigApplicationContext(DefaultTaskListenerConfiguration.class,
|
||||
TestDefaultConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
|
||||
this.context.setId("testTask");
|
||||
}
|
||||
|
||||
private void setupContextForAnnotatedListener() {
|
||||
this.context = new AnnotationConfigApplicationContext(
|
||||
TestDefaultConfiguration.class, DefaultAnnotationConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
this.context = new AnnotationConfigApplicationContext(TestDefaultConfiguration.class,
|
||||
DefaultAnnotationConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
|
||||
this.context.setId("annotatedTask");
|
||||
}
|
||||
|
||||
private void setupContextForBeforeTaskErrorAnnotatedListener() {
|
||||
this.context = new AnnotationConfigApplicationContext(
|
||||
TestDefaultConfiguration.class,
|
||||
BeforeTaskErrorAnnotationConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
this.context = new AnnotationConfigApplicationContext(TestDefaultConfiguration.class,
|
||||
BeforeTaskErrorAnnotationConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
|
||||
this.context.setId("beforeTaskAnnotatedTask");
|
||||
}
|
||||
|
||||
private void setupContextForFailedTaskErrorAnnotatedListener() {
|
||||
this.context = new AnnotationConfigApplicationContext(
|
||||
TestDefaultConfiguration.class,
|
||||
FailedTaskErrorAnnotationConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
this.context = new AnnotationConfigApplicationContext(TestDefaultConfiguration.class,
|
||||
FailedTaskErrorAnnotationConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
|
||||
this.context.setId("failedTaskAnnotatedTask");
|
||||
}
|
||||
|
||||
private void setupContextForAfterTaskErrorAnnotatedListener() {
|
||||
this.context = new AnnotationConfigApplicationContext(
|
||||
TestDefaultConfiguration.class,
|
||||
AfterTaskErrorAnnotationConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
this.context = new AnnotationConfigApplicationContext(TestDefaultConfiguration.class,
|
||||
AfterTaskErrorAnnotationConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
|
||||
this.context.setId("afterTaskAnnotatedTask");
|
||||
}
|
||||
|
||||
@@ -457,8 +428,7 @@ public class TaskExecutionListenerTests {
|
||||
return new TestTaskExecutionListener();
|
||||
}
|
||||
|
||||
public static class TestTaskExecutionListener extends TestListener
|
||||
implements TaskExecutionListener {
|
||||
public static class TestTaskExecutionListener extends TestListener implements TaskExecutionListener {
|
||||
|
||||
@Override
|
||||
public void onTaskStartup(TaskExecution taskExecution) {
|
||||
|
||||
@@ -74,8 +74,7 @@ public class TaskLifecycleListenerTests {
|
||||
public void setUp() {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context.setId("testTask");
|
||||
this.context.register(TestDefaultConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
this.context.register(TestDefaultConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
|
||||
TestListener.getStartupOrderList().clear();
|
||||
TestListener.getFailOrderList().clear();
|
||||
TestListener.getEndOrderList().clear();
|
||||
@@ -109,8 +108,8 @@ public class TaskLifecycleListenerTests {
|
||||
this.context.refresh();
|
||||
this.taskExplorer = this.context.getBean(TaskExplorer.class);
|
||||
|
||||
this.context.publishEvent(new ApplicationReadyEvent(new SpringApplication(),
|
||||
new String[0], this.context, Duration.ofSeconds(50)));
|
||||
this.context.publishEvent(new ApplicationReadyEvent(new SpringApplication(), new String[0], this.context,
|
||||
Duration.ofSeconds(50)));
|
||||
|
||||
verifyTaskExecution(0, true, 0);
|
||||
}
|
||||
@@ -121,8 +120,7 @@ public class TaskLifecycleListenerTests {
|
||||
RuntimeException exception = new RuntimeException("This was expected");
|
||||
SpringApplication application = new SpringApplication();
|
||||
this.taskExplorer = this.context.getBean(TaskExplorer.class);
|
||||
this.context.publishEvent(new ApplicationFailedEvent(application, new String[0],
|
||||
this.context, exception));
|
||||
this.context.publishEvent(new ApplicationFailedEvent(application, new String[0], this.context, exception));
|
||||
this.context.publishEvent(
|
||||
new ApplicationReadyEvent(application, new String[0], this.context, Duration.ofSeconds(50)));
|
||||
|
||||
@@ -140,17 +138,14 @@ public class TaskLifecycleListenerTests {
|
||||
SpringApplication application = new SpringApplication();
|
||||
this.taskExplorer = this.context.getBean(TaskExplorer.class);
|
||||
this.context.publishEvent(new ExitCodeEvent(this.context, exitCode));
|
||||
this.context.publishEvent(new ApplicationFailedEvent(application, new String[0],
|
||||
this.context, exception));
|
||||
this.context.publishEvent(new ApplicationFailedEvent(application, new String[0], this.context, exception));
|
||||
this.context.publishEvent(
|
||||
new ApplicationReadyEvent(application, new String[0], this.context, Duration.ofSeconds(50)));
|
||||
|
||||
verifyTaskExecution(0, true, exitCode, exception, null);
|
||||
assertThat(TestListener.getStartupOrderList().size()).isEqualTo(2);
|
||||
assertThat(TestListener.getStartupOrderList().get(0))
|
||||
.isEqualTo(Integer.valueOf(2));
|
||||
assertThat(TestListener.getStartupOrderList().get(1))
|
||||
.isEqualTo(Integer.valueOf(1));
|
||||
assertThat(TestListener.getStartupOrderList().get(0)).isEqualTo(Integer.valueOf(2));
|
||||
assertThat(TestListener.getStartupOrderList().get(1)).isEqualTo(Integer.valueOf(1));
|
||||
|
||||
assertThat(TestListener.getEndOrderList().size()).isEqualTo(2);
|
||||
assertThat(TestListener.getEndOrderList().get(0)).isEqualTo(Integer.valueOf(1));
|
||||
@@ -166,8 +161,7 @@ public class TaskLifecycleListenerTests {
|
||||
public void testNoClosingOfContext() {
|
||||
|
||||
try (ConfigurableApplicationContext applicationContext = SpringApplication.run(
|
||||
new Class[] { TestDefaultConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class },
|
||||
new Class[] { TestDefaultConfiguration.class, PropertyPlaceholderAutoConfiguration.class },
|
||||
new String[] { "--spring.cloud.task.closecontext_enabled=false" })) {
|
||||
assertThat(applicationContext.isActive()).isTrue();
|
||||
}
|
||||
@@ -180,8 +174,7 @@ public class TaskLifecycleListenerTests {
|
||||
MutablePropertySources propertySources = environment.getPropertySources();
|
||||
Map<String, Object> myMap = new HashMap<>();
|
||||
myMap.put("spring.cloud.task.executionid", "55");
|
||||
propertySources
|
||||
.addFirst(new MapPropertySource("EnvrionmentTestPropsource", myMap));
|
||||
propertySources.addFirst(new MapPropertySource("EnvrionmentTestPropsource", myMap));
|
||||
this.context.setEnvironment(environment);
|
||||
this.context.refresh();
|
||||
});
|
||||
@@ -190,8 +183,7 @@ public class TaskLifecycleListenerTests {
|
||||
@Test
|
||||
public void testRestartExistingTask(CapturedOutput capturedOutput) {
|
||||
this.context.refresh();
|
||||
TaskLifecycleListener taskLifecycleListener = this.context
|
||||
.getBean(TaskLifecycleListener.class);
|
||||
TaskLifecycleListener taskLifecycleListener = this.context.getBean(TaskLifecycleListener.class);
|
||||
taskLifecycleListener.start();
|
||||
String output = capturedOutput.toString();
|
||||
assertThat(output.contains("Multiple start events have been received"))
|
||||
@@ -204,8 +196,7 @@ public class TaskLifecycleListenerTests {
|
||||
MutablePropertySources propertySources = environment.getPropertySources();
|
||||
Map<String, Object> myMap = new HashMap<>();
|
||||
myMap.put("spring.cloud.task.external-execution-id", "myid");
|
||||
propertySources
|
||||
.addFirst(new MapPropertySource("EnvrionmentTestPropsource", myMap));
|
||||
propertySources.addFirst(new MapPropertySource("EnvrionmentTestPropsource", myMap));
|
||||
this.context.setEnvironment(environment);
|
||||
this.context.refresh();
|
||||
this.taskExplorer = this.context.getBean(TaskExplorer.class);
|
||||
@@ -219,8 +210,7 @@ public class TaskLifecycleListenerTests {
|
||||
MutablePropertySources propertySources = environment.getPropertySources();
|
||||
Map<String, Object> myMap = new HashMap<>();
|
||||
myMap.put("spring.cloud.task.parentExecutionId", 789);
|
||||
propertySources
|
||||
.addFirst(new MapPropertySource("EnvrionmentTestPropsource", myMap));
|
||||
propertySources.addFirst(new MapPropertySource("EnvrionmentTestPropsource", myMap));
|
||||
this.context.setEnvironment(environment);
|
||||
this.context.refresh();
|
||||
this.taskExplorer = this.context.getBean(TaskExplorer.class);
|
||||
@@ -228,8 +218,7 @@ public class TaskLifecycleListenerTests {
|
||||
verifyTaskExecution(0, false, null, null, null, 789L);
|
||||
}
|
||||
|
||||
private void verifyTaskExecution(int numberOfParams, boolean update,
|
||||
Integer exitCode) {
|
||||
private void verifyTaskExecution(int numberOfParams, boolean update, Integer exitCode) {
|
||||
verifyTaskExecution(numberOfParams, update, exitCode, null, null);
|
||||
}
|
||||
|
||||
@@ -237,21 +226,19 @@ public class TaskLifecycleListenerTests {
|
||||
verifyTaskExecution(numberOfParams, update, null, null, null);
|
||||
}
|
||||
|
||||
private void verifyTaskExecution(int numberOfParams, boolean update, Integer exitCode,
|
||||
Throwable exception, String externalExecutionId) {
|
||||
verifyTaskExecution(numberOfParams, update, exitCode, exception,
|
||||
externalExecutionId, null);
|
||||
private void verifyTaskExecution(int numberOfParams, boolean update, Integer exitCode, Throwable exception,
|
||||
String externalExecutionId) {
|
||||
verifyTaskExecution(numberOfParams, update, exitCode, exception, externalExecutionId, null);
|
||||
}
|
||||
|
||||
private void verifyTaskExecution(int numberOfParams, boolean update, Integer exitCode,
|
||||
Throwable exception, String externalExecutionId, Long parentExecutionId) {
|
||||
private void verifyTaskExecution(int numberOfParams, boolean update, Integer exitCode, Throwable exception,
|
||||
String externalExecutionId, Long parentExecutionId) {
|
||||
|
||||
Sort sort = Sort.by("id");
|
||||
|
||||
PageRequest request = PageRequest.of(0, Integer.MAX_VALUE, sort);
|
||||
|
||||
Page<TaskExecution> taskExecutionsByName = this.taskExplorer
|
||||
.findTaskExecutionsByName("testTask", request);
|
||||
Page<TaskExecution> taskExecutionsByName = this.taskExplorer.findTaskExecutionsByName("testTask", request);
|
||||
assertThat(taskExecutionsByName.iterator().hasNext()).isTrue();
|
||||
TaskExecution taskExecution = taskExecutionsByName.iterator().next();
|
||||
|
||||
@@ -261,16 +248,14 @@ public class TaskLifecycleListenerTests {
|
||||
assertThat(taskExecution.getParentExecutionId()).isEqualTo(parentExecutionId);
|
||||
|
||||
if (exception != null) {
|
||||
assertThat(taskExecution.getErrorMessage()
|
||||
.length() > exception.getStackTrace().length).isTrue();
|
||||
assertThat(taskExecution.getErrorMessage().length() > exception.getStackTrace().length).isTrue();
|
||||
}
|
||||
else {
|
||||
assertThat(taskExecution.getExitMessage()).isNull();
|
||||
}
|
||||
|
||||
if (update) {
|
||||
assertThat(taskExecution.getEndTime().getTime() >= taskExecution
|
||||
.getStartTime().getTime()).isTrue();
|
||||
assertThat(taskExecution.getEndTime().getTime() >= taskExecution.getStartTime().getTime()).isTrue();
|
||||
assertThat(taskExecution.getExitCode()).isNotNull();
|
||||
}
|
||||
else {
|
||||
@@ -310,8 +295,7 @@ public class TaskLifecycleListenerTests {
|
||||
|
||||
int i = 0;
|
||||
for (Map.Entry<String, String> stringStringEntry : this.args.entrySet()) {
|
||||
sourceArgs[i] = "--" + stringStringEntry.getKey() + "="
|
||||
+ stringStringEntry.getValue();
|
||||
sourceArgs[i] = "--" + stringStringEntry.getKey() + "=" + stringStringEntry.getValue();
|
||||
i++;
|
||||
}
|
||||
|
||||
|
||||
@@ -46,8 +46,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @since 2.1.0
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(classes = {
|
||||
TaskListenerExecutorObjectFactoryTests.TaskExecutionListenerConfiguration.class })
|
||||
@ContextConfiguration(classes = { TaskListenerExecutorObjectFactoryTests.TaskExecutionListenerConfiguration.class })
|
||||
@DirtiesContext
|
||||
public class TaskListenerExecutorObjectFactoryTests {
|
||||
|
||||
@@ -77,8 +76,7 @@ public class TaskListenerExecutorObjectFactoryTests {
|
||||
|
||||
public void setup(ConfigurableApplicationContext context) {
|
||||
taskExecutionListenerResults.clear();
|
||||
this.taskListenerExecutorObjectFactory = new TaskListenerExecutorObjectFactory(
|
||||
context);
|
||||
this.taskListenerExecutorObjectFactory = new TaskListenerExecutorObjectFactory(context);
|
||||
this.taskListenerExecutor = this.taskListenerExecutorObjectFactory.getObject();
|
||||
}
|
||||
|
||||
@@ -90,8 +88,7 @@ public class TaskListenerExecutorObjectFactoryTests {
|
||||
applicationContextRunner.run((context) -> {
|
||||
setup(context);
|
||||
|
||||
this.taskListenerExecutor
|
||||
.onTaskStartup(createSampleTaskExecution(BEFORE_LISTENER));
|
||||
this.taskListenerExecutor.onTaskStartup(createSampleTaskExecution(BEFORE_LISTENER));
|
||||
validateSingleEntry(BEFORE_LISTENER);
|
||||
});
|
||||
}
|
||||
@@ -104,8 +101,7 @@ public class TaskListenerExecutorObjectFactoryTests {
|
||||
applicationContextRunner.run((context) -> {
|
||||
setup(context);
|
||||
|
||||
this.taskListenerExecutor.onTaskFailed(
|
||||
createSampleTaskExecution(FAIL_LISTENER),
|
||||
this.taskListenerExecutor.onTaskFailed(createSampleTaskExecution(FAIL_LISTENER),
|
||||
new IllegalStateException("oops"));
|
||||
validateSingleEntry(FAIL_LISTENER);
|
||||
});
|
||||
@@ -119,8 +115,7 @@ public class TaskListenerExecutorObjectFactoryTests {
|
||||
applicationContextRunner.run((context) -> {
|
||||
setup(context);
|
||||
|
||||
this.taskListenerExecutor
|
||||
.onTaskEnd(createSampleTaskExecution(AFTER_LISTENER));
|
||||
this.taskListenerExecutor.onTaskEnd(createSampleTaskExecution(AFTER_LISTENER));
|
||||
validateSingleEntry(AFTER_LISTENER);
|
||||
});
|
||||
}
|
||||
@@ -133,34 +128,26 @@ public class TaskListenerExecutorObjectFactoryTests {
|
||||
applicationContextRunner.run((context) -> {
|
||||
setup(context);
|
||||
|
||||
this.taskListenerExecutor
|
||||
.onTaskStartup(createSampleTaskExecution(BEFORE_LISTENER));
|
||||
this.taskListenerExecutor.onTaskFailed(
|
||||
createSampleTaskExecution(FAIL_LISTENER),
|
||||
this.taskListenerExecutor.onTaskStartup(createSampleTaskExecution(BEFORE_LISTENER));
|
||||
this.taskListenerExecutor.onTaskFailed(createSampleTaskExecution(FAIL_LISTENER),
|
||||
new IllegalStateException("oops"));
|
||||
this.taskListenerExecutor
|
||||
.onTaskEnd(createSampleTaskExecution(AFTER_LISTENER));
|
||||
this.taskListenerExecutor.onTaskEnd(createSampleTaskExecution(AFTER_LISTENER));
|
||||
assertThat(taskExecutionListenerResults.size()).isEqualTo(3);
|
||||
assertThat(taskExecutionListenerResults.get(0).getTaskName())
|
||||
.isEqualTo(BEFORE_LISTENER);
|
||||
assertThat(taskExecutionListenerResults.get(1).getTaskName())
|
||||
.isEqualTo(FAIL_LISTENER);
|
||||
assertThat(taskExecutionListenerResults.get(2).getTaskName())
|
||||
.isEqualTo(AFTER_LISTENER);
|
||||
assertThat(taskExecutionListenerResults.get(0).getTaskName()).isEqualTo(BEFORE_LISTENER);
|
||||
assertThat(taskExecutionListenerResults.get(1).getTaskName()).isEqualTo(FAIL_LISTENER);
|
||||
assertThat(taskExecutionListenerResults.get(2).getTaskName()).isEqualTo(AFTER_LISTENER);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyTaskStartupListenerWithMultipleInstances() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(
|
||||
TaskExecutionListenerMultipleInstanceConfiguration.class);
|
||||
.withUserConfiguration(TaskExecutionListenerMultipleInstanceConfiguration.class);
|
||||
|
||||
applicationContextRunner.run((context) -> {
|
||||
setup(context);
|
||||
|
||||
this.taskListenerExecutor
|
||||
.onTaskStartup(createSampleTaskExecution(BEFORE_LISTENER));
|
||||
this.taskListenerExecutor.onTaskStartup(createSampleTaskExecution(BEFORE_LISTENER));
|
||||
validateSingleEventWithMultipleInstances(BEFORE_LISTENER);
|
||||
});
|
||||
}
|
||||
@@ -168,14 +155,12 @@ public class TaskListenerExecutorObjectFactoryTests {
|
||||
@Test
|
||||
public void verifyTaskFailedListenerWithMultipleInstances() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(
|
||||
TaskExecutionListenerMultipleInstanceConfiguration.class);
|
||||
.withUserConfiguration(TaskExecutionListenerMultipleInstanceConfiguration.class);
|
||||
|
||||
applicationContextRunner.run((context) -> {
|
||||
setup(context);
|
||||
|
||||
this.taskListenerExecutor.onTaskFailed(
|
||||
createSampleTaskExecution(FAIL_LISTENER),
|
||||
this.taskListenerExecutor.onTaskFailed(createSampleTaskExecution(FAIL_LISTENER),
|
||||
new IllegalStateException("oops"));
|
||||
validateSingleEventWithMultipleInstances(FAIL_LISTENER);
|
||||
});
|
||||
@@ -184,14 +169,12 @@ public class TaskListenerExecutorObjectFactoryTests {
|
||||
@Test
|
||||
public void verifyTaskEndListenerWithMultipleInstances() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(
|
||||
TaskExecutionListenerMultipleInstanceConfiguration.class);
|
||||
.withUserConfiguration(TaskExecutionListenerMultipleInstanceConfiguration.class);
|
||||
|
||||
applicationContextRunner.run((context) -> {
|
||||
setup(context);
|
||||
|
||||
this.taskListenerExecutor
|
||||
.onTaskEnd(createSampleTaskExecution(AFTER_LISTENER));
|
||||
this.taskListenerExecutor.onTaskEnd(createSampleTaskExecution(AFTER_LISTENER));
|
||||
validateSingleEventWithMultipleInstances(AFTER_LISTENER);
|
||||
});
|
||||
}
|
||||
@@ -199,32 +182,22 @@ public class TaskListenerExecutorObjectFactoryTests {
|
||||
@Test
|
||||
public void verifyAllListenerWithMultipleInstances() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(
|
||||
TaskExecutionListenerMultipleInstanceConfiguration.class);
|
||||
.withUserConfiguration(TaskExecutionListenerMultipleInstanceConfiguration.class);
|
||||
|
||||
applicationContextRunner.run((context) -> {
|
||||
setup(context);
|
||||
|
||||
this.taskListenerExecutor
|
||||
.onTaskStartup(createSampleTaskExecution(BEFORE_LISTENER));
|
||||
this.taskListenerExecutor.onTaskFailed(
|
||||
createSampleTaskExecution(FAIL_LISTENER),
|
||||
this.taskListenerExecutor.onTaskStartup(createSampleTaskExecution(BEFORE_LISTENER));
|
||||
this.taskListenerExecutor.onTaskFailed(createSampleTaskExecution(FAIL_LISTENER),
|
||||
new IllegalStateException("oops"));
|
||||
this.taskListenerExecutor
|
||||
.onTaskEnd(createSampleTaskExecution(AFTER_LISTENER));
|
||||
this.taskListenerExecutor.onTaskEnd(createSampleTaskExecution(AFTER_LISTENER));
|
||||
assertThat(taskExecutionListenerResults.size()).isEqualTo(6);
|
||||
assertThat(taskExecutionListenerResults.get(0).getTaskName())
|
||||
.isEqualTo(BEFORE_LISTENER);
|
||||
assertThat(taskExecutionListenerResults.get(1).getTaskName())
|
||||
.isEqualTo(BEFORE_LISTENER);
|
||||
assertThat(taskExecutionListenerResults.get(2).getTaskName())
|
||||
.isEqualTo(FAIL_LISTENER);
|
||||
assertThat(taskExecutionListenerResults.get(3).getTaskName())
|
||||
.isEqualTo(FAIL_LISTENER);
|
||||
assertThat(taskExecutionListenerResults.get(4).getTaskName())
|
||||
.isEqualTo(AFTER_LISTENER);
|
||||
assertThat(taskExecutionListenerResults.get(5).getTaskName())
|
||||
.isEqualTo(AFTER_LISTENER);
|
||||
assertThat(taskExecutionListenerResults.get(0).getTaskName()).isEqualTo(BEFORE_LISTENER);
|
||||
assertThat(taskExecutionListenerResults.get(1).getTaskName()).isEqualTo(BEFORE_LISTENER);
|
||||
assertThat(taskExecutionListenerResults.get(2).getTaskName()).isEqualTo(FAIL_LISTENER);
|
||||
assertThat(taskExecutionListenerResults.get(3).getTaskName()).isEqualTo(FAIL_LISTENER);
|
||||
assertThat(taskExecutionListenerResults.get(4).getTaskName()).isEqualTo(AFTER_LISTENER);
|
||||
assertThat(taskExecutionListenerResults.get(5).getTaskName()).isEqualTo(AFTER_LISTENER);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -241,8 +214,7 @@ public class TaskListenerExecutorObjectFactoryTests {
|
||||
|
||||
private void validateSingleEventWithMultipleInstances(String event) {
|
||||
assertThat(taskExecutionListenerResults.size()).isEqualTo(2);
|
||||
assertThat(taskExecutionListenerResults)
|
||||
.allSatisfy(task -> assertThat(task.getTaskName()).isEqualTo(event));
|
||||
assertThat(taskExecutionListenerResults).allSatisfy(task -> assertThat(task.getTaskName()).isEqualTo(event));
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@@ -267,26 +239,24 @@ public class TaskListenerExecutorObjectFactoryTests {
|
||||
public TaskRunComponent otherTaskRunComponent() {
|
||||
return new TaskRunComponent();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class TaskRunComponent {
|
||||
|
||||
@BeforeTask
|
||||
public void initBeforeListener(TaskExecution taskExecution) {
|
||||
TaskListenerExecutorObjectFactoryTests.taskExecutionListenerResults
|
||||
.add(taskExecution);
|
||||
TaskListenerExecutorObjectFactoryTests.taskExecutionListenerResults.add(taskExecution);
|
||||
}
|
||||
|
||||
@AfterTask
|
||||
public void initAfterListener(TaskExecution taskExecution) {
|
||||
TaskListenerExecutorObjectFactoryTests.taskExecutionListenerResults
|
||||
.add(taskExecution);
|
||||
TaskListenerExecutorObjectFactoryTests.taskExecutionListenerResults.add(taskExecution);
|
||||
}
|
||||
|
||||
@FailedTask
|
||||
public void initFailedListener(TaskExecution taskExecution, Throwable exception) {
|
||||
TaskListenerExecutorObjectFactoryTests.taskExecutionListenerResults
|
||||
.add(taskExecution);
|
||||
TaskListenerExecutorObjectFactoryTests.taskExecutionListenerResults.add(taskExecution);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -63,7 +63,8 @@ public class TaskObservationsTests {
|
||||
public void before() {
|
||||
this.simpleMeterRegistry = new SimpleMeterRegistry();
|
||||
this.observationRegistry = TestObservationRegistry.create();
|
||||
ObservationHandler<Observation.Context> timerObservationHandler = new TimerObservationHandler(this.simpleMeterRegistry);
|
||||
ObservationHandler<Observation.Context> timerObservationHandler = new TimerObservationHandler(
|
||||
this.simpleMeterRegistry);
|
||||
this.observationRegistry.observationConfig().observationHandler(timerObservationHandler);
|
||||
this.taskObservations = new TaskObservations(this.observationRegistry, null, null);
|
||||
}
|
||||
@@ -86,9 +87,8 @@ public class TaskObservationsTests {
|
||||
|
||||
verifyDefaultKeyValues();
|
||||
TaskExecutionObservation.TASK_ACTIVE.getDefaultConvention();
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags("spring.cloud.task",
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_STATUS.getKeyName(), TaskObservations.STATUS_SUCCESS));
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags("spring.cloud.task", Tags
|
||||
.of(TaskExecutionObservation.TaskKeyValues.TASK_STATUS.getKeyName(), TaskObservations.STATUS_SUCCESS));
|
||||
|
||||
verifyLongTaskTimerAfterStop(longTaskTimer, "myTask72", "123");
|
||||
}
|
||||
@@ -96,43 +96,35 @@ public class TaskObservationsTests {
|
||||
@Test
|
||||
public void defaultTaskTest() {
|
||||
|
||||
TaskExecution taskExecution = new TaskExecution(123L, 0, null, new Date(),
|
||||
new Date(), null, new ArrayList<>(), null, null, null);
|
||||
TaskExecution taskExecution = new TaskExecution(123L, 0, null, new Date(), new Date(), null, new ArrayList<>(),
|
||||
null, null, null);
|
||||
|
||||
// Start Task
|
||||
taskObservations.onTaskStartup(taskExecution);
|
||||
|
||||
LongTaskTimer longTaskTimer = initializeBasicTest(UNKNOWN, "123");
|
||||
|
||||
|
||||
// Finish Task
|
||||
taskObservations.onTaskEnd(taskExecution);
|
||||
|
||||
// Test Timer
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_NAME.getKeyName(), UNKNOWN));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_EXECUTION_ID.getKeyName(), "123"));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_PARENT_EXECUTION_ID.getKeyName(), UNKNOWN));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_EXTERNAL_EXECUTION_ID.getKeyName(), UNKNOWN));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_EXIT_CODE.getKeyName(), "0"));
|
||||
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_STATUS.getKeyName(), TaskObservations.STATUS_SUCCESS));
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX, Tags
|
||||
.of(TaskExecutionObservation.TaskKeyValues.TASK_STATUS.getKeyName(), TaskObservations.STATUS_SUCCESS));
|
||||
|
||||
verifyLongTaskTimerAfterStop(longTaskTimer, "unknown", "123");
|
||||
|
||||
@@ -153,25 +145,20 @@ public class TaskObservationsTests {
|
||||
taskExecution.setExitCode(1);
|
||||
taskObservations.onTaskEnd(taskExecution);
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_NAME.getKeyName(), "myTask72"));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_EXECUTION_ID.getKeyName(), "123"));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_PARENT_EXECUTION_ID.getKeyName(), "-1"));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_EXIT_CODE.getKeyName(), "1"));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_STATUS.getKeyName(), TaskObservations.STATUS_FAILURE));
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX, Tags
|
||||
.of(TaskExecutionObservation.TaskKeyValues.TASK_STATUS.getKeyName(), TaskObservations.STATUS_FAILURE));
|
||||
|
||||
verifyLongTaskTimerAfterStop(longTaskTimer, "myTask72", "123");
|
||||
}
|
||||
@@ -204,37 +191,29 @@ public class TaskObservationsTests {
|
||||
|
||||
verifyDefaultKeyValues();
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_CF_ORG_NAME.getKeyName(), ORGANIZATION_NAME));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_CF_SPACE_ID.getKeyName(), SPACE_ID));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_CF_SPACE_NAME.getKeyName(), SPACE_NAME));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_CF_APP_NAME.getKeyName(), APPLICATION_NAME));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_CF_APP_ID.getKeyName(), APPLICATION_ID));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_CF_APP_VERSION.getKeyName(), APPLICATION_VERSION));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_CF_INSTANCE_INDEX.getKeyName(), INSTANCE_INDEX));
|
||||
|
||||
// Test Timer
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_NAME.getKeyName(), "myTask72"));
|
||||
|
||||
verifyLongTaskTimerAfterStop(longTaskTimer, "myTask72", "123");
|
||||
@@ -243,14 +222,13 @@ public class TaskObservationsTests {
|
||||
@Test
|
||||
public void testCloudVariablesUninitialized() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
CloudConfigurationForDefaultValues.class));
|
||||
.withConfiguration(AutoConfigurations.of(CloudConfigurationForDefaultValues.class));
|
||||
applicationContextRunner.run((context) -> {
|
||||
TaskObservationCloudKeyValues taskObservationCloudKeyValues = context
|
||||
.getBean(TaskObservationCloudKeyValues.class);
|
||||
.getBean(TaskObservationCloudKeyValues.class);
|
||||
|
||||
assertThat(taskObservationCloudKeyValues)
|
||||
.as("taskObservationCloudKeyValues should not be null").isNotNull();
|
||||
assertThat(taskObservationCloudKeyValues).as("taskObservationCloudKeyValues should not be null")
|
||||
.isNotNull();
|
||||
|
||||
this.taskObservations = new TaskObservations(this.observationRegistry, taskObservationCloudKeyValues, null);
|
||||
|
||||
@@ -263,37 +241,29 @@ public class TaskObservationsTests {
|
||||
|
||||
verifyDefaultKeyValues();
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_CF_ORG_NAME.getKeyName(), "default"));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_CF_SPACE_ID.getKeyName(), UNKNOWN));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_CF_SPACE_NAME.getKeyName(), UNKNOWN));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_CF_APP_NAME.getKeyName(), UNKNOWN));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_CF_APP_ID.getKeyName(), UNKNOWN));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_CF_APP_VERSION.getKeyName(), UNKNOWN));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_CF_INSTANCE_INDEX.getKeyName(), "0"));
|
||||
|
||||
// Test Timer
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_NAME.getKeyName(), "myTask72"));
|
||||
|
||||
verifyLongTaskTimerAfterStop(longTaskTimer, "myTask72", "123");
|
||||
@@ -301,8 +271,8 @@ public class TaskObservationsTests {
|
||||
}
|
||||
|
||||
private TaskExecution startupObservationForBasicTests(String taskName, long taskExecutionId) {
|
||||
TaskExecution taskExecution = new TaskExecution(taskExecutionId, 0, taskName, new Date(),
|
||||
new Date(), null, new ArrayList<>(), null, "-1", -1L);
|
||||
TaskExecution taskExecution = new TaskExecution(taskExecutionId, 0, taskName, new Date(), new Date(), null,
|
||||
new ArrayList<>(), null, "-1", -1L);
|
||||
|
||||
// Start Task
|
||||
taskObservations.onTaskStartup(taskExecution);
|
||||
@@ -312,56 +282,52 @@ public class TaskObservationsTests {
|
||||
private LongTaskTimer initializeBasicTest(String taskName, String executionId) {
|
||||
// Test Long Task Timer while the task is running.
|
||||
LongTaskTimer longTaskTimer = simpleMeterRegistry
|
||||
.find(TaskExecutionObservation.TASK_ACTIVE.getPrefix() + ".active").longTaskTimer();
|
||||
.find(TaskExecutionObservation.TASK_ACTIVE.getPrefix() + ".active").longTaskTimer();
|
||||
System.out.println(simpleMeterRegistry.getMetersAsString());
|
||||
assertThat(longTaskTimer)
|
||||
.withFailMessage("LongTask timer should be created on Task start")
|
||||
.isNotNull();
|
||||
assertThat(longTaskTimer).withFailMessage("LongTask timer should be created on Task start").isNotNull();
|
||||
assertThat(longTaskTimer.activeTasks()).isEqualTo(1);
|
||||
assertThat(longTaskTimer.getId().getTag(TaskExecutionObservation.TaskKeyValues.TASK_NAME.getKeyName()))
|
||||
.isEqualTo(taskName);
|
||||
.isEqualTo(taskName);
|
||||
assertThat(longTaskTimer.getId().getTag(TaskExecutionObservation.TaskKeyValues.TASK_EXECUTION_ID.getKeyName()))
|
||||
.isEqualTo(executionId);
|
||||
.isEqualTo(executionId);
|
||||
return longTaskTimer;
|
||||
}
|
||||
|
||||
private void verifyDefaultKeyValues() {
|
||||
// Test Timer
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_NAME.getKeyName(), "myTask72"));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_EXECUTION_ID.getKeyName(), "123"));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_PARENT_EXECUTION_ID.getKeyName(), "-1"));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_EXIT_CODE.getKeyName(), "0"));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_STATUS.getKeyName(), TaskObservations.STATUS_SUCCESS));
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX, Tags
|
||||
.of(TaskExecutionObservation.TaskKeyValues.TASK_STATUS.getKeyName(), TaskObservations.STATUS_SUCCESS));
|
||||
}
|
||||
|
||||
private void verifyLongTaskTimerAfterStop(LongTaskTimer longTaskTimer, String taskName, String executionId) {
|
||||
// Test Long Task Timer after the task has completed.
|
||||
assertThat(longTaskTimer.activeTasks()).isEqualTo(0);
|
||||
assertThat(longTaskTimer.getId().getTag(TaskExecutionObservation.TaskKeyValues.TASK_NAME.getKeyName()))
|
||||
.isEqualTo(taskName);
|
||||
.isEqualTo(taskName);
|
||||
assertThat(longTaskTimer.getId().getTag(TaskExecutionObservation.TaskKeyValues.TASK_EXECUTION_ID.getKeyName()))
|
||||
.isEqualTo(executionId);
|
||||
.isEqualTo(executionId);
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class CloudConfigurationForDefaultValues {
|
||||
|
||||
@Bean
|
||||
public TaskObservationCloudKeyValues taskObservationCloudKeyValues() {
|
||||
return new TaskObservationCloudKeyValues();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -42,9 +42,8 @@ class H2TaskRepositoryIntegrationTests {
|
||||
void testTaskRepository(ModeEnum mode) {
|
||||
String connectionUrl = String.format("jdbc:h2:mem:%s;DB_CLOSE_DELAY=-1;MODE=%s", UUID.randomUUID(), mode);
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(TestConfiguration.class)
|
||||
.withBean(DataSource.class,
|
||||
() -> new SimpleDriverDataSource(new org.h2.Driver(), connectionUrl, "sa", ""));
|
||||
.withUserConfiguration(TestConfiguration.class).withBean(DataSource.class,
|
||||
() -> new SimpleDriverDataSource(new org.h2.Driver(), connectionUrl, "sa", ""));
|
||||
|
||||
applicationContextRunner.run((context -> {
|
||||
TaskExplorer taskExplorer = context.getBean(TaskExplorer.class);
|
||||
@@ -55,6 +54,7 @@ class H2TaskRepositoryIntegrationTests {
|
||||
@EnableTask
|
||||
@ImportAutoConfiguration(SimpleTaskAutoConfiguration.class)
|
||||
static class TestConfiguration {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -46,8 +46,7 @@ public abstract class BaseTaskExecutionDaoTestCases {
|
||||
this.dao.getLatestTaskExecutionsByTaskNames(null);
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
assertThat(e.getMessage())
|
||||
.isEqualTo("At least 1 task name must be provided.");
|
||||
assertThat(e.getMessage()).isEqualTo("At least 1 task name must be provided.");
|
||||
return;
|
||||
}
|
||||
fail("Expected an IllegalArgumentException to be thrown.");
|
||||
@@ -60,8 +59,7 @@ public abstract class BaseTaskExecutionDaoTestCases {
|
||||
this.dao.getLatestTaskExecutionsByTaskNames(new String[0]);
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
assertThat(e.getMessage())
|
||||
.isEqualTo("At least 1 task name must be provided.");
|
||||
assertThat(e.getMessage()).isEqualTo("At least 1 task name must be provided.");
|
||||
return;
|
||||
}
|
||||
fail("Expected an IllegalArgumentException to be thrown.");
|
||||
@@ -74,8 +72,8 @@ public abstract class BaseTaskExecutionDaoTestCases {
|
||||
this.dao.getLatestTaskExecutionsByTaskNames("foo", null, "bar", " ");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
assertThat(e.getMessage()).isEqualTo(
|
||||
"Task names must not contain any empty elements but 2 of 4 were empty or null.");
|
||||
assertThat(e.getMessage())
|
||||
.isEqualTo("Task names must not contain any empty elements but 2 of 4 were empty or null.");
|
||||
return;
|
||||
}
|
||||
fail("Expected an IllegalArgumentException to be thrown.");
|
||||
@@ -85,11 +83,9 @@ public abstract class BaseTaskExecutionDaoTestCases {
|
||||
@DirtiesContext
|
||||
public void getLatestTaskExecutionsByTaskNamesWithSingleTaskName() {
|
||||
initializeRepositoryNotInOrderWithMultipleTaskExecutions();
|
||||
final List<TaskExecution> latestTaskExecutions = this.dao
|
||||
.getLatestTaskExecutionsByTaskNames("FOO1");
|
||||
assertThat(latestTaskExecutions.size() == 1).as(
|
||||
"Expected only 1 taskExecution but got " + latestTaskExecutions.size())
|
||||
.isTrue();
|
||||
final List<TaskExecution> latestTaskExecutions = this.dao.getLatestTaskExecutionsByTaskNames("FOO1");
|
||||
assertThat(latestTaskExecutions.size() == 1)
|
||||
.as("Expected only 1 taskExecution but got " + latestTaskExecutions.size()).isTrue();
|
||||
|
||||
final TaskExecution lastTaskExecution = latestTaskExecutions.get(0);
|
||||
assertThat(lastTaskExecution.getTaskName()).isEqualTo("FOO1");
|
||||
@@ -109,11 +105,10 @@ public abstract class BaseTaskExecutionDaoTestCases {
|
||||
@DirtiesContext
|
||||
public void getLatestTaskExecutionsByTaskNamesWithMultipleTaskNames() {
|
||||
initializeRepositoryNotInOrderWithMultipleTaskExecutions();
|
||||
final List<TaskExecution> latestTaskExecutions = this.dao
|
||||
.getLatestTaskExecutionsByTaskNames("FOO1", "FOO3", "FOO4");
|
||||
final List<TaskExecution> latestTaskExecutions = this.dao.getLatestTaskExecutionsByTaskNames("FOO1", "FOO3",
|
||||
"FOO4");
|
||||
assertThat(latestTaskExecutions.size() == 3)
|
||||
.as("Expected 3 taskExecutions but got " + latestTaskExecutions.size())
|
||||
.isTrue();
|
||||
.as("Expected 3 taskExecutions but got " + latestTaskExecutions.size()).isTrue();
|
||||
|
||||
final Calendar dateTimeFoo3 = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
|
||||
dateTimeFoo3.setTime(latestTaskExecutions.get(0).getStartTime());
|
||||
@@ -155,11 +150,9 @@ public abstract class BaseTaskExecutionDaoTestCases {
|
||||
@DirtiesContext
|
||||
public void getLatestTaskExecutionsByTaskNamesWithIdenticalTaskExecutions() {
|
||||
long executionIdOffset = initializeRepositoryNotInOrderWithMultipleTaskExecutions();
|
||||
final List<TaskExecution> latestTaskExecutions = this.dao
|
||||
.getLatestTaskExecutionsByTaskNames("FOO5");
|
||||
assertThat(latestTaskExecutions.size() == 1).as(
|
||||
"Expected only 1 taskExecution but got " + latestTaskExecutions.size())
|
||||
.isTrue();
|
||||
final List<TaskExecution> latestTaskExecutions = this.dao.getLatestTaskExecutionsByTaskNames("FOO5");
|
||||
assertThat(latestTaskExecutions.size() == 1)
|
||||
.as("Expected only 1 taskExecution but got " + latestTaskExecutions.size()).isTrue();
|
||||
|
||||
final Calendar dateTime = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
|
||||
dateTime.setTime(latestTaskExecutions.get(0).getStartTime());
|
||||
@@ -170,8 +163,7 @@ public abstract class BaseTaskExecutionDaoTestCases {
|
||||
assertThat(dateTime.get(Calendar.HOUR_OF_DAY)).isEqualTo(23);
|
||||
assertThat(dateTime.get(Calendar.MINUTE)).isEqualTo(59);
|
||||
assertThat(dateTime.get(Calendar.SECOND)).isEqualTo(0);
|
||||
assertThat(latestTaskExecutions.get(0).getExecutionId())
|
||||
.isEqualTo(9 + executionIdOffset);
|
||||
assertThat(latestTaskExecutions.get(0).getExecutionId()).isEqualTo(9 + executionIdOffset);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -204,11 +196,8 @@ public abstract class BaseTaskExecutionDaoTestCases {
|
||||
@DirtiesContext
|
||||
public void getLatestTaskExecutionForNonExistingTaskName() {
|
||||
initializeRepositoryNotInOrderWithMultipleTaskExecutions();
|
||||
final TaskExecution latestTaskExecution = this.dao
|
||||
.getLatestTaskExecutionForTaskName("Bar5");
|
||||
assertThat(latestTaskExecution)
|
||||
.as("Expected the latestTaskExecution to be null but got"
|
||||
+ latestTaskExecution)
|
||||
final TaskExecution latestTaskExecution = this.dao.getLatestTaskExecutionForTaskName("Bar5");
|
||||
assertThat(latestTaskExecution).as("Expected the latestTaskExecution to be null but got" + latestTaskExecution)
|
||||
.isNull();
|
||||
}
|
||||
|
||||
@@ -216,10 +205,8 @@ public abstract class BaseTaskExecutionDaoTestCases {
|
||||
@DirtiesContext
|
||||
public void getLatestTaskExecutionForExistingTaskName() {
|
||||
initializeRepositoryNotInOrderWithMultipleTaskExecutions();
|
||||
final TaskExecution latestTaskExecution = this.dao
|
||||
.getLatestTaskExecutionForTaskName("FOO1");
|
||||
assertThat(latestTaskExecution)
|
||||
.as("Expected the latestTaskExecution not to be null").isNotNull();
|
||||
final TaskExecution latestTaskExecution = this.dao.getLatestTaskExecutionForTaskName("FOO1");
|
||||
assertThat(latestTaskExecution).as("Expected the latestTaskExecution not to be null").isNotNull();
|
||||
|
||||
final Calendar dateTime = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
|
||||
dateTime.setTime(latestTaskExecution.getStartTime());
|
||||
@@ -241,10 +228,8 @@ public abstract class BaseTaskExecutionDaoTestCases {
|
||||
@DirtiesContext
|
||||
public void getLatestTaskExecutionForTaskNameWithIdenticalTaskExecutions() {
|
||||
long executionIdOffset = initializeRepositoryNotInOrderWithMultipleTaskExecutions();
|
||||
final TaskExecution latestTaskExecution = this.dao
|
||||
.getLatestTaskExecutionForTaskName("FOO5");
|
||||
assertThat(latestTaskExecution)
|
||||
.as("Expected the latestTaskExecution not to be null").isNotNull();
|
||||
final TaskExecution latestTaskExecution = this.dao.getLatestTaskExecutionForTaskName("FOO5");
|
||||
assertThat(latestTaskExecution).as("Expected the latestTaskExecution not to be null").isNotNull();
|
||||
|
||||
final Calendar dateTime = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
|
||||
dateTime.setTime(latestTaskExecution.getStartTime());
|
||||
@@ -262,11 +247,9 @@ public abstract class BaseTaskExecutionDaoTestCases {
|
||||
@DirtiesContext
|
||||
public void getRunningTaskExecutions() {
|
||||
initializeRepositoryNotInOrderWithMultipleTaskExecutions();
|
||||
assertThat(this.dao.getRunningTaskExecutionCount())
|
||||
.isEqualTo(this.dao.getTaskExecutionCount());
|
||||
assertThat(this.dao.getRunningTaskExecutionCount()).isEqualTo(this.dao.getTaskExecutionCount());
|
||||
this.dao.completeTaskExecution(1, 0, new Date(), "c'est fini!");
|
||||
assertThat(this.dao.getRunningTaskExecutionCount())
|
||||
.isEqualTo(this.dao.getTaskExecutionCount() - 1);
|
||||
assertThat(this.dao.getRunningTaskExecutionCount()).isEqualTo(this.dao.getTaskExecutionCount() - 1);
|
||||
}
|
||||
|
||||
protected long initializeRepositoryNotInOrderWithMultipleTaskExecutions() {
|
||||
@@ -325,12 +308,11 @@ public abstract class BaseTaskExecutionDaoTestCases {
|
||||
}
|
||||
|
||||
private long createTaskExecution(TaskExecution te) {
|
||||
return this.dao.createTaskExecution(te.getTaskName(), te.getStartTime(),
|
||||
te.getArguments(), te.getExternalExecutionId()).getExecutionId();
|
||||
return this.dao.createTaskExecution(te.getTaskName(), te.getStartTime(), te.getArguments(),
|
||||
te.getExternalExecutionId()).getExecutionId();
|
||||
}
|
||||
|
||||
protected TaskExecution getTaskExecution(String taskName,
|
||||
String externalExecutionId) {
|
||||
protected TaskExecution getTaskExecution(String taskName, String externalExecutionId) {
|
||||
TaskExecution taskExecution = new TaskExecution();
|
||||
taskExecution.setTaskName(taskName);
|
||||
taskExecution.setExternalExecutionId(externalExecutionId);
|
||||
|
||||
@@ -56,9 +56,8 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
* @author Michael Minella
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(
|
||||
classes = { TestConfiguration.class, EmbeddedDataSourceConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class })
|
||||
@ContextConfiguration(classes = { TestConfiguration.class, EmbeddedDataSourceConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class })
|
||||
public class JdbcTaskExecutionDaoTests extends BaseTaskExecutionDaoTestCases {
|
||||
|
||||
@Autowired
|
||||
@@ -77,65 +76,52 @@ public class JdbcTaskExecutionDaoTests extends BaseTaskExecutionDaoTestCases {
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testStartTaskExecution() {
|
||||
TaskExecution expectedTaskExecution = this.dao.createTaskExecution(null, null,
|
||||
new ArrayList<>(0), null);
|
||||
TaskExecution expectedTaskExecution = this.dao.createTaskExecution(null, null, new ArrayList<>(0), null);
|
||||
|
||||
expectedTaskExecution.setArguments(
|
||||
Collections.singletonList("foo=" + UUID.randomUUID().toString()));
|
||||
expectedTaskExecution.setArguments(Collections.singletonList("foo=" + UUID.randomUUID().toString()));
|
||||
expectedTaskExecution.setStartTime(new Date());
|
||||
expectedTaskExecution.setTaskName(UUID.randomUUID().toString());
|
||||
|
||||
this.dao.startTaskExecution(expectedTaskExecution.getExecutionId(),
|
||||
expectedTaskExecution.getTaskName(), expectedTaskExecution.getStartTime(),
|
||||
expectedTaskExecution.getArguments(),
|
||||
this.dao.startTaskExecution(expectedTaskExecution.getExecutionId(), expectedTaskExecution.getTaskName(),
|
||||
expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments(),
|
||||
expectedTaskExecution.getExternalExecutionId());
|
||||
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
|
||||
TestDBUtils.getTaskExecutionFromDB(this.dataSource,
|
||||
expectedTaskExecution.getExecutionId()));
|
||||
TestDBUtils.getTaskExecutionFromDB(this.dataSource, expectedTaskExecution.getExecutionId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void createTaskExecution() {
|
||||
TaskExecution expectedTaskExecution = TestVerifierUtils
|
||||
.createSampleTaskExecutionNoArg();
|
||||
expectedTaskExecution = this.dao.createTaskExecution(
|
||||
expectedTaskExecution.getTaskName(), expectedTaskExecution.getStartTime(),
|
||||
expectedTaskExecution.getArguments(),
|
||||
TaskExecution expectedTaskExecution = TestVerifierUtils.createSampleTaskExecutionNoArg();
|
||||
expectedTaskExecution = this.dao.createTaskExecution(expectedTaskExecution.getTaskName(),
|
||||
expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments(),
|
||||
expectedTaskExecution.getExternalExecutionId());
|
||||
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
|
||||
TestDBUtils.getTaskExecutionFromDB(this.dataSource,
|
||||
expectedTaskExecution.getExecutionId()));
|
||||
TestDBUtils.getTaskExecutionFromDB(this.dataSource, expectedTaskExecution.getExecutionId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void createEmptyTaskExecution() {
|
||||
TaskExecution expectedTaskExecution = this.dao.createTaskExecution(null, null,
|
||||
new ArrayList<>(0), null);
|
||||
TaskExecution expectedTaskExecution = this.dao.createTaskExecution(null, null, new ArrayList<>(0), null);
|
||||
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
|
||||
TestDBUtils.getTaskExecutionFromDB(this.dataSource,
|
||||
expectedTaskExecution.getExecutionId()));
|
||||
TestDBUtils.getTaskExecutionFromDB(this.dataSource, expectedTaskExecution.getExecutionId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void completeTaskExecution() {
|
||||
TaskExecution expectedTaskExecution = TestVerifierUtils
|
||||
.endSampleTaskExecutionNoArg();
|
||||
expectedTaskExecution = this.dao.createTaskExecution(
|
||||
expectedTaskExecution.getTaskName(), expectedTaskExecution.getStartTime(),
|
||||
expectedTaskExecution.getArguments(),
|
||||
TaskExecution expectedTaskExecution = TestVerifierUtils.endSampleTaskExecutionNoArg();
|
||||
expectedTaskExecution = this.dao.createTaskExecution(expectedTaskExecution.getTaskName(),
|
||||
expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments(),
|
||||
expectedTaskExecution.getExternalExecutionId());
|
||||
this.dao.completeTaskExecution(expectedTaskExecution.getExecutionId(),
|
||||
expectedTaskExecution.getExitCode(), expectedTaskExecution.getEndTime(),
|
||||
expectedTaskExecution.getExitMessage());
|
||||
this.dao.completeTaskExecution(expectedTaskExecution.getExecutionId(), expectedTaskExecution.getExitCode(),
|
||||
expectedTaskExecution.getEndTime(), expectedTaskExecution.getExitMessage());
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
|
||||
TestDBUtils.getTaskExecutionFromDB(this.dataSource,
|
||||
expectedTaskExecution.getExecutionId()));
|
||||
TestDBUtils.getTaskExecutionFromDB(this.dataSource, expectedTaskExecution.getExecutionId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -143,13 +129,10 @@ public class JdbcTaskExecutionDaoTests extends BaseTaskExecutionDaoTestCases {
|
||||
public void completeTaskExecutionWithNoCreate() {
|
||||
JdbcTaskExecutionDao dao = new JdbcTaskExecutionDao(this.dataSource);
|
||||
|
||||
TaskExecution expectedTaskExecution = TestVerifierUtils
|
||||
.endSampleTaskExecutionNoArg();
|
||||
TaskExecution expectedTaskExecution = TestVerifierUtils.endSampleTaskExecutionNoArg();
|
||||
assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> {
|
||||
dao.completeTaskExecution(expectedTaskExecution.getExecutionId(),
|
||||
expectedTaskExecution.getExitCode(),
|
||||
expectedTaskExecution.getEndTime(),
|
||||
expectedTaskExecution.getExitMessage());
|
||||
dao.completeTaskExecution(expectedTaskExecution.getExecutionId(), expectedTaskExecution.getExitCode(),
|
||||
expectedTaskExecution.getEndTime(), expectedTaskExecution.getExitMessage());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -189,12 +172,10 @@ public class JdbcTaskExecutionDaoTests extends BaseTaskExecutionDaoTestCases {
|
||||
public void testStartExecutionWithNullExternalExecutionIdExisting() {
|
||||
TaskExecution expectedTaskExecution = initializeTaskExecutionWithExternalExecutionId();
|
||||
|
||||
this.dao.startTaskExecution(expectedTaskExecution.getExecutionId(),
|
||||
expectedTaskExecution.getTaskName(), expectedTaskExecution.getStartTime(),
|
||||
expectedTaskExecution.getArguments(), null);
|
||||
this.dao.startTaskExecution(expectedTaskExecution.getExecutionId(), expectedTaskExecution.getTaskName(),
|
||||
expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments(), null);
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
|
||||
TestDBUtils.getTaskExecutionFromDB(this.dataSource,
|
||||
expectedTaskExecution.getExecutionId()));
|
||||
TestDBUtils.getTaskExecutionFromDB(this.dataSource, expectedTaskExecution.getExecutionId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -202,50 +183,48 @@ public class JdbcTaskExecutionDaoTests extends BaseTaskExecutionDaoTestCases {
|
||||
public void testStartExecutionWithNullExternalExecutionIdNonExisting() {
|
||||
TaskExecution expectedTaskExecution = initializeTaskExecutionWithExternalExecutionId();
|
||||
|
||||
this.dao.startTaskExecution(expectedTaskExecution.getExecutionId(),
|
||||
expectedTaskExecution.getTaskName(), expectedTaskExecution.getStartTime(),
|
||||
expectedTaskExecution.getArguments(), "BAR");
|
||||
this.dao.startTaskExecution(expectedTaskExecution.getExecutionId(), expectedTaskExecution.getTaskName(),
|
||||
expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments(), "BAR");
|
||||
expectedTaskExecution.setExternalExecutionId("BAR");
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
|
||||
TestDBUtils.getTaskExecutionFromDB(this.dataSource,
|
||||
expectedTaskExecution.getExecutionId()));
|
||||
TestDBUtils.getTaskExecutionFromDB(this.dataSource, expectedTaskExecution.getExecutionId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testFindRunningTaskExecutions() {
|
||||
initializeRepositoryNotInOrderWithMultipleTaskExecutions();
|
||||
assertThat(this.dao.findRunningTaskExecutions("FOO1", PageRequest.of(1, Integer.MAX_VALUE, Sort.by("START_TIME"))).getTotalElements())
|
||||
.isEqualTo(4);
|
||||
assertThat(
|
||||
this.dao.findRunningTaskExecutions("FOO1", PageRequest.of(1, Integer.MAX_VALUE, Sort.by("START_TIME")))
|
||||
.getTotalElements()).isEqualTo(4);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testFindRunningTaskExecutionsIllegalSort() {
|
||||
initializeRepositoryNotInOrderWithMultipleTaskExecutions();
|
||||
assertThatThrownBy(() -> this.dao.findRunningTaskExecutions("FOO1", PageRequest.of(1, Integer.MAX_VALUE, Sort.by("ILLEGAL_SORT"))).getTotalElements())
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("Invalid sort option selected: ILLEGAL_SORT");
|
||||
assertThatThrownBy(() -> this.dao
|
||||
.findRunningTaskExecutions("FOO1", PageRequest.of(1, Integer.MAX_VALUE, Sort.by("ILLEGAL_SORT")))
|
||||
.getTotalElements()).isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("Invalid sort option selected: ILLEGAL_SORT");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testFindRunningTaskExecutionsSortWithDifferentCase() {
|
||||
initializeRepositoryNotInOrderWithMultipleTaskExecutions();
|
||||
assertThat(this.dao.findRunningTaskExecutions("FOO1", PageRequest.of(1, Integer.MAX_VALUE, Sort.by("StArT_TiMe"))).getTotalElements())
|
||||
.isEqualTo(4);
|
||||
assertThat(
|
||||
this.dao.findRunningTaskExecutions("FOO1", PageRequest.of(1, Integer.MAX_VALUE, Sort.by("StArT_TiMe")))
|
||||
.getTotalElements()).isEqualTo(4);
|
||||
}
|
||||
|
||||
private TaskExecution initializeTaskExecutionWithExternalExecutionId() {
|
||||
TaskExecution expectedTaskExecution = TestVerifierUtils
|
||||
.createSampleTaskExecutionNoArg();
|
||||
return this.dao.createTaskExecution(expectedTaskExecution.getTaskName(),
|
||||
expectedTaskExecution.getStartTime(),
|
||||
TaskExecution expectedTaskExecution = TestVerifierUtils.createSampleTaskExecutionNoArg();
|
||||
return this.dao.createTaskExecution(expectedTaskExecution.getTaskName(), expectedTaskExecution.getStartTime(),
|
||||
expectedTaskExecution.getArguments(), "FOO1");
|
||||
}
|
||||
|
||||
private Iterator<TaskExecution> getPageIterator(int pageNum, int pageSize,
|
||||
Sort sort) {
|
||||
private Iterator<TaskExecution> getPageIterator(int pageNum, int pageSize, Sort sort) {
|
||||
Pageable pageable = (sort == null) ? PageRequest.of(pageNum, pageSize)
|
||||
: PageRequest.of(pageNum, pageSize, sort);
|
||||
Page<TaskExecution> page = this.dao.findAll(pageable);
|
||||
|
||||
@@ -52,20 +52,16 @@ public class MapTaskExecutionDaoTests extends BaseTaskExecutionDaoTestCases {
|
||||
|
||||
@Test
|
||||
public void testStartTaskExecution() {
|
||||
TaskExecution expectedTaskExecution = this.dao.createTaskExecution(null, null,
|
||||
new ArrayList<>(0), null);
|
||||
TaskExecution expectedTaskExecution = this.dao.createTaskExecution(null, null, new ArrayList<>(0), null);
|
||||
|
||||
expectedTaskExecution.setArguments(
|
||||
Collections.singletonList("foo=" + UUID.randomUUID().toString()));
|
||||
expectedTaskExecution.setArguments(Collections.singletonList("foo=" + UUID.randomUUID().toString()));
|
||||
expectedTaskExecution.setStartTime(new Date());
|
||||
expectedTaskExecution.setTaskName(UUID.randomUUID().toString());
|
||||
|
||||
this.dao.startTaskExecution(expectedTaskExecution.getExecutionId(),
|
||||
expectedTaskExecution.getTaskName(), expectedTaskExecution.getStartTime(),
|
||||
expectedTaskExecution.getArguments(),
|
||||
this.dao.startTaskExecution(expectedTaskExecution.getExecutionId(), expectedTaskExecution.getTaskName(),
|
||||
expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments(),
|
||||
expectedTaskExecution.getExternalExecutionId());
|
||||
Map<Long, TaskExecution> taskExecutionMap = this.mapTaskExecutionDao
|
||||
.getTaskExecutions();
|
||||
Map<Long, TaskExecution> taskExecutionMap = this.mapTaskExecutionDao.getTaskExecutions();
|
||||
assertThat(taskExecutionMap).as("taskExecutionMap must not be null").isNotNull();
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
|
||||
taskExecutionMap.get(expectedTaskExecution.getExecutionId()));
|
||||
@@ -73,37 +69,29 @@ public class MapTaskExecutionDaoTests extends BaseTaskExecutionDaoTestCases {
|
||||
|
||||
@Test
|
||||
public void createEmptyTaskExecution() {
|
||||
TaskExecution expectedTaskExecution = this.dao.createTaskExecution(null, null,
|
||||
new ArrayList<>(0), null);
|
||||
TaskExecution expectedTaskExecution = this.dao.createTaskExecution(null, null, new ArrayList<>(0), null);
|
||||
|
||||
Map<Long, TaskExecution> taskExecutionMap = this.mapTaskExecutionDao
|
||||
.getTaskExecutions();
|
||||
Map<Long, TaskExecution> taskExecutionMap = this.mapTaskExecutionDao.getTaskExecutions();
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
|
||||
taskExecutionMap.get(expectedTaskExecution.getExecutionId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void completeTaskExecutionWithNoCreate() {
|
||||
TaskExecution expectedTaskExecution = TestVerifierUtils
|
||||
.createSampleTaskExecutionNoArg();
|
||||
TaskExecution expectedTaskExecution = TestVerifierUtils.createSampleTaskExecutionNoArg();
|
||||
assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> {
|
||||
this.dao.completeTaskExecution(expectedTaskExecution.getExecutionId(),
|
||||
expectedTaskExecution.getExitCode(),
|
||||
expectedTaskExecution.getEndTime(),
|
||||
expectedTaskExecution.getExitMessage());
|
||||
this.dao.completeTaskExecution(expectedTaskExecution.getExecutionId(), expectedTaskExecution.getExitCode(),
|
||||
expectedTaskExecution.getEndTime(), expectedTaskExecution.getExitMessage());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void saveTaskExecution() {
|
||||
TaskExecution expectedTaskExecution = TestVerifierUtils
|
||||
.createSampleTaskExecutionNoArg();
|
||||
expectedTaskExecution = this.dao.createTaskExecution(
|
||||
expectedTaskExecution.getTaskName(), expectedTaskExecution.getStartTime(),
|
||||
expectedTaskExecution.getArguments(),
|
||||
TaskExecution expectedTaskExecution = TestVerifierUtils.createSampleTaskExecutionNoArg();
|
||||
expectedTaskExecution = this.dao.createTaskExecution(expectedTaskExecution.getTaskName(),
|
||||
expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments(),
|
||||
expectedTaskExecution.getExternalExecutionId());
|
||||
Map<Long, TaskExecution> taskExecutionMap = this.mapTaskExecutionDao
|
||||
.getTaskExecutions();
|
||||
Map<Long, TaskExecution> taskExecutionMap = this.mapTaskExecutionDao.getTaskExecutions();
|
||||
assertThat(taskExecutionMap).as("taskExecutionMap must not be null").isNotNull();
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
|
||||
taskExecutionMap.get(expectedTaskExecution.getExecutionId()));
|
||||
@@ -111,17 +99,13 @@ public class MapTaskExecutionDaoTests extends BaseTaskExecutionDaoTestCases {
|
||||
|
||||
@Test
|
||||
public void completeTaskExecution() {
|
||||
TaskExecution expectedTaskExecution = TestVerifierUtils
|
||||
.createSampleTaskExecutionNoArg();
|
||||
expectedTaskExecution = this.dao.createTaskExecution(
|
||||
expectedTaskExecution.getTaskName(), expectedTaskExecution.getStartTime(),
|
||||
expectedTaskExecution.getArguments(),
|
||||
TaskExecution expectedTaskExecution = TestVerifierUtils.createSampleTaskExecutionNoArg();
|
||||
expectedTaskExecution = this.dao.createTaskExecution(expectedTaskExecution.getTaskName(),
|
||||
expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments(),
|
||||
expectedTaskExecution.getExternalExecutionId());
|
||||
this.dao.completeTaskExecution(expectedTaskExecution.getExecutionId(),
|
||||
expectedTaskExecution.getExitCode(), expectedTaskExecution.getEndTime(),
|
||||
expectedTaskExecution.getExitMessage());
|
||||
Map<Long, TaskExecution> taskExecutionMap = this.mapTaskExecutionDao
|
||||
.getTaskExecutions();
|
||||
this.dao.completeTaskExecution(expectedTaskExecution.getExecutionId(), expectedTaskExecution.getExitCode(),
|
||||
expectedTaskExecution.getEndTime(), expectedTaskExecution.getExitMessage());
|
||||
Map<Long, TaskExecution> taskExecutionMap = this.mapTaskExecutionDao.getTaskExecutions();
|
||||
assertThat(taskExecutionMap).as("taskExecutionMap must not be null").isNotNull();
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
|
||||
taskExecutionMap.get(expectedTaskExecution.getExecutionId()));
|
||||
@@ -134,37 +118,31 @@ public class MapTaskExecutionDaoTests extends BaseTaskExecutionDaoTestCases {
|
||||
expectedTaskExecutionList.add(TestVerifierUtils.createSampleTaskExecutionNoArg());
|
||||
|
||||
for (TaskExecution expectedTaskExecution : expectedTaskExecutionList) {
|
||||
expectedTaskExecution = this.dao.createTaskExecution(
|
||||
expectedTaskExecution.getTaskName(),
|
||||
expectedTaskExecution.getStartTime(),
|
||||
expectedTaskExecution.getArguments(),
|
||||
expectedTaskExecution = this.dao.createTaskExecution(expectedTaskExecution.getTaskName(),
|
||||
expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments(),
|
||||
expectedTaskExecution.getExternalExecutionId());
|
||||
this.dao.completeTaskExecution(expectedTaskExecution.getExecutionId(),
|
||||
expectedTaskExecution.getExitCode(),
|
||||
expectedTaskExecution.getEndTime(),
|
||||
expectedTaskExecution.getExitMessage());
|
||||
this.dao.completeTaskExecution(expectedTaskExecution.getExecutionId(), expectedTaskExecution.getExitCode(),
|
||||
expectedTaskExecution.getEndTime(), expectedTaskExecution.getExitMessage());
|
||||
}
|
||||
Set<Long> jobIds = new HashSet<>(2);
|
||||
jobIds.add(123L);
|
||||
jobIds.add(456L);
|
||||
this.mapTaskExecutionDao.getBatchJobAssociations()
|
||||
.put(expectedTaskExecutionList.get(0).getExecutionId(), jobIds);
|
||||
this.mapTaskExecutionDao.getBatchJobAssociations().put(expectedTaskExecutionList.get(0).getExecutionId(),
|
||||
jobIds);
|
||||
|
||||
assertThat(this.dao.getTaskExecutionIdByJobExecutionId(123L)).isEqualTo(
|
||||
Long.valueOf(expectedTaskExecutionList.get(0).getExecutionId()));
|
||||
assertThat(this.dao.getTaskExecutionIdByJobExecutionId(456L)).isEqualTo(
|
||||
Long.valueOf(expectedTaskExecutionList.get(0).getExecutionId()));
|
||||
assertThat(this.dao.getTaskExecutionIdByJobExecutionId(123L))
|
||||
.isEqualTo(Long.valueOf(expectedTaskExecutionList.get(0).getExecutionId()));
|
||||
assertThat(this.dao.getTaskExecutionIdByJobExecutionId(456L))
|
||||
.isEqualTo(Long.valueOf(expectedTaskExecutionList.get(0).getExecutionId()));
|
||||
assertThat(this.dao.getTaskExecutionIdByJobExecutionId(789L)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStartExecutionWithNullExternalExecutionIdExisting() {
|
||||
TaskExecution expectedTaskExecution = initializeTaskExecutionWithExternalExecutionId();
|
||||
Map<Long, TaskExecution> taskExecutionMap = this.mapTaskExecutionDao
|
||||
.getTaskExecutions();
|
||||
this.dao.startTaskExecution(expectedTaskExecution.getExecutionId(),
|
||||
expectedTaskExecution.getTaskName(), expectedTaskExecution.getStartTime(),
|
||||
expectedTaskExecution.getArguments(), null);
|
||||
Map<Long, TaskExecution> taskExecutionMap = this.mapTaskExecutionDao.getTaskExecutions();
|
||||
this.dao.startTaskExecution(expectedTaskExecution.getExecutionId(), expectedTaskExecution.getTaskName(),
|
||||
expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments(), null);
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
|
||||
taskExecutionMap.get(expectedTaskExecution.getExecutionId()));
|
||||
}
|
||||
@@ -172,20 +150,16 @@ public class MapTaskExecutionDaoTests extends BaseTaskExecutionDaoTestCases {
|
||||
@Test
|
||||
public void testStartExecutionWithNullExternalExecutionIdNonExisting() {
|
||||
TaskExecution expectedTaskExecution = initializeTaskExecutionWithExternalExecutionId();
|
||||
Map<Long, TaskExecution> taskExecutionMap = this.mapTaskExecutionDao
|
||||
.getTaskExecutions();
|
||||
this.dao.startTaskExecution(expectedTaskExecution.getExecutionId(),
|
||||
expectedTaskExecution.getTaskName(), expectedTaskExecution.getStartTime(),
|
||||
expectedTaskExecution.getArguments(), "BAR");
|
||||
Map<Long, TaskExecution> taskExecutionMap = this.mapTaskExecutionDao.getTaskExecutions();
|
||||
this.dao.startTaskExecution(expectedTaskExecution.getExecutionId(), expectedTaskExecution.getTaskName(),
|
||||
expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments(), "BAR");
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
|
||||
taskExecutionMap.get(expectedTaskExecution.getExecutionId()));
|
||||
}
|
||||
|
||||
private TaskExecution initializeTaskExecutionWithExternalExecutionId() {
|
||||
TaskExecution expectedTaskExecution = TestVerifierUtils
|
||||
.createSampleTaskExecutionNoArg();
|
||||
return this.dao.createTaskExecution(expectedTaskExecution.getTaskName(),
|
||||
expectedTaskExecution.getStartTime(),
|
||||
TaskExecution expectedTaskExecution = TestVerifierUtils.createSampleTaskExecutionNoArg();
|
||||
return this.dao.createTaskExecution(expectedTaskExecution.getTaskName(), expectedTaskExecution.getStartTime(),
|
||||
expectedTaskExecution.getArguments(), "FOO1");
|
||||
}
|
||||
|
||||
|
||||
@@ -37,16 +37,14 @@ public class FindAllPagingQueryProviderTests {
|
||||
private Pageable pageable = PageRequest.of(0, 10);
|
||||
|
||||
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, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID FROM "
|
||||
+ "(SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, TASK_NAME, "
|
||||
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID, ROWNUM as "
|
||||
+ "TMP_ROW_NUM FROM (SELECT TASK_EXECUTION_ID, START_TIME, "
|
||||
+ "END_TIME, TASK_NAME, EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID "
|
||||
+ "FROM %PREFIX%EXECUTION ORDER BY START_TIME DESC, "
|
||||
+ "TASK_EXECUTION_ID DESC)) WHERE TMP_ROW_NUM >= 1 AND "
|
||||
+ "TMP_ROW_NUM < 11" },
|
||||
return Arrays.asList(new Object[][] { { "Oracle", "SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, TASK_NAME, "
|
||||
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID FROM "
|
||||
+ "(SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, TASK_NAME, "
|
||||
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID, ROWNUM as "
|
||||
+ "TMP_ROW_NUM FROM (SELECT TASK_EXECUTION_ID, START_TIME, "
|
||||
+ "END_TIME, TASK_NAME, EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID "
|
||||
+ "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, "
|
||||
+ "ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID FROM %PREFIX%EXECUTION ORDER BY "
|
||||
@@ -57,37 +55,31 @@ public class FindAllPagingQueryProviderTests {
|
||||
+ "TASK_EXECUTION_ID DESC LIMIT 10 OFFSET 0" },
|
||||
{ "MySQL", "SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, TASK_NAME, "
|
||||
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID 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, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID FROM "
|
||||
+ "(SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, TASK_NAME, "
|
||||
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID, 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, "
|
||||
+ "TASK_EXECUTION_ID DESC" },
|
||||
{ "DB2/Linux",
|
||||
"SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, "
|
||||
+ "TASK_NAME, EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID FROM "
|
||||
+ "(SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, TASK_NAME, "
|
||||
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID, ROW_NUMBER() "
|
||||
+ "OVER() as TMP_ROW_NUM FROM "
|
||||
+ "(SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, TASK_NAME, EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, "
|
||||
+ "EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID FROM %PREFIX%EXECUTION ORDER BY START_TIME DESC, TASK_EXECUTION_ID DESC)) "
|
||||
+ "WHERE TMP_ROW_NUM >= 1 AND TMP_ROW_NUM < 11"}});
|
||||
+ "%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, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID FROM "
|
||||
+ "(SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, TASK_NAME, "
|
||||
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID, 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, "
|
||||
+ "TASK_EXECUTION_ID DESC" },
|
||||
{ "DB2/Linux", "SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, "
|
||||
+ "TASK_NAME, EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID FROM "
|
||||
+ "(SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, TASK_NAME, "
|
||||
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID, ROW_NUMBER() "
|
||||
+ "OVER() as TMP_ROW_NUM FROM "
|
||||
+ "(SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, TASK_NAME, EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, "
|
||||
+ "EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID FROM %PREFIX%EXECUTION ORDER BY START_TIME DESC, TASK_EXECUTION_ID DESC)) "
|
||||
+ "WHERE TMP_ROW_NUM >= 1 AND TMP_ROW_NUM < 11" } });
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("data")
|
||||
public void testGeneratedQuery(String databaseProductName, String expectedQuery)
|
||||
throws Exception {
|
||||
String actualQuery = TestDBUtils.getPagingQueryProvider(databaseProductName)
|
||||
.getPageQuery(this.pageable);
|
||||
assertThat(actualQuery).as(
|
||||
String.format("the generated query for %s, was not the expected query",
|
||||
databaseProductName))
|
||||
public void testGeneratedQuery(String databaseProductName, String expectedQuery) throws Exception {
|
||||
String actualQuery = TestDBUtils.getPagingQueryProvider(databaseProductName).getPageQuery(this.pageable);
|
||||
assertThat(actualQuery)
|
||||
.as(String.format("the generated query for %s, was not the expected query", databaseProductName))
|
||||
.isEqualTo(expectedQuery);
|
||||
}
|
||||
|
||||
|
||||
@@ -64,16 +64,12 @@ class H2PagingQueryProviderTests {
|
||||
sortKeys.put("ID", Order.ASCENDING);
|
||||
queryProvider.setSortKeys(sortKeys);
|
||||
|
||||
List<String> firstPage = jdbcTemplate.queryForList(
|
||||
queryProvider.getPageQuery(PageRequest.of(0, 2)),
|
||||
String.class
|
||||
);
|
||||
List<String> firstPage = jdbcTemplate.queryForList(queryProvider.getPageQuery(PageRequest.of(0, 2)),
|
||||
String.class);
|
||||
assertThat(firstPage).containsExactly("Spring", "Cloud");
|
||||
|
||||
List<String> secondPage = jdbcTemplate.queryForList(
|
||||
queryProvider.getPageQuery(PageRequest.of(1, 2)),
|
||||
String.class
|
||||
);
|
||||
List<String> secondPage = jdbcTemplate.queryForList(queryProvider.getPageQuery(PageRequest.of(1, 2)),
|
||||
String.class);
|
||||
assertThat(secondPage).containsExactly("Task");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -37,53 +37,45 @@ public class WhereClausePagingQueryProviderTests {
|
||||
private Pageable pageable = PageRequest.of(0, 10);
|
||||
|
||||
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, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID FROM "
|
||||
+ "(SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, TASK_NAME, "
|
||||
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID, ROWNUM as "
|
||||
+ "TMP_ROW_NUM FROM (SELECT TASK_EXECUTION_ID, START_TIME, "
|
||||
+ "END_TIME, TASK_NAME, EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, "
|
||||
+ "LAST_UPDATED, EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID 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" },
|
||||
return Arrays.asList(new Object[][] { { "Oracle", "SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, TASK_NAME, "
|
||||
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID FROM "
|
||||
+ "(SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, TASK_NAME, "
|
||||
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID, ROWNUM as "
|
||||
+ "TMP_ROW_NUM FROM (SELECT TASK_EXECUTION_ID, START_TIME, "
|
||||
+ "END_TIME, TASK_NAME, EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, "
|
||||
+ "LAST_UPDATED, EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID 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, "
|
||||
+ "ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID FROM %PREFIX%EXECUTION "
|
||||
+ "WHERE TASK_EXECUTION_ID = '0000' ORDER BY "
|
||||
+ "START_TIME DESC, TASK_EXECUTION_ID DESC" },
|
||||
+ "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, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID "
|
||||
+ "FROM %PREFIX%EXECUTION WHERE TASK_EXECUTION_ID = '0000' "
|
||||
+ "ORDER BY START_TIME DESC, "
|
||||
+ "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, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID FROM "
|
||||
+ "%PREFIX%EXECUTION WHERE TASK_EXECUTION_ID = '0000' "
|
||||
+ "ORDER BY START_TIME DESC, "
|
||||
+ "%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, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID FROM "
|
||||
+ "(SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, TASK_NAME, "
|
||||
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID, 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 "
|
||||
+ "AND TMP_ROW_NUM < 11 ORDER BY START_TIME DESC, TASK_EXECUTION_ID DESC" } });
|
||||
{ "Microsoft SQL Server", "SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, "
|
||||
+ "TASK_NAME, EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID FROM "
|
||||
+ "(SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, TASK_NAME, "
|
||||
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID, 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 "
|
||||
+ "AND TMP_ROW_NUM < 11 ORDER BY START_TIME DESC, TASK_EXECUTION_ID DESC" } });
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("data")
|
||||
public void testGeneratedQuery(String databaseProductName, String expectedQuery)
|
||||
throws Exception {
|
||||
PagingQueryProvider pagingQueryProvider = TestDBUtils.getPagingQueryProvider(
|
||||
databaseProductName, "TASK_EXECUTION_ID = '0000'");
|
||||
public void testGeneratedQuery(String databaseProductName, String expectedQuery) throws Exception {
|
||||
PagingQueryProvider pagingQueryProvider = TestDBUtils.getPagingQueryProvider(databaseProductName,
|
||||
"TASK_EXECUTION_ID = '0000'");
|
||||
String actualQuery = pagingQueryProvider.getPageQuery(this.pageable);
|
||||
assertThat(actualQuery).as(
|
||||
String.format("the generated query for %s, was not the expected query",
|
||||
databaseProductName))
|
||||
assertThat(actualQuery)
|
||||
.as(String.format("the generated query for %s, was not the expected query", databaseProductName))
|
||||
.isEqualTo(expectedQuery);
|
||||
}
|
||||
|
||||
|
||||
@@ -51,8 +51,7 @@ public class DatabaseTypeTests {
|
||||
|
||||
@Test
|
||||
public void testInvalidProductName() {
|
||||
assertThatExceptionOfType(IllegalArgumentException.class)
|
||||
.isThrownBy(() -> fromProductName("bad product name"));
|
||||
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> fromProductName("bad product name"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -94,13 +94,10 @@ public class SimpleTaskExplorerTests {
|
||||
testDefaultContext(testType);
|
||||
Map<Long, TaskExecution> expectedResults = createSampleDataSet(5);
|
||||
for (Long taskExecutionId : expectedResults.keySet()) {
|
||||
TaskExecution actualTaskExecution = this.taskExplorer
|
||||
.getTaskExecution(taskExecutionId);
|
||||
assertThat(actualTaskExecution).as(String.format(
|
||||
"expected a taskExecution but got null for test type %s", testType))
|
||||
.isNotNull();
|
||||
TestVerifierUtils.verifyTaskExecution(expectedResults.get(taskExecutionId),
|
||||
actualTaskExecution);
|
||||
TaskExecution actualTaskExecution = this.taskExplorer.getTaskExecution(taskExecutionId);
|
||||
assertThat(actualTaskExecution)
|
||||
.as(String.format("expected a taskExecution but got null for test type %s", testType)).isNotNull();
|
||||
TestVerifierUtils.verifyTaskExecution(expectedResults.get(taskExecutionId), actualTaskExecution);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,8 +108,7 @@ public class SimpleTaskExplorerTests {
|
||||
createSampleDataSet(5);
|
||||
|
||||
TaskExecution actualTaskExecution = this.taskExplorer.getTaskExecution(-5);
|
||||
assertThat(actualTaskExecution)
|
||||
.as(String.format("expected null for actualTaskExecution %s", testType))
|
||||
assertThat(actualTaskExecution).as(String.format("expected null for actualTaskExecution %s", testType))
|
||||
.isNull();
|
||||
}
|
||||
|
||||
@@ -123,10 +119,8 @@ public class SimpleTaskExplorerTests {
|
||||
Map<Long, TaskExecution> expectedResults = createSampleDataSet(5);
|
||||
for (Map.Entry<Long, TaskExecution> entry : expectedResults.entrySet()) {
|
||||
String taskName = entry.getValue().getTaskName();
|
||||
assertThat(this.taskExplorer.getTaskExecutionCountByTaskName(taskName))
|
||||
.as(String.format(
|
||||
"task count for task name did not match expected result for testType %s",
|
||||
testType))
|
||||
assertThat(this.taskExplorer.getTaskExecutionCountByTaskName(taskName)).as(
|
||||
String.format("task count for task name did not match expected result for testType %s", testType))
|
||||
.isEqualTo(1);
|
||||
}
|
||||
}
|
||||
@@ -136,9 +130,8 @@ public class SimpleTaskExplorerTests {
|
||||
public void getTaskCount(DaoType testType) {
|
||||
testDefaultContext(testType);
|
||||
createSampleDataSet(33);
|
||||
assertThat(this.taskExplorer.getTaskExecutionCount()).as(String.format(
|
||||
"task count did not match expected result for test Type %s", testType))
|
||||
.isEqualTo(33);
|
||||
assertThat(this.taskExplorer.getTaskExecutionCount())
|
||||
.as(String.format("task count did not match expected result for test Type %s", testType)).isEqualTo(33);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@@ -146,9 +139,8 @@ public class SimpleTaskExplorerTests {
|
||||
public void getRunningTaskCount(DaoType testType) {
|
||||
testDefaultContext(testType);
|
||||
createSampleDataSet(33);
|
||||
assertThat(this.taskExplorer.getRunningTaskExecutionCount()).as(String.format(
|
||||
"task count did not match expected result for test Type %s", testType))
|
||||
.isEqualTo(33);
|
||||
assertThat(this.taskExplorer.getRunningTaskExecutionCount())
|
||||
.as(String.format("task count did not match expected result for test Type %s", testType)).isEqualTo(33);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@@ -166,27 +158,23 @@ public class SimpleTaskExplorerTests {
|
||||
}
|
||||
|
||||
for (; i < (COMPLETE_COUNT + TEST_COUNT); i++) {
|
||||
TaskExecution expectedTaskExecution = this.taskRepository
|
||||
.createTaskExecution(getSimpleTaskExecution());
|
||||
expectedResults.put(expectedTaskExecution.getExecutionId(),
|
||||
expectedTaskExecution);
|
||||
TaskExecution expectedTaskExecution = this.taskRepository.createTaskExecution(getSimpleTaskExecution());
|
||||
expectedResults.put(expectedTaskExecution.getExecutionId(), expectedTaskExecution);
|
||||
}
|
||||
Pageable pageable = PageRequest.of(0, 10);
|
||||
|
||||
Page<TaskExecution> actualResults = this.taskExplorer
|
||||
.findRunningTaskExecutions(TASK_NAME, pageable);
|
||||
assertThat(actualResults.getNumberOfElements()).as(String.format(
|
||||
"Running task count for task name did not match expected result for testType %s",
|
||||
testType)).isEqualTo(TEST_COUNT);
|
||||
Page<TaskExecution> actualResults = this.taskExplorer.findRunningTaskExecutions(TASK_NAME, pageable);
|
||||
assertThat(actualResults.getNumberOfElements()).as(String
|
||||
.format("Running task count for task name did not match expected result for testType %s", testType))
|
||||
.isEqualTo(TEST_COUNT);
|
||||
|
||||
for (TaskExecution result : actualResults) {
|
||||
assertThat(expectedResults.containsKey(result.getExecutionId())).as(String
|
||||
.format("result returned from repo %s not expected for testType %s",
|
||||
assertThat(expectedResults.containsKey(result.getExecutionId()))
|
||||
.as(String.format("result returned from repo %s not expected for testType %s",
|
||||
result.getExecutionId(), testType))
|
||||
.isTrue();
|
||||
assertThat(result.getEndTime()).as(String.format(
|
||||
"result had non null for endTime for the testType %s", testType))
|
||||
.isNull();
|
||||
assertThat(result.getEndTime())
|
||||
.as(String.format("result had non null for endTime for the testType %s", testType)).isNull();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,26 +192,22 @@ public class SimpleTaskExplorerTests {
|
||||
}
|
||||
|
||||
for (int i = 0; i < TEST_COUNT; i++) {
|
||||
TaskExecution expectedTaskExecution = this.taskRepository
|
||||
.createTaskExecution(getSimpleTaskExecution());
|
||||
expectedResults.put(expectedTaskExecution.getExecutionId(),
|
||||
expectedTaskExecution);
|
||||
TaskExecution expectedTaskExecution = this.taskRepository.createTaskExecution(getSimpleTaskExecution());
|
||||
expectedResults.put(expectedTaskExecution.getExecutionId(), expectedTaskExecution);
|
||||
}
|
||||
|
||||
Pageable pageable = PageRequest.of(0, 10);
|
||||
Page<TaskExecution> resultSet = this.taskExplorer
|
||||
.findTaskExecutionsByName(TASK_NAME, pageable);
|
||||
assertThat(resultSet.getNumberOfElements()).as(String.format(
|
||||
"Running task count for task name did not match expected result for testType %s",
|
||||
testType)).isEqualTo(TEST_COUNT);
|
||||
Page<TaskExecution> resultSet = this.taskExplorer.findTaskExecutionsByName(TASK_NAME, pageable);
|
||||
assertThat(resultSet.getNumberOfElements()).as(String
|
||||
.format("Running task count for task name did not match expected result for testType %s", testType))
|
||||
.isEqualTo(TEST_COUNT);
|
||||
|
||||
for (TaskExecution result : resultSet) {
|
||||
assertThat(expectedResults.containsKey(result.getExecutionId()))
|
||||
.as(String.format("result returned from %s repo %s not expected",
|
||||
testType, result.getExecutionId()))
|
||||
assertThat(expectedResults.containsKey(result.getExecutionId())).as(
|
||||
String.format("result returned from %s repo %s not expected", testType, result.getExecutionId()))
|
||||
.isTrue();
|
||||
assertThat(result.getTaskName()).as(String.format(
|
||||
"taskName for taskExecution is incorrect for testType %s", testType))
|
||||
assertThat(result.getTaskName())
|
||||
.as(String.format("taskName for taskExecution is incorrect for testType %s", testType))
|
||||
.isEqualTo(TASK_NAME);
|
||||
}
|
||||
}
|
||||
@@ -240,9 +224,8 @@ public class SimpleTaskExplorerTests {
|
||||
}
|
||||
List<String> actualTaskNames = this.taskExplorer.getTaskNames();
|
||||
for (String taskName : actualTaskNames) {
|
||||
assertThat(expectedResults.contains(taskName)).as(String.format(
|
||||
"taskName was not in expected results for testType %s", testType))
|
||||
.isTrue();
|
||||
assertThat(expectedResults.contains(taskName))
|
||||
.as(String.format("taskName was not in expected results for testType %s", testType)).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -289,8 +272,7 @@ public class SimpleTaskExplorerTests {
|
||||
@MethodSource("data")
|
||||
public void findJobsExecutionIdsForInvalidTask(DaoType testType) {
|
||||
testDefaultContext(testType);
|
||||
assertThat(this.taskExplorer.getJobExecutionIdsByTaskExecutionId(555555L).size())
|
||||
.isEqualTo(0);
|
||||
assertThat(this.taskExplorer.getJobExecutionIdsByTaskExecutionId(555555L).size()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@@ -298,16 +280,12 @@ public class SimpleTaskExplorerTests {
|
||||
public void getLatestTaskExecutionForTaskName(DaoType testType) {
|
||||
testDefaultContext(testType);
|
||||
Map<Long, TaskExecution> expectedResults = createSampleDataSet(5);
|
||||
for (Map.Entry<Long, TaskExecution> taskExecutionMapEntry : expectedResults
|
||||
.entrySet()) {
|
||||
for (Map.Entry<Long, TaskExecution> taskExecutionMapEntry : expectedResults.entrySet()) {
|
||||
TaskExecution latestTaskExecution = this.taskExplorer
|
||||
.getLatestTaskExecutionForTaskName(
|
||||
taskExecutionMapEntry.getValue().getTaskName());
|
||||
assertThat(latestTaskExecution).as(String.format(
|
||||
"expected a taskExecution but got null for test type %s", testType))
|
||||
.isNotNull();
|
||||
TestVerifierUtils.verifyTaskExecution(
|
||||
expectedResults.get(latestTaskExecution.getExecutionId()),
|
||||
.getLatestTaskExecutionForTaskName(taskExecutionMapEntry.getValue().getTaskName());
|
||||
assertThat(latestTaskExecution)
|
||||
.as(String.format("expected a taskExecution but got null for test type %s", testType)).isNotNull();
|
||||
TestVerifierUtils.verifyTaskExecution(expectedResults.get(latestTaskExecution.getExecutionId()),
|
||||
latestTaskExecution);
|
||||
}
|
||||
}
|
||||
@@ -325,33 +303,26 @@ public class SimpleTaskExplorerTests {
|
||||
}
|
||||
|
||||
final List<TaskExecution> latestTaskExecutions = this.taskExplorer
|
||||
.getLatestTaskExecutionsByTaskNames(
|
||||
taskNamesAsList.toArray(new String[taskNamesAsList.size()]));
|
||||
.getLatestTaskExecutionsByTaskNames(taskNamesAsList.toArray(new String[taskNamesAsList.size()]));
|
||||
|
||||
for (TaskExecution latestTaskExecution : latestTaskExecutions) {
|
||||
assertThat(latestTaskExecution).as(String.format(
|
||||
"expected a taskExecution but got null for test type %s", testType))
|
||||
.isNotNull();
|
||||
TestVerifierUtils.verifyTaskExecution(
|
||||
expectedResults.get(latestTaskExecution.getExecutionId()),
|
||||
assertThat(latestTaskExecution)
|
||||
.as(String.format("expected a taskExecution but got null for test type %s", testType)).isNotNull();
|
||||
TestVerifierUtils.verifyTaskExecution(expectedResults.get(latestTaskExecution.getExecutionId()),
|
||||
latestTaskExecution);
|
||||
}
|
||||
}
|
||||
|
||||
private void verifyPageResults(Pageable pageable, int totalNumberOfExecs) {
|
||||
Map<Long, TaskExecution> expectedResults = createSampleDataSet(
|
||||
totalNumberOfExecs);
|
||||
Map<Long, TaskExecution> expectedResults = createSampleDataSet(totalNumberOfExecs);
|
||||
List<Long> sortedExecIds = getSortedOfTaskExecIds(expectedResults);
|
||||
Iterator<Long> expectedTaskExecutionIter = sortedExecIds.iterator();
|
||||
// Verify pageable totals
|
||||
Page<TaskExecution> taskPage = this.taskExplorer.findAll(pageable);
|
||||
int pagesExpected = (int) Math
|
||||
.ceil(totalNumberOfExecs / ((double) pageable.getPageSize()));
|
||||
assertThat(taskPage.getTotalPages())
|
||||
.as("actual page count return was not the expected total")
|
||||
int pagesExpected = (int) Math.ceil(totalNumberOfExecs / ((double) pageable.getPageSize()));
|
||||
assertThat(taskPage.getTotalPages()).as("actual page count return was not the expected total")
|
||||
.isEqualTo(pagesExpected);
|
||||
assertThat(taskPage.getTotalElements())
|
||||
.as("actual element count was not the expected count")
|
||||
assertThat(taskPage.getTotalElements()).as("actual element count was not the expected count")
|
||||
.isEqualTo(totalNumberOfExecs);
|
||||
|
||||
// Verify pagination
|
||||
@@ -367,16 +338,14 @@ public class SimpleTaskExplorerTests {
|
||||
if (!hasMorePages && pageable.getPageSize() != actualTaskExecutions.size()) {
|
||||
expectedPageSize = totalNumberOfExecs % pageable.getPageSize();
|
||||
}
|
||||
assertThat(actualTaskExecutions.size()).as(String.format(
|
||||
"Element count on page did not match on the %n page", pageNumber))
|
||||
assertThat(actualTaskExecutions.size())
|
||||
.as(String.format("Element count on page did not match on the %n page", pageNumber))
|
||||
.isEqualTo(expectedPageSize);
|
||||
for (TaskExecution actualExecution : actualTaskExecutions) {
|
||||
assertThat(actualExecution.getExecutionId())
|
||||
.as(String.format("Element on page %n did not match expected",
|
||||
pageNumber))
|
||||
.as(String.format("Element on page %n did not match expected", pageNumber))
|
||||
.isEqualTo((long) expectedTaskExecutionIter.next());
|
||||
TestVerifierUtils.verifyTaskExecution(
|
||||
expectedResults.get(actualExecution.getExecutionId()),
|
||||
TestVerifierUtils.verifyTaskExecution(expectedResults.get(actualExecution.getExecutionId()),
|
||||
actualExecution);
|
||||
elementCount++;
|
||||
}
|
||||
@@ -384,10 +353,8 @@ public class SimpleTaskExplorerTests {
|
||||
pageNumber++;
|
||||
}
|
||||
// Verify actual totals
|
||||
assertThat(pageNumber).as("Pages processed did not equal expected")
|
||||
.isEqualTo(pagesExpected);
|
||||
assertThat(elementCount).as("Elements processed did not equal expected,")
|
||||
.isEqualTo(totalNumberOfExecs);
|
||||
assertThat(pageNumber).as("Pages processed did not equal expected").isEqualTo(pagesExpected);
|
||||
assertThat(elementCount).as("Elements processed did not equal expected,").isEqualTo(totalNumberOfExecs);
|
||||
}
|
||||
|
||||
private TaskExecution createAndSaveTaskExecution(int i) {
|
||||
@@ -398,8 +365,7 @@ public class SimpleTaskExplorerTests {
|
||||
|
||||
private void initializeJdbcExplorerTest() {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context.register(TestConfiguration.class,
|
||||
EmbeddedDataSourceConfiguration.class,
|
||||
this.context.register(TestConfiguration.class, EmbeddedDataSourceConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
|
||||
@@ -409,8 +375,7 @@ public class SimpleTaskExplorerTests {
|
||||
|
||||
private void initializeMapExplorerTest() {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context.register(TestConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
this.context.register(TestConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
|
||||
this.context.getAutowireCapableBeanFactory().autowireBeanProperties(this,
|
||||
@@ -421,8 +386,7 @@ public class SimpleTaskExplorerTests {
|
||||
Map<Long, TaskExecution> expectedResults = new HashMap<>();
|
||||
for (int i = 0; i < count; i++) {
|
||||
TaskExecution expectedTaskExecution = createAndSaveTaskExecution(i);
|
||||
expectedResults.put(expectedTaskExecution.getExecutionId(),
|
||||
expectedTaskExecution);
|
||||
expectedResults.put(expectedTaskExecution.getExecutionId(), expectedTaskExecution);
|
||||
}
|
||||
return expectedResults;
|
||||
}
|
||||
@@ -444,8 +408,7 @@ public class SimpleTaskExplorerTests {
|
||||
public int compare(TaskExecution e1, TaskExecution e2) {
|
||||
int result = e1.getStartTime().compareTo(e2.getStartTime());
|
||||
if (result == 0) {
|
||||
result = Long.valueOf(e1.getExecutionId())
|
||||
.compareTo(e2.getExecutionId());
|
||||
result = Long.valueOf(e1.getExecutionId()).compareTo(e2.getExecutionId());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -34,9 +34,8 @@ public class SimpleTaskNameResolverTests {
|
||||
SimpleTaskNameResolver taskNameResolver = new SimpleTaskNameResolver();
|
||||
taskNameResolver.setApplicationContext(context);
|
||||
|
||||
assertThat(taskNameResolver.getTaskName().startsWith(
|
||||
"org.springframework.context.support.GenericApplicationContext"))
|
||||
.isTrue();
|
||||
assertThat(taskNameResolver.getTaskName()
|
||||
.startsWith("org.springframework.context.support.GenericApplicationContext")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -49,8 +49,8 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
* @author Ilayaperumal Gopinathan
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(classes = { EmbeddedDataSourceConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class })
|
||||
@ContextConfiguration(classes = { EmbeddedDataSourceConfiguration.class, SimpleTaskAutoConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class })
|
||||
@DirtiesContext
|
||||
public class SimpleTaskRepositoryJdbcTests {
|
||||
|
||||
@@ -65,8 +65,8 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
public void testCreateEmptyExecution() {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreEmptyTaskExecution(this.taskRepository);
|
||||
TaskExecution actualTaskExecution = TestDBUtils.getTaskExecutionFromDB(
|
||||
this.dataSource, expectedTaskExecution.getExecutionId());
|
||||
TaskExecution actualTaskExecution = TestDBUtils.getTaskExecutionFromDB(this.dataSource,
|
||||
expectedTaskExecution.getExecutionId());
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution, actualTaskExecution);
|
||||
}
|
||||
|
||||
@@ -75,8 +75,8 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
public void testCreateTaskExecutionNoParam() {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
TaskExecution actualTaskExecution = TestDBUtils.getTaskExecutionFromDB(
|
||||
this.dataSource, expectedTaskExecution.getExecutionId());
|
||||
TaskExecution actualTaskExecution = TestDBUtils.getTaskExecutionFromDB(this.dataSource,
|
||||
expectedTaskExecution.getExecutionId());
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution, actualTaskExecution);
|
||||
}
|
||||
|
||||
@@ -85,8 +85,8 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
public void testCreateTaskExecutionWithParam() {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionWithParams(this.taskRepository);
|
||||
TaskExecution actualTaskExecution = TestDBUtils.getTaskExecutionFromDB(
|
||||
this.dataSource, expectedTaskExecution.getExecutionId());
|
||||
TaskExecution actualTaskExecution = TestDBUtils.getTaskExecutionFromDB(this.dataSource,
|
||||
expectedTaskExecution.getExecutionId());
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution, actualTaskExecution);
|
||||
}
|
||||
|
||||
@@ -96,15 +96,13 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreEmptyTaskExecution(this.taskRepository);
|
||||
|
||||
expectedTaskExecution.setArguments(
|
||||
Collections.singletonList("foo=" + UUID.randomUUID().toString()));
|
||||
expectedTaskExecution.setArguments(Collections.singletonList("foo=" + UUID.randomUUID().toString()));
|
||||
expectedTaskExecution.setStartTime(new Date());
|
||||
expectedTaskExecution.setTaskName(UUID.randomUUID().toString());
|
||||
|
||||
TaskExecution actualTaskExecution = this.taskRepository.startTaskExecution(
|
||||
expectedTaskExecution.getExecutionId(),
|
||||
expectedTaskExecution.getTaskName(), expectedTaskExecution.getStartTime(),
|
||||
expectedTaskExecution.getArguments(),
|
||||
expectedTaskExecution.getExecutionId(), expectedTaskExecution.getTaskName(),
|
||||
expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments(),
|
||||
expectedTaskExecution.getExternalExecutionId());
|
||||
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution, actualTaskExecution);
|
||||
@@ -120,9 +118,8 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
expectedTaskExecution.setTaskName(UUID.randomUUID().toString());
|
||||
|
||||
TaskExecution actualTaskExecution = this.taskRepository.startTaskExecution(
|
||||
expectedTaskExecution.getExecutionId(),
|
||||
expectedTaskExecution.getTaskName(), expectedTaskExecution.getStartTime(),
|
||||
expectedTaskExecution.getArguments(),
|
||||
expectedTaskExecution.getExecutionId(), expectedTaskExecution.getTaskName(),
|
||||
expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments(),
|
||||
expectedTaskExecution.getExternalExecutionId());
|
||||
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution, actualTaskExecution);
|
||||
@@ -133,12 +130,10 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
expectedTaskExecution.setExternalExecutionId(UUID.randomUUID().toString());
|
||||
this.taskRepository.updateExternalExecutionId(
|
||||
expectedTaskExecution.getExecutionId(),
|
||||
this.taskRepository.updateExternalExecutionId(expectedTaskExecution.getExecutionId(),
|
||||
expectedTaskExecution.getExternalExecutionId());
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
|
||||
TestDBUtils.getTaskExecutionFromDB(this.dataSource,
|
||||
expectedTaskExecution.getExecutionId()));
|
||||
TestDBUtils.getTaskExecutionFromDB(this.dataSource, expectedTaskExecution.getExecutionId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -146,12 +141,10 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
expectedTaskExecution.setExternalExecutionId(null);
|
||||
this.taskRepository.updateExternalExecutionId(
|
||||
expectedTaskExecution.getExecutionId(),
|
||||
this.taskRepository.updateExternalExecutionId(expectedTaskExecution.getExecutionId(),
|
||||
expectedTaskExecution.getExternalExecutionId());
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
|
||||
TestDBUtils.getTaskExecutionFromDB(this.dataSource,
|
||||
expectedTaskExecution.getExecutionId()));
|
||||
TestDBUtils.getTaskExecutionFromDB(this.dataSource, expectedTaskExecution.getExecutionId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -160,8 +153,7 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
expectedTaskExecution.setExternalExecutionId(null);
|
||||
assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> {
|
||||
this.taskRepository.updateExternalExecutionId(-1,
|
||||
expectedTaskExecution.getExternalExecutionId());
|
||||
this.taskRepository.updateExternalExecutionId(-1, expectedTaskExecution.getExternalExecutionId());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -176,11 +168,9 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
expectedTaskExecution.setParentExecutionId(12345L);
|
||||
|
||||
TaskExecution actualTaskExecution = this.taskRepository.startTaskExecution(
|
||||
expectedTaskExecution.getExecutionId(),
|
||||
expectedTaskExecution.getTaskName(), expectedTaskExecution.getStartTime(),
|
||||
expectedTaskExecution.getArguments(),
|
||||
expectedTaskExecution.getExternalExecutionId(),
|
||||
expectedTaskExecution.getParentExecutionId());
|
||||
expectedTaskExecution.getExecutionId(), expectedTaskExecution.getTaskName(),
|
||||
expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments(),
|
||||
expectedTaskExecution.getExternalExecutionId(), expectedTaskExecution.getParentExecutionId());
|
||||
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution, actualTaskExecution);
|
||||
}
|
||||
@@ -194,8 +184,8 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
expectedTaskExecution.setExitCode(77);
|
||||
expectedTaskExecution.setExitMessage(UUID.randomUUID().toString());
|
||||
|
||||
TaskExecution actualTaskExecution = TaskExecutionCreator
|
||||
.completeExecution(this.taskRepository, expectedTaskExecution);
|
||||
TaskExecution actualTaskExecution = TaskExecutionCreator.completeExecution(this.taskRepository,
|
||||
expectedTaskExecution);
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution, actualTaskExecution);
|
||||
}
|
||||
|
||||
@@ -204,14 +194,11 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
public void testCreateTaskExecutionNoParamMaxExitDefaultMessageSize() {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
expectedTaskExecution.setExitMessage(
|
||||
new String(new char[SimpleTaskRepository.MAX_EXIT_MESSAGE_SIZE + 1]));
|
||||
expectedTaskExecution.setExitMessage(new String(new char[SimpleTaskRepository.MAX_EXIT_MESSAGE_SIZE + 1]));
|
||||
expectedTaskExecution.setEndTime(new Date());
|
||||
expectedTaskExecution.setExitCode(0);
|
||||
TaskExecution actualTaskExecution = completeTaskExecution(expectedTaskExecution,
|
||||
this.taskRepository);
|
||||
assertThat(actualTaskExecution.getExitMessage().length())
|
||||
.isEqualTo(SimpleTaskRepository.MAX_EXIT_MESSAGE_SIZE);
|
||||
TaskExecution actualTaskExecution = completeTaskExecution(expectedTaskExecution, this.taskRepository);
|
||||
assertThat(actualTaskExecution.getExitMessage().length()).isEqualTo(SimpleTaskRepository.MAX_EXIT_MESSAGE_SIZE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -222,12 +209,10 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(simpleTaskRepository);
|
||||
expectedTaskExecution.setExitMessage(
|
||||
new String(new char[SimpleTaskRepository.MAX_EXIT_MESSAGE_SIZE + 1]));
|
||||
expectedTaskExecution.setExitMessage(new String(new char[SimpleTaskRepository.MAX_EXIT_MESSAGE_SIZE + 1]));
|
||||
expectedTaskExecution.setEndTime(new Date());
|
||||
expectedTaskExecution.setExitCode(0);
|
||||
TaskExecution actualTaskExecution = completeTaskExecution(expectedTaskExecution,
|
||||
simpleTaskRepository);
|
||||
TaskExecution actualTaskExecution = completeTaskExecution(expectedTaskExecution, simpleTaskRepository);
|
||||
assertThat(actualTaskExecution.getExitMessage().length()).isEqualTo(5);
|
||||
}
|
||||
|
||||
@@ -236,12 +221,10 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
public void testCreateTaskExecutionNoParamMaxErrorDefaultMessageSize() {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
expectedTaskExecution.setErrorMessage(
|
||||
new String(new char[SimpleTaskRepository.MAX_ERROR_MESSAGE_SIZE + 1]));
|
||||
expectedTaskExecution.setErrorMessage(new String(new char[SimpleTaskRepository.MAX_ERROR_MESSAGE_SIZE + 1]));
|
||||
expectedTaskExecution.setEndTime(new Date());
|
||||
expectedTaskExecution.setExitCode(0);
|
||||
TaskExecution actualTaskExecution = completeTaskExecution(expectedTaskExecution,
|
||||
this.taskRepository);
|
||||
TaskExecution actualTaskExecution = completeTaskExecution(expectedTaskExecution, this.taskRepository);
|
||||
assertThat(actualTaskExecution.getErrorMessage().length())
|
||||
.isEqualTo(SimpleTaskRepository.MAX_ERROR_MESSAGE_SIZE);
|
||||
}
|
||||
@@ -254,12 +237,10 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(simpleTaskRepository);
|
||||
expectedTaskExecution.setErrorMessage(
|
||||
new String(new char[SimpleTaskRepository.MAX_ERROR_MESSAGE_SIZE + 1]));
|
||||
expectedTaskExecution.setErrorMessage(new String(new char[SimpleTaskRepository.MAX_ERROR_MESSAGE_SIZE + 1]));
|
||||
expectedTaskExecution.setEndTime(new Date());
|
||||
expectedTaskExecution.setExitCode(0);
|
||||
TaskExecution actualTaskExecution = completeTaskExecution(expectedTaskExecution,
|
||||
simpleTaskRepository);
|
||||
TaskExecution actualTaskExecution = completeTaskExecution(expectedTaskExecution, simpleTaskRepository);
|
||||
assertThat(actualTaskExecution.getErrorMessage().length()).isEqualTo(5);
|
||||
}
|
||||
|
||||
@@ -269,10 +250,9 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
final int MAX_ERROR_MESSAGE_SIZE = 20;
|
||||
final int MAX_TASK_NAME_SIZE = 30;
|
||||
SimpleTaskRepository simpleTaskRepository = new SimpleTaskRepository(
|
||||
new TaskExecutionDaoFactoryBean(this.dataSource), MAX_EXIT_MESSAGE_SIZE,
|
||||
MAX_TASK_NAME_SIZE, MAX_ERROR_MESSAGE_SIZE);
|
||||
TaskExecution expectedTaskExecution = TestVerifierUtils
|
||||
.createSampleTaskExecutionNoArg();
|
||||
new TaskExecutionDaoFactoryBean(this.dataSource), MAX_EXIT_MESSAGE_SIZE, MAX_TASK_NAME_SIZE,
|
||||
MAX_ERROR_MESSAGE_SIZE);
|
||||
TaskExecution expectedTaskExecution = TestVerifierUtils.createSampleTaskExecutionNoArg();
|
||||
expectedTaskExecution.setTaskName(new String(new char[MAX_TASK_NAME_SIZE + 1]));
|
||||
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {
|
||||
simpleTaskRepository.createTaskExecution(expectedTaskExecution);
|
||||
@@ -283,10 +263,8 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
public void testDefaultMaxTaskNameSizeForConstructor() {
|
||||
SimpleTaskRepository simpleTaskRepository = new SimpleTaskRepository(
|
||||
new TaskExecutionDaoFactoryBean(this.dataSource), null, null, null);
|
||||
TaskExecution expectedTaskExecution = TestVerifierUtils
|
||||
.createSampleTaskExecutionNoArg();
|
||||
expectedTaskExecution.setTaskName(
|
||||
new String(new char[SimpleTaskRepository.MAX_TASK_NAME_SIZE + 1]));
|
||||
TaskExecution expectedTaskExecution = TestVerifierUtils.createSampleTaskExecutionNoArg();
|
||||
expectedTaskExecution.setTaskName(new String(new char[SimpleTaskRepository.MAX_TASK_NAME_SIZE + 1]));
|
||||
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {
|
||||
simpleTaskRepository.createTaskExecution(expectedTaskExecution);
|
||||
});
|
||||
@@ -297,10 +275,8 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
final int MAX_EXIT_MESSAGE_SIZE = 10;
|
||||
final int MAX_ERROR_MESSAGE_SIZE = 20;
|
||||
SimpleTaskRepository simpleTaskRepository = new SimpleTaskRepository(
|
||||
new TaskExecutionDaoFactoryBean(this.dataSource), MAX_EXIT_MESSAGE_SIZE,
|
||||
null, MAX_ERROR_MESSAGE_SIZE);
|
||||
verifyTaskRepositoryConstructor(MAX_EXIT_MESSAGE_SIZE, MAX_ERROR_MESSAGE_SIZE,
|
||||
simpleTaskRepository);
|
||||
new TaskExecutionDaoFactoryBean(this.dataSource), MAX_EXIT_MESSAGE_SIZE, null, MAX_ERROR_MESSAGE_SIZE);
|
||||
verifyTaskRepositoryConstructor(MAX_EXIT_MESSAGE_SIZE, MAX_ERROR_MESSAGE_SIZE, simpleTaskRepository);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -315,8 +291,7 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
@DirtiesContext
|
||||
public void testCreateTaskExecutionNoParamMaxTaskName() {
|
||||
TaskExecution taskExecution = new TaskExecution();
|
||||
taskExecution.setTaskName(
|
||||
new String(new char[SimpleTaskRepository.MAX_TASK_NAME_SIZE + 1]));
|
||||
taskExecution.setTaskName(new String(new char[SimpleTaskRepository.MAX_TASK_NAME_SIZE + 1]));
|
||||
taskExecution.setStartTime(new Date());
|
||||
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {
|
||||
this.taskRepository.createTaskExecution(taskExecution);
|
||||
@@ -332,10 +307,9 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
expectedTaskExecution.setExitCode(-1);
|
||||
|
||||
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {
|
||||
TaskExecution actualTaskExecution = TaskExecutionCreator
|
||||
.completeExecution(this.taskRepository, expectedTaskExecution);
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
|
||||
actualTaskExecution);
|
||||
TaskExecution actualTaskExecution = TaskExecutionCreator.completeExecution(this.taskRepository,
|
||||
expectedTaskExecution);
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution, actualTaskExecution);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -346,35 +320,27 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
expectedTaskExecution.setExitCode(-1);
|
||||
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {
|
||||
TaskExecutionCreator.completeExecution(this.taskRepository,
|
||||
expectedTaskExecution);
|
||||
TaskExecutionCreator.completeExecution(this.taskRepository, expectedTaskExecution);
|
||||
});
|
||||
}
|
||||
|
||||
private TaskExecution completeTaskExecution(TaskExecution expectedTaskExecution,
|
||||
TaskRepository taskRepository) {
|
||||
return taskRepository.completeTaskExecution(
|
||||
expectedTaskExecution.getExecutionId(),
|
||||
expectedTaskExecution.getExitCode(), new Date(),
|
||||
expectedTaskExecution.getExitMessage(),
|
||||
private TaskExecution completeTaskExecution(TaskExecution expectedTaskExecution, TaskRepository taskRepository) {
|
||||
return taskRepository.completeTaskExecution(expectedTaskExecution.getExecutionId(),
|
||||
expectedTaskExecution.getExitCode(), new Date(), expectedTaskExecution.getExitMessage(),
|
||||
expectedTaskExecution.getErrorMessage());
|
||||
}
|
||||
|
||||
private void verifyTaskRepositoryConstructor(Integer maxExitMessage,
|
||||
Integer maxErrorMessage, TaskRepository taskRepository) {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(taskRepository);
|
||||
private void verifyTaskRepositoryConstructor(Integer maxExitMessage, Integer maxErrorMessage,
|
||||
TaskRepository taskRepository) {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator.createAndStoreTaskExecutionNoParams(taskRepository);
|
||||
expectedTaskExecution.setErrorMessage(new String(new char[maxErrorMessage + 1]));
|
||||
expectedTaskExecution.setExitMessage(new String(new char[maxExitMessage + 1]));
|
||||
expectedTaskExecution.setEndTime(new Date());
|
||||
expectedTaskExecution.setExitCode(0);
|
||||
|
||||
TaskExecution actualTaskExecution = completeTaskExecution(expectedTaskExecution,
|
||||
taskRepository);
|
||||
assertThat(actualTaskExecution.getErrorMessage().length())
|
||||
.isEqualTo(maxErrorMessage.intValue());
|
||||
assertThat(actualTaskExecution.getExitMessage().length())
|
||||
.isEqualTo(maxExitMessage.intValue());
|
||||
TaskExecution actualTaskExecution = completeTaskExecution(expectedTaskExecution, taskRepository);
|
||||
assertThat(actualTaskExecution.getErrorMessage().length()).isEqualTo(maxErrorMessage.intValue());
|
||||
assertThat(actualTaskExecution.getExitMessage().length()).isEqualTo(maxExitMessage.intValue());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -53,8 +53,7 @@ public class SimpleTaskRepositoryMapTests {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreEmptyTaskExecution(this.taskRepository);
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
|
||||
getSingleTaskExecutionFromMapRepository(
|
||||
expectedTaskExecution.getExecutionId()));
|
||||
getSingleTaskExecutionFromMapRepository(expectedTaskExecution.getExecutionId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -62,8 +61,7 @@ public class SimpleTaskRepositoryMapTests {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
|
||||
getSingleTaskExecutionFromMapRepository(
|
||||
expectedTaskExecution.getExecutionId()));
|
||||
getSingleTaskExecutionFromMapRepository(expectedTaskExecution.getExecutionId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -71,12 +69,10 @@ public class SimpleTaskRepositoryMapTests {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
expectedTaskExecution.setExternalExecutionId(UUID.randomUUID().toString());
|
||||
this.taskRepository.updateExternalExecutionId(
|
||||
expectedTaskExecution.getExecutionId(),
|
||||
this.taskRepository.updateExternalExecutionId(expectedTaskExecution.getExecutionId(),
|
||||
expectedTaskExecution.getExternalExecutionId());
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
|
||||
getSingleTaskExecutionFromMapRepository(
|
||||
expectedTaskExecution.getExecutionId()));
|
||||
getSingleTaskExecutionFromMapRepository(expectedTaskExecution.getExecutionId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -84,12 +80,10 @@ public class SimpleTaskRepositoryMapTests {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
expectedTaskExecution.setExternalExecutionId(null);
|
||||
this.taskRepository.updateExternalExecutionId(
|
||||
expectedTaskExecution.getExecutionId(),
|
||||
this.taskRepository.updateExternalExecutionId(expectedTaskExecution.getExecutionId(),
|
||||
expectedTaskExecution.getExternalExecutionId());
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
|
||||
getSingleTaskExecutionFromMapRepository(
|
||||
expectedTaskExecution.getExecutionId()));
|
||||
getSingleTaskExecutionFromMapRepository(expectedTaskExecution.getExecutionId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -98,8 +92,7 @@ public class SimpleTaskRepositoryMapTests {
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
expectedTaskExecution.setExternalExecutionId(null);
|
||||
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {
|
||||
this.taskRepository.updateExternalExecutionId(-1,
|
||||
expectedTaskExecution.getExternalExecutionId());
|
||||
this.taskRepository.updateExternalExecutionId(-1, expectedTaskExecution.getExternalExecutionId());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -108,8 +101,7 @@ public class SimpleTaskRepositoryMapTests {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionWithParams(this.taskRepository);
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
|
||||
getSingleTaskExecutionFromMapRepository(
|
||||
expectedTaskExecution.getExecutionId()));
|
||||
getSingleTaskExecutionFromMapRepository(expectedTaskExecution.getExecutionId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -117,17 +109,14 @@ public class SimpleTaskRepositoryMapTests {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreEmptyTaskExecution(this.taskRepository);
|
||||
|
||||
expectedTaskExecution.setArguments(
|
||||
Collections.singletonList("foo=" + UUID.randomUUID().toString()));
|
||||
expectedTaskExecution.setArguments(Collections.singletonList("foo=" + UUID.randomUUID().toString()));
|
||||
expectedTaskExecution.setStartTime(new Date());
|
||||
expectedTaskExecution.setTaskName(UUID.randomUUID().toString());
|
||||
|
||||
TaskExecution actualTaskExecution = this.taskRepository.startTaskExecution(
|
||||
expectedTaskExecution.getExecutionId(),
|
||||
expectedTaskExecution.getTaskName(), expectedTaskExecution.getStartTime(),
|
||||
expectedTaskExecution.getArguments(),
|
||||
expectedTaskExecution.getExternalExecutionId(),
|
||||
expectedTaskExecution.getParentExecutionId());
|
||||
expectedTaskExecution.getExecutionId(), expectedTaskExecution.getTaskName(),
|
||||
expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments(),
|
||||
expectedTaskExecution.getExternalExecutionId(), expectedTaskExecution.getParentExecutionId());
|
||||
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution, actualTaskExecution);
|
||||
}
|
||||
@@ -141,9 +130,8 @@ public class SimpleTaskRepositoryMapTests {
|
||||
expectedTaskExecution.setTaskName(UUID.randomUUID().toString());
|
||||
|
||||
TaskExecution actualTaskExecution = this.taskRepository.startTaskExecution(
|
||||
expectedTaskExecution.getExecutionId(),
|
||||
expectedTaskExecution.getTaskName(), expectedTaskExecution.getStartTime(),
|
||||
expectedTaskExecution.getArguments(),
|
||||
expectedTaskExecution.getExecutionId(), expectedTaskExecution.getTaskName(),
|
||||
expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments(),
|
||||
expectedTaskExecution.getExternalExecutionId());
|
||||
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution, actualTaskExecution);
|
||||
@@ -159,9 +147,8 @@ public class SimpleTaskRepositoryMapTests {
|
||||
expectedTaskExecution.setParentExecutionId(12345L);
|
||||
|
||||
TaskExecution actualTaskExecution = this.taskRepository.startTaskExecution(
|
||||
expectedTaskExecution.getExecutionId(),
|
||||
expectedTaskExecution.getTaskName(), expectedTaskExecution.getStartTime(),
|
||||
expectedTaskExecution.getArguments(),
|
||||
expectedTaskExecution.getExecutionId(), expectedTaskExecution.getTaskName(),
|
||||
expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments(),
|
||||
expectedTaskExecution.getExternalExecutionId());
|
||||
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution, actualTaskExecution);
|
||||
@@ -173,16 +160,15 @@ public class SimpleTaskRepositoryMapTests {
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
expectedTaskExecution.setEndTime(new Date());
|
||||
expectedTaskExecution.setExitCode(0);
|
||||
TaskExecution actualTaskExecution = TaskExecutionCreator
|
||||
.completeExecution(this.taskRepository, expectedTaskExecution);
|
||||
TaskExecution actualTaskExecution = TaskExecutionCreator.completeExecution(this.taskRepository,
|
||||
expectedTaskExecution);
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution, actualTaskExecution);
|
||||
}
|
||||
|
||||
private TaskExecution getSingleTaskExecutionFromMapRepository(long taskExecutionId) {
|
||||
Map<Long, TaskExecution> taskMap = ((MapTaskExecutionDao) ((SimpleTaskRepository) this.taskRepository)
|
||||
.getTaskExecutionDao()).getTaskExecutions();
|
||||
assertTrue("taskExecutionId must be in MapTaskExecutionRepository",
|
||||
taskMap.containsKey(taskExecutionId));
|
||||
assertTrue("taskExecutionId must be in MapTaskExecutionRepository", taskMap.containsKey(taskExecutionId));
|
||||
return taskMap.get(taskExecutionId);
|
||||
}
|
||||
|
||||
@@ -192,8 +178,7 @@ public class SimpleTaskRepositoryMapTests {
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
expectedTaskExecution.setExitCode(-1);
|
||||
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {
|
||||
TaskExecutionCreator.completeExecution(this.taskRepository,
|
||||
expectedTaskExecution);
|
||||
TaskExecutionCreator.completeExecution(this.taskRepository, expectedTaskExecution);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ public class SqlServerSequenceMaxValueIncrementerTests {
|
||||
@Test
|
||||
public void testDefaultDataSourceConfiguration() throws Exception {
|
||||
this.context = new AnnotationConfigApplicationContext(
|
||||
TaskExecutionDaoFactoryBeanTests.DefaultDataSourceConfiguration.class);
|
||||
TaskExecutionDaoFactoryBeanTests.DefaultDataSourceConfiguration.class);
|
||||
|
||||
DataSource dataSource = this.context.getBean(DataSource.class);
|
||||
|
||||
@@ -48,4 +48,5 @@ public class SqlServerSequenceMaxValueIncrementerTests {
|
||||
assertThat(incrementer.getSequenceQuery()).isEqualTo("select next value for foo");
|
||||
assertThat(incrementer.getIncrementerName()).isEqualTo("foo");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -54,21 +54,18 @@ public class TaskDatabaseInitializerTests {
|
||||
@Test
|
||||
public void testDefaultContext() {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context.register(TestConfiguration.class,
|
||||
EmbeddedDataSourceConfiguration.class,
|
||||
this.context.register(TestConfiguration.class, EmbeddedDataSourceConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
assertThat(new JdbcTemplate(this.context.getBean(DataSource.class))
|
||||
.queryForList("select * from TASK_EXECUTION").size()).isEqualTo(0);
|
||||
assertThat(new JdbcTemplate(this.context.getBean(DataSource.class)).queryForList("select * from TASK_EXECUTION")
|
||||
.size()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoDatabase() {
|
||||
this.context = new AnnotationConfigApplicationContext(EmptyConfiguration.class);
|
||||
SimpleTaskRepository repository = new SimpleTaskRepository(
|
||||
new TaskExecutionDaoFactoryBean());
|
||||
assertThat(repository.getTaskExecutionDao())
|
||||
.isInstanceOf(MapTaskExecutionDao.class);
|
||||
SimpleTaskRepository repository = new SimpleTaskRepository(new TaskExecutionDaoFactoryBean());
|
||||
assertThat(repository.getTaskExecutionDao()).isInstanceOf(MapTaskExecutionDao.class);
|
||||
MapTaskExecutionDao dao = (MapTaskExecutionDao) repository.getTaskExecutionDao();
|
||||
assertThat(dao.getTaskExecutions().size()).isEqualTo(0);
|
||||
}
|
||||
@@ -76,19 +73,16 @@ public class TaskDatabaseInitializerTests {
|
||||
@Test
|
||||
public void testNoTaskConfiguration() {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context.register(EmptyConfiguration.class,
|
||||
EmbeddedDataSourceConfiguration.class,
|
||||
this.context.register(EmptyConfiguration.class, EmbeddedDataSourceConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
assertThat(this.context.getBeanNamesForType(SimpleTaskRepository.class).length)
|
||||
.isEqualTo(0);
|
||||
assertThat(this.context.getBeanNamesForType(SimpleTaskRepository.class).length).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleDataSourcesContext() {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context.register(SimpleTaskAutoConfiguration.class,
|
||||
EmbeddedDataSourceConfiguration.class,
|
||||
this.context.register(SimpleTaskAutoConfiguration.class, EmbeddedDataSourceConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
DataSource dataSource = mock(DataSource.class);
|
||||
this.context.getBeanFactory().registerSingleton("mockDataSource", dataSource);
|
||||
|
||||
@@ -51,8 +51,7 @@ public class TaskExecutionDaoFactoryBeanTests {
|
||||
|
||||
@Test
|
||||
public void testGetObjectType() {
|
||||
assertThat(TaskExecutionDao.class)
|
||||
.isEqualTo(new TaskExecutionDaoFactoryBean().getObjectType());
|
||||
assertThat(TaskExecutionDao.class).isEqualTo(new TaskExecutionDaoFactoryBean().getObjectType());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -81,13 +80,11 @@ public class TaskExecutionDaoFactoryBeanTests {
|
||||
|
||||
@Test
|
||||
public void testDefaultDataSourceConfiguration() throws Exception {
|
||||
this.context = new AnnotationConfigApplicationContext(
|
||||
DefaultDataSourceConfiguration.class);
|
||||
this.context = new AnnotationConfigApplicationContext(DefaultDataSourceConfiguration.class);
|
||||
|
||||
DataSource dataSource = this.context.getBean(DataSource.class);
|
||||
|
||||
TaskExecutionDaoFactoryBean factoryBean = new TaskExecutionDaoFactoryBean(
|
||||
dataSource);
|
||||
TaskExecutionDaoFactoryBean factoryBean = new TaskExecutionDaoFactoryBean(dataSource);
|
||||
TaskExecutionDao taskExecutionDao = factoryBean.getObject();
|
||||
|
||||
assertThat(taskExecutionDao instanceof JdbcTaskExecutionDao).isTrue();
|
||||
@@ -99,17 +96,14 @@ public class TaskExecutionDaoFactoryBeanTests {
|
||||
|
||||
@Test
|
||||
public void testSettingTablePrefix() throws Exception {
|
||||
this.context = new AnnotationConfigApplicationContext(
|
||||
DefaultDataSourceConfiguration.class);
|
||||
this.context = new AnnotationConfigApplicationContext(DefaultDataSourceConfiguration.class);
|
||||
|
||||
DataSource dataSource = this.context.getBean(DataSource.class);
|
||||
|
||||
TaskExecutionDaoFactoryBean factoryBean = new TaskExecutionDaoFactoryBean(
|
||||
dataSource, "foo_");
|
||||
TaskExecutionDaoFactoryBean factoryBean = new TaskExecutionDaoFactoryBean(dataSource, "foo_");
|
||||
TaskExecutionDao taskExecutionDao = factoryBean.getObject();
|
||||
|
||||
assertThat(ReflectionTestUtils.getField(taskExecutionDao, "tablePrefix"))
|
||||
.isEqualTo("foo_");
|
||||
assertThat(ReflectionTestUtils.getField(taskExecutionDao, "tablePrefix")).isEqualTo("foo_");
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@@ -117,8 +111,7 @@ public class TaskExecutionDaoFactoryBeanTests {
|
||||
|
||||
@Bean
|
||||
public DataSource dataSource() {
|
||||
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder()
|
||||
.setType(EmbeddedDatabaseType.H2);
|
||||
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -38,8 +38,7 @@ public final class TaskExecutionCreator {
|
||||
* @param taskRepository the taskRepository where the taskExecution should be stored.
|
||||
* @return the taskExecution created.
|
||||
*/
|
||||
public static TaskExecution createAndStoreEmptyTaskExecution(
|
||||
TaskRepository taskRepository) {
|
||||
public static TaskExecution createAndStoreEmptyTaskExecution(TaskRepository taskRepository) {
|
||||
return taskRepository.createTaskExecution();
|
||||
}
|
||||
|
||||
@@ -48,8 +47,7 @@ public final class TaskExecutionCreator {
|
||||
* @param taskRepository the taskRepository where the taskExecution should be stored.
|
||||
* @return the taskExecution created.
|
||||
*/
|
||||
public static TaskExecution createAndStoreTaskExecutionNoParams(
|
||||
TaskRepository taskRepository) {
|
||||
public static TaskExecution createAndStoreTaskExecutionNoParams(TaskRepository taskRepository) {
|
||||
TaskExecution expectedTaskExecution = taskRepository.createTaskExecution();
|
||||
return expectedTaskExecution;
|
||||
}
|
||||
@@ -59,10 +57,8 @@ public final class TaskExecutionCreator {
|
||||
* @param taskRepository the taskRepository where the taskExecution should be stored.
|
||||
* @return the taskExecution created.
|
||||
*/
|
||||
public static TaskExecution createAndStoreTaskExecutionWithParams(
|
||||
TaskRepository taskRepository) {
|
||||
TaskExecution expectedTaskExecution = TestVerifierUtils
|
||||
.createSampleTaskExecutionNoArg();
|
||||
public static TaskExecution createAndStoreTaskExecutionWithParams(TaskRepository taskRepository) {
|
||||
TaskExecution expectedTaskExecution = TestVerifierUtils.createSampleTaskExecutionNoArg();
|
||||
List<String> params = new ArrayList<>();
|
||||
params.add(UUID.randomUUID().toString());
|
||||
params.add(UUID.randomUUID().toString());
|
||||
@@ -77,13 +73,10 @@ public final class TaskExecutionCreator {
|
||||
* @param expectedTaskExecution the expected task execution.
|
||||
* @return the taskExecution created.
|
||||
*/
|
||||
public static TaskExecution completeExecution(TaskRepository taskRepository,
|
||||
TaskExecution expectedTaskExecution) {
|
||||
return taskRepository.completeTaskExecution(
|
||||
expectedTaskExecution.getExecutionId(),
|
||||
public static TaskExecution completeExecution(TaskRepository taskRepository, TaskExecution expectedTaskExecution) {
|
||||
return taskRepository.completeTaskExecution(expectedTaskExecution.getExecutionId(),
|
||||
expectedTaskExecution.getExitCode(), expectedTaskExecution.getEndTime(),
|
||||
expectedTaskExecution.getExitMessage(),
|
||||
expectedTaskExecution.getErrorMessage());
|
||||
expectedTaskExecution.getExitMessage(), expectedTaskExecution.getErrorMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -63,29 +63,22 @@ public final class TestDBUtils {
|
||||
* @param taskExecutionId The id of the task to search.
|
||||
* @return taskExecution retrieved from the database.
|
||||
*/
|
||||
public static TaskExecution getTaskExecutionFromDB(DataSource dataSource,
|
||||
long taskExecutionId) {
|
||||
String sql = "SELECT * FROM TASK_EXECUTION WHERE " + "TASK_EXECUTION_ID = '"
|
||||
+ taskExecutionId + "'";
|
||||
public static TaskExecution getTaskExecutionFromDB(DataSource dataSource, long taskExecutionId) {
|
||||
String sql = "SELECT * FROM TASK_EXECUTION WHERE " + "TASK_EXECUTION_ID = '" + taskExecutionId + "'";
|
||||
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
List<TaskExecution> rows = jdbcTemplate.query(sql,
|
||||
new RowMapper<TaskExecution>() {
|
||||
@Override
|
||||
public TaskExecution mapRow(ResultSet rs, int rownumber)
|
||||
throws SQLException {
|
||||
TaskExecution taskExecution = new TaskExecution(
|
||||
rs.getLong("TASK_EXECUTION_ID"),
|
||||
StringUtils.hasText(rs.getString("EXIT_CODE"))
|
||||
? Integer.valueOf(rs.getString("EXIT_CODE"))
|
||||
: null,
|
||||
rs.getString("TASK_NAME"), rs.getTimestamp("START_TIME"),
|
||||
rs.getTimestamp("END_TIME"), rs.getString("EXIT_MESSAGE"),
|
||||
new ArrayList<>(0), rs.getString("ERROR_MESSAGE"),
|
||||
rs.getString("EXTERNAL_EXECUTION_ID"));
|
||||
return taskExecution;
|
||||
}
|
||||
});
|
||||
List<TaskExecution> rows = jdbcTemplate.query(sql, new RowMapper<TaskExecution>() {
|
||||
@Override
|
||||
public TaskExecution mapRow(ResultSet rs, int rownumber) throws SQLException {
|
||||
TaskExecution taskExecution = new TaskExecution(rs.getLong("TASK_EXECUTION_ID"),
|
||||
StringUtils.hasText(rs.getString("EXIT_CODE")) ? Integer.valueOf(rs.getString("EXIT_CODE"))
|
||||
: null,
|
||||
rs.getString("TASK_NAME"), rs.getTimestamp("START_TIME"), rs.getTimestamp("END_TIME"),
|
||||
rs.getString("EXIT_MESSAGE"), new ArrayList<>(0), rs.getString("ERROR_MESSAGE"),
|
||||
rs.getString("EXTERNAL_EXECUTION_ID"));
|
||||
return taskExecution;
|
||||
}
|
||||
});
|
||||
assertThat(rows.size()).as("only one row should be returned").isEqualTo(1);
|
||||
TaskExecution taskExecution = rows.get(0);
|
||||
|
||||
@@ -101,8 +94,7 @@ public final class TestDBUtils {
|
||||
* @throws Exception exception thrown if error occurs creating
|
||||
* {@link PagingQueryProvider}.
|
||||
*/
|
||||
public static PagingQueryProvider getPagingQueryProvider(String databaseProductName)
|
||||
throws Exception {
|
||||
public static PagingQueryProvider getPagingQueryProvider(String databaseProductName) throws Exception {
|
||||
return getPagingQueryProvider(databaseProductName, null);
|
||||
}
|
||||
|
||||
@@ -115,8 +107,8 @@ public final class TestDBUtils {
|
||||
* @throws Exception exception thrown if error occurs creating
|
||||
* {@link PagingQueryProvider}.
|
||||
*/
|
||||
public static PagingQueryProvider getPagingQueryProvider(String databaseProductName,
|
||||
String whereClause) throws Exception {
|
||||
public static PagingQueryProvider getPagingQueryProvider(String databaseProductName, String whereClause)
|
||||
throws Exception {
|
||||
DataSource dataSource = getMockDataSource(databaseProductName);
|
||||
Map<String, Order> orderMap = new TreeMap<>();
|
||||
orderMap.put("START_TIME", Order.DESCENDING);
|
||||
@@ -147,8 +139,7 @@ public final class TestDBUtils {
|
||||
* @throws Exception exception thrown if error occurs creating mock
|
||||
* {@link DataSource}.
|
||||
*/
|
||||
public static DataSource getMockDataSource(String databaseProductName)
|
||||
throws Exception {
|
||||
public static DataSource getMockDataSource(String databaseProductName) throws Exception {
|
||||
DatabaseMetaData dmd = mock(DatabaseMetaData.class);
|
||||
DataSource ds = mock(DataSource.class);
|
||||
Connection con = mock(Connection.class);
|
||||
@@ -180,10 +171,9 @@ public final class TestDBUtils {
|
||||
return incrementerFactory.getIncrementer(databaseType, "TASK_SEQ");
|
||||
}
|
||||
|
||||
private static void populateParamsToDB(DataSource dataSource,
|
||||
TaskExecution taskExecution) {
|
||||
String sql = "SELECT * FROM TASK_EXECUTION_PARAMS WHERE TASK_EXECUTION_ID = '"
|
||||
+ taskExecution.getExecutionId() + "'";
|
||||
private static void populateParamsToDB(DataSource dataSource, TaskExecution taskExecution) {
|
||||
String sql = "SELECT * FROM TASK_EXECUTION_PARAMS WHERE TASK_EXECUTION_ID = '" + taskExecution.getExecutionId()
|
||||
+ "'";
|
||||
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
List<Map<String, Object>> rows = jdbcTemplate.queryForList(sql);
|
||||
|
||||
@@ -86,11 +86,12 @@ public class TestDefaultConfiguration implements InitializingBean {
|
||||
|
||||
@Bean
|
||||
public TaskLifecycleListener taskHandler(TaskExplorer taskExplorer,
|
||||
@Autowired(required = false) io.micrometer.core.instrument.MeterRegistry meterRegistry, @Autowired(required = false) ObservationRegistry observationRegistry) {
|
||||
@Autowired(required = false) io.micrometer.core.instrument.MeterRegistry meterRegistry,
|
||||
@Autowired(required = false) ObservationRegistry observationRegistry) {
|
||||
|
||||
return new TaskLifecycleListener(taskRepository(), taskNameResolver(),
|
||||
this.applicationArguments, taskExplorer, this.taskProperties,
|
||||
taskListenerExecutorObjectProvider(this.context), observationRegistry, new TaskObservationCloudKeyValues());
|
||||
return new TaskLifecycleListener(taskRepository(), taskNameResolver(), this.applicationArguments, taskExplorer,
|
||||
this.taskProperties, taskListenerExecutorObjectProvider(this.context), observationRegistry,
|
||||
new TaskObservationCloudKeyValues());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -71,13 +71,11 @@ public final class TestVerifierUtils {
|
||||
* @param mockAppender The appender that is associated with the test.
|
||||
* @param logSample The string to search for in the log entry.
|
||||
*/
|
||||
public static void verifyLogEntryExists(Appender mockAppender,
|
||||
final String logSample) {
|
||||
public static void verifyLogEntryExists(Appender mockAppender, final String logSample) {
|
||||
verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {
|
||||
@Override
|
||||
public boolean matches(final Object argument) {
|
||||
return ((LoggingEvent) argument).getFormattedMessage()
|
||||
.contains(logSample);
|
||||
return ((LoggingEvent) argument).getFormattedMessage().contains(logSample);
|
||||
}
|
||||
}));
|
||||
}
|
||||
@@ -92,8 +90,7 @@ public final class TestVerifierUtils {
|
||||
long executionId = randomGenerator.nextLong();
|
||||
String taskName = UUID.randomUUID().toString();
|
||||
|
||||
return new TaskExecution(executionId, null, taskName, startTime, null, null,
|
||||
new ArrayList<>(), null, null);
|
||||
return new TaskExecution(executionId, null, taskName, startTime, null, null, new ArrayList<>(), null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,8 +106,8 @@ public final class TestVerifierUtils {
|
||||
String taskName = UUID.randomUUID().toString();
|
||||
String exitMessage = UUID.randomUUID().toString();
|
||||
|
||||
return new TaskExecution(executionId, exitCode, taskName, startTime, endTime,
|
||||
exitMessage, new ArrayList<>(), null, null);
|
||||
return new TaskExecution(executionId, exitCode, taskName, startTime, endTime, exitMessage, new ArrayList<>(),
|
||||
null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -126,8 +123,7 @@ public final class TestVerifierUtils {
|
||||
for (int i = 0; i < ARG_SIZE; i++) {
|
||||
args.add(UUID.randomUUID().toString());
|
||||
}
|
||||
return new TaskExecution(executionId, null, taskName, startTime, null, null, args,
|
||||
null, externalExecutionId);
|
||||
return new TaskExecution(executionId, null, taskName, startTime, null, null, args, null, externalExecutionId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -135,10 +131,8 @@ public final class TestVerifierUtils {
|
||||
* @param expectedTaskExecution The expected value for the task execution.
|
||||
* @param actualTaskExecution The actual value for the task execution.
|
||||
*/
|
||||
public static void verifyTaskExecution(TaskExecution expectedTaskExecution,
|
||||
TaskExecution actualTaskExecution) {
|
||||
assertThat(actualTaskExecution.getExecutionId())
|
||||
.as("taskExecutionId must be equal")
|
||||
public static void verifyTaskExecution(TaskExecution expectedTaskExecution, TaskExecution actualTaskExecution) {
|
||||
assertThat(actualTaskExecution.getExecutionId()).as("taskExecutionId must be equal")
|
||||
.isEqualTo(expectedTaskExecution.getExecutionId());
|
||||
if (actualTaskExecution.getStartTime() != null) {
|
||||
assertThat(actualTaskExecution.getStartTime()).as("startTime must be equal")
|
||||
@@ -156,31 +150,26 @@ public final class TestVerifierUtils {
|
||||
.isEqualTo(expectedTaskExecution.getExitMessage());
|
||||
assertThat(actualTaskExecution.getErrorMessage()).as("errorMessage must be equal")
|
||||
.isEqualTo(expectedTaskExecution.getErrorMessage());
|
||||
assertThat(actualTaskExecution.getExternalExecutionId())
|
||||
.as("externalExecutionId must be equal")
|
||||
assertThat(actualTaskExecution.getExternalExecutionId()).as("externalExecutionId must be equal")
|
||||
.isEqualTo(expectedTaskExecution.getExternalExecutionId());
|
||||
assertThat(actualTaskExecution.getParentExecutionId())
|
||||
.as("parentExecutionId must be equal")
|
||||
assertThat(actualTaskExecution.getParentExecutionId()).as("parentExecutionId must be equal")
|
||||
.isEqualTo(expectedTaskExecution.getParentExecutionId());
|
||||
|
||||
if (expectedTaskExecution.getArguments() != null) {
|
||||
assertThat(actualTaskExecution.getArguments())
|
||||
.as("arguments should not be null").isNotNull();
|
||||
assertThat(actualTaskExecution.getArguments()).as("arguments should not be null").isNotNull();
|
||||
assertThat(actualTaskExecution.getArguments().size())
|
||||
.as("arguments result set count should match expected count")
|
||||
.isEqualTo(expectedTaskExecution.getArguments().size());
|
||||
}
|
||||
else {
|
||||
assertThat(actualTaskExecution.getArguments()).as("arguments should be null")
|
||||
.isNull();
|
||||
assertThat(actualTaskExecution.getArguments()).as("arguments should be null").isNull();
|
||||
}
|
||||
Set<String> args = new HashSet<>();
|
||||
for (String param : expectedTaskExecution.getArguments()) {
|
||||
args.add(param);
|
||||
}
|
||||
for (String arg : actualTaskExecution.getArguments()) {
|
||||
assertThat(args.contains(arg)).as("arg must exist in the repository")
|
||||
.isTrue();
|
||||
assertThat(args.contains(arg)).as("arg must exist in the repository").isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user