Added checkstyle
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
/*
|
||||
* Copyright 2017-2018 the original author or authors.
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.task;
|
||||
@@ -25,8 +25,7 @@ import org.springframework.cloud.task.configuration.SimpleTaskAutoConfiguration;
|
||||
import org.springframework.cloud.task.configuration.SingleInstanceTaskListener;
|
||||
import org.springframework.cloud.task.configuration.SingleTaskConfiguration;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Verifies that the beans created by the SimpleSingleTaskAutoConfigurationConfiguration
|
||||
@@ -43,15 +42,18 @@ public class SimpleSingleTaskAutoConfigurationTests {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class,
|
||||
SingleTaskConfiguration.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);
|
||||
|
||||
assertNotNull("singleInstanceTaskListener should not be null", singleInstanceTaskListener);
|
||||
assertThat(singleInstanceTaskListener)
|
||||
.as("singleInstanceTaskListener should not be null").isNotNull();
|
||||
|
||||
assertEquals(singleInstanceTaskListener.getClass(), SingleInstanceTaskListener.class); });
|
||||
assertThat(SingleInstanceTaskListener.class)
|
||||
.isEqualTo(singleInstanceTaskListener.getClass());
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/*
|
||||
* Copyright 2017-2018 the original author or authors.
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.task;
|
||||
@@ -26,8 +26,7 @@ import org.springframework.cloud.task.configuration.SimpleTaskAutoConfiguration;
|
||||
import org.springframework.cloud.task.configuration.SingleInstanceTaskListener;
|
||||
import org.springframework.cloud.task.configuration.SingleTaskConfiguration;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Verifies that the beans created by the SimpleSingleTaskAutoConfigurationConfiguration
|
||||
@@ -44,16 +43,19 @@ public class SimpleSingleTaskAutoConfigurationWithDataSourceTests {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class,
|
||||
SingleTaskConfiguration.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);
|
||||
|
||||
assertNotNull("singleInstanceTaskListener should not be null", singleInstanceTaskListener);
|
||||
assertThat(singleInstanceTaskListener)
|
||||
.as("singleInstanceTaskListener should not be null").isNotNull();
|
||||
|
||||
assertEquals(singleInstanceTaskListener.getClass(), SingleInstanceTaskListener.class);
|
||||
assertThat(SingleInstanceTaskListener.class)
|
||||
.isEqualTo(singleInstanceTaskListener.getClass());
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2018 the original author or authors.
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -48,7 +48,7 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
@@ -71,10 +71,10 @@ 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);
|
||||
@@ -89,50 +89,50 @@ public class SimpleTaskAutoConfigurationTests {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class,
|
||||
SingleTaskConfiguration.class))
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
|
||||
.withPropertyValues("spring.cloud.task.autoconfiguration.enabled=false");
|
||||
Executable executable = () -> {
|
||||
applicationContextRunner.run((context) -> {
|
||||
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,
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
EmbeddedDataSourceConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class,
|
||||
SingleTaskConfiguration.class))
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
|
||||
.withUserConfiguration(TaskLifecycleListenerConfiguration.class);
|
||||
applicationContextRunner.run((context) -> {
|
||||
TaskExplorer taskExplorer = context.getBean(TaskExplorer.class);
|
||||
assertThat(taskExplorer.getTaskExecutionCount()).isEqualTo(1l);
|
||||
assertThat(taskExplorer.getTaskExecutionCount()).isEqualTo(1L);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRepositoryNotInitialized() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(EmbeddedDataSourceConfiguration.class,
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
EmbeddedDataSourceConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class,
|
||||
SingleTaskConfiguration.class))
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
|
||||
.withUserConfiguration(TaskLifecycleListenerConfiguration.class)
|
||||
.withPropertyValues("spring.cloud.task.tablePrefix=foobarless");
|
||||
|
||||
verifyExceptionThrownDefaultExecutable(ApplicationContextException.class, "Failed to start " +
|
||||
"bean 'taskLifecycleListener'; nested exception is " +
|
||||
"org.springframework.dao.DataAccessResourceFailureException: " +
|
||||
"Could not obtain sequence value; nested exception is org.h2.jdbc.JdbcSQLException: " +
|
||||
"Syntax error in SQL statement \"SELECT FOOBARLESSSEQ.NEXTVAL FROM[*] DUAL \"; " +
|
||||
"expected \"identifier\"; SQL statement:\n" +
|
||||
"select foobarlessSEQ.nextval from dual [42001-197]", applicationContextRunner);
|
||||
verifyExceptionThrownDefaultExecutable(ApplicationContextException.class,
|
||||
"Failed to start " + "bean 'taskLifecycleListener'; nested exception is "
|
||||
+ "org.springframework.dao.DataAccessResourceFailureException: "
|
||||
+ "Could not obtain sequence value; nested exception is org.h2.jdbc.JdbcSQLException: "
|
||||
+ "Syntax error in SQL statement \"SELECT FOOBARLESSSEQ.NEXTVAL FROM[*] DUAL \"; "
|
||||
+ "expected \"identifier\"; SQL statement:\n"
|
||||
+ "select foobarlessSEQ.nextval from dual [42001-197]",
|
||||
applicationContextRunner);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -140,29 +140,32 @@ public class SimpleTaskAutoConfigurationTests {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class,
|
||||
SingleTaskConfiguration.class))
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
|
||||
.withUserConfiguration(MultipleConfigurers.class);
|
||||
|
||||
verifyExceptionThrownDefaultExecutable(BeanCreationException.class, "Error creating bean " +
|
||||
"with name 'simpleTaskAutoConfiguration': Invocation of init " +
|
||||
"method failed; nested exception is java.lang.IllegalStateException:" +
|
||||
" Expected one TaskConfigurer but found 2", applicationContextRunner);
|
||||
verifyExceptionThrownDefaultExecutable(BeanCreationException.class,
|
||||
"Error creating bean "
|
||||
+ "with name 'simpleTaskAutoConfiguration': Invocation of init "
|
||||
+ "method failed; nested exception is java.lang.IllegalStateException:"
|
||||
+ " Expected one TaskConfigurer but found 2",
|
||||
applicationContextRunner);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleDataSources() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class,
|
||||
SingleTaskConfiguration.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; nested exception is java.lang.IllegalStateException: To use " +
|
||||
"the default TaskConfigurer the context must contain no more than " +
|
||||
"one DataSource, found 2", applicationContextRunner);
|
||||
verifyExceptionThrownDefaultExecutable(BeanCreationException.class,
|
||||
"Error creating bean "
|
||||
+ "with name 'simpleTaskAutoConfiguration': Invocation of init method "
|
||||
+ "failed; nested exception is java.lang.IllegalStateException: To use "
|
||||
+ "the default TaskConfigurer the context must contain no more than "
|
||||
+ "one DataSource, found 2",
|
||||
applicationContextRunner);
|
||||
|
||||
}
|
||||
|
||||
@@ -178,14 +181,15 @@ public class SimpleTaskAutoConfigurationTests {
|
||||
verifyExceptionThrown(classToCheck, message, executable);
|
||||
}
|
||||
|
||||
public void verifyExceptionThrown(Class classToCheck, String message, Executable executable) {
|
||||
Throwable exception = assertThrows(classToCheck, executable);
|
||||
assertThat(exception.getMessage()).isEqualTo(message);
|
||||
public void verifyExceptionThrown(Class classToCheck, String message,
|
||||
Executable executable) {
|
||||
assertThatExceptionOfType(classToCheck).isThrownBy(executable::execute)
|
||||
.withMessage(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that the verifyEnvironment method skips DataSource Proxy Beans when determining
|
||||
* the number of available dataSources.
|
||||
* Verify that the verifyEnvironment method skips DataSource Proxy Beans when
|
||||
* determining the number of available dataSources.
|
||||
*/
|
||||
@Test
|
||||
public void testWithDataSourceProxy() {
|
||||
@@ -193,12 +197,12 @@ public class SimpleTaskAutoConfigurationTests {
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
EmbeddedDataSourceConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class,
|
||||
SingleTaskConfiguration.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();
|
||||
});
|
||||
@@ -216,6 +220,7 @@ public class SimpleTaskAutoConfigurationTests {
|
||||
public TaskConfigurer taskConfigurer2() {
|
||||
return new DefaultTaskConfigurer((DataSource) null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@@ -243,9 +248,10 @@ 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2018 the original author or authors.
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -31,7 +31,7 @@ import org.springframework.context.ApplicationContextException;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Verifies core behavior for Tasks.
|
||||
@@ -41,42 +41,49 @@ import static org.junit.Assert.assertTrue;
|
||||
public class TaskCoreTests {
|
||||
|
||||
private static final String TASK_NAME = "taskEventTest";
|
||||
private static final String EXCEPTION_MESSAGE = "FOO EXCEPTION";
|
||||
private static final String CREATE_TASK_MESSAGE = "Creating: TaskExecution{executionId=";
|
||||
private static final String UPDATE_TASK_MESSAGE = "Updating: TaskExecution with executionId=";
|
||||
private static final String SUCCESS_EXIT_CODE_MESSAGE = "with the following {exitCode=0";
|
||||
private static final String EXCEPTION_EXIT_CODE_MESSAGE = "with the following {exitCode=1";
|
||||
private static final String EXCEPTION_INVALID_TASK_EXECUTION_ID =
|
||||
"java.lang.IllegalArgumentException: Invalid TaskExecution, ID 55 not found";
|
||||
private static final String ERROR_MESSAGE =
|
||||
"errorMessage='java.lang.IllegalStateException: Failed to execute CommandLineRunner";
|
||||
|
||||
private ConfigurableApplicationContext applicationContext;
|
||||
private static final String EXCEPTION_MESSAGE = "FOO EXCEPTION";
|
||||
|
||||
private static final String CREATE_TASK_MESSAGE = "Creating: TaskExecution{executionId=";
|
||||
|
||||
private static final String UPDATE_TASK_MESSAGE = "Updating: TaskExecution with executionId=";
|
||||
|
||||
private static final String SUCCESS_EXIT_CODE_MESSAGE = "with the following {exitCode=0";
|
||||
|
||||
private static final String EXCEPTION_EXIT_CODE_MESSAGE = "with the following {exitCode=1";
|
||||
|
||||
private static final String EXCEPTION_INVALID_TASK_EXECUTION_ID = "java.lang.IllegalArgumentException: "
|
||||
+ "Invalid TaskExecution, ID 55 not found";
|
||||
|
||||
private static final String ERROR_MESSAGE = "errorMessage='java.lang.IllegalStateException: "
|
||||
+ "Failed to execute CommandLineRunner";
|
||||
|
||||
@Rule
|
||||
public OutputCapture outputCapture = new OutputCapture();
|
||||
|
||||
private ConfigurableApplicationContext applicationContext;
|
||||
|
||||
@After
|
||||
public void teardown() {
|
||||
if (applicationContext != null && applicationContext.isActive()) {
|
||||
applicationContext.close();
|
||||
if (this.applicationContext != null && this.applicationContext.isActive()) {
|
||||
this.applicationContext.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void successfulTaskTest() {
|
||||
this.applicationContext = SpringApplication.run( TaskConfiguration.class,
|
||||
this.applicationContext = SpringApplication.run(TaskConfiguration.class,
|
||||
"--spring.cloud.task.closecontext.enable=false",
|
||||
"--spring.cloud.task.name=" + TASK_NAME,
|
||||
"--spring.main.web-environment=false");
|
||||
|
||||
String output = this.outputCapture.toString();
|
||||
assertTrue("Test results do not show create task message: " + output,
|
||||
output.contains(CREATE_TASK_MESSAGE));
|
||||
assertTrue("Test results do not show success message: " + output,
|
||||
output.contains(UPDATE_TASK_MESSAGE));
|
||||
assertTrue("Test results have incorrect exit code: " + output,
|
||||
output.contains(SUCCESS_EXIT_CODE_MESSAGE));
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,25 +91,27 @@ public class TaskCoreTests {
|
||||
*/
|
||||
@Test
|
||||
public void successfulTaskTestWithAnnotation() {
|
||||
this.applicationContext = SpringApplication.run( TaskConfigurationWithAnotation.class,
|
||||
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 = this.outputCapture.toString();
|
||||
assertTrue("Test results do not show create task message: " + output,
|
||||
output.contains(CREATE_TASK_MESSAGE));
|
||||
assertTrue("Test results do not show success message: " + output,
|
||||
output.contains(UPDATE_TASK_MESSAGE));
|
||||
assertTrue("Test results have incorrect exit code: " + output,
|
||||
output.contains(SUCCESS_EXIT_CODE_MESSAGE));
|
||||
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() {
|
||||
boolean exceptionFired = false;
|
||||
try {
|
||||
this.applicationContext = SpringApplication.run( TaskExceptionConfiguration.class,
|
||||
this.applicationContext = SpringApplication.run(
|
||||
TaskExceptionConfiguration.class,
|
||||
"--spring.cloud.task.closecontext.enable=false",
|
||||
"--spring.cloud.task.name=" + TASK_NAME,
|
||||
"--spring.main.web-environment=false");
|
||||
@@ -110,19 +119,20 @@ public class TaskCoreTests {
|
||||
catch (IllegalStateException exception) {
|
||||
exceptionFired = true;
|
||||
}
|
||||
assertTrue("An IllegalStateException should have been thrown", exceptionFired);
|
||||
assertThat(exceptionFired).as("An IllegalStateException should have been thrown")
|
||||
.isTrue();
|
||||
|
||||
String output = this.outputCapture.toString();
|
||||
assertTrue("Test results do not show create task message: " + output,
|
||||
output.contains(CREATE_TASK_MESSAGE));
|
||||
assertTrue("Test results do not show success message: " + output,
|
||||
output.contains(UPDATE_TASK_MESSAGE));
|
||||
assertTrue("Test results have incorrect exit code: " + output,
|
||||
output.contains(EXCEPTION_EXIT_CODE_MESSAGE));
|
||||
assertTrue("Test results have incorrect exit message: " + output,
|
||||
output.contains(ERROR_MESSAGE));
|
||||
assertTrue("Test results have exception message: " + output,
|
||||
output.contains(EXCEPTION_MESSAGE));
|
||||
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
|
||||
@@ -130,7 +140,8 @@ public class TaskCoreTests {
|
||||
boolean exceptionFired = false;
|
||||
try {
|
||||
this.applicationContext = SpringApplication.run(
|
||||
TaskExceptionConfiguration.class, "--spring.cloud.task.closecontext.enable=false",
|
||||
TaskExceptionConfiguration.class,
|
||||
"--spring.cloud.task.closecontext.enable=false",
|
||||
"--spring.cloud.task.name=" + TASK_NAME,
|
||||
"--spring.main.web-environment=false",
|
||||
"--spring.cloud.task.executionid=55");
|
||||
@@ -138,15 +149,18 @@ public class TaskCoreTests {
|
||||
catch (ApplicationContextException exception) {
|
||||
exceptionFired = true;
|
||||
}
|
||||
assertTrue("An ApplicationContextException should have been thrown", exceptionFired);
|
||||
assertThat(exceptionFired)
|
||||
.as("An ApplicationContextException should have been thrown").isTrue();
|
||||
|
||||
String output = this.outputCapture.toString();
|
||||
assertTrue("Test results do not show the correct exception message: " + output,
|
||||
output.contains(EXCEPTION_INVALID_TASK_EXECUTION_ID));
|
||||
assertThat(output.contains(EXCEPTION_INVALID_TASK_EXECUTION_ID))
|
||||
.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
|
||||
@@ -157,10 +171,12 @@ public class TaskCoreTests {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@EnableTask
|
||||
@ImportAutoConfiguration({SimpleTaskAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class})
|
||||
@ImportAutoConfiguration({ SimpleTaskAutoConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class })
|
||||
public static class TaskConfigurationWithAnotation {
|
||||
|
||||
@Bean
|
||||
@@ -171,10 +187,12 @@ public class TaskCoreTests {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@EnableTask
|
||||
@ImportAutoConfiguration({SimpleTaskAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class})
|
||||
@ImportAutoConfiguration({ SimpleTaskAutoConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class })
|
||||
public static class TaskExceptionConfiguration {
|
||||
|
||||
@Bean
|
||||
@@ -186,5 +204,7 @@ public class TaskCoreTests {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.task;
|
||||
@@ -36,15 +36,15 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
|
||||
|
||||
/**
|
||||
* Verifies that TaskRepositoryInitializer creates tables if a {@link TaskConfigurer}
|
||||
* has a {@link DataSource}.
|
||||
* Verifies that TaskRepositoryInitializer creates tables if a {@link TaskConfigurer} has
|
||||
* a {@link DataSource}.
|
||||
*
|
||||
* @author Glenn Renfro
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(classes = {SimpleTaskAutoConfiguration.class,
|
||||
EmbeddedDataSourceConfiguration.class})
|
||||
@ContextConfiguration(classes = { SimpleTaskAutoConfiguration.class,
|
||||
EmbeddedDataSourceConfiguration.class })
|
||||
@DirtiesContext
|
||||
public class TaskRepositoryInitializerDefaultTaskConfigurerTests {
|
||||
|
||||
@@ -53,8 +53,9 @@ public class TaskRepositoryInitializerDefaultTaskConfigurerTests {
|
||||
|
||||
@Test
|
||||
public void testTablesCreated() {
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
List<Map<String, Object>> rows= jdbcTemplate.queryForList("SHOW TABLES");
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(this.dataSource);
|
||||
List<Map<String, Object>> rows = jdbcTemplate.queryForList("SHOW TABLES");
|
||||
assertThat(rows.size()).isEqualTo(4);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.task;
|
||||
@@ -37,16 +37,16 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
|
||||
|
||||
/**
|
||||
* Verifies that TaskRepositoryInitializer does not create tables if a {@link TaskConfigurer}
|
||||
* has no {@link DataSource}.
|
||||
* Verifies that TaskRepositoryInitializer does not create tables if a
|
||||
* {@link TaskConfigurer} has no {@link DataSource}.
|
||||
*
|
||||
* @author Glenn Renfro
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@RunWith(SpringRunner.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
|
||||
@@ -54,8 +54,9 @@ public class TaskRepositoryInitializerNoDataSourceTaskConfigurerTests {
|
||||
|
||||
@Test
|
||||
public void testNoTablesCreated() {
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
List<Map<String, Object>> rows= jdbcTemplate.queryForList("SHOW TABLES");
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(this.dataSource);
|
||||
List<Map<String, Object>> rows = jdbcTemplate.queryForList("SHOW TABLES");
|
||||
assertThat(rows.size()).isEqualTo(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.task.configuration;
|
||||
@@ -31,11 +31,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
import static org.hamcrest.core.IsNull.notNullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
@@ -54,64 +50,80 @@ public class DefaultTaskConfigurerTests {
|
||||
@Test
|
||||
public void resourcelessTransactionManagerTest() {
|
||||
DefaultTaskConfigurer defaultTaskConfigurer = new DefaultTaskConfigurer();
|
||||
assertThat(defaultTaskConfigurer.getTransactionManager().getClass().getName(),
|
||||
is("org.springframework.batch.support.transaction.ResourcelessTransactionManager"));
|
||||
assertThat(defaultTaskConfigurer.getTransactionManager().getClass().getName())
|
||||
.isEqualTo(
|
||||
"org.springframework.batch.support.transaction.ResourcelessTransactionManager");
|
||||
defaultTaskConfigurer = new DefaultTaskConfigurer("foo");
|
||||
assertThat(defaultTaskConfigurer.getTransactionManager().getClass().getName(),
|
||||
is("org.springframework.batch.support.transaction.ResourcelessTransactionManager"));
|
||||
assertThat(defaultTaskConfigurer.getTransactionManager().getClass().getName())
|
||||
.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(dataSource, TaskProperties.DEFAULT_TABLE_PREFIX, localContext);
|
||||
assertThat(defaultTaskConfigurer.getTransactionManager().getClass().getName(), is(equalTo("org.springframework.orm.jpa.JpaTransactionManager")));
|
||||
DefaultTaskConfigurer defaultTaskConfigurer = new DefaultTaskConfigurer(
|
||||
this.dataSource, TaskProperties.DEFAULT_TABLE_PREFIX, localContext);
|
||||
assertThat(defaultTaskConfigurer.getTransactionManager().getClass().getName())
|
||||
.isEqualTo("org.springframework.orm.jpa.JpaTransactionManager");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dataSourceTransactionManagerTest() {
|
||||
DefaultTaskConfigurer defaultTaskConfigurer = new DefaultTaskConfigurer(dataSource);
|
||||
assertThat(defaultTaskConfigurer.getTransactionManager().getClass().getName(),
|
||||
is("org.springframework.jdbc.datasource.DataSourceTransactionManager"));
|
||||
defaultTaskConfigurer = new DefaultTaskConfigurer(dataSource, "FOO", null);
|
||||
assertThat(defaultTaskConfigurer.getTransactionManager().getClass().getName(),
|
||||
is("org.springframework.jdbc.datasource.DataSourceTransactionManager"));
|
||||
defaultTaskConfigurer = new DefaultTaskConfigurer(dataSource, "FOO", context);
|
||||
assertThat(defaultTaskConfigurer.getTransactionManager().getClass().getName(),
|
||||
is("org.springframework.jdbc.datasource.DataSourceTransactionManager"));
|
||||
DefaultTaskConfigurer defaultTaskConfigurer = new DefaultTaskConfigurer(
|
||||
this.dataSource);
|
||||
assertThat(defaultTaskConfigurer.getTransactionManager().getClass().getName())
|
||||
.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);
|
||||
assertThat(defaultTaskConfigurer.getTransactionManager().getClass().getName())
|
||||
.isEqualTo(
|
||||
"org.springframework.jdbc.datasource.DataSourceTransactionManager");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void taskExplorerTest() {
|
||||
DefaultTaskConfigurer defaultTaskConfigurer = new DefaultTaskConfigurer(dataSource);
|
||||
assertThat(defaultTaskConfigurer.getTaskExplorer(), is(notNullValue()));
|
||||
DefaultTaskConfigurer defaultTaskConfigurer = new DefaultTaskConfigurer(
|
||||
this.dataSource);
|
||||
assertThat(defaultTaskConfigurer.getTaskExplorer()).isNotNull();
|
||||
defaultTaskConfigurer = new DefaultTaskConfigurer();
|
||||
assertThat(defaultTaskConfigurer.getTaskExplorer(), is(notNullValue()));
|
||||
assertThat(defaultTaskConfigurer.getTaskExplorer()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void taskRepositoryTest() {
|
||||
DefaultTaskConfigurer defaultTaskConfigurer = new DefaultTaskConfigurer(dataSource);
|
||||
assertThat(defaultTaskConfigurer.getTaskRepository(), is(notNullValue()));
|
||||
DefaultTaskConfigurer defaultTaskConfigurer = new DefaultTaskConfigurer(
|
||||
this.dataSource);
|
||||
assertThat(defaultTaskConfigurer.getTaskRepository()).isNotNull();
|
||||
defaultTaskConfigurer = new DefaultTaskConfigurer();
|
||||
assertThat(defaultTaskConfigurer.getTaskRepository(), is(notNullValue()));
|
||||
assertThat(defaultTaskConfigurer.getTaskRepository()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void taskDataSource() {
|
||||
DefaultTaskConfigurer defaultTaskConfigurer = new DefaultTaskConfigurer(dataSource);
|
||||
assertThat(defaultTaskConfigurer.getTaskDataSource(), is(notNullValue()));
|
||||
DefaultTaskConfigurer defaultTaskConfigurer = new DefaultTaskConfigurer(
|
||||
this.dataSource);
|
||||
assertThat(defaultTaskConfigurer.getTaskDataSource()).isNotNull();
|
||||
defaultTaskConfigurer = new DefaultTaskConfigurer();
|
||||
assertThat(defaultTaskConfigurer.getTaskDataSource(), is(nullValue()));
|
||||
assertThat(defaultTaskConfigurer.getTaskDataSource()).isNull();
|
||||
}
|
||||
|
||||
@Configuration
|
||||
public static class EntityManagerConfiguration {
|
||||
|
||||
@Bean
|
||||
public EntityManager entityManager() {
|
||||
return mock(EntityManager.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017-2018 the original author or authors.
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,36 +27,37 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@RunWith(Suite.class)
|
||||
@SuiteClasses({
|
||||
TaskPropertiesTests.CloseContextEnabledTest.class
|
||||
|
||||
@SuiteClasses({ TaskPropertiesTests.CloseContextEnabledTest.class
|
||||
|
||||
})
|
||||
|
||||
@DirtiesContext
|
||||
public class TaskPropertiesTests {
|
||||
|
||||
@Autowired
|
||||
TaskProperties taskProperties;
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
assertThat(taskProperties.getClosecontextEnabled(), is(false));
|
||||
assertThat(this.taskProperties.getClosecontextEnabled()).isFalse();
|
||||
}
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes={TaskPropertiesTests.Config.class,
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class},
|
||||
properties = { "spring.cloud.task.closecontextEnabled=false" })
|
||||
@SpringBootTest(classes = { TaskPropertiesTests.Config.class,
|
||||
SimpleTaskAutoConfiguration.class,
|
||||
SingleTaskConfiguration.class }, properties = {
|
||||
"spring.cloud.task.closecontextEnabled=false" })
|
||||
@DirtiesContext
|
||||
public static class CloseContextEnabledTest extends TaskPropertiesTests {}
|
||||
|
||||
|
||||
public static class CloseContextEnabledTest extends TaskPropertiesTests {
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
public static class Config {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2016 the original author or authors.
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.task.configuration;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
@@ -63,27 +64,29 @@ public class TestConfiguration implements InitializingBean {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TaskRepository taskRepository(){
|
||||
public TaskRepository taskRepository() {
|
||||
return new SimpleTaskRepository(this.taskExecutionDaoFactoryBean);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public PlatformTransactionManager transactionManager() {
|
||||
if(dataSource == null) {
|
||||
if (this.dataSource == null) {
|
||||
return new ResourcelessTransactionManager();
|
||||
}
|
||||
else {
|
||||
return new DataSourceTransactionManager(dataSource);
|
||||
return new DataSourceTransactionManager(this.dataSource);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
if(this.dataSource != null) {
|
||||
this.taskExecutionDaoFactoryBean = new TaskExecutionDaoFactoryBean(this.dataSource);
|
||||
if (this.dataSource != null) {
|
||||
this.taskExecutionDaoFactoryBean = new TaskExecutionDaoFactoryBean(
|
||||
this.dataSource);
|
||||
}
|
||||
else {
|
||||
this.taskExecutionDaoFactoryBean = new TaskExecutionDaoFactoryBean();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,25 +1,24 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.task.listener;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Glenn Renfro
|
||||
@@ -31,24 +30,25 @@ public class TaskExceptionTests {
|
||||
@Test
|
||||
public void testTaskException() {
|
||||
TaskException taskException = new TaskException(ERROR_MESSAGE);
|
||||
assertEquals(ERROR_MESSAGE, taskException.getMessage());
|
||||
assertThat(taskException.getMessage()).isEqualTo(ERROR_MESSAGE);
|
||||
|
||||
taskException = new TaskException(ERROR_MESSAGE,
|
||||
new IllegalStateException(ERROR_MESSAGE));
|
||||
assertEquals(ERROR_MESSAGE, taskException.getMessage());
|
||||
assertNotNull(taskException.getCause());
|
||||
assertEquals(ERROR_MESSAGE, taskException.getCause().getMessage());
|
||||
assertThat(taskException.getMessage()).isEqualTo(ERROR_MESSAGE);
|
||||
assertThat(taskException.getCause()).isNotNull();
|
||||
assertThat(taskException.getCause().getMessage()).isEqualTo(ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTaskExecutionException() {
|
||||
TaskExecutionException taskException = new TaskExecutionException(ERROR_MESSAGE);
|
||||
assertEquals(ERROR_MESSAGE, taskException.getMessage());
|
||||
assertThat(taskException.getMessage()).isEqualTo(ERROR_MESSAGE);
|
||||
|
||||
taskException = new TaskExecutionException(ERROR_MESSAGE,
|
||||
new IllegalStateException(ERROR_MESSAGE));
|
||||
assertEquals(ERROR_MESSAGE, taskException.getMessage());
|
||||
assertNotNull(taskException.getCause());
|
||||
assertEquals(ERROR_MESSAGE, taskException.getCause().getMessage());
|
||||
assertThat(taskException.getMessage()).isEqualTo(ERROR_MESSAGE);
|
||||
assertThat(taskException.getCause()).isNotNull();
|
||||
assertThat(taskException.getCause().getMessage()).isEqualTo(ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-2018 the original author or authors.
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -37,10 +37,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Verifies that the TaskExecutionListener invocations occur at the appropriate task
|
||||
@@ -49,14 +46,17 @@ import static org.junit.Assert.assertTrue;
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
public class TaskExecutionListenerTests {
|
||||
private AnnotationConfigApplicationContext context;
|
||||
|
||||
private static final String EXCEPTION_MESSAGE = "This was expected";
|
||||
|
||||
private static boolean beforeTaskDidFireOnError = false;
|
||||
|
||||
private static boolean endTaskDidFireOnError = false;
|
||||
|
||||
private static boolean failedTaskDidFireOnError = false;
|
||||
|
||||
private AnnotationConfigApplicationContext context;
|
||||
|
||||
@BeforeTask
|
||||
public void setup() {
|
||||
beforeTaskDidFireOnError = false;
|
||||
@@ -66,27 +66,29 @@ public class TaskExecutionListenerTests {
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
if(context != null && context.isActive()) {
|
||||
context.close();
|
||||
if (this.context != null && this.context.isActive()) {
|
||||
this.context.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that if a TaskExecutionListener Bean is present that the onTaskStartup method
|
||||
* is called.
|
||||
* Verify that if a TaskExecutionListener Bean is present that the onTaskStartup
|
||||
* method is called.
|
||||
*/
|
||||
@Test
|
||||
public void testTaskCreate() {
|
||||
setupContextForTaskExecutionListener();
|
||||
DefaultTaskListenerConfiguration.TestTaskExecutionListener taskExecutionListener =
|
||||
context.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);
|
||||
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);
|
||||
verifyListenerResults(false, false, taskExecution, taskExecutionListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that if a LifecycleProcessor executes all TaskExecutionListeners if BeforeTask throws exception.
|
||||
* Verify that if a LifecycleProcessor executes all TaskExecutionListeners if
|
||||
* BeforeTask throws exception.
|
||||
*/
|
||||
@Test
|
||||
public void testBeforeTaskErrorCreate() {
|
||||
@@ -97,14 +99,18 @@ public class TaskExecutionListenerTests {
|
||||
catch (Exception exception) {
|
||||
exceptionFired = true;
|
||||
}
|
||||
assertTrue("Exception should have fired", exceptionFired);
|
||||
assertTrue("BeforeTask Listener should have executed", beforeTaskDidFireOnError);
|
||||
assertTrue("EndTask Listener should have executed", endTaskDidFireOnError);
|
||||
assertTrue("FailedTask Listener should have executed", failedTaskDidFireOnError);
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that if a LifecycleProcessor executes AfterTask TaskExecutionListeners if FailedTask throws exception.
|
||||
* Verify that if a LifecycleProcessor executes AfterTask TaskExecutionListeners if
|
||||
* FailedTask throws exception.
|
||||
*/
|
||||
@Test
|
||||
public void testFailedTaskErrorCreate() {
|
||||
@@ -115,42 +121,52 @@ public class TaskExecutionListenerTests {
|
||||
catch (Exception exception) {
|
||||
exceptionFired = true;
|
||||
}
|
||||
assertTrue("Exception should have fired", exceptionFired);
|
||||
assertTrue("EndTask Listener should have executed", endTaskDidFireOnError);
|
||||
assertTrue("FailedTask Listener should not have executed", failedTaskDidFireOnError);
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that if a LifecycleProcessor stores the correct exit code if AfterTask listener fails.
|
||||
* Verify that if a LifecycleProcessor stores the correct exit code if AfterTask
|
||||
* listener fails.
|
||||
*/
|
||||
@Test
|
||||
public void testAfterTaskErrorCreate() {
|
||||
setupContextForAfterTaskErrorAnnotatedListener();
|
||||
AfterTaskErrorAnnotationConfiguration.AnnotatedTaskListener taskExecutionListener =
|
||||
context.getBean(AfterTaskErrorAnnotationConfiguration.AnnotatedTaskListener.class);
|
||||
context.publishEvent(new ApplicationReadyEvent(new SpringApplication(), new String[0], context));
|
||||
AfterTaskErrorAnnotationConfiguration.AnnotatedTaskListener taskExecutionListener = this.context
|
||||
.getBean(
|
||||
AfterTaskErrorAnnotationConfiguration.AnnotatedTaskListener.class);
|
||||
this.context.publishEvent(new ApplicationReadyEvent(new SpringApplication(),
|
||||
new String[0], this.context));
|
||||
|
||||
assertTrue(taskExecutionListener.isTaskStartup());
|
||||
assertTrue(taskExecutionListener.isTaskEnd());
|
||||
assertEquals(TestListener.END_MESSAGE, taskExecutionListener.getTaskExecution().getExitMessage());
|
||||
assertTrue(taskExecutionListener.getTaskExecution().getErrorMessage().contains("Failed to process @BeforeTask or @AfterTask annotation because: AfterTaskFailure"));
|
||||
assertNull(taskExecutionListener.getThrowable());
|
||||
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.getThrowable()).isNull();
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that if a TaskExecutionListener Bean is present that the onTaskEnd method
|
||||
* is called.
|
||||
* Verify that if a TaskExecutionListener Bean is present that the onTaskEnd method is
|
||||
* called.
|
||||
*/
|
||||
@Test
|
||||
public void testTaskUpdate() {
|
||||
setupContextForTaskExecutionListener();
|
||||
DefaultTaskListenerConfiguration.TestTaskExecutionListener taskExecutionListener =
|
||||
context.getBean(DefaultTaskListenerConfiguration.TestTaskExecutionListener.class);
|
||||
context.publishEvent(new ApplicationReadyEvent(new SpringApplication(), new String[0], context));
|
||||
DefaultTaskListenerConfiguration.TestTaskExecutionListener taskExecutionListener = this.context
|
||||
.getBean(
|
||||
DefaultTaskListenerConfiguration.TestTaskExecutionListener.class);
|
||||
this.context.publishEvent(new ApplicationReadyEvent(new SpringApplication(),
|
||||
new String[0], this.context));
|
||||
|
||||
TaskExecution taskExecution = new TaskExecution(0, 0, "wombat",
|
||||
new Date(), new Date(), null, new ArrayList<>(), null, null);
|
||||
verifyListenerResults(true, false, taskExecution,taskExecutionListener);
|
||||
TaskExecution taskExecution = new TaskExecution(0, 0, "wombat", new Date(),
|
||||
new Date(), null, new ArrayList<>(), null, null);
|
||||
verifyListenerResults(true, false, taskExecution, taskExecutionListener);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -162,14 +178,17 @@ public class TaskExecutionListenerTests {
|
||||
RuntimeException exception = new RuntimeException(EXCEPTION_MESSAGE);
|
||||
setupContextForTaskExecutionListener();
|
||||
SpringApplication application = new SpringApplication();
|
||||
DefaultTaskListenerConfiguration.TestTaskExecutionListener taskExecutionListener =
|
||||
context.getBean(DefaultTaskListenerConfiguration.TestTaskExecutionListener.class);
|
||||
context.publishEvent(new ApplicationFailedEvent(application, new String[0], context, exception));
|
||||
context.publishEvent(new ApplicationReadyEvent(application, new String[0], context));
|
||||
DefaultTaskListenerConfiguration.TestTaskExecutionListener taskExecutionListener = this.context
|
||||
.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));
|
||||
|
||||
TaskExecution taskExecution = new TaskExecution(0, 1, "wombat", new Date(),
|
||||
new Date(), null, new ArrayList<>(), null, null);
|
||||
verifyListenerResults(true, true, taskExecution,taskExecutionListener);
|
||||
verifyListenerResults(true, true, taskExecution, taskExecutionListener);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -179,11 +198,11 @@ public class TaskExecutionListenerTests {
|
||||
@Test
|
||||
public void testAnnotationCreate() {
|
||||
setupContextForAnnotatedListener();
|
||||
DefaultAnnotationConfiguration.AnnotatedTaskListener annotatedListener =
|
||||
context.getBean(DefaultAnnotationConfiguration.AnnotatedTaskListener.class);
|
||||
TaskExecution taskExecution = new TaskExecution(0, null, "wombat",
|
||||
new Date(), new Date(), null, new ArrayList<>(), null, null);
|
||||
verifyListenerResults(false, false, taskExecution,annotatedListener);
|
||||
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);
|
||||
verifyListenerResults(false, false, taskExecution, annotatedListener);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -193,13 +212,14 @@ public class TaskExecutionListenerTests {
|
||||
@Test
|
||||
public void testAnnotationUpdate() {
|
||||
setupContextForAnnotatedListener();
|
||||
DefaultAnnotationConfiguration.AnnotatedTaskListener annotatedListener =
|
||||
context.getBean(DefaultAnnotationConfiguration.AnnotatedTaskListener.class);
|
||||
context.publishEvent(new ApplicationReadyEvent(new SpringApplication(), new String[0], context));
|
||||
DefaultAnnotationConfiguration.AnnotatedTaskListener annotatedListener = this.context
|
||||
.getBean(DefaultAnnotationConfiguration.AnnotatedTaskListener.class);
|
||||
this.context.publishEvent(new ApplicationReadyEvent(new SpringApplication(),
|
||||
new String[0], this.context));
|
||||
|
||||
TaskExecution taskExecution = new TaskExecution(0, 0, "wombat",
|
||||
new Date(), new Date(), null, new ArrayList<>(), null, null);
|
||||
verifyListenerResults(true, false, taskExecution,annotatedListener);
|
||||
TaskExecution taskExecution = new TaskExecution(0, 0, "wombat", new Date(),
|
||||
new Date(), null, new ArrayList<>(), null, null);
|
||||
verifyListenerResults(true, false, taskExecution, annotatedListener);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -211,73 +231,91 @@ public class TaskExecutionListenerTests {
|
||||
RuntimeException exception = new RuntimeException(EXCEPTION_MESSAGE);
|
||||
setupContextForAnnotatedListener();
|
||||
SpringApplication application = new SpringApplication();
|
||||
DefaultAnnotationConfiguration.AnnotatedTaskListener annotatedListener =
|
||||
context.getBean(DefaultAnnotationConfiguration.AnnotatedTaskListener.class);
|
||||
context.publishEvent(new ApplicationFailedEvent(application, new String[0], context, exception));
|
||||
context.publishEvent(new ApplicationReadyEvent(application, new String[0], context));
|
||||
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 ApplicationReadyEvent(application, new String[0], this.context));
|
||||
|
||||
TaskExecution taskExecution = new TaskExecution(0, 1, "wombat", new Date(),
|
||||
new Date(), null, new ArrayList<>(), null, null);
|
||||
verifyListenerResults(true, true, taskExecution,annotatedListener);
|
||||
verifyListenerResults(true, true, taskExecution, annotatedListener);
|
||||
}
|
||||
|
||||
private void verifyListenerResults(boolean isTaskEnd,
|
||||
boolean isTaskFailed, TaskExecution taskExecution,
|
||||
TestListener actualListener){
|
||||
assertTrue(actualListener.isTaskStartup());
|
||||
assertEquals(isTaskEnd,actualListener.isTaskEnd());
|
||||
assertEquals(isTaskFailed,actualListener.isTaskFailed());
|
||||
if(isTaskFailed){
|
||||
assertEquals(TestListener.END_MESSAGE, actualListener.getTaskExecution().getExitMessage());
|
||||
assertNotNull(actualListener.getThrowable());
|
||||
assertTrue(actualListener.getThrowable() instanceof RuntimeException);
|
||||
assertTrue(actualListener.getTaskExecution().getErrorMessage().startsWith("java.lang.RuntimeException: This was expected"));
|
||||
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.getThrowable()).isNotNull();
|
||||
assertThat(actualListener.getThrowable() instanceof RuntimeException)
|
||||
.isTrue();
|
||||
assertThat(actualListener.getTaskExecution().getErrorMessage()
|
||||
.startsWith("java.lang.RuntimeException: This was expected"))
|
||||
.isTrue();
|
||||
}
|
||||
else if(isTaskEnd){
|
||||
assertEquals(TestListener.END_MESSAGE, actualListener.getTaskExecution().getExitMessage());
|
||||
assertEquals(taskExecution.getErrorMessage(), actualListener.getTaskExecution().getErrorMessage());
|
||||
assertNull(actualListener.getThrowable());
|
||||
else if (isTaskEnd) {
|
||||
assertThat(actualListener.getTaskExecution().getExitMessage())
|
||||
.isEqualTo(TestListener.END_MESSAGE);
|
||||
assertThat(actualListener.getTaskExecution().getErrorMessage())
|
||||
.isEqualTo(taskExecution.getErrorMessage());
|
||||
assertThat(actualListener.getThrowable()).isNull();
|
||||
}
|
||||
else {
|
||||
assertEquals(TestListener.START_MESSAGE, actualListener.getTaskExecution().getExitMessage());
|
||||
assertNull(actualListener.getTaskExecution().getErrorMessage());
|
||||
assertNull(actualListener.getThrowable());
|
||||
assertThat(actualListener.getTaskExecution().getExitMessage())
|
||||
.isEqualTo(TestListener.START_MESSAGE);
|
||||
assertThat(actualListener.getTaskExecution().getErrorMessage()).isNull();
|
||||
assertThat(actualListener.getThrowable()).isNull();
|
||||
}
|
||||
|
||||
assertEquals(taskExecution.getExecutionId(), actualListener.getTaskExecution().getExecutionId());
|
||||
assertEquals(taskExecution.getExitCode(), actualListener.getTaskExecution().getExitCode());
|
||||
assertEquals(taskExecution.getExternalExecutionId(), actualListener.getTaskExecution().getExternalExecutionId());
|
||||
assertThat(actualListener.getTaskExecution().getExecutionId())
|
||||
.isEqualTo(taskExecution.getExecutionId());
|
||||
assertThat(actualListener.getTaskExecution().getExitCode())
|
||||
.isEqualTo(taskExecution.getExitCode());
|
||||
assertThat(actualListener.getTaskExecution().getExternalExecutionId())
|
||||
.isEqualTo(taskExecution.getExternalExecutionId());
|
||||
}
|
||||
|
||||
private void setupContextForTaskExecutionListener(){
|
||||
context = new AnnotationConfigApplicationContext(DefaultTaskListenerConfiguration.class,
|
||||
private void setupContextForTaskExecutionListener() {
|
||||
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.setId("annotatedTask");
|
||||
}
|
||||
|
||||
private void setupContextForBeforeTaskErrorAnnotatedListener() {
|
||||
this.context = new AnnotationConfigApplicationContext(
|
||||
TestDefaultConfiguration.class,
|
||||
BeforeTaskErrorAnnotationConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
context.setId("testTask");
|
||||
this.context.setId("beforeTaskAnnotatedTask");
|
||||
}
|
||||
|
||||
private void setupContextForAnnotatedListener(){
|
||||
context = new AnnotationConfigApplicationContext(TestDefaultConfiguration.class, DefaultAnnotationConfiguration.class,
|
||||
private void setupContextForFailedTaskErrorAnnotatedListener() {
|
||||
this.context = new AnnotationConfigApplicationContext(
|
||||
TestDefaultConfiguration.class,
|
||||
FailedTaskErrorAnnotationConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
context.setId("annotatedTask");
|
||||
this.context.setId("failedTaskAnnotatedTask");
|
||||
}
|
||||
|
||||
private void setupContextForBeforeTaskErrorAnnotatedListener(){
|
||||
context = new AnnotationConfigApplicationContext(TestDefaultConfiguration.class, BeforeTaskErrorAnnotationConfiguration.class,
|
||||
private void setupContextForAfterTaskErrorAnnotatedListener() {
|
||||
this.context = new AnnotationConfigApplicationContext(
|
||||
TestDefaultConfiguration.class,
|
||||
AfterTaskErrorAnnotationConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
context.setId("beforeTaskAnnotatedTask");
|
||||
}
|
||||
|
||||
private void setupContextForFailedTaskErrorAnnotatedListener(){
|
||||
context = new AnnotationConfigApplicationContext(TestDefaultConfiguration.class, FailedTaskErrorAnnotationConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
context.setId("failedTaskAnnotatedTask");
|
||||
}
|
||||
|
||||
private void setupContextForAfterTaskErrorAnnotatedListener(){
|
||||
context = new AnnotationConfigApplicationContext(TestDefaultConfiguration.class, AfterTaskErrorAnnotationConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
context.setId("afterTaskAnnotatedTask");
|
||||
this.context.setId("afterTaskAnnotatedTask");
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@@ -292,14 +330,14 @@ public class TaskExecutionListenerTests {
|
||||
|
||||
@BeforeTask
|
||||
public void methodA(TaskExecution taskExecution) {
|
||||
isTaskStartup = true;
|
||||
this.isTaskStartup = true;
|
||||
this.taskExecution = taskExecution;
|
||||
this.taskExecution.setExitMessage(START_MESSAGE);
|
||||
}
|
||||
|
||||
@AfterTask
|
||||
public void methodB(TaskExecution taskExecution) {
|
||||
isTaskEnd = true;
|
||||
this.isTaskEnd = true;
|
||||
this.taskExecution = taskExecution;
|
||||
this.taskExecution.setExitMessage(END_MESSAGE);
|
||||
|
||||
@@ -307,12 +345,14 @@ public class TaskExecutionListenerTests {
|
||||
|
||||
@FailedTask
|
||||
public void methodC(TaskExecution taskExecution, Throwable throwable) {
|
||||
isTaskFailed = true;
|
||||
this.isTaskFailed = true;
|
||||
this.taskExecution = taskExecution;
|
||||
this.throwable = throwable;
|
||||
this.taskExecution.setExitMessage(ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@@ -345,7 +385,9 @@ public class TaskExecutionListenerTests {
|
||||
public void methodC(TaskExecution taskExecution, Throwable throwable) {
|
||||
failedTaskDidFireOnError = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@@ -356,7 +398,6 @@ public class TaskExecutionListenerTests {
|
||||
return new AnnotatedTaskListener();
|
||||
}
|
||||
|
||||
|
||||
public static class AnnotatedTaskListener {
|
||||
|
||||
@BeforeTask
|
||||
@@ -375,7 +416,9 @@ public class TaskExecutionListenerTests {
|
||||
failedTaskDidFireOnError = true;
|
||||
throw new TaskExecutionException("FailedTaskFailure");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@@ -386,21 +429,23 @@ public class TaskExecutionListenerTests {
|
||||
return new AnnotatedTaskListener();
|
||||
}
|
||||
|
||||
public static class AnnotatedTaskListener extends TestListener{
|
||||
public static class AnnotatedTaskListener extends TestListener {
|
||||
|
||||
@BeforeTask
|
||||
public void methodA(TaskExecution taskExecution) {
|
||||
isTaskStartup = true;
|
||||
this.isTaskStartup = true;
|
||||
}
|
||||
|
||||
@AfterTask
|
||||
public void methodB(TaskExecution taskExecution) {
|
||||
isTaskEnd = true;
|
||||
this.isTaskEnd = true;
|
||||
this.taskExecution = taskExecution;
|
||||
this.taskExecution.setExitMessage(END_MESSAGE);
|
||||
throw new TaskExecutionException("AfterTaskFailure");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@@ -411,31 +456,33 @@ 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) {
|
||||
isTaskStartup = true;
|
||||
this.isTaskStartup = true;
|
||||
this.taskExecution = taskExecution;
|
||||
this.taskExecution.setExitMessage(START_MESSAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTaskEnd(TaskExecution taskExecution) {
|
||||
isTaskEnd = true;
|
||||
this.isTaskEnd = true;
|
||||
this.taskExecution = taskExecution;
|
||||
this.taskExecution.setExitMessage(END_MESSAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTaskFailed(TaskExecution taskExecution, Throwable throwable) {
|
||||
isTaskFailed = true;
|
||||
this.isTaskFailed = true;
|
||||
this.taskExecution = taskExecution;
|
||||
this.throwable = throwable;
|
||||
this.taskExecution.setExitMessage(ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2018 the original author or authors.
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -51,32 +51,30 @@ import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Verifies that the TaskLifecycleListener Methods record the appropriate log header entries and
|
||||
* result codes.
|
||||
* Verifies that the TaskLifecycleListener Methods record the appropriate log header
|
||||
* entries and result codes.
|
||||
*
|
||||
* @author Glenn Renfro
|
||||
* @author Michael Minella
|
||||
*/
|
||||
public class TaskLifecycleListenerTests {
|
||||
|
||||
@Rule
|
||||
public OutputCapture outputCapture = new OutputCapture();
|
||||
|
||||
private AnnotationConfigApplicationContext context;
|
||||
|
||||
private TaskExplorer taskExplorer;
|
||||
|
||||
@Rule
|
||||
public OutputCapture outputCapture = new OutputCapture();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
context = new AnnotationConfigApplicationContext();
|
||||
context.setId("testTask");
|
||||
context.register(TestDefaultConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context.setId("testTask");
|
||||
this.context.register(TestDefaultConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
TestListener.getStartupOrderList().clear();
|
||||
TestListener.getFailOrderList().clear();
|
||||
TestListener.getEndOrderList().clear();
|
||||
@@ -85,44 +83,47 @@ public class TaskLifecycleListenerTests {
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
if(context != null && context.isActive()) {
|
||||
context.close();
|
||||
if (this.context != null && this.context.isActive()) {
|
||||
this.context.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTaskCreate() {
|
||||
context.refresh();
|
||||
this.taskExplorer = context.getBean(TaskExplorer.class);
|
||||
this.context.refresh();
|
||||
this.taskExplorer = this.context.getBean(TaskExplorer.class);
|
||||
verifyTaskExecution(0, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTaskCreateWithArgs() {
|
||||
context.register(ArgsConfiguration.class);
|
||||
context.refresh();
|
||||
this.taskExplorer = context.getBean(TaskExplorer.class);
|
||||
this.context.register(ArgsConfiguration.class);
|
||||
this.context.refresh();
|
||||
this.taskExplorer = this.context.getBean(TaskExplorer.class);
|
||||
verifyTaskExecution(2, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTaskUpdate() {
|
||||
context.refresh();
|
||||
this.taskExplorer = context.getBean(TaskExplorer.class);
|
||||
this.context.refresh();
|
||||
this.taskExplorer = this.context.getBean(TaskExplorer.class);
|
||||
|
||||
context.publishEvent(new ApplicationReadyEvent(new SpringApplication(), new String[0], context));
|
||||
this.context.publishEvent(new ApplicationReadyEvent(new SpringApplication(),
|
||||
new String[0], this.context));
|
||||
|
||||
verifyTaskExecution(0, true, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTaskFailedUpdate() {
|
||||
context.refresh();
|
||||
this.context.refresh();
|
||||
RuntimeException exception = new RuntimeException("This was expected");
|
||||
SpringApplication application = new SpringApplication();
|
||||
this.taskExplorer = context.getBean(TaskExplorer.class);
|
||||
context.publishEvent(new ApplicationFailedEvent(application, new String[0], context, exception));
|
||||
context.publishEvent(new ApplicationReadyEvent(application, new String[0], context));
|
||||
this.taskExplorer = this.context.getBean(TaskExplorer.class);
|
||||
this.context.publishEvent(new ApplicationFailedEvent(application, new String[0],
|
||||
this.context, exception));
|
||||
this.context.publishEvent(
|
||||
new ApplicationReadyEvent(application, new String[0], this.context));
|
||||
|
||||
verifyTaskExecution(0, true, 1, exception, null);
|
||||
}
|
||||
@@ -130,38 +131,44 @@ public class TaskLifecycleListenerTests {
|
||||
@Test
|
||||
public void testTaskFailedWithExitCodeEvent() {
|
||||
final int exitCode = 10;
|
||||
context.register(TestListener.class);
|
||||
context.register(TestListener2.class);
|
||||
this.context.register(TestListener.class);
|
||||
this.context.register(TestListener2.class);
|
||||
|
||||
context.refresh();
|
||||
this.context.refresh();
|
||||
RuntimeException exception = new RuntimeException("This was expected");
|
||||
SpringApplication application = new SpringApplication();
|
||||
this.taskExplorer = context.getBean(TaskExplorer.class);
|
||||
context.publishEvent(new ExitCodeEvent(context, exitCode));
|
||||
context.publishEvent(new ApplicationFailedEvent(application, new String[0], context, exception));
|
||||
context.publishEvent(new ApplicationReadyEvent(application, new String[0], context));
|
||||
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 ApplicationReadyEvent(application, new String[0], this.context));
|
||||
|
||||
verifyTaskExecution(0, true, exitCode, exception, null);
|
||||
assertEquals(2, TestListener.getStartupOrderList().size());
|
||||
assertEquals(Integer.valueOf(2), TestListener.getStartupOrderList().get(0));
|
||||
assertEquals(Integer.valueOf(1), TestListener.getStartupOrderList().get(1));
|
||||
assertThat(TestListener.getStartupOrderList().size()).isEqualTo(2);
|
||||
assertThat(TestListener.getStartupOrderList().get(0))
|
||||
.isEqualTo(Integer.valueOf(2));
|
||||
assertThat(TestListener.getStartupOrderList().get(1))
|
||||
.isEqualTo(Integer.valueOf(1));
|
||||
|
||||
assertEquals(2, TestListener.getEndOrderList().size());
|
||||
assertEquals(Integer.valueOf(1), TestListener.getEndOrderList().get(0));
|
||||
assertEquals(Integer.valueOf(2), TestListener.getEndOrderList().get(1));
|
||||
assertThat(TestListener.getEndOrderList().size()).isEqualTo(2);
|
||||
assertThat(TestListener.getEndOrderList().get(0)).isEqualTo(Integer.valueOf(1));
|
||||
assertThat(TestListener.getEndOrderList().get(1)).isEqualTo(Integer.valueOf(2));
|
||||
|
||||
assertEquals(2, TestListener.getFailOrderList().size());
|
||||
assertEquals(Integer.valueOf(1), TestListener.getFailOrderList().get(0));
|
||||
assertEquals(Integer.valueOf(2), TestListener.getFailOrderList().get(1));
|
||||
assertThat(TestListener.getFailOrderList().size()).isEqualTo(2);
|
||||
assertThat(TestListener.getFailOrderList().get(0)).isEqualTo(Integer.valueOf(1));
|
||||
assertThat(TestListener.getFailOrderList().get(1)).isEqualTo(Integer.valueOf(2));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoClosingOfContext() {
|
||||
|
||||
try (ConfigurableApplicationContext applicationContext = SpringApplication.run(new Class[] {TestDefaultConfiguration.class, PropertyPlaceholderAutoConfiguration.class},
|
||||
new String[] {"--spring.cloud.task.closecontext_enabled=false"})) {
|
||||
assertTrue(applicationContext.isActive());
|
||||
try (ConfigurableApplicationContext applicationContext = SpringApplication.run(
|
||||
new Class[] { TestDefaultConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class },
|
||||
new String[] { "--spring.cloud.task.closecontext_enabled=false" })) {
|
||||
assertThat(applicationContext.isActive()).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,20 +178,21 @@ 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));
|
||||
context.setEnvironment(environment);
|
||||
context.refresh();
|
||||
propertySources
|
||||
.addFirst(new MapPropertySource("EnvrionmentTestPropsource", myMap));
|
||||
this.context.setEnvironment(environment);
|
||||
this.context.refresh();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRestartExistingTask() {
|
||||
context.refresh();
|
||||
TaskLifecycleListener taskLifecycleListener =
|
||||
context.getBean(TaskLifecycleListener.class);
|
||||
this.context.refresh();
|
||||
TaskLifecycleListener taskLifecycleListener = this.context
|
||||
.getBean(TaskLifecycleListener.class);
|
||||
taskLifecycleListener.start();
|
||||
String output = this.outputCapture.toString();
|
||||
assertTrue("Test results do not show error message: " + output,
|
||||
output.contains("Multiple start events have been received"));
|
||||
assertThat(output.contains("Multiple start events have been received"))
|
||||
.as("Test results do not show error message: " + output).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -193,10 +201,11 @@ 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));
|
||||
context.setEnvironment(environment);
|
||||
context.refresh();
|
||||
this.taskExplorer = context.getBean(TaskExplorer.class);
|
||||
propertySources
|
||||
.addFirst(new MapPropertySource("EnvrionmentTestPropsource", myMap));
|
||||
this.context.setEnvironment(environment);
|
||||
this.context.refresh();
|
||||
this.taskExplorer = this.context.getBean(TaskExplorer.class);
|
||||
|
||||
verifyTaskExecution(0, false, null, null, "myid");
|
||||
}
|
||||
@@ -207,15 +216,17 @@ 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));
|
||||
context.setEnvironment(environment);
|
||||
context.refresh();
|
||||
this.taskExplorer = context.getBean(TaskExplorer.class);
|
||||
propertySources
|
||||
.addFirst(new MapPropertySource("EnvrionmentTestPropsource", myMap));
|
||||
this.context.setEnvironment(environment);
|
||||
this.context.refresh();
|
||||
this.taskExplorer = this.context.getBean(TaskExplorer.class);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -223,47 +234,48 @@ public class TaskLifecycleListenerTests {
|
||||
verifyTaskExecution(numberOfParams, update, null, null, null);
|
||||
}
|
||||
|
||||
private void verifyTaskExecution(int numberOfParams, boolean update,
|
||||
Integer exitCode, Throwable exception, String externalExecutionId) {
|
||||
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);
|
||||
assertTrue(taskExecutionsByName.iterator().hasNext());
|
||||
Page<TaskExecution> taskExecutionsByName = this.taskExplorer
|
||||
.findTaskExecutionsByName("testTask", request);
|
||||
assertThat(taskExecutionsByName.iterator().hasNext()).isTrue();
|
||||
TaskExecution taskExecution = taskExecutionsByName.iterator().next();
|
||||
|
||||
assertEquals(numberOfParams, taskExecution.getArguments().size());
|
||||
assertEquals(exitCode, taskExecution.getExitCode());
|
||||
assertEquals(externalExecutionId, taskExecution.getExternalExecutionId());
|
||||
assertEquals(parentExecutionId, taskExecution.getParentExecutionId());
|
||||
assertThat(taskExecution.getArguments().size()).isEqualTo(numberOfParams);
|
||||
assertThat(taskExecution.getExitCode()).isEqualTo(exitCode);
|
||||
assertThat(taskExecution.getExternalExecutionId()).isEqualTo(externalExecutionId);
|
||||
assertThat(taskExecution.getParentExecutionId()).isEqualTo(parentExecutionId);
|
||||
|
||||
if(exception != null) {
|
||||
assertTrue(taskExecution.getErrorMessage().length() > exception.getStackTrace().length);
|
||||
if (exception != null) {
|
||||
assertThat(taskExecution.getErrorMessage()
|
||||
.length() > exception.getStackTrace().length).isTrue();
|
||||
}
|
||||
else {
|
||||
assertNull(taskExecution.getExitMessage());
|
||||
assertThat(taskExecution.getExitMessage()).isNull();
|
||||
}
|
||||
|
||||
if(update) {
|
||||
assertTrue(taskExecution.getEndTime().getTime() >= taskExecution.getStartTime().getTime());
|
||||
assertNotNull(taskExecution.getExitCode());
|
||||
if (update) {
|
||||
assertThat(taskExecution.getEndTime().getTime() >= taskExecution
|
||||
.getStartTime().getTime()).isTrue();
|
||||
assertThat(taskExecution.getExitCode()).isNotNull();
|
||||
}
|
||||
else {
|
||||
assertNull(taskExecution.getEndTime());
|
||||
assertTrue(taskExecution.getExitCode() == null);
|
||||
assertThat(taskExecution.getEndTime()).isNull();
|
||||
assertThat(taskExecution.getExitCode() == null).isTrue();
|
||||
}
|
||||
|
||||
assertEquals("testTask", taskExecution.getTaskName());
|
||||
assertThat(taskExecution.getTaskName()).isEqualTo("testTask");
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@@ -278,23 +290,25 @@ public class TaskLifecycleListenerTests {
|
||||
|
||||
return new SimpleApplicationArgs(args);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class SimpleApplicationArgs implements ApplicationArguments {
|
||||
|
||||
private Map<String, String> args;
|
||||
|
||||
public SimpleApplicationArgs(Map<String, String> args) {
|
||||
SimpleApplicationArgs(Map<String, String> args) {
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getSourceArgs() {
|
||||
String [] sourceArgs = new String[this.args.size()];
|
||||
String[] sourceArgs = new String[this.args.size()];
|
||||
|
||||
int i = 0;
|
||||
for (Map.Entry<String, String> stringStringEntry : args.entrySet()) {
|
||||
sourceArgs[i] = "--" + stringStringEntry.getKey() + "=" + stringStringEntry.getValue();
|
||||
for (Map.Entry<String, String> stringStringEntry : this.args.entrySet()) {
|
||||
sourceArgs[i] = "--" + stringStringEntry.getKey() + "="
|
||||
+ stringStringEntry.getValue();
|
||||
i++;
|
||||
}
|
||||
|
||||
@@ -320,6 +334,7 @@ public class TaskLifecycleListenerTests {
|
||||
public List<String> getNonOptionArgs() {
|
||||
throw new UnsupportedOperationException("Not supported at this time.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class TestListener2 extends TestListener {
|
||||
@@ -328,34 +343,17 @@ public class TaskLifecycleListenerTests {
|
||||
|
||||
private static class TestListener implements TaskExecutionListener {
|
||||
|
||||
static List<Integer> startupOrderList = new ArrayList<>();
|
||||
static List<Integer> endOrderList = new ArrayList<>();
|
||||
static List<Integer> failOrderList = new ArrayList<>();
|
||||
|
||||
private static int currentCount = 0;
|
||||
|
||||
private int id = 0;
|
||||
|
||||
static List<Integer> startupOrderList = new ArrayList<>();
|
||||
|
||||
static List<Integer> endOrderList = new ArrayList<>();
|
||||
|
||||
static List<Integer> failOrderList = new ArrayList<>();
|
||||
|
||||
public TestListener() {
|
||||
TestListener() {
|
||||
currentCount++;
|
||||
id = currentCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTaskStartup(TaskExecution taskExecution) {
|
||||
startupOrderList.add(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTaskEnd(TaskExecution taskExecution) {
|
||||
endOrderList.add(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTaskFailed(TaskExecution taskExecution, Throwable throwable) {
|
||||
failOrderList.add(id);
|
||||
this.id = currentCount;
|
||||
}
|
||||
|
||||
public static List<Integer> getStartupOrderList() {
|
||||
@@ -369,5 +367,22 @@ public class TaskLifecycleListenerTests {
|
||||
public static List<Integer> getFailOrderList() {
|
||||
return failOrderList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTaskStartup(TaskExecution taskExecution) {
|
||||
startupOrderList.add(this.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTaskEnd(TaskExecution taskExecution) {
|
||||
endOrderList.add(this.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTaskFailed(TaskExecution taskExecution, Throwable throwable) {
|
||||
failOrderList.add(this.id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.task.listener;
|
||||
@@ -46,7 +46,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @since 2.1.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(classes = { TaskListenerExecutorObjectFactoryTests.TaskExecutionListenerConfiguration.class })
|
||||
@ContextConfiguration(classes = {
|
||||
TaskListenerExecutorObjectFactoryTests.TaskExecutionListenerConfiguration.class })
|
||||
@DirtiesContext
|
||||
public class TaskListenerExecutorObjectFactoryTests {
|
||||
|
||||
@@ -68,13 +69,15 @@ public class TaskListenerExecutorObjectFactoryTests {
|
||||
@Before
|
||||
public void setup() {
|
||||
taskExecutionListenerResults.clear();
|
||||
this.taskListenerExecutorObjectFactory = new TaskListenerExecutorObjectFactory(this.context);
|
||||
this.taskListenerExecutorObjectFactory = new TaskListenerExecutorObjectFactory(
|
||||
this.context);
|
||||
this.taskListenerExecutor = this.taskListenerExecutorObjectFactory.getObject();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyTaskStartupListener() {
|
||||
this.taskListenerExecutor.onTaskStartup(createSampleTaskExecution(BEFORE_LISTENER));
|
||||
this.taskListenerExecutor
|
||||
.onTaskStartup(createSampleTaskExecution(BEFORE_LISTENER));
|
||||
validateSingleEntry(BEFORE_LISTENER);
|
||||
}
|
||||
|
||||
@@ -93,14 +96,18 @@ public class TaskListenerExecutorObjectFactoryTests {
|
||||
|
||||
@Test
|
||||
public void verifyAllListener() {
|
||||
this.taskListenerExecutor.onTaskStartup(createSampleTaskExecution(BEFORE_LISTENER));
|
||||
this.taskListenerExecutor
|
||||
.onTaskStartup(createSampleTaskExecution(BEFORE_LISTENER));
|
||||
this.taskListenerExecutor.onTaskFailed(createSampleTaskExecution(FAIL_LISTENER),
|
||||
new IllegalStateException("oops"));
|
||||
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);
|
||||
}
|
||||
|
||||
private TaskExecution createSampleTaskExecution(String taskName) {
|
||||
@@ -121,23 +128,29 @@ public class TaskListenerExecutorObjectFactoryTests {
|
||||
public TaskRunComponent taskRunComponent() {
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,22 +18,20 @@ package org.springframework.cloud.task.repository.dao;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.cloud.task.repository.TaskExecution;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Defines test cases that shall be shared between {@link JdbcTaskExecutionDaoTests} and {@link MapTaskExecutionDaoTests}.
|
||||
* Defines test cases that shall be shared between {@link JdbcTaskExecutionDaoTests} and
|
||||
* {@link MapTaskExecutionDaoTests}.
|
||||
*
|
||||
* @author Gunnar Hillert
|
||||
*/
|
||||
@@ -43,12 +41,13 @@ public class BaseTaskExecutionDaoTestCases {
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void getLatestTaskExecutionsByTaskNamesWithNullParameter() {
|
||||
public void getLatestTaskExecutionsByTaskNamesWithNullParameter() {
|
||||
try {
|
||||
dao.getLatestTaskExecutionsByTaskNames(null);
|
||||
this.dao.getLatestTaskExecutionsByTaskNames(null);
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
assertEquals("At least 1 task name must be provided.", e.getMessage());
|
||||
assertThat(e.getMessage())
|
||||
.isEqualTo("At least 1 task name must be provided.");
|
||||
return;
|
||||
}
|
||||
fail("Expected an IllegalArgumentException to be thrown.");
|
||||
@@ -56,12 +55,13 @@ public class BaseTaskExecutionDaoTestCases {
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void getLatestTaskExecutionsByTaskNamesWithEmptyArrayParameter() {
|
||||
public void getLatestTaskExecutionsByTaskNamesWithEmptyArrayParameter() {
|
||||
try {
|
||||
dao.getLatestTaskExecutionsByTaskNames(new String[0]);
|
||||
this.dao.getLatestTaskExecutionsByTaskNames(new String[0]);
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
assertEquals("At least 1 task name must be provided.", e.getMessage());
|
||||
assertThat(e.getMessage())
|
||||
.isEqualTo("At least 1 task name must be provided.");
|
||||
return;
|
||||
}
|
||||
fail("Expected an IllegalArgumentException to be thrown.");
|
||||
@@ -69,12 +69,13 @@ public class BaseTaskExecutionDaoTestCases {
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void getLatestTaskExecutionsByTaskNamesWithArrayParametersContainingNullAndEmptyValues() {
|
||||
public void getLatestTaskExecutionsByTaskNamesWithArrayParametersContainingNullAndEmptyValues() {
|
||||
try {
|
||||
dao.getLatestTaskExecutionsByTaskNames("foo", null, "bar", " ");
|
||||
this.dao.getLatestTaskExecutionsByTaskNames("foo", null, "bar", " ");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
assertEquals("Task names must not contain any empty elements but 2 of 4 were empty or null.", e.getMessage());
|
||||
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.");
|
||||
@@ -82,95 +83,105 @@ public class BaseTaskExecutionDaoTestCases {
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void getLatestTaskExecutionsByTaskNamesWithSingleTaskName() {
|
||||
public void getLatestTaskExecutionsByTaskNamesWithSingleTaskName() {
|
||||
initializeRepositoryNotInOrderWithMultipleTaskExecutions();
|
||||
final List<TaskExecution> latestTaskExecutions = dao.getLatestTaskExecutionsByTaskNames("FOO1");
|
||||
assertTrue("Expected only 1 taskExecution but got " + latestTaskExecutions.size(), latestTaskExecutions.size() == 1);
|
||||
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);
|
||||
assertEquals("FOO1", lastTaskExecution.getTaskName());
|
||||
assertThat(lastTaskExecution.getTaskName()).isEqualTo("FOO1");
|
||||
|
||||
final Calendar dateTime = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
|
||||
dateTime.setTime(lastTaskExecution.getStartTime());
|
||||
|
||||
assertEquals(2015, dateTime.get(Calendar.YEAR));
|
||||
assertEquals(2, dateTime.get(Calendar.MONTH) + 1);
|
||||
assertEquals(22, dateTime.get(Calendar.DAY_OF_MONTH));
|
||||
assertEquals(23, dateTime.get(Calendar.HOUR_OF_DAY));
|
||||
assertEquals(59, dateTime.get(Calendar.MINUTE));
|
||||
assertEquals(0, dateTime.get(Calendar.SECOND));
|
||||
assertThat(dateTime.get(Calendar.YEAR)).isEqualTo(2015);
|
||||
assertThat(dateTime.get(Calendar.MONTH) + 1).isEqualTo(2);
|
||||
assertThat(dateTime.get(Calendar.DAY_OF_MONTH)).isEqualTo(22);
|
||||
assertThat(dateTime.get(Calendar.HOUR_OF_DAY)).isEqualTo(23);
|
||||
assertThat(dateTime.get(Calendar.MINUTE)).isEqualTo(59);
|
||||
assertThat(dateTime.get(Calendar.SECOND)).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void getLatestTaskExecutionsByTaskNamesWithMultipleTaskNames() {
|
||||
public void getLatestTaskExecutionsByTaskNamesWithMultipleTaskNames() {
|
||||
initializeRepositoryNotInOrderWithMultipleTaskExecutions();
|
||||
final List<TaskExecution> latestTaskExecutions = dao.getLatestTaskExecutionsByTaskNames("FOO1", "FOO3", "FOO4");
|
||||
assertTrue("Expected 3 taskExecutions but got " + latestTaskExecutions.size(), latestTaskExecutions.size() == 3);
|
||||
final List<TaskExecution> latestTaskExecutions = this.dao
|
||||
.getLatestTaskExecutionsByTaskNames("FOO1", "FOO3", "FOO4");
|
||||
assertThat(latestTaskExecutions.size() == 3)
|
||||
.as("Expected 3 taskExecutions but got " + latestTaskExecutions.size())
|
||||
.isTrue();
|
||||
|
||||
final Calendar dateTimeFoo3 = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
|
||||
dateTimeFoo3.setTime(latestTaskExecutions.get(0).getStartTime());
|
||||
|
||||
assertEquals(2016, dateTimeFoo3.get(Calendar.YEAR));
|
||||
assertEquals(8, dateTimeFoo3.get(Calendar.MONTH) + 1);
|
||||
assertEquals(20, dateTimeFoo3.get(Calendar.DAY_OF_MONTH));
|
||||
assertEquals(14, dateTimeFoo3.get(Calendar.HOUR_OF_DAY));
|
||||
assertEquals(45, dateTimeFoo3.get(Calendar.MINUTE));
|
||||
assertEquals(0, dateTimeFoo3.get(Calendar.SECOND));
|
||||
assertThat(dateTimeFoo3.get(Calendar.YEAR)).isEqualTo(2016);
|
||||
assertThat(dateTimeFoo3.get(Calendar.MONTH) + 1).isEqualTo(8);
|
||||
assertThat(dateTimeFoo3.get(Calendar.DAY_OF_MONTH)).isEqualTo(20);
|
||||
assertThat(dateTimeFoo3.get(Calendar.HOUR_OF_DAY)).isEqualTo(14);
|
||||
assertThat(dateTimeFoo3.get(Calendar.MINUTE)).isEqualTo(45);
|
||||
assertThat(dateTimeFoo3.get(Calendar.SECOND)).isEqualTo(0);
|
||||
|
||||
final Calendar dateTimeFoo1 = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
|
||||
dateTimeFoo1.setTime(latestTaskExecutions.get(1).getStartTime());
|
||||
|
||||
assertEquals(2015, dateTimeFoo1.get(Calendar.YEAR));
|
||||
assertEquals(2, dateTimeFoo1.get(Calendar.MONTH) + 1);
|
||||
assertEquals(22, dateTimeFoo1.get(Calendar.DAY_OF_MONTH));
|
||||
assertEquals(23, dateTimeFoo1.get(Calendar.HOUR_OF_DAY));
|
||||
assertEquals(59, dateTimeFoo1.get(Calendar.MINUTE));
|
||||
assertEquals(0, dateTimeFoo1.get(Calendar.SECOND));
|
||||
assertThat(dateTimeFoo1.get(Calendar.YEAR)).isEqualTo(2015);
|
||||
assertThat(dateTimeFoo1.get(Calendar.MONTH) + 1).isEqualTo(2);
|
||||
assertThat(dateTimeFoo1.get(Calendar.DAY_OF_MONTH)).isEqualTo(22);
|
||||
assertThat(dateTimeFoo1.get(Calendar.HOUR_OF_DAY)).isEqualTo(23);
|
||||
assertThat(dateTimeFoo1.get(Calendar.MINUTE)).isEqualTo(59);
|
||||
assertThat(dateTimeFoo1.get(Calendar.SECOND)).isEqualTo(0);
|
||||
|
||||
final Calendar dateTimeFoo4 = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
|
||||
dateTimeFoo4.setTime(latestTaskExecutions.get(2).getStartTime());
|
||||
|
||||
assertEquals(2015, dateTimeFoo4.get(Calendar.YEAR));
|
||||
assertEquals(2, dateTimeFoo4.get(Calendar.MONTH) + 1);
|
||||
assertEquals(20, dateTimeFoo4.get(Calendar.DAY_OF_MONTH));
|
||||
assertEquals(14, dateTimeFoo4.get(Calendar.HOUR_OF_DAY));
|
||||
assertEquals(45, dateTimeFoo4.get(Calendar.MINUTE));
|
||||
assertEquals(0, dateTimeFoo4.get(Calendar.SECOND));
|
||||
assertThat(dateTimeFoo4.get(Calendar.YEAR)).isEqualTo(2015);
|
||||
assertThat(dateTimeFoo4.get(Calendar.MONTH) + 1).isEqualTo(2);
|
||||
assertThat(dateTimeFoo4.get(Calendar.DAY_OF_MONTH)).isEqualTo(20);
|
||||
assertThat(dateTimeFoo4.get(Calendar.HOUR_OF_DAY)).isEqualTo(14);
|
||||
assertThat(dateTimeFoo4.get(Calendar.MINUTE)).isEqualTo(45);
|
||||
assertThat(dateTimeFoo4.get(Calendar.SECOND)).isEqualTo(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* This test is a special use-case. While not common, it is theoretically possible, that a task may have
|
||||
* executed with the exact same start time multiple times. In that case we should still only get 1 returned
|
||||
* {@link TaskExecution}.
|
||||
* This test is a special use-case. While not common, it is theoretically possible,
|
||||
* that a task may have executed with the exact same start time multiple times. In
|
||||
* that case we should still only get 1 returned {@link TaskExecution}.
|
||||
*/
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void getLatestTaskExecutionsByTaskNamesWithIdenticalTaskExecutions() {
|
||||
public void getLatestTaskExecutionsByTaskNamesWithIdenticalTaskExecutions() {
|
||||
long executionIdOffset = initializeRepositoryNotInOrderWithMultipleTaskExecutions();
|
||||
final List<TaskExecution> latestTaskExecutions = dao.getLatestTaskExecutionsByTaskNames("FOO5");
|
||||
assertTrue("Expected only 1 taskExecution but got " + latestTaskExecutions.size(), latestTaskExecutions.size() == 1);
|
||||
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());
|
||||
|
||||
assertEquals(2015, dateTime.get(Calendar.YEAR));
|
||||
assertEquals(2, dateTime.get(Calendar.MONTH) + 1);
|
||||
assertEquals(22, dateTime.get(Calendar.DAY_OF_MONTH));
|
||||
assertEquals(23, dateTime.get(Calendar.HOUR_OF_DAY));
|
||||
assertEquals(59, dateTime.get(Calendar.MINUTE));
|
||||
assertEquals(0, dateTime.get(Calendar.SECOND));
|
||||
assertEquals(9 + executionIdOffset, latestTaskExecutions.get(0).getExecutionId());
|
||||
assertThat(dateTime.get(Calendar.YEAR)).isEqualTo(2015);
|
||||
assertThat(dateTime.get(Calendar.MONTH) + 1).isEqualTo(2);
|
||||
assertThat(dateTime.get(Calendar.DAY_OF_MONTH)).isEqualTo(22);
|
||||
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);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void getLatestTaskExecutionForTaskNameWithNullParameter() {
|
||||
public void getLatestTaskExecutionForTaskNameWithNullParameter() {
|
||||
try {
|
||||
dao.getLatestTaskExecutionForTaskName(null);
|
||||
this.dao.getLatestTaskExecutionForTaskName(null);
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
assertEquals("The task name must not be empty.", e.getMessage());
|
||||
assertThat(e.getMessage()).isEqualTo("The task name must not be empty.");
|
||||
return;
|
||||
}
|
||||
fail("Expected an IllegalArgumentException to be thrown.");
|
||||
@@ -178,12 +189,12 @@ public class BaseTaskExecutionDaoTestCases {
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void getLatestTaskExecutionForTaskNameWithEmptyStringParameter() {
|
||||
public void getLatestTaskExecutionForTaskNameWithEmptyStringParameter() {
|
||||
try {
|
||||
dao.getLatestTaskExecutionForTaskName("");
|
||||
this.dao.getLatestTaskExecutionForTaskName("");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
assertEquals("The task name must not be empty.", e.getMessage());
|
||||
assertThat(e.getMessage()).isEqualTo("The task name must not be empty.");
|
||||
return;
|
||||
}
|
||||
fail("Expected an IllegalArgumentException to be thrown.");
|
||||
@@ -191,61 +202,71 @@ public class BaseTaskExecutionDaoTestCases {
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void getLatestTaskExecutionForNonExistingTaskName() {
|
||||
public void getLatestTaskExecutionForNonExistingTaskName() {
|
||||
initializeRepositoryNotInOrderWithMultipleTaskExecutions();
|
||||
final TaskExecution latestTaskExecution = dao.getLatestTaskExecutionForTaskName("Bar5");
|
||||
assertNull("Expected the latestTaskExecution to be null but got" + latestTaskExecution, latestTaskExecution);
|
||||
final TaskExecution latestTaskExecution = this.dao
|
||||
.getLatestTaskExecutionForTaskName("Bar5");
|
||||
assertThat(latestTaskExecution)
|
||||
.as("Expected the latestTaskExecution to be null but got"
|
||||
+ latestTaskExecution)
|
||||
.isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void getLatestTaskExecutionForExistingTaskName() {
|
||||
public void getLatestTaskExecutionForExistingTaskName() {
|
||||
initializeRepositoryNotInOrderWithMultipleTaskExecutions();
|
||||
final TaskExecution latestTaskExecution = dao.getLatestTaskExecutionForTaskName("FOO1");
|
||||
assertNotNull("Expected the latestTaskExecution not to be null", latestTaskExecution);
|
||||
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());
|
||||
|
||||
assertEquals(2015, dateTime.get(Calendar.YEAR));
|
||||
assertEquals(2, dateTime.get(Calendar.MONTH) + 1);
|
||||
assertEquals(22, dateTime.get(Calendar.DAY_OF_MONTH));
|
||||
assertEquals(23, dateTime.get(Calendar.HOUR_OF_DAY));
|
||||
assertEquals(59, dateTime.get(Calendar.MINUTE));
|
||||
assertEquals(0, dateTime.get(Calendar.SECOND));
|
||||
assertThat(dateTime.get(Calendar.YEAR)).isEqualTo(2015);
|
||||
assertThat(dateTime.get(Calendar.MONTH) + 1).isEqualTo(2);
|
||||
assertThat(dateTime.get(Calendar.DAY_OF_MONTH)).isEqualTo(22);
|
||||
assertThat(dateTime.get(Calendar.HOUR_OF_DAY)).isEqualTo(23);
|
||||
assertThat(dateTime.get(Calendar.MINUTE)).isEqualTo(59);
|
||||
assertThat(dateTime.get(Calendar.SECOND)).isEqualTo(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* This test is a special use-case. While not common, it is theoretically possible, that a task may have
|
||||
* executed with the exact same start time multiple times. In that case we should still only get 1 returned
|
||||
* {@link TaskExecution}.
|
||||
* This test is a special use-case. While not common, it is theoretically possible,
|
||||
* that a task may have executed with the exact same start time multiple times. In
|
||||
* that case we should still only get 1 returned {@link TaskExecution}.
|
||||
*/
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void getLatestTaskExecutionForTaskNameWithIdenticalTaskExecutions() {
|
||||
public void getLatestTaskExecutionForTaskNameWithIdenticalTaskExecutions() {
|
||||
long executionIdOffset = initializeRepositoryNotInOrderWithMultipleTaskExecutions();
|
||||
final TaskExecution latestTaskExecution = dao.getLatestTaskExecutionForTaskName("FOO5");
|
||||
assertNotNull("Expected the latestTaskExecution not to be null", latestTaskExecution);
|
||||
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());
|
||||
|
||||
assertEquals(2015, dateTime.get(Calendar.YEAR));
|
||||
assertEquals(2, dateTime.get(Calendar.MONTH) + 1);
|
||||
assertEquals(22, dateTime.get(Calendar.DAY_OF_MONTH));
|
||||
assertEquals(23, dateTime.get(Calendar.HOUR_OF_DAY));
|
||||
assertEquals(59, dateTime.get(Calendar.MINUTE));
|
||||
assertEquals(0, dateTime.get(Calendar.SECOND));
|
||||
assertEquals(9 + executionIdOffset, latestTaskExecution.getExecutionId());
|
||||
assertThat(dateTime.get(Calendar.YEAR)).isEqualTo(2015);
|
||||
assertThat(dateTime.get(Calendar.MONTH) + 1).isEqualTo(2);
|
||||
assertThat(dateTime.get(Calendar.DAY_OF_MONTH)).isEqualTo(22);
|
||||
assertThat(dateTime.get(Calendar.HOUR_OF_DAY)).isEqualTo(23);
|
||||
assertThat(dateTime.get(Calendar.MINUTE)).isEqualTo(59);
|
||||
assertThat(dateTime.get(Calendar.SECOND)).isEqualTo(0);
|
||||
assertThat(latestTaskExecution.getExecutionId()).isEqualTo(9 + executionIdOffset);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void getRunningTaskExecutions() {
|
||||
initializeRepositoryNotInOrderWithMultipleTaskExecutions();
|
||||
assertEquals(dao.getTaskExecutionCount(), dao.getRunningTaskExecutionCount());
|
||||
dao.completeTaskExecution(1, 0, new Date(), "c'est fini!" );
|
||||
assertEquals(dao.getTaskExecutionCount() - 1, dao.getRunningTaskExecutionCount());
|
||||
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);
|
||||
}
|
||||
|
||||
protected long initializeRepositoryNotInOrderWithMultipleTaskExecutions() {
|
||||
@@ -304,7 +325,8 @@ public class BaseTaskExecutionDaoTestCases {
|
||||
}
|
||||
|
||||
private long createTaskExecution(TaskExecution te) {
|
||||
return 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,
|
||||
@@ -315,4 +337,5 @@ public class BaseTaskExecutionDaoTestCases {
|
||||
taskExecution.setStartTime(new Date());
|
||||
return taskExecution;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2018 the original author or authors.
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -44,7 +44,7 @@ import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Executes unit tests on JdbcTaskExecutionDao.
|
||||
@@ -53,83 +53,95 @@ import static org.junit.Assert.assertEquals;
|
||||
* @author Gunnar Hillert
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(classes = {TestConfiguration.class,
|
||||
@ContextConfiguration(classes = { TestConfiguration.class,
|
||||
EmbeddedDataSourceConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class})
|
||||
PropertyPlaceholderAutoConfiguration.class })
|
||||
public class JdbcTaskExecutionDaoTests extends BaseTaskExecutionDaoTestCases {
|
||||
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
|
||||
@Autowired
|
||||
TaskRepository repository;
|
||||
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
|
||||
@Before
|
||||
public void setup(){
|
||||
final JdbcTaskExecutionDao dao = new JdbcTaskExecutionDao(dataSource);
|
||||
dao.setTaskIncrementer(TestDBUtils.getIncrementer(dataSource));
|
||||
public void setup() {
|
||||
final JdbcTaskExecutionDao dao = new JdbcTaskExecutionDao(this.dataSource);
|
||||
dao.setTaskIncrementer(TestDBUtils.getIncrementer(this.dataSource));
|
||||
super.dao = dao;
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testStartTaskExecution() {
|
||||
TaskExecution expectedTaskExecution = dao.createTaskExecution(null, null,
|
||||
new ArrayList<String>(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());
|
||||
|
||||
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(dataSource, expectedTaskExecution.getExecutionId()));
|
||||
TestDBUtils.getTaskExecutionFromDB(this.dataSource,
|
||||
expectedTaskExecution.getExecutionId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void createTaskExecution() {
|
||||
TaskExecution expectedTaskExecution = TestVerifierUtils.createSampleTaskExecutionNoArg();
|
||||
expectedTaskExecution = dao.createTaskExecution(expectedTaskExecution.getTaskName(), expectedTaskExecution.getStartTime(),
|
||||
expectedTaskExecution.getArguments(), expectedTaskExecution.getExternalExecutionId());
|
||||
TaskExecution expectedTaskExecution = TestVerifierUtils
|
||||
.createSampleTaskExecutionNoArg();
|
||||
expectedTaskExecution = this.dao.createTaskExecution(
|
||||
expectedTaskExecution.getTaskName(), expectedTaskExecution.getStartTime(),
|
||||
expectedTaskExecution.getArguments(),
|
||||
expectedTaskExecution.getExternalExecutionId());
|
||||
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
|
||||
TestDBUtils.getTaskExecutionFromDB(dataSource, expectedTaskExecution.getExecutionId()));
|
||||
TestDBUtils.getTaskExecutionFromDB(this.dataSource,
|
||||
expectedTaskExecution.getExecutionId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void createEmptyTaskExecution() {
|
||||
TaskExecution expectedTaskExecution = dao.createTaskExecution(null, null,
|
||||
new ArrayList<String>(0), null);
|
||||
TaskExecution expectedTaskExecution = this.dao.createTaskExecution(null, null,
|
||||
new ArrayList<>(0), null);
|
||||
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
|
||||
TestDBUtils.getTaskExecutionFromDB(dataSource, expectedTaskExecution.getExecutionId()));
|
||||
TestDBUtils.getTaskExecutionFromDB(this.dataSource,
|
||||
expectedTaskExecution.getExecutionId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void completeTaskExecution() {
|
||||
TaskExecution expectedTaskExecution = TestVerifierUtils.endSampleTaskExecutionNoArg();
|
||||
expectedTaskExecution = dao.createTaskExecution(expectedTaskExecution.getTaskName(),
|
||||
expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments(),
|
||||
TaskExecution expectedTaskExecution = TestVerifierUtils
|
||||
.endSampleTaskExecutionNoArg();
|
||||
expectedTaskExecution = this.dao.createTaskExecution(
|
||||
expectedTaskExecution.getTaskName(), expectedTaskExecution.getStartTime(),
|
||||
expectedTaskExecution.getArguments(),
|
||||
expectedTaskExecution.getExternalExecutionId());
|
||||
dao.completeTaskExecution(expectedTaskExecution.getExecutionId(),
|
||||
this.dao.completeTaskExecution(expectedTaskExecution.getExecutionId(),
|
||||
expectedTaskExecution.getExitCode(), expectedTaskExecution.getEndTime(),
|
||||
expectedTaskExecution.getExitMessage());
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
|
||||
TestDBUtils.getTaskExecutionFromDB(dataSource, expectedTaskExecution.getExecutionId()));
|
||||
TestDBUtils.getTaskExecutionFromDB(this.dataSource,
|
||||
expectedTaskExecution.getExecutionId()));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@DirtiesContext
|
||||
public void completeTaskExecutionWithNoCreate() {
|
||||
JdbcTaskExecutionDao dao = new JdbcTaskExecutionDao(dataSource);
|
||||
JdbcTaskExecutionDao dao = new JdbcTaskExecutionDao(this.dataSource);
|
||||
|
||||
TaskExecution expectedTaskExecution = TestVerifierUtils.endSampleTaskExecutionNoArg();
|
||||
TaskExecution expectedTaskExecution = TestVerifierUtils
|
||||
.endSampleTaskExecutionNoArg();
|
||||
dao.completeTaskExecution(expectedTaskExecution.getExecutionId(),
|
||||
expectedTaskExecution.getExitCode(), expectedTaskExecution.getEndTime(),
|
||||
expectedTaskExecution.getExitMessage());
|
||||
@@ -137,89 +149,90 @@ public class JdbcTaskExecutionDaoTests extends BaseTaskExecutionDaoTestCases {
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testFindAllPageableSort() {
|
||||
public void testFindAllPageableSort() {
|
||||
initializeRepositoryNotInOrder();
|
||||
Sort sort = Sort.by(new Sort.Order(Sort.Direction.ASC,
|
||||
"EXTERNAL_EXECUTION_ID"));
|
||||
Sort sort = Sort.by(new Sort.Order(Sort.Direction.ASC, "EXTERNAL_EXECUTION_ID"));
|
||||
Iterator<TaskExecution> iter = getPageIterator(0, 2, sort);
|
||||
TaskExecution taskExecution = iter.next();
|
||||
assertEquals("FOO2", taskExecution.getTaskName());
|
||||
assertThat(taskExecution.getTaskName()).isEqualTo("FOO2");
|
||||
taskExecution = iter.next();
|
||||
assertEquals("FOO3", taskExecution.getTaskName());
|
||||
assertThat(taskExecution.getTaskName()).isEqualTo("FOO3");
|
||||
|
||||
iter = getPageIterator(1, 2, sort);
|
||||
taskExecution = iter.next();
|
||||
assertEquals("FOO1", taskExecution.getTaskName());
|
||||
assertThat(taskExecution.getTaskName()).isEqualTo("FOO1");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testFindAllDefaultSort() {
|
||||
public void testFindAllDefaultSort() {
|
||||
initializeRepository();
|
||||
Iterator<TaskExecution> iter = getPageIterator(0, 2, null);
|
||||
TaskExecution taskExecution = iter.next();
|
||||
assertEquals("FOO1", taskExecution.getTaskName());
|
||||
assertThat(taskExecution.getTaskName()).isEqualTo("FOO1");
|
||||
taskExecution = iter.next();
|
||||
assertEquals("FOO2", taskExecution.getTaskName());
|
||||
assertThat(taskExecution.getTaskName()).isEqualTo("FOO2");
|
||||
|
||||
iter = getPageIterator(1, 2, null);
|
||||
taskExecution = iter.next();
|
||||
assertEquals("FOO3", taskExecution.getTaskName());
|
||||
assertThat(taskExecution.getTaskName()).isEqualTo("FOO3");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testStartExecutionWithNullExternalExecutionIdExisting() {
|
||||
TaskExecution expectedTaskExecution =
|
||||
initializeTaskExecutionWithExternalExecutionId();
|
||||
TaskExecution expectedTaskExecution = initializeTaskExecutionWithExternalExecutionId();
|
||||
|
||||
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(dataSource, expectedTaskExecution.getExecutionId()));
|
||||
TestDBUtils.getTaskExecutionFromDB(this.dataSource,
|
||||
expectedTaskExecution.getExecutionId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testStartExecutionWithNullExternalExecutionIdNonExisting() {
|
||||
TaskExecution expectedTaskExecution =
|
||||
initializeTaskExecutionWithExternalExecutionId();
|
||||
TaskExecution expectedTaskExecution = initializeTaskExecutionWithExternalExecutionId();
|
||||
|
||||
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(dataSource, expectedTaskExecution.getExecutionId()));
|
||||
TestDBUtils.getTaskExecutionFromDB(this.dataSource,
|
||||
expectedTaskExecution.getExecutionId()));
|
||||
}
|
||||
|
||||
private TaskExecution initializeTaskExecutionWithExternalExecutionId() {
|
||||
TaskExecution expectedTaskExecution = TestVerifierUtils.createSampleTaskExecutionNoArg();
|
||||
TaskExecution expectedTaskExecution = TestVerifierUtils
|
||||
.createSampleTaskExecutionNoArg();
|
||||
return this.dao.createTaskExecution(expectedTaskExecution.getTaskName(),
|
||||
expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments(),
|
||||
"FOO1");
|
||||
expectedTaskExecution.getStartTime(),
|
||||
expectedTaskExecution.getArguments(), "FOO1");
|
||||
}
|
||||
|
||||
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 = dao.findAll(pageable);
|
||||
assertEquals(3, page.getTotalElements());
|
||||
assertEquals(2, page.getTotalPages());
|
||||
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);
|
||||
assertThat(page.getTotalElements()).isEqualTo(3);
|
||||
assertThat(page.getTotalPages()).isEqualTo(2);
|
||||
return page.iterator();
|
||||
}
|
||||
|
||||
private void initializeRepository() {
|
||||
repository.createTaskExecution(getTaskExecution("FOO3", "externalA"));
|
||||
repository.createTaskExecution(getTaskExecution("FOO2", "externalB"));
|
||||
repository.createTaskExecution(getTaskExecution("FOO1", "externalC"));
|
||||
this.repository.createTaskExecution(getTaskExecution("FOO3", "externalA"));
|
||||
this.repository.createTaskExecution(getTaskExecution("FOO2", "externalB"));
|
||||
this.repository.createTaskExecution(getTaskExecution("FOO1", "externalC"));
|
||||
}
|
||||
|
||||
private void initializeRepositoryNotInOrder() {
|
||||
repository.createTaskExecution(getTaskExecution("FOO1", "externalC"));
|
||||
repository.createTaskExecution(getTaskExecution("FOO2", "externalA"));
|
||||
repository.createTaskExecution(getTaskExecution("FOO3", "externalB"));
|
||||
this.repository.createTaskExecution(getTaskExecution("FOO1", "externalC"));
|
||||
this.repository.createTaskExecution(getTaskExecution("FOO2", "externalA"));
|
||||
this.repository.createTaskExecution(getTaskExecution("FOO3", "externalB"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2018 the original author or authors.
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,12 +27,11 @@ import java.util.UUID;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.cloud.task.repository.TaskExecution;
|
||||
import org.springframework.cloud.task.util.TestVerifierUtils;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Executes unit tests on MapTaskExecutionDaoTests.
|
||||
@@ -40,7 +39,7 @@ import static org.junit.Assert.assertNull;
|
||||
* @author Glenn Renfro
|
||||
* @author Gunnar Hillert
|
||||
*/
|
||||
public class MapTaskExecutionDaoTests extends BaseTaskExecutionDaoTestCases{
|
||||
public class MapTaskExecutionDaoTests extends BaseTaskExecutionDaoTestCases {
|
||||
|
||||
private MapTaskExecutionDao mapTaskExecutionDao;
|
||||
|
||||
@@ -52,122 +51,138 @@ public class MapTaskExecutionDaoTests extends BaseTaskExecutionDaoTestCases{
|
||||
|
||||
@Test
|
||||
public void testStartTaskExecution() {
|
||||
TaskExecution expectedTaskExecution = this.dao.createTaskExecution(null, null, new ArrayList<String>(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();
|
||||
assertNotNull("taskExecutionMap must not be null", taskExecutionMap);
|
||||
Map<Long, TaskExecution> taskExecutionMap = this.mapTaskExecutionDao
|
||||
.getTaskExecutions();
|
||||
assertThat(taskExecutionMap).as("taskExecutionMap must not be null").isNotNull();
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
|
||||
taskExecutionMap.get(expectedTaskExecution.getExecutionId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createEmptyTaskExecution() {
|
||||
TaskExecution expectedTaskExecution = dao.createTaskExecution(null, null,
|
||||
new ArrayList<String>(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(expected = IllegalStateException.class)
|
||||
public void completeTaskExecutionWithNoCreate() {
|
||||
TaskExecution expectedTaskExecution = TestVerifierUtils.createSampleTaskExecutionNoArg();
|
||||
TaskExecution expectedTaskExecution = TestVerifierUtils
|
||||
.createSampleTaskExecutionNoArg();
|
||||
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(),
|
||||
public void saveTaskExecution() {
|
||||
TaskExecution expectedTaskExecution = TestVerifierUtils
|
||||
.createSampleTaskExecutionNoArg();
|
||||
expectedTaskExecution = this.dao.createTaskExecution(
|
||||
expectedTaskExecution.getTaskName(), expectedTaskExecution.getStartTime(),
|
||||
expectedTaskExecution.getArguments(),
|
||||
expectedTaskExecution.getExternalExecutionId());
|
||||
Map<Long, TaskExecution> taskExecutionMap = this.mapTaskExecutionDao.getTaskExecutions();
|
||||
assertNotNull("taskExecutionMap must not be null", taskExecutionMap);
|
||||
Map<Long, TaskExecution> taskExecutionMap = this.mapTaskExecutionDao
|
||||
.getTaskExecutions();
|
||||
assertThat(taskExecutionMap).as("taskExecutionMap must not be null").isNotNull();
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
|
||||
taskExecutionMap.get(expectedTaskExecution.getExecutionId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void completeTaskExecution(){
|
||||
TaskExecution expectedTaskExecution = TestVerifierUtils.createSampleTaskExecutionNoArg();
|
||||
expectedTaskExecution = this.dao.createTaskExecution(expectedTaskExecution.getTaskName(),
|
||||
expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments(),
|
||||
public void completeTaskExecution() {
|
||||
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();
|
||||
assertNotNull("taskExecutionMap must not be null", taskExecutionMap);
|
||||
Map<Long, TaskExecution> taskExecutionMap = this.mapTaskExecutionDao
|
||||
.getTaskExecutions();
|
||||
assertThat(taskExecutionMap).as("taskExecutionMap must not be null").isNotNull();
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
|
||||
taskExecutionMap.get(expectedTaskExecution.getExecutionId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJobQueries(){
|
||||
public void testJobQueries() {
|
||||
List<TaskExecution> expectedTaskExecutionList = new ArrayList<>(2);
|
||||
expectedTaskExecutionList.add(TestVerifierUtils.createSampleTaskExecutionNoArg());
|
||||
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.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);
|
||||
|
||||
assertEquals(Long.valueOf(expectedTaskExecutionList.get(0).getExecutionId()),
|
||||
this.dao.getTaskExecutionIdByJobExecutionId(123L));
|
||||
assertEquals(Long.valueOf(expectedTaskExecutionList.get(0).getExecutionId()),
|
||||
this.dao.getTaskExecutionIdByJobExecutionId(456L));
|
||||
assertNull(this.dao.getTaskExecutionIdByJobExecutionId(789L));
|
||||
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);
|
||||
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);
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
|
||||
taskExecutionMap.get(expectedTaskExecution.getExecutionId()));
|
||||
}
|
||||
|
||||
@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");
|
||||
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");
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
|
||||
taskExecutionMap.get(expectedTaskExecution.getExecutionId()));
|
||||
}
|
||||
|
||||
private TaskExecution initializeTaskExecutionWithExternalExecutionId() {
|
||||
TaskExecution expectedTaskExecution = TestVerifierUtils.createSampleTaskExecutionNoArg();
|
||||
TaskExecution expectedTaskExecution = TestVerifierUtils
|
||||
.createSampleTaskExecutionNoArg();
|
||||
return this.dao.createTaskExecution(expectedTaskExecution.getTaskName(),
|
||||
expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments(),
|
||||
"FOO1");
|
||||
expectedTaskExecution.getStartTime(),
|
||||
expectedTaskExecution.getArguments(), "FOO1");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2017 the original author or authors.
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,7 +27,7 @@ import org.springframework.cloud.task.util.TestDBUtils;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Glenn Renfro
|
||||
@@ -36,13 +36,22 @@ import static org.junit.Assert.assertEquals;
|
||||
public class FindAllPagingQueryProviderTests {
|
||||
|
||||
private String databaseProductName;
|
||||
|
||||
private String expectedQuery;
|
||||
|
||||
private Pageable pageable = PageRequest.of(0, 10);
|
||||
|
||||
public FindAllPagingQueryProviderTests(String databaseProductName,
|
||||
String expectedQuery) {
|
||||
this.databaseProductName = databaseProductName;
|
||||
this.expectedQuery = expectedQuery;
|
||||
}
|
||||
|
||||
// @checkstyle:off
|
||||
@Parameterized.Parameters
|
||||
public static Collection<Object[]> data() {
|
||||
return Arrays.asList(new Object[][]{
|
||||
{"Oracle", "SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, TASK_NAME, "
|
||||
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 "
|
||||
@@ -50,41 +59,39 @@ public class FindAllPagingQueryProviderTests {
|
||||
+ "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, "
|
||||
+ "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 "
|
||||
+ "START_TIME DESC, TASK_EXECUTION_ID DESC"},
|
||||
{"PostgreSQL","SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, "
|
||||
+ "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 ORDER BY START_TIME DESC, "
|
||||
+ "TASK_EXECUTION_ID DESC LIMIT 10 OFFSET 0"},
|
||||
{"MySQL","SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, TASK_NAME, "
|
||||
+ "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"}
|
||||
});
|
||||
}
|
||||
|
||||
public FindAllPagingQueryProviderTests(String databaseProductName, String expectedQuery) {
|
||||
this.databaseProductName = databaseProductName;
|
||||
this.expectedQuery = expectedQuery;
|
||||
+ "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" } });
|
||||
}
|
||||
// @checkstyle:on
|
||||
|
||||
@Test
|
||||
public void testGeneratedQuery() throws Exception{
|
||||
String actualQuery = TestDBUtils.getPagingQueryProvider(databaseProductName).getPageQuery(pageable);
|
||||
assertEquals(String.format(
|
||||
"the generated query for %s, was not the expected query",
|
||||
databaseProductName), expectedQuery, actualQuery);
|
||||
public void testGeneratedQuery() throws Exception {
|
||||
String actualQuery = TestDBUtils.getPagingQueryProvider(this.databaseProductName)
|
||||
.getPageQuery(this.pageable);
|
||||
assertThat(actualQuery).as(
|
||||
String.format("the generated query for %s, was not the expected query",
|
||||
this.databaseProductName))
|
||||
.isEqualTo(this.expectedQuery);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015 the original author or authors.
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.cloud.task.repository.database.support;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.cloud.task.util.TestDBUtils;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
@@ -27,8 +28,9 @@ import org.springframework.data.domain.Pageable;
|
||||
public class InvalidPagingQueryProviderTests {
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testInvalidDatabase() throws Exception{
|
||||
public void testInvalidDatabase() throws Exception {
|
||||
Pageable pageable = PageRequest.of(0, 10);
|
||||
TestDBUtils.getPagingQueryProvider("Invalid").getPageQuery(pageable);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015 the original author or authors.
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,20 +16,19 @@
|
||||
|
||||
package org.springframework.cloud.task.repository.database.support;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.batch.item.database.Order;
|
||||
import org.springframework.cloud.task.repository.dao.JdbcTaskExecutionDao;
|
||||
import org.springframework.cloud.task.repository.database.PagingQueryProvider;
|
||||
import org.springframework.cloud.task.util.TestDBUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
@@ -38,28 +37,28 @@ public class SqlPagingQueryProviderFactoryBeanTests {
|
||||
private SqlPagingQueryProviderFactoryBean factoryBean;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception{
|
||||
factoryBean = new SqlPagingQueryProviderFactoryBean();
|
||||
factoryBean.setDataSource(TestDBUtils.getMockDataSource("MySQL"));
|
||||
factoryBean.setDatabaseType("Oracle");
|
||||
factoryBean.setSelectClause(JdbcTaskExecutionDao.SELECT_CLAUSE);
|
||||
factoryBean.setFromClause(JdbcTaskExecutionDao.FROM_CLAUSE);
|
||||
public void setup() throws Exception {
|
||||
this.factoryBean = new SqlPagingQueryProviderFactoryBean();
|
||||
this.factoryBean.setDataSource(TestDBUtils.getMockDataSource("MySQL"));
|
||||
this.factoryBean.setDatabaseType("Oracle");
|
||||
this.factoryBean.setSelectClause(JdbcTaskExecutionDao.SELECT_CLAUSE);
|
||||
this.factoryBean.setFromClause(JdbcTaskExecutionDao.FROM_CLAUSE);
|
||||
Map<String, Order> orderMap = new TreeMap<>();
|
||||
orderMap.put("START_TIME", Order.DESCENDING);
|
||||
orderMap.put("TASK_EXECUTION_ID", Order.DESCENDING);
|
||||
factoryBean.setSortKeys(orderMap);
|
||||
this.factoryBean.setSortKeys(orderMap);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDatabaseType() throws Exception{
|
||||
PagingQueryProvider pagingQueryProvider = factoryBean.getObject();
|
||||
assertThat(pagingQueryProvider, instanceOf(OraclePagingQueryProvider.class));
|
||||
public void testDatabaseType() throws Exception {
|
||||
PagingQueryProvider pagingQueryProvider = this.factoryBean.getObject();
|
||||
assertThat(pagingQueryProvider).isInstanceOf(OraclePagingQueryProvider.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsSingleton(){
|
||||
assertTrue(factoryBean.isSingleton());
|
||||
public void testIsSingleton() {
|
||||
assertThat(this.factoryBean.isSingleton()).isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2017 the original author or authors.
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -28,7 +28,7 @@ import org.springframework.cloud.task.util.TestDBUtils;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Glenn Renfro
|
||||
@@ -37,13 +37,22 @@ import static org.junit.Assert.assertEquals;
|
||||
public class WhereClausePagingQueryProviderTests {
|
||||
|
||||
private String databaseProductName;
|
||||
|
||||
private String expectedQuery;
|
||||
|
||||
private Pageable pageable = PageRequest.of(0, 10);
|
||||
|
||||
public WhereClausePagingQueryProviderTests(String databaseProductName,
|
||||
String expectedQuery) {
|
||||
this.databaseProductName = databaseProductName;
|
||||
this.expectedQuery = expectedQuery;
|
||||
}
|
||||
|
||||
// @checkstyle:off
|
||||
@Parameterized.Parameters
|
||||
public static Collection<Object[]> data() {
|
||||
return Arrays.asList(new Object[][]{
|
||||
{"Oracle", "SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, TASK_NAME, "
|
||||
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 "
|
||||
@@ -52,46 +61,43 @@ public class WhereClausePagingQueryProviderTests {
|
||||
+ "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, "
|
||||
+ "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"},
|
||||
{"PostgreSQL","SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, "
|
||||
+ "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, "
|
||||
+ "TASK_EXECUTION_ID DESC LIMIT 10 OFFSET 0"},
|
||||
{"MySQL","SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, TASK_NAME, "
|
||||
+ "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, "
|
||||
+ "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"}
|
||||
});
|
||||
}
|
||||
|
||||
public WhereClausePagingQueryProviderTests(String databaseProductName, String expectedQuery) {
|
||||
this.databaseProductName = databaseProductName;
|
||||
this.expectedQuery = expectedQuery;
|
||||
+ "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" } });
|
||||
}
|
||||
// @checkstyle:on
|
||||
|
||||
@Test
|
||||
public void testGeneratedQuery() throws Exception{
|
||||
PagingQueryProvider pagingQueryProvider =
|
||||
TestDBUtils.getPagingQueryProvider(databaseProductName,
|
||||
"TASK_EXECUTION_ID = '0000'");
|
||||
String actualQuery = pagingQueryProvider.getPageQuery(pageable);
|
||||
assertEquals(String.format(
|
||||
"the generated query for %s, was not the expected query",
|
||||
databaseProductName), expectedQuery, actualQuery);
|
||||
public void testGeneratedQuery() throws Exception {
|
||||
PagingQueryProvider pagingQueryProvider = TestDBUtils.getPagingQueryProvider(
|
||||
this.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",
|
||||
this.databaseProductName))
|
||||
.isEqualTo(this.expectedQuery);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015 the original author or authors.
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,20 +13,22 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.task.repository.support;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.cloud.task.util.TestDBUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.cloud.task.repository.support.DatabaseType.HSQL;
|
||||
import static org.springframework.cloud.task.repository.support.DatabaseType.MYSQL;
|
||||
import static org.springframework.cloud.task.repository.support.DatabaseType.ORACLE;
|
||||
import static org.springframework.cloud.task.repository.support.DatabaseType.POSTGRES;
|
||||
import static org.springframework.cloud.task.repository.support.DatabaseType.fromProductName;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.cloud.task.util.TestDBUtils;
|
||||
|
||||
/**
|
||||
* Tests that the correct database names are selected from datasource metadata.
|
||||
*
|
||||
@@ -39,10 +41,10 @@ public class DatabaseTypeTests {
|
||||
|
||||
@Test
|
||||
public void testFromProductName() {
|
||||
assertEquals(HSQL, fromProductName("HSQL Database Engine"));
|
||||
assertEquals(ORACLE, fromProductName("Oracle"));
|
||||
assertEquals(POSTGRES, fromProductName("PostgreSQL"));
|
||||
assertEquals(MYSQL, fromProductName("MySQL"));
|
||||
assertThat(fromProductName("HSQL Database Engine")).isEqualTo(HSQL);
|
||||
assertThat(fromProductName("Oracle")).isEqualTo(ORACLE);
|
||||
assertThat(fromProductName("PostgreSQL")).isEqualTo(POSTGRES);
|
||||
assertThat(fromProductName("MySQL")).isEqualTo(MYSQL);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@@ -53,25 +55,25 @@ public class DatabaseTypeTests {
|
||||
@Test
|
||||
public void testFromMetaDataForHsql() throws Exception {
|
||||
DataSource ds = TestDBUtils.getMockDataSource("HSQL Database Engine");
|
||||
assertEquals(HSQL, DatabaseType.fromMetaData(ds));
|
||||
assertThat(DatabaseType.fromMetaData(ds)).isEqualTo(HSQL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFromMetaDataForOracle() throws Exception {
|
||||
DataSource ds = TestDBUtils.getMockDataSource("Oracle");
|
||||
assertEquals(ORACLE, DatabaseType.fromMetaData(ds));
|
||||
assertThat(DatabaseType.fromMetaData(ds)).isEqualTo(ORACLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFromMetaDataForPostgres() throws Exception {
|
||||
DataSource ds = TestDBUtils.getMockDataSource("PostgreSQL");
|
||||
assertEquals(POSTGRES, DatabaseType.fromMetaData(ds));
|
||||
assertThat(DatabaseType.fromMetaData(ds)).isEqualTo(POSTGRES);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFromMetaDataForMySQL() throws Exception {
|
||||
DataSource ds = TestDBUtils.getMockDataSource("MySQL");
|
||||
assertEquals(MYSQL, DatabaseType.fromMetaData(ds));
|
||||
assertThat(DatabaseType.fromMetaData(ds)).isEqualTo(MYSQL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2018 the original author or authors.
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,11 +16,6 @@
|
||||
|
||||
package org.springframework.cloud.task.repository.support;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@@ -41,6 +36,7 @@ import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
|
||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||
@@ -56,6 +52,8 @@ import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Glenn Renfro
|
||||
* @author Gunnar Hillert
|
||||
@@ -67,6 +65,9 @@ public class SimpleTaskExplorerTests {
|
||||
|
||||
private final static String EXTERNAL_EXECUTION_ID = "123ABC";
|
||||
|
||||
@Rule
|
||||
public ExpectedException expected = ExpectedException.none();
|
||||
|
||||
private AnnotationConfigApplicationContext context;
|
||||
|
||||
@Autowired
|
||||
@@ -77,18 +78,14 @@ public class SimpleTaskExplorerTests {
|
||||
|
||||
private DaoType testType;
|
||||
|
||||
@Parameterized.Parameters
|
||||
public static Collection<Object> data() {
|
||||
return Arrays.asList(new Object[]{
|
||||
DaoType.jdbc, DaoType.map });
|
||||
}
|
||||
|
||||
public SimpleTaskExplorerTests(DaoType testType) {
|
||||
this.testType = testType;
|
||||
}
|
||||
|
||||
@Rule
|
||||
public ExpectedException expected = ExpectedException.none();
|
||||
@Parameterized.Parameters
|
||||
public static Collection<Object> data() {
|
||||
return Arrays.asList(new Object[] { DaoType.jdbc, DaoType.map });
|
||||
}
|
||||
|
||||
@Before
|
||||
public void testDefaultContext() throws Exception {
|
||||
@@ -112,11 +109,11 @@ public class SimpleTaskExplorerTests {
|
||||
public void getTaskExecution() {
|
||||
Map<Long, TaskExecution> expectedResults = createSampleDataSet(5);
|
||||
for (Long taskExecutionId : expectedResults.keySet()) {
|
||||
TaskExecution actualTaskExecution =
|
||||
taskExplorer.getTaskExecution(taskExecutionId);
|
||||
assertNotNull(String.format(
|
||||
"expected a taskExecution but got null for test type %s", testType),
|
||||
actualTaskExecution);
|
||||
TaskExecution actualTaskExecution = this.taskExplorer
|
||||
.getTaskExecution(taskExecutionId);
|
||||
assertThat(actualTaskExecution).as(String.format(
|
||||
"expected a taskExecution but got null for test type %s",
|
||||
this.testType)).isNotNull();
|
||||
TestVerifierUtils.verifyTaskExecution(expectedResults.get(taskExecutionId),
|
||||
actualTaskExecution);
|
||||
}
|
||||
@@ -126,11 +123,10 @@ public class SimpleTaskExplorerTests {
|
||||
public void taskExecutionNotFound() {
|
||||
createSampleDataSet(5);
|
||||
|
||||
TaskExecution actualTaskExecution =
|
||||
taskExplorer.getTaskExecution(-5);
|
||||
assertNull(String.format(
|
||||
"expected null for actualTaskExecution %s", testType),
|
||||
actualTaskExecution);
|
||||
TaskExecution actualTaskExecution = this.taskExplorer.getTaskExecution(-5);
|
||||
assertThat(actualTaskExecution).as(
|
||||
String.format("expected null for actualTaskExecution %s", this.testType))
|
||||
.isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -138,29 +134,30 @@ public class SimpleTaskExplorerTests {
|
||||
Map<Long, TaskExecution> expectedResults = createSampleDataSet(5);
|
||||
for (Map.Entry<Long, TaskExecution> entry : expectedResults.entrySet()) {
|
||||
String taskName = entry.getValue().getTaskName();
|
||||
assertEquals(String.format(
|
||||
"task count for task name did not match expected result for testType %s",
|
||||
testType),
|
||||
1, taskExplorer.getTaskExecutionCountByTaskName(taskName));
|
||||
assertThat(this.taskExplorer.getTaskExecutionCountByTaskName(taskName))
|
||||
.as(String.format(
|
||||
"task count for task name did not match expected result for testType %s",
|
||||
this.testType))
|
||||
.isEqualTo(1);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTaskCount() {
|
||||
createSampleDataSet(33);
|
||||
assertEquals(String.format(
|
||||
"task count did not match expected result for test Type %s",
|
||||
testType),
|
||||
33, taskExplorer.getTaskExecutionCount());
|
||||
assertThat(this.taskExplorer.getTaskExecutionCount()).as(
|
||||
String.format("task count did not match expected result for test Type %s",
|
||||
this.testType))
|
||||
.isEqualTo(33);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRunningTaskCount() {
|
||||
createSampleDataSet(33);
|
||||
assertEquals(String.format(
|
||||
"task count did not match expected result for test Type %s",
|
||||
testType),
|
||||
33, taskExplorer.getRunningTaskExecutionCount());
|
||||
assertThat(this.taskExplorer.getRunningTaskExecutionCount()).as(
|
||||
String.format("task count did not match expected result for test Type %s",
|
||||
this.testType))
|
||||
.isEqualTo(33);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -169,31 +166,34 @@ public class SimpleTaskExplorerTests {
|
||||
final int COMPLETE_COUNT = 5;
|
||||
|
||||
Map<Long, TaskExecution> expectedResults = new HashMap<>();
|
||||
//Store completed jobs
|
||||
// Store completed jobs
|
||||
int i = 0;
|
||||
for (; i < COMPLETE_COUNT; i++) {
|
||||
createAndSaveTaskExecution(i);
|
||||
}
|
||||
|
||||
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 = taskExplorer.findRunningTaskExecutions(TASK_NAME, pageable);
|
||||
assertEquals(String.format(
|
||||
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), TEST_COUNT, actualResults.getNumberOfElements());
|
||||
this.testType)).isEqualTo(TEST_COUNT);
|
||||
|
||||
for (TaskExecution result : actualResults) {
|
||||
assertTrue(String.format(
|
||||
"result returned from repo %s not expected for testType %s",
|
||||
result.getExecutionId(), testType),
|
||||
expectedResults.containsKey(result.getExecutionId()));
|
||||
assertNull(String.format("result had non null for endTime for the testType %s",
|
||||
testType), result.getEndTime());
|
||||
assertThat(expectedResults.containsKey(result.getExecutionId())).as(String
|
||||
.format("result returned from repo %s not expected for testType %s",
|
||||
result.getExecutionId(), this.testType))
|
||||
.isTrue();
|
||||
assertThat(result.getEndTime()).as(String.format(
|
||||
"result had non null for endTime for the testType %s", this.testType))
|
||||
.isNull();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,30 +203,33 @@ public class SimpleTaskExplorerTests {
|
||||
final int COMPLETE_COUNT = 7;
|
||||
|
||||
Map<Long, TaskExecution> expectedResults = new HashMap<>();
|
||||
//Store completed jobs
|
||||
// Store completed jobs
|
||||
for (int i = 0; i < COMPLETE_COUNT; i++) {
|
||||
createAndSaveTaskExecution(i);
|
||||
}
|
||||
|
||||
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 = taskExplorer.findTaskExecutionsByName(TASK_NAME, pageable);
|
||||
assertEquals(String.format(
|
||||
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), TEST_COUNT, resultSet.getNumberOfElements());
|
||||
this.testType)).isEqualTo(TEST_COUNT);
|
||||
|
||||
for (TaskExecution result : resultSet) {
|
||||
assertTrue(String.format("result returned from %s repo %s not expected",
|
||||
testType, result.getExecutionId()),
|
||||
expectedResults.containsKey(result.getExecutionId()));
|
||||
assertEquals(
|
||||
String.format("taskName for taskExecution is incorrect for testType %s",
|
||||
testType), TASK_NAME, result.getTaskName());
|
||||
assertThat(expectedResults.containsKey(result.getExecutionId()))
|
||||
.as(String.format("result returned from %s repo %s not expected",
|
||||
this.testType, result.getExecutionId()))
|
||||
.isTrue();
|
||||
assertThat(result.getTaskName()).as(String.format(
|
||||
"taskName for taskExecution is incorrect for testType %s",
|
||||
this.testType)).isEqualTo(TASK_NAME);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -238,10 +241,12 @@ public class SimpleTaskExplorerTests {
|
||||
TaskExecution expectedTaskExecution = createAndSaveTaskExecution(i);
|
||||
expectedResults.add(expectedTaskExecution.getTaskName());
|
||||
}
|
||||
List<String> actualTaskNames = taskExplorer.getTaskNames();
|
||||
List<String> actualTaskNames = this.taskExplorer.getTaskNames();
|
||||
for (String taskName : actualTaskNames) {
|
||||
assertTrue(String.format("taskName was not in expected results for testType %s",
|
||||
testType), expectedResults.contains(taskName));
|
||||
assertThat(expectedResults.contains(taskName)).as(
|
||||
String.format("taskName was not in expected results for testType %s",
|
||||
this.testType))
|
||||
.isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -271,23 +276,26 @@ public class SimpleTaskExplorerTests {
|
||||
|
||||
@Test
|
||||
public void findTasksForInvalidJob() {
|
||||
assertNull(taskExplorer.getTaskExecutionIdByJobExecutionId(55555L));
|
||||
assertThat(this.taskExplorer.getTaskExecutionIdByJobExecutionId(55555L)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findJobsExecutionIdsForInvalidTask () {
|
||||
assertEquals(0, taskExplorer.getJobExecutionIdsByTaskExecutionId(555555L).size());
|
||||
public void findJobsExecutionIdsForInvalidTask() {
|
||||
assertThat(this.taskExplorer.getJobExecutionIdsByTaskExecutionId(555555L).size())
|
||||
.isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getLatestTaskExecutionForTaskName() {
|
||||
Map<Long, TaskExecution> expectedResults = createSampleDataSet(5);
|
||||
for (Map.Entry<Long, TaskExecution> taskExecutionMapEntry: expectedResults.entrySet()) {
|
||||
TaskExecution latestTaskExecution =
|
||||
taskExplorer.getLatestTaskExecutionForTaskName(taskExecutionMapEntry.getValue().getTaskName());
|
||||
assertNotNull(String.format(
|
||||
"expected a taskExecution but got null for test type %s", testType),
|
||||
latestTaskExecution);
|
||||
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",
|
||||
this.testType)).isNotNull();
|
||||
TestVerifierUtils.verifyTaskExecution(
|
||||
expectedResults.get(latestTaskExecution.getExecutionId()),
|
||||
latestTaskExecution);
|
||||
@@ -304,13 +312,14 @@ public class SimpleTaskExplorerTests {
|
||||
taskNamesAsList.add(taskExecution.getTaskName());
|
||||
}
|
||||
|
||||
final List<TaskExecution> latestTaskExecutions = taskExplorer.getLatestTaskExecutionsByTaskNames(
|
||||
taskNamesAsList.toArray(new String[taskNamesAsList.size()]));
|
||||
final List<TaskExecution> latestTaskExecutions = this.taskExplorer
|
||||
.getLatestTaskExecutionsByTaskNames(
|
||||
taskNamesAsList.toArray(new String[taskNamesAsList.size()]));
|
||||
|
||||
for (TaskExecution latestTaskExecution : latestTaskExecutions) {
|
||||
assertNotNull(String.format(
|
||||
"expected a taskExecution but got null for test type %s", testType),
|
||||
latestTaskExecution);
|
||||
assertThat(latestTaskExecution).as(String.format(
|
||||
"expected a taskExecution but got null for test type %s",
|
||||
this.testType)).isNotNull();
|
||||
TestVerifierUtils.verifyTaskExecution(
|
||||
expectedResults.get(latestTaskExecution.getExecutionId()),
|
||||
latestTaskExecution);
|
||||
@@ -318,38 +327,42 @@ public class SimpleTaskExplorerTests {
|
||||
}
|
||||
|
||||
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 = taskExplorer.findAll(pageable);
|
||||
int pagesExpected = (int) Math.ceil(totalNumberOfExecs / ((double) pageable.getPageSize()));
|
||||
assertEquals("actual page count return was not the expected total",
|
||||
pagesExpected,
|
||||
taskPage.getTotalPages());
|
||||
assertEquals("actual element count was not the expected count", totalNumberOfExecs,
|
||||
taskPage.getTotalElements());
|
||||
// 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")
|
||||
.isEqualTo(pagesExpected);
|
||||
assertThat(taskPage.getTotalElements())
|
||||
.as("actual element count was not the expected count")
|
||||
.isEqualTo(totalNumberOfExecs);
|
||||
|
||||
//Verify pagination
|
||||
// Verify pagination
|
||||
Pageable actualPageable = PageRequest.of(0, pageable.getPageSize());
|
||||
boolean hasMorePages = taskPage.hasContent();
|
||||
int pageNumber = 0;
|
||||
int elementCount = 0;
|
||||
while (hasMorePages) {
|
||||
taskPage = taskExplorer.findAll(actualPageable);
|
||||
taskPage = this.taskExplorer.findAll(actualPageable);
|
||||
hasMorePages = taskPage.hasNext();
|
||||
List<TaskExecution> actualTaskExecutions = taskPage.getContent();
|
||||
int expectedPageSize = pageable.getPageSize();
|
||||
if (!hasMorePages && pageable.getPageSize() != actualTaskExecutions.size()) {
|
||||
expectedPageSize = totalNumberOfExecs % pageable.getPageSize();
|
||||
}
|
||||
assertEquals(
|
||||
String.format("Element count on page did not match on the %n page",
|
||||
pageNumber), expectedPageSize, actualTaskExecutions.size());
|
||||
assertThat(actualTaskExecutions.size()).as(String.format(
|
||||
"Element count on page did not match on the %n page", pageNumber))
|
||||
.isEqualTo(expectedPageSize);
|
||||
for (TaskExecution actualExecution : actualTaskExecutions) {
|
||||
assertEquals(String.format("Element on page %n did not match expected",
|
||||
pageNumber), (long)expectedTaskExecutionIter.next(),
|
||||
actualExecution.getExecutionId());
|
||||
assertThat(actualExecution.getExecutionId())
|
||||
.as(String.format("Element on page %n did not match expected",
|
||||
pageNumber))
|
||||
.isEqualTo((long) expectedTaskExecutionIter.next());
|
||||
TestVerifierUtils.verifyTaskExecution(
|
||||
expectedResults.get(actualExecution.getExecutionId()),
|
||||
actualExecution);
|
||||
@@ -358,9 +371,11 @@ public class SimpleTaskExplorerTests {
|
||||
actualPageable = taskPage.nextPageable();
|
||||
pageNumber++;
|
||||
}
|
||||
//Verify actual totals
|
||||
assertEquals("Pages processed did not equal expected", pagesExpected, pageNumber);
|
||||
assertEquals("Elements processed did not equal expected,", totalNumberOfExecs, elementCount);
|
||||
// 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);
|
||||
}
|
||||
|
||||
private TaskExecution createAndSaveTaskExecution(int i) {
|
||||
@@ -376,7 +391,7 @@ public class SimpleTaskExplorerTests {
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
|
||||
context.getAutowireCapableBeanFactory().autowireBeanProperties(this,
|
||||
this.context.getAutowireCapableBeanFactory().autowireBeanProperties(this,
|
||||
AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
|
||||
}
|
||||
|
||||
@@ -386,11 +401,11 @@ public class SimpleTaskExplorerTests {
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
|
||||
context.getAutowireCapableBeanFactory().autowireBeanProperties(this,
|
||||
this.context.getAutowireCapableBeanFactory().autowireBeanProperties(this,
|
||||
AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
|
||||
}
|
||||
|
||||
private Map<Long, TaskExecution> createSampleDataSet(int count){
|
||||
private Map<Long, TaskExecution> createSampleDataSet(int count) {
|
||||
Map<Long, TaskExecution> expectedResults = new HashMap<>();
|
||||
for (int i = 0; i < count; i++) {
|
||||
TaskExecution expectedTaskExecution = createAndSaveTaskExecution(i);
|
||||
@@ -400,24 +415,25 @@ public class SimpleTaskExplorerTests {
|
||||
return expectedResults;
|
||||
}
|
||||
|
||||
private List<Long> getSortedOfTaskExecIds(Map<Long, TaskExecution> taskExecutionMap){
|
||||
private List<Long> getSortedOfTaskExecIds(Map<Long, TaskExecution> taskExecutionMap) {
|
||||
List<Long> sortedExecIds = new ArrayList<>(taskExecutionMap.size());
|
||||
TreeSet<TaskExecution> sortedSet = getTreeSet();
|
||||
sortedSet.addAll(taskExecutionMap.values());
|
||||
Iterator <TaskExecution> iterator = sortedSet.descendingIterator();
|
||||
while(iterator.hasNext()){
|
||||
Iterator<TaskExecution> iterator = sortedSet.descendingIterator();
|
||||
while (iterator.hasNext()) {
|
||||
sortedExecIds.add(iterator.next().getExecutionId());
|
||||
}
|
||||
return sortedExecIds;
|
||||
}
|
||||
|
||||
private TreeSet<TaskExecution> getTreeSet(){
|
||||
return new TreeSet<TaskExecution>(new Comparator<TaskExecution>() {
|
||||
private TreeSet<TaskExecution> getTreeSet() {
|
||||
return new TreeSet<>(new Comparator<TaskExecution>() {
|
||||
@Override
|
||||
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());
|
||||
if (result == 0) {
|
||||
result = Long.valueOf(e1.getExecutionId())
|
||||
.compareTo(e2.getExecutionId());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -432,11 +448,20 @@ public class SimpleTaskExplorerTests {
|
||||
return taskExecution;
|
||||
}
|
||||
|
||||
private enum DaoType{jdbc, map}
|
||||
private enum DaoType {
|
||||
|
||||
jdbc, map
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
public static class DataSourceConfiguration{}
|
||||
public static class DataSourceConfiguration {
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
public static class EmptyConfiguration{}
|
||||
public static class EmptyConfiguration {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,14 +13,14 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.task.repository.support;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Michael Minella
|
||||
@@ -34,7 +34,9 @@ public class SimpleTaskNameResolverTests {
|
||||
SimpleTaskNameResolver taskNameResolver = new SimpleTaskNameResolver();
|
||||
taskNameResolver.setApplicationContext(context);
|
||||
|
||||
assertTrue(taskNameResolver.getTaskName().startsWith("org.springframework.context.support.GenericApplicationContext"));
|
||||
assertThat(taskNameResolver.getTaskName().startsWith(
|
||||
"org.springframework.context.support.GenericApplicationContext"))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -45,7 +47,7 @@ public class SimpleTaskNameResolverTests {
|
||||
SimpleTaskNameResolver taskNameResolver = new SimpleTaskNameResolver();
|
||||
taskNameResolver.setApplicationContext(context);
|
||||
|
||||
assertTrue(taskNameResolver.getTaskName().startsWith("foo_bar"));
|
||||
assertThat(taskNameResolver.getTaskName().startsWith("foo_bar")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -56,7 +58,7 @@ public class SimpleTaskNameResolverTests {
|
||||
SimpleTaskNameResolver taskNameResolver = new SimpleTaskNameResolver();
|
||||
taskNameResolver.setApplicationContext(context);
|
||||
|
||||
assertEquals("foo", taskNameResolver.getTaskName());
|
||||
assertThat(taskNameResolver.getTaskName()).isEqualTo("foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -69,6 +71,7 @@ public class SimpleTaskNameResolverTests {
|
||||
|
||||
taskNameResolver.setConfiguredName("bar");
|
||||
|
||||
assertEquals("bar", taskNameResolver.getTaskName());
|
||||
assertThat(taskNameResolver.getTaskName()).isEqualTo("bar");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2017 the original author or authors.
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -38,7 +38,7 @@ import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for the SimpleTaskRepository that uses JDBC as a datastore.
|
||||
@@ -48,9 +48,8 @@ import static org.junit.Assert.assertEquals;
|
||||
* @author Ilayaperumal Gopinathan
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(classes = {EmbeddedDataSourceConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class})
|
||||
@ContextConfiguration(classes = { EmbeddedDataSourceConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class })
|
||||
@DirtiesContext
|
||||
public class SimpleTaskRepositoryJdbcTests {
|
||||
|
||||
@@ -63,47 +62,49 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testCreateEmptyExecution() {
|
||||
TaskExecution expectedTaskExecution =
|
||||
TaskExecutionCreator.createAndStoreEmptyTaskExecution(taskRepository);
|
||||
TaskExecution actualTaskExecution = TestDBUtils.getTaskExecutionFromDB(dataSource,
|
||||
expectedTaskExecution.getExecutionId());
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
|
||||
actualTaskExecution);
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreEmptyTaskExecution(this.taskRepository);
|
||||
TaskExecution actualTaskExecution = TestDBUtils.getTaskExecutionFromDB(
|
||||
this.dataSource, expectedTaskExecution.getExecutionId());
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution, actualTaskExecution);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testCreateTaskExecutionNoParam() {
|
||||
TaskExecution expectedTaskExecution =
|
||||
TaskExecutionCreator.createAndStoreTaskExecutionNoParams(taskRepository);
|
||||
TaskExecution actualTaskExecution = TestDBUtils.getTaskExecutionFromDB(dataSource,
|
||||
expectedTaskExecution.getExecutionId());
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
TaskExecution actualTaskExecution = TestDBUtils.getTaskExecutionFromDB(
|
||||
this.dataSource, expectedTaskExecution.getExecutionId());
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution, actualTaskExecution);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testCreateTaskExecutionWithParam() {
|
||||
TaskExecution expectedTaskExecution =
|
||||
TaskExecutionCreator.createAndStoreTaskExecutionWithParams(taskRepository);
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionWithParams(this.taskRepository);
|
||||
TaskExecution actualTaskExecution = TestDBUtils.getTaskExecutionFromDB(
|
||||
dataSource, expectedTaskExecution.getExecutionId());
|
||||
this.dataSource, expectedTaskExecution.getExecutionId());
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution, actualTaskExecution);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void startTaskExecutionWithParam() {
|
||||
TaskExecution expectedTaskExecution =
|
||||
TaskExecutionCreator.createAndStoreEmptyTaskExecution(taskRepository);
|
||||
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(),
|
||||
TaskExecution actualTaskExecution = this.taskRepository.startTaskExecution(
|
||||
expectedTaskExecution.getExecutionId(),
|
||||
expectedTaskExecution.getTaskName(), expectedTaskExecution.getStartTime(),
|
||||
expectedTaskExecution.getArguments(), expectedTaskExecution.getExternalExecutionId());
|
||||
expectedTaskExecution.getArguments(),
|
||||
expectedTaskExecution.getExternalExecutionId());
|
||||
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution, actualTaskExecution);
|
||||
}
|
||||
@@ -111,66 +112,68 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void startTaskExecutionWithNoParam() {
|
||||
TaskExecution expectedTaskExecution =
|
||||
TaskExecutionCreator.createAndStoreEmptyTaskExecution(taskRepository);
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreEmptyTaskExecution(this.taskRepository);
|
||||
|
||||
expectedTaskExecution.setStartTime(new Date());
|
||||
expectedTaskExecution.setTaskName(UUID.randomUUID().toString());
|
||||
|
||||
TaskExecution actualTaskExecution = this.taskRepository.startTaskExecution(expectedTaskExecution.getExecutionId(),
|
||||
TaskExecution actualTaskExecution = this.taskRepository.startTaskExecution(
|
||||
expectedTaskExecution.getExecutionId(),
|
||||
expectedTaskExecution.getTaskName(), expectedTaskExecution.getStartTime(),
|
||||
expectedTaskExecution.getArguments(), expectedTaskExecution.getExternalExecutionId());
|
||||
expectedTaskExecution.getArguments(),
|
||||
expectedTaskExecution.getExternalExecutionId());
|
||||
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution, actualTaskExecution);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateExternalExecutionId() {
|
||||
TaskExecution expectedTaskExecution =
|
||||
TaskExecutionCreator.createAndStoreTaskExecutionNoParams(taskRepository);
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
expectedTaskExecution.setExternalExecutionId(UUID.randomUUID().toString());
|
||||
taskRepository.updateExternalExecutionId(
|
||||
this.taskRepository.updateExternalExecutionId(
|
||||
expectedTaskExecution.getExecutionId(),
|
||||
expectedTaskExecution.getExternalExecutionId());
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
|
||||
TestDBUtils.getTaskExecutionFromDB(dataSource,
|
||||
TestDBUtils.getTaskExecutionFromDB(this.dataSource,
|
||||
expectedTaskExecution.getExecutionId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateNullExternalExecutionId() {
|
||||
TaskExecution expectedTaskExecution =
|
||||
TaskExecutionCreator.createAndStoreTaskExecutionNoParams(taskRepository);
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
expectedTaskExecution.setExternalExecutionId(null);
|
||||
taskRepository.updateExternalExecutionId(
|
||||
this.taskRepository.updateExternalExecutionId(
|
||||
expectedTaskExecution.getExecutionId(),
|
||||
expectedTaskExecution.getExternalExecutionId());
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
|
||||
TestDBUtils.getTaskExecutionFromDB(dataSource,
|
||||
TestDBUtils.getTaskExecutionFromDB(this.dataSource,
|
||||
expectedTaskExecution.getExecutionId()));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testInvalidExecutionIdForExternalExecutionIdUpdate() {
|
||||
TaskExecution expectedTaskExecution =
|
||||
TaskExecutionCreator.createAndStoreTaskExecutionNoParams(taskRepository);
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
expectedTaskExecution.setExternalExecutionId(null);
|
||||
taskRepository.updateExternalExecutionId(
|
||||
-1,
|
||||
this.taskRepository.updateExternalExecutionId(-1,
|
||||
expectedTaskExecution.getExternalExecutionId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void startTaskExecutionWithParent() {
|
||||
TaskExecution expectedTaskExecution =
|
||||
TaskExecutionCreator.createAndStoreEmptyTaskExecution(taskRepository);
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreEmptyTaskExecution(this.taskRepository);
|
||||
|
||||
expectedTaskExecution.setStartTime(new Date());
|
||||
expectedTaskExecution.setTaskName(UUID.randomUUID().toString());
|
||||
expectedTaskExecution.setParentExecutionId(12345L);
|
||||
|
||||
TaskExecution actualTaskExecution = this.taskRepository.startTaskExecution(expectedTaskExecution.getExecutionId(),
|
||||
TaskExecution actualTaskExecution = this.taskRepository.startTaskExecution(
|
||||
expectedTaskExecution.getExecutionId(),
|
||||
expectedTaskExecution.getTaskName(), expectedTaskExecution.getStartTime(),
|
||||
expectedTaskExecution.getArguments(),
|
||||
expectedTaskExecution.getExternalExecutionId(),
|
||||
@@ -182,62 +185,79 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testCompleteTaskExecution() {
|
||||
TaskExecution expectedTaskExecution =
|
||||
TaskExecutionCreator.createAndStoreTaskExecutionNoParams(taskRepository);
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
expectedTaskExecution.setEndTime(new Date());
|
||||
expectedTaskExecution.setExitCode(77);
|
||||
expectedTaskExecution.setExitMessage(UUID.randomUUID().toString());
|
||||
|
||||
TaskExecution actualTaskExecution = TaskExecutionCreator.completeExecution(taskRepository, expectedTaskExecution);
|
||||
TaskExecution actualTaskExecution = TaskExecutionCreator
|
||||
.completeExecution(this.taskRepository, expectedTaskExecution);
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution, actualTaskExecution);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testCreateTaskExecutionNoParamMaxExitDefaultMessageSize(){
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator.createAndStoreTaskExecutionNoParams(taskRepository);
|
||||
expectedTaskExecution.setExitMessage(new String(new char[SimpleTaskRepository.MAX_EXIT_MESSAGE_SIZE+1]));
|
||||
public void testCreateTaskExecutionNoParamMaxExitDefaultMessageSize() {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
expectedTaskExecution.setExitMessage(
|
||||
new String(new char[SimpleTaskRepository.MAX_EXIT_MESSAGE_SIZE + 1]));
|
||||
expectedTaskExecution.setEndTime(new Date());
|
||||
expectedTaskExecution.setExitCode(0);
|
||||
TaskExecution actualTaskExecution = completeTaskExecution(expectedTaskExecution, taskRepository);
|
||||
assertEquals(SimpleTaskRepository.MAX_EXIT_MESSAGE_SIZE, actualTaskExecution.getExitMessage().length());
|
||||
TaskExecution actualTaskExecution = completeTaskExecution(expectedTaskExecution,
|
||||
this.taskRepository);
|
||||
assertThat(actualTaskExecution.getExitMessage().length())
|
||||
.isEqualTo(SimpleTaskRepository.MAX_EXIT_MESSAGE_SIZE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateTaskExecutionNoParamMaxExitMessageSize() {
|
||||
SimpleTaskRepository simpleTaskRepository = new SimpleTaskRepository(new TaskExecutionDaoFactoryBean(this.dataSource));
|
||||
SimpleTaskRepository simpleTaskRepository = new SimpleTaskRepository(
|
||||
new TaskExecutionDaoFactoryBean(this.dataSource));
|
||||
simpleTaskRepository.setMaxExitMessageSize(5);
|
||||
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator.createAndStoreTaskExecutionNoParams(simpleTaskRepository);
|
||||
expectedTaskExecution.setExitMessage(new String(new char[SimpleTaskRepository.MAX_EXIT_MESSAGE_SIZE + 1]));
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(simpleTaskRepository);
|
||||
expectedTaskExecution.setExitMessage(
|
||||
new String(new char[SimpleTaskRepository.MAX_EXIT_MESSAGE_SIZE + 1]));
|
||||
expectedTaskExecution.setEndTime(new Date());
|
||||
expectedTaskExecution.setExitCode(0);
|
||||
TaskExecution actualTaskExecution = completeTaskExecution(expectedTaskExecution, simpleTaskRepository);
|
||||
assertEquals(5, actualTaskExecution.getExitMessage().length());
|
||||
TaskExecution actualTaskExecution = completeTaskExecution(expectedTaskExecution,
|
||||
simpleTaskRepository);
|
||||
assertThat(actualTaskExecution.getExitMessage().length()).isEqualTo(5);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testCreateTaskExecutionNoParamMaxErrorDefaultMessageSize(){
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator.createAndStoreTaskExecutionNoParams(taskRepository);
|
||||
expectedTaskExecution.setErrorMessage(new String(new char[SimpleTaskRepository.MAX_ERROR_MESSAGE_SIZE+1]));
|
||||
public void testCreateTaskExecutionNoParamMaxErrorDefaultMessageSize() {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
expectedTaskExecution.setErrorMessage(
|
||||
new String(new char[SimpleTaskRepository.MAX_ERROR_MESSAGE_SIZE + 1]));
|
||||
expectedTaskExecution.setEndTime(new Date());
|
||||
expectedTaskExecution.setExitCode(0);
|
||||
TaskExecution actualTaskExecution = completeTaskExecution(expectedTaskExecution, taskRepository);
|
||||
assertEquals(SimpleTaskRepository.MAX_ERROR_MESSAGE_SIZE, actualTaskExecution.getErrorMessage().length());
|
||||
TaskExecution actualTaskExecution = completeTaskExecution(expectedTaskExecution,
|
||||
this.taskRepository);
|
||||
assertThat(actualTaskExecution.getErrorMessage().length())
|
||||
.isEqualTo(SimpleTaskRepository.MAX_ERROR_MESSAGE_SIZE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateTaskExecutionNoParamMaxErrorMessageSize() {
|
||||
SimpleTaskRepository simpleTaskRepository = new SimpleTaskRepository(new TaskExecutionDaoFactoryBean(this.dataSource));
|
||||
SimpleTaskRepository simpleTaskRepository = new SimpleTaskRepository(
|
||||
new TaskExecutionDaoFactoryBean(this.dataSource));
|
||||
simpleTaskRepository.setMaxErrorMessageSize(5);
|
||||
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator.createAndStoreTaskExecutionNoParams(simpleTaskRepository);
|
||||
expectedTaskExecution.setErrorMessage(new String(new char[SimpleTaskRepository.MAX_ERROR_MESSAGE_SIZE + 1]));
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(simpleTaskRepository);
|
||||
expectedTaskExecution.setErrorMessage(
|
||||
new String(new char[SimpleTaskRepository.MAX_ERROR_MESSAGE_SIZE + 1]));
|
||||
expectedTaskExecution.setEndTime(new Date());
|
||||
expectedTaskExecution.setExitCode(0);
|
||||
TaskExecution actualTaskExecution = completeTaskExecution(expectedTaskExecution, simpleTaskRepository);
|
||||
assertEquals(5, actualTaskExecution.getErrorMessage().length());
|
||||
TaskExecution actualTaskExecution = completeTaskExecution(expectedTaskExecution,
|
||||
simpleTaskRepository);
|
||||
assertThat(actualTaskExecution.getErrorMessage().length()).isEqualTo(5);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@@ -246,9 +266,10 @@ 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]));
|
||||
simpleTaskRepository.createTaskExecution(expectedTaskExecution);
|
||||
}
|
||||
@@ -257,8 +278,10 @@ 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]));
|
||||
simpleTaskRepository.createTaskExecution(expectedTaskExecution);
|
||||
}
|
||||
|
||||
@@ -267,9 +290,10 @@ 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
|
||||
@@ -280,54 +304,63 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
SimpleTaskRepository.MAX_ERROR_MESSAGE_SIZE, simpleTaskRepository);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@DirtiesContext
|
||||
public void testCreateTaskExecutionNoParamMaxTaskName(){
|
||||
public void testCreateTaskExecutionNoParamMaxTaskName() {
|
||||
TaskExecution taskExecution = new TaskExecution();
|
||||
taskExecution.setTaskName(
|
||||
new String(new char[SimpleTaskRepository.MAX_TASK_NAME_SIZE+1]));
|
||||
new String(new char[SimpleTaskRepository.MAX_TASK_NAME_SIZE + 1]));
|
||||
taskExecution.setStartTime(new Date());
|
||||
taskRepository.createTaskExecution(taskExecution);
|
||||
this.taskRepository.createTaskExecution(taskExecution);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@DirtiesContext
|
||||
public void testCreateTaskExecutionNegativeException(){
|
||||
TaskExecution expectedTaskExecution =
|
||||
TaskExecutionCreator.createAndStoreTaskExecutionNoParams(taskRepository);
|
||||
public void testCreateTaskExecutionNegativeException() {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
expectedTaskExecution.setEndTime(new Date());
|
||||
expectedTaskExecution.setExitCode(-1);
|
||||
|
||||
TaskExecution actualTaskExecution = TaskExecutionCreator.completeExecution(taskRepository, expectedTaskExecution);
|
||||
TaskExecution actualTaskExecution = TaskExecutionCreator
|
||||
.completeExecution(this.taskRepository, expectedTaskExecution);
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution, actualTaskExecution);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@DirtiesContext
|
||||
public void testCreateTaskExecutionNullEndTime(){
|
||||
TaskExecution expectedTaskExecution =
|
||||
TaskExecutionCreator.createAndStoreTaskExecutionNoParams(taskRepository);
|
||||
public void testCreateTaskExecutionNullEndTime() {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
expectedTaskExecution.setExitCode(-1);
|
||||
TaskExecutionCreator.completeExecution(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(), expectedTaskExecution.getErrorMessage());
|
||||
}
|
||||
|
||||
private void verifyTaskRepositoryConstructor(Integer maxExitMessage, Integer maxErrorMessage,
|
||||
private TaskExecution completeTaskExecution(TaskExecution expectedTaskExecution,
|
||||
TaskRepository taskRepository) {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator.createAndStoreTaskExecutionNoParams(taskRepository);
|
||||
expectedTaskExecution.setErrorMessage(new String(new char[maxErrorMessage+ 1]));
|
||||
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);
|
||||
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);
|
||||
assertEquals(maxErrorMessage.intValue(), actualTaskExecution.getErrorMessage().length());
|
||||
assertEquals(maxExitMessage.intValue(), actualTaskExecution.getExitMessage().length());
|
||||
TaskExecution actualTaskExecution = completeTaskExecution(expectedTaskExecution,
|
||||
taskRepository);
|
||||
assertThat(actualTaskExecution.getErrorMessage().length())
|
||||
.isEqualTo(maxErrorMessage.intValue());
|
||||
assertThat(actualTaskExecution.getExitMessage().length())
|
||||
.isEqualTo(maxExitMessage.intValue());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2017 the original author or authors.
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -49,72 +49,78 @@ public class SimpleTaskRepositoryMapTests {
|
||||
|
||||
@Test
|
||||
public void testCreateEmptyExecution() {
|
||||
TaskExecution expectedTaskExecution =
|
||||
TaskExecutionCreator.createAndStoreEmptyTaskExecution(taskRepository);
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreEmptyTaskExecution(this.taskRepository);
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
|
||||
getSingleTaskExecutionFromMapRepository(expectedTaskExecution.getExecutionId()));
|
||||
getSingleTaskExecutionFromMapRepository(
|
||||
expectedTaskExecution.getExecutionId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateTaskExecutionNoParam() {
|
||||
TaskExecution expectedTaskExecution =
|
||||
TaskExecutionCreator.createAndStoreTaskExecutionNoParams(taskRepository);
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
|
||||
getSingleTaskExecutionFromMapRepository(expectedTaskExecution.getExecutionId()));
|
||||
getSingleTaskExecutionFromMapRepository(
|
||||
expectedTaskExecution.getExecutionId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateExternalExecutionId() {
|
||||
TaskExecution expectedTaskExecution =
|
||||
TaskExecutionCreator.createAndStoreTaskExecutionNoParams(taskRepository);
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
expectedTaskExecution.setExternalExecutionId(UUID.randomUUID().toString());
|
||||
taskRepository.updateExternalExecutionId(
|
||||
this.taskRepository.updateExternalExecutionId(
|
||||
expectedTaskExecution.getExecutionId(),
|
||||
expectedTaskExecution.getExternalExecutionId());
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
|
||||
getSingleTaskExecutionFromMapRepository(expectedTaskExecution.getExecutionId()));
|
||||
getSingleTaskExecutionFromMapRepository(
|
||||
expectedTaskExecution.getExecutionId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateNullExternalExecutionId() {
|
||||
TaskExecution expectedTaskExecution =
|
||||
TaskExecutionCreator.createAndStoreTaskExecutionNoParams(taskRepository);
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
expectedTaskExecution.setExternalExecutionId(null);
|
||||
taskRepository.updateExternalExecutionId(
|
||||
this.taskRepository.updateExternalExecutionId(
|
||||
expectedTaskExecution.getExecutionId(),
|
||||
expectedTaskExecution.getExternalExecutionId());
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
|
||||
getSingleTaskExecutionFromMapRepository(expectedTaskExecution.getExecutionId()));
|
||||
getSingleTaskExecutionFromMapRepository(
|
||||
expectedTaskExecution.getExecutionId()));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testInvalidExecutionIdForExternalExecutionIdUpdate() {
|
||||
TaskExecution expectedTaskExecution =
|
||||
TaskExecutionCreator.createAndStoreTaskExecutionNoParams(taskRepository);
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
expectedTaskExecution.setExternalExecutionId(null);
|
||||
taskRepository.updateExternalExecutionId(
|
||||
-1,
|
||||
this.taskRepository.updateExternalExecutionId(-1,
|
||||
expectedTaskExecution.getExternalExecutionId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateTaskExecutionWithParam() {
|
||||
TaskExecution expectedTaskExecution =
|
||||
TaskExecutionCreator.createAndStoreTaskExecutionWithParams(taskRepository);
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionWithParams(this.taskRepository);
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
|
||||
getSingleTaskExecutionFromMapRepository(expectedTaskExecution.getExecutionId()));
|
||||
getSingleTaskExecutionFromMapRepository(
|
||||
expectedTaskExecution.getExecutionId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startTaskExecutionWithParam() {
|
||||
TaskExecution expectedTaskExecution =
|
||||
TaskExecutionCreator.createAndStoreEmptyTaskExecution(taskRepository);
|
||||
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(),
|
||||
TaskExecution actualTaskExecution = this.taskRepository.startTaskExecution(
|
||||
expectedTaskExecution.getExecutionId(),
|
||||
expectedTaskExecution.getTaskName(), expectedTaskExecution.getStartTime(),
|
||||
expectedTaskExecution.getArguments(),
|
||||
expectedTaskExecution.getExternalExecutionId(),
|
||||
@@ -125,59 +131,65 @@ public class SimpleTaskRepositoryMapTests {
|
||||
|
||||
@Test
|
||||
public void startTaskExecutionWithNoParam() {
|
||||
TaskExecution expectedTaskExecution =
|
||||
TaskExecutionCreator.createAndStoreEmptyTaskExecution(taskRepository);
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreEmptyTaskExecution(this.taskRepository);
|
||||
|
||||
expectedTaskExecution.setStartTime(new Date());
|
||||
expectedTaskExecution.setTaskName(UUID.randomUUID().toString());
|
||||
|
||||
TaskExecution actualTaskExecution = this.taskRepository.startTaskExecution(expectedTaskExecution.getExecutionId(),
|
||||
TaskExecution actualTaskExecution = this.taskRepository.startTaskExecution(
|
||||
expectedTaskExecution.getExecutionId(),
|
||||
expectedTaskExecution.getTaskName(), expectedTaskExecution.getStartTime(),
|
||||
expectedTaskExecution.getArguments(), expectedTaskExecution.getExternalExecutionId());
|
||||
expectedTaskExecution.getArguments(),
|
||||
expectedTaskExecution.getExternalExecutionId());
|
||||
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution, actualTaskExecution);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void startTaskExecutionWithParent() {
|
||||
TaskExecution expectedTaskExecution =
|
||||
TaskExecutionCreator.createAndStoreEmptyTaskExecution(taskRepository);
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreEmptyTaskExecution(this.taskRepository);
|
||||
|
||||
expectedTaskExecution.setStartTime(new Date());
|
||||
expectedTaskExecution.setTaskName(UUID.randomUUID().toString());
|
||||
expectedTaskExecution.setParentExecutionId(12345L);
|
||||
|
||||
TaskExecution actualTaskExecution = this.taskRepository.startTaskExecution(expectedTaskExecution.getExecutionId(),
|
||||
TaskExecution actualTaskExecution = this.taskRepository.startTaskExecution(
|
||||
expectedTaskExecution.getExecutionId(),
|
||||
expectedTaskExecution.getTaskName(), expectedTaskExecution.getStartTime(),
|
||||
expectedTaskExecution.getArguments(), expectedTaskExecution.getExternalExecutionId());
|
||||
expectedTaskExecution.getArguments(),
|
||||
expectedTaskExecution.getExternalExecutionId());
|
||||
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution, actualTaskExecution);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompleteTaskExecution() {
|
||||
TaskExecution expectedTaskExecution =
|
||||
TaskExecutionCreator.createAndStoreTaskExecutionNoParams(taskRepository);
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
expectedTaskExecution.setEndTime(new Date());
|
||||
expectedTaskExecution.setExitCode(0);
|
||||
TaskExecution actualTaskExecution = TaskExecutionCreator.completeExecution(taskRepository, expectedTaskExecution);
|
||||
TaskExecution actualTaskExecution = TaskExecutionCreator
|
||||
.completeExecution(this.taskRepository, expectedTaskExecution);
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution, actualTaskExecution);
|
||||
}
|
||||
|
||||
private TaskExecution getSingleTaskExecutionFromMapRepository(long taskExecutionId){
|
||||
Map<Long, TaskExecution> taskMap = ((MapTaskExecutionDao)
|
||||
((SimpleTaskRepository)taskRepository).getTaskExecutionDao()).getTaskExecutions();
|
||||
private TaskExecution getSingleTaskExecutionFromMapRepository(long taskExecutionId) {
|
||||
Map<Long, TaskExecution> taskMap = ((MapTaskExecutionDao) ((SimpleTaskRepository) this.taskRepository)
|
||||
.getTaskExecutionDao()).getTaskExecutions();
|
||||
assertTrue("taskExecutionId must be in MapTaskExecutionRepository",
|
||||
taskMap.containsKey(taskExecutionId));
|
||||
return taskMap.get(taskExecutionId);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testCreateTaskExecutionNullEndTime(){
|
||||
TaskExecution expectedTaskExecution =
|
||||
TaskExecutionCreator.createAndStoreTaskExecutionNoParams(taskRepository);
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testCreateTaskExecutionNullEndTime() {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
expectedTaskExecution.setExitCode(-1);
|
||||
TaskExecutionCreator.completeExecution(taskRepository, expectedTaskExecution);
|
||||
TaskExecutionCreator.completeExecution(this.taskRepository,
|
||||
expectedTaskExecution);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2018 the original author or authors.
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -33,9 +33,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
@@ -44,11 +42,12 @@ import static org.mockito.Mockito.mock;
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
public class TaskDatabaseInitializerTests {
|
||||
private AnnotationConfigApplicationContext context;
|
||||
|
||||
@Rule
|
||||
public ExpectedException expected = ExpectedException.none();
|
||||
|
||||
private AnnotationConfigApplicationContext context;
|
||||
|
||||
@After
|
||||
public void close() {
|
||||
if (this.context != null) {
|
||||
@@ -59,21 +58,23 @@ public class TaskDatabaseInitializerTests {
|
||||
@Test
|
||||
public void testDefaultContext() {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context.register( TestConfiguration.class,
|
||||
this.context.register(TestConfiguration.class,
|
||||
EmbeddedDataSourceConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
assertEquals(0, new JdbcTemplate(this.context.getBean(DataSource.class))
|
||||
.queryForList("select * from TASK_EXECUTION").size());
|
||||
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(), instanceOf(MapTaskExecutionDao.class));
|
||||
SimpleTaskRepository repository = new SimpleTaskRepository(
|
||||
new TaskExecutionDaoFactoryBean());
|
||||
assertThat(repository.getTaskExecutionDao())
|
||||
.isInstanceOf(MapTaskExecutionDao.class);
|
||||
MapTaskExecutionDao dao = (MapTaskExecutionDao) repository.getTaskExecutionDao();
|
||||
assertEquals(0, dao.getTaskExecutions().size());
|
||||
assertThat(dao.getTaskExecutions().size()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -83,20 +84,24 @@ public class TaskDatabaseInitializerTests {
|
||||
EmbeddedDataSourceConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
assertEquals(0, this.context.getBeanNamesForType(SimpleTaskRepository.class).length);
|
||||
assertThat(this.context.getBeanNamesForType(SimpleTaskRepository.class).length)
|
||||
.isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test(expected = BeanCreationException.class)
|
||||
public void testMultipleDataSourcesContext() {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context.register( SimpleTaskAutoConfiguration.class,
|
||||
this.context.register(SimpleTaskAutoConfiguration.class,
|
||||
EmbeddedDataSourceConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
DataSource dataSource = mock(DataSource.class);
|
||||
context.getBeanFactory().registerSingleton("mockDataSource", dataSource);
|
||||
this.context.getBeanFactory().registerSingleton("mockDataSource", dataSource);
|
||||
this.context.refresh();
|
||||
}
|
||||
|
||||
@Configuration
|
||||
public static class EmptyConfiguration {}
|
||||
public static class EmptyConfiguration {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.task.repository.support;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
@@ -31,8 +32,7 @@ import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Michael Minella
|
||||
@@ -43,19 +43,20 @@ public class TaskExecutionDaoFactoryBeanTests {
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
if(this.context != null) {
|
||||
if (this.context != null) {
|
||||
this.context.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetObjectType() {
|
||||
assertEquals(new TaskExecutionDaoFactoryBean().getObjectType(), TaskExecutionDao.class);
|
||||
assertThat(TaskExecutionDao.class)
|
||||
.isEqualTo(new TaskExecutionDaoFactoryBean().getObjectType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsSingleton() {
|
||||
assertTrue(new TaskExecutionDaoFactoryBean().isSingleton());
|
||||
assertThat(new TaskExecutionDaoFactoryBean().isSingleton()).isTrue();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@@ -63,46 +64,49 @@ public class TaskExecutionDaoFactoryBeanTests {
|
||||
new TaskExecutionDaoFactoryBean(null);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testMapTaskExecutionDaoWithoutAppContext() throws Exception {
|
||||
TaskExecutionDaoFactoryBean factoryBean = new TaskExecutionDaoFactoryBean();
|
||||
TaskExecutionDao taskExecutionDao = factoryBean.getObject();
|
||||
|
||||
assertTrue(taskExecutionDao instanceof MapTaskExecutionDao);
|
||||
assertThat(taskExecutionDao instanceof MapTaskExecutionDao).isTrue();
|
||||
|
||||
TaskExecutionDao taskExecutionDao2 = factoryBean.getObject();
|
||||
|
||||
assertTrue(taskExecutionDao == taskExecutionDao2);
|
||||
assertThat(taskExecutionDao == taskExecutionDao2).isTrue();
|
||||
}
|
||||
|
||||
@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();
|
||||
|
||||
assertTrue(taskExecutionDao instanceof JdbcTaskExecutionDao);
|
||||
assertThat(taskExecutionDao instanceof JdbcTaskExecutionDao).isTrue();
|
||||
|
||||
TaskExecutionDao taskExecutionDao2 = factoryBean.getObject();
|
||||
|
||||
assertTrue(taskExecutionDao == taskExecutionDao2);
|
||||
assertThat(taskExecutionDao == taskExecutionDao2).isTrue();
|
||||
}
|
||||
|
||||
|
||||
@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();
|
||||
|
||||
assertEquals("foo_", ReflectionTestUtils.getField(taskExecutionDao, "tablePrefix"));
|
||||
assertThat(ReflectionTestUtils.getField(taskExecutionDao, "tablePrefix"))
|
||||
.isEqualTo("foo_");
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@@ -110,8 +114,11 @@ public class TaskExecutionDaoFactoryBeanTests {
|
||||
|
||||
@Bean
|
||||
public DataSource dataSource() {
|
||||
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2);
|
||||
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder()
|
||||
.setType(EmbeddedDatabaseType.H2);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2017 the original author or authors.
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -32,34 +32,35 @@ public class TaskExecutionCreator {
|
||||
|
||||
/**
|
||||
* Creates a sample TaskExecution and stores it in the taskRepository.
|
||||
*
|
||||
* @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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a sample TaskExecution and stores it in the taskRepository.
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a sample TaskExecution and stores it in the taskRepository with params.
|
||||
*
|
||||
* @param taskRepository the taskRepository where the taskExecution should be stored.
|
||||
* @return the taskExecution created.
|
||||
*/
|
||||
public static TaskExecution createAndStoreTaskExecutionWithParams(TaskRepository taskRepository) {
|
||||
TaskExecution expectedTaskExecution = TestVerifierUtils.createSampleTaskExecutionNoArg();
|
||||
List<String> params = new ArrayList<String>();
|
||||
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());
|
||||
expectedTaskExecution.setArguments(params);
|
||||
@@ -69,14 +70,16 @@ public class TaskExecutionCreator {
|
||||
|
||||
/**
|
||||
* Updates a sample TaskExecution in the taskRepository.
|
||||
*
|
||||
* @param taskRepository the taskRepository where the taskExecution should be updated.
|
||||
* @return the taskExecution created.
|
||||
*/
|
||||
public static TaskExecution completeExecution(TaskRepository taskRepository,
|
||||
TaskExecution expectedTaskExecution) {
|
||||
return taskRepository.completeTaskExecution(expectedTaskExecution.getExecutionId(),
|
||||
return taskRepository.completeTaskExecution(
|
||||
expectedTaskExecution.getExecutionId(),
|
||||
expectedTaskExecution.getExitCode(), expectedTaskExecution.getEndTime(),
|
||||
expectedTaskExecution.getExitMessage(), expectedTaskExecution.getErrorMessage());
|
||||
expectedTaskExecution.getExitMessage(),
|
||||
expectedTaskExecution.getErrorMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015 the original author or authors.
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,6 +24,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.batch.item.database.Order;
|
||||
@@ -40,7 +41,7 @@ import org.springframework.jdbc.support.MetaDataAccessException;
|
||||
import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -60,28 +61,29 @@ public class TestDBUtils {
|
||||
* @return taskExecution retrieved from the database.
|
||||
*/
|
||||
public static TaskExecution getTaskExecutionFromDB(DataSource dataSource,
|
||||
long taskExecutionId) {
|
||||
String sql = "SELECT * FROM TASK_EXECUTION WHERE "
|
||||
+ "TASK_EXECUTION_ID = '"
|
||||
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<String>(0),
|
||||
rs.getString("ERROR_MESSAGE"),
|
||||
rs.getString("EXTERNAL_EXECUTION_ID"));
|
||||
return taskExecution;
|
||||
}
|
||||
});
|
||||
assertEquals("only one row should be returned", 1, rows.size());
|
||||
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);
|
||||
|
||||
populateParamsToDB(dataSource, taskExecution);
|
||||
@@ -92,21 +94,23 @@ public class TestDBUtils {
|
||||
* Create a pagingQueryProvider specific database type with a findAll.
|
||||
* @param databaseProductName of the database.
|
||||
* @return a PagingQueryPovider that will return all the requested information.
|
||||
* @throws Exception
|
||||
* @throws Exception exception
|
||||
*/
|
||||
public static PagingQueryProvider getPagingQueryProvider(String databaseProductName) throws Exception{
|
||||
public static PagingQueryProvider getPagingQueryProvider(String databaseProductName)
|
||||
throws Exception {
|
||||
return getPagingQueryProvider(databaseProductName, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a pagingQueryProvider specific database type with a query containing a where clause.
|
||||
* Create a pagingQueryProvider specific database type with a query containing a where
|
||||
* clause.
|
||||
* @param databaseProductName of the database.
|
||||
* @param whereClause to be applied to the query.
|
||||
* @param whereClause to be applied to the query.
|
||||
* @return a PagingQueryProvider that will return the requested information.
|
||||
* @throws Exception
|
||||
* @throws Exception exception
|
||||
*/
|
||||
public static PagingQueryProvider getPagingQueryProvider(String databaseProductName,
|
||||
String whereClause) throws Exception{
|
||||
String whereClause) throws Exception {
|
||||
DataSource dataSource = getMockDataSource(databaseProductName);
|
||||
Map<String, Order> orderMap = new TreeMap<>();
|
||||
orderMap.put("START_TIME", Order.DESCENDING);
|
||||
@@ -114,7 +118,7 @@ public class TestDBUtils {
|
||||
SqlPagingQueryProviderFactoryBean factoryBean = new SqlPagingQueryProviderFactoryBean();
|
||||
factoryBean.setSelectClause(JdbcTaskExecutionDao.SELECT_CLAUSE);
|
||||
factoryBean.setFromClause(JdbcTaskExecutionDao.FROM_CLAUSE);
|
||||
if(whereClause != null){
|
||||
if (whereClause != null) {
|
||||
factoryBean.setWhereClause(whereClause);
|
||||
}
|
||||
factoryBean.setSortKeys(orderMap);
|
||||
@@ -134,9 +138,10 @@ public class TestDBUtils {
|
||||
* Creates a mock DataSource for use in testing.
|
||||
* @param databaseProductName the name of the database type to mock.
|
||||
* @return a mock DataSource.
|
||||
* @throws Exception
|
||||
* @throws Exception exception
|
||||
*/
|
||||
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);
|
||||
@@ -148,12 +153,13 @@ public class TestDBUtils {
|
||||
|
||||
/**
|
||||
* Creates a incrementer for the DataSource.
|
||||
* @param dataSource the datasource that the incrementer will use to record current id.
|
||||
* @param dataSource the datasource that the incrementer will use to record current
|
||||
* id.
|
||||
* @return a DataFieldMaxValueIncrementer object.
|
||||
*/
|
||||
public static DataFieldMaxValueIncrementer getIncrementer(DataSource dataSource){
|
||||
DataFieldMaxValueIncrementerFactory incrementerFactory =
|
||||
new DefaultDataFieldMaxValueIncrementerFactory(dataSource);
|
||||
public static DataFieldMaxValueIncrementer getIncrementer(DataSource dataSource) {
|
||||
DataFieldMaxValueIncrementerFactory incrementerFactory = new DefaultDataFieldMaxValueIncrementerFactory(
|
||||
dataSource);
|
||||
String databaseType = null;
|
||||
try {
|
||||
databaseType = DatabaseType.fromMetaData(dataSource).name();
|
||||
@@ -161,11 +167,11 @@ public class TestDBUtils {
|
||||
catch (MetaDataAccessException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
return incrementerFactory.getIncrementer(databaseType,
|
||||
"TASK_SEQ");
|
||||
return incrementerFactory.getIncrementer(databaseType, "TASK_SEQ");
|
||||
}
|
||||
|
||||
private static void populateParamsToDB(DataSource dataSource, TaskExecution taskExecution) {
|
||||
private static void populateParamsToDB(DataSource dataSource,
|
||||
TaskExecution taskExecution) {
|
||||
String sql = "SELECT * FROM TASK_EXECUTION_PARAMS WHERE TASK_EXECUTION_ID = '"
|
||||
+ taskExecution.getExecutionId() + "'";
|
||||
|
||||
@@ -177,4 +183,5 @@ public class TestDBUtils {
|
||||
}
|
||||
taskExecution.setArguments(arguments);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2018 the original author or authors.
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -46,11 +46,11 @@ import org.springframework.context.annotation.Configuration;
|
||||
@EnableConfigurationProperties(TaskProperties.class)
|
||||
public class TestDefaultConfiguration implements InitializingBean {
|
||||
|
||||
private TaskExecutionDaoFactoryBean factoryBean;
|
||||
|
||||
@Autowired
|
||||
TaskProperties taskProperties;
|
||||
|
||||
private TaskExecutionDaoFactoryBean factoryBean;
|
||||
|
||||
@Autowired(required = false)
|
||||
private ApplicationArguments applicationArguments;
|
||||
|
||||
@@ -61,7 +61,7 @@ public class TestDefaultConfiguration implements InitializingBean {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TaskRepository taskRepository(){
|
||||
public TaskRepository taskRepository() {
|
||||
return new SimpleTaskRepository(this.factoryBean);
|
||||
}
|
||||
|
||||
@@ -76,19 +76,21 @@ public class TestDefaultConfiguration implements InitializingBean {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TaskListenerExecutorObjectFactory taskListenerExecutorObjectProvider(ConfigurableApplicationContext context) {
|
||||
public TaskListenerExecutorObjectFactory taskListenerExecutorObjectProvider(
|
||||
ConfigurableApplicationContext context) {
|
||||
return new TaskListenerExecutorObjectFactory(context);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TaskLifecycleListener taskHandler(TaskExplorer taskExplorer){
|
||||
public TaskLifecycleListener taskHandler(TaskExplorer taskExplorer) {
|
||||
return new TaskLifecycleListener(taskRepository(), taskNameResolver(),
|
||||
applicationArguments, taskExplorer, taskProperties, taskListenerExecutorObjectProvider(context));
|
||||
this.applicationArguments, taskExplorer, this.taskProperties,
|
||||
taskListenerExecutorObjectProvider(this.context));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
if(this.context.getBeanNamesForType(DataSource.class).length == 1){
|
||||
if (this.context.getBeanNamesForType(DataSource.class).length == 1) {
|
||||
DataSource dataSource = this.context.getBean(DataSource.class);
|
||||
this.factoryBean = new TaskExecutionDaoFactoryBean(dataSource);
|
||||
}
|
||||
@@ -96,4 +98,5 @@ public class TestDefaultConfiguration implements InitializingBean {
|
||||
this.factoryBean = new TaskExecutionDaoFactoryBean();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,20 +19,26 @@ package org.springframework.cloud.task.util;
|
||||
import org.springframework.cloud.task.repository.TaskExecution;
|
||||
|
||||
/**
|
||||
* Provides the basic infrastructure for evaluating if task listener performed
|
||||
* properly.
|
||||
* Provides the basic infrastructure for evaluating if task listener performed properly.
|
||||
*
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
public abstract class TestListener {
|
||||
|
||||
public static final String START_MESSAGE = "FOO";
|
||||
|
||||
public static final String ERROR_MESSAGE = "BAR";
|
||||
|
||||
public static final String END_MESSAGE = "BAZ";
|
||||
|
||||
protected boolean isTaskStartup;
|
||||
|
||||
protected boolean isTaskEnd;
|
||||
|
||||
protected boolean isTaskFailed;
|
||||
|
||||
protected TaskExecution taskExecution;
|
||||
|
||||
protected Throwable throwable;
|
||||
|
||||
/**
|
||||
@@ -40,15 +46,15 @@ public abstract class TestListener {
|
||||
* @return true if task listener was called during task creation, else false.
|
||||
*/
|
||||
public boolean isTaskStartup() {
|
||||
return isTaskStartup;
|
||||
return this.isTaskStartup;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if the task listener was called during task end.
|
||||
* @return true if the task listener was called during task end, else false.
|
||||
* @return true if the task listener was called during task end, else false.
|
||||
*/
|
||||
public boolean isTaskEnd() {
|
||||
return isTaskEnd;
|
||||
return this.isTaskEnd;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,20 +62,21 @@ public abstract class TestListener {
|
||||
* @return true if task listener was called during task failure, else false.
|
||||
*/
|
||||
public boolean isTaskFailed() {
|
||||
return isTaskFailed;
|
||||
return this.isTaskFailed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Task Execution that was updated during listener call.
|
||||
*/
|
||||
public TaskExecution getTaskExecution() {
|
||||
return taskExecution;
|
||||
return this.taskExecution;
|
||||
}
|
||||
|
||||
/**
|
||||
* The throwable that was sent with the task if task failed.
|
||||
*/
|
||||
public Throwable getThrowable() {
|
||||
return throwable;
|
||||
return this.throwable;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2017 the original author or authors.
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -31,17 +31,14 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.springframework.cloud.task.repository.TaskExecution;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Matchers.argThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Offers utils to test the results produced by the code being tested.
|
||||
* Offers utils to test the results produced by the code being tested.
|
||||
*
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
@@ -51,11 +48,11 @@ public class TestVerifierUtils {
|
||||
|
||||
/**
|
||||
* Creates a mock {@link Appender} to be added to the root logger.
|
||||
*
|
||||
* @return reference to the mock appender.
|
||||
*/
|
||||
public static Appender getMockAppender() {
|
||||
ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
|
||||
ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory
|
||||
.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
|
||||
final Appender mockAppender = mock(Appender.class);
|
||||
when(mockAppender.getName()).thenReturn("MOCK");
|
||||
root.addAppender(mockAppender);
|
||||
@@ -63,24 +60,24 @@ public class TestVerifierUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that the log sample is contained within the content that was written
|
||||
* to the mock appender.
|
||||
*
|
||||
* Verifies that the log sample is contained within the content that was written to
|
||||
* the mock appender.
|
||||
* @param mockAppender The appender that is associated with the test.
|
||||
* @param logSample The string to search for in the log entry.
|
||||
* @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);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a fully populated TaskExecution (except args) for testing.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static TaskExecution createSampleTaskExecutionNoArg() {
|
||||
@@ -89,13 +86,12 @@ public class TestVerifierUtils {
|
||||
long executionId = randomGenerator.nextLong();
|
||||
String taskName = UUID.randomUUID().toString();
|
||||
|
||||
return new TaskExecution(executionId, null, taskName,
|
||||
startTime, null, null, new ArrayList<String>(), null, null);
|
||||
return new TaskExecution(executionId, null, taskName, startTime, null, null,
|
||||
new ArrayList<>(), null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a fully populated TaskExecution (except args) for testing.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static TaskExecution endSampleTaskExecutionNoArg() {
|
||||
@@ -107,13 +103,12 @@ public class TestVerifierUtils {
|
||||
String taskName = UUID.randomUUID().toString();
|
||||
String exitMessage = UUID.randomUUID().toString();
|
||||
|
||||
return new TaskExecution(executionId, exitCode, taskName,
|
||||
startTime, endTime, exitMessage, new ArrayList<String>(), null, null);
|
||||
return new TaskExecution(executionId, exitCode, taskName, startTime, endTime,
|
||||
exitMessage, new ArrayList<>(), null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a fully populated TaskExecution for testing.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static TaskExecution createSampleTaskExecution(long executionId) {
|
||||
@@ -121,66 +116,65 @@ public class TestVerifierUtils {
|
||||
String taskName = UUID.randomUUID().toString();
|
||||
String externalExecutionId = UUID.randomUUID().toString();
|
||||
List<String> args = new ArrayList<>(ARG_SIZE);
|
||||
for (int i = 0; i < ARG_SIZE; i++){
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that all the fields in between the expected and actual are the same;
|
||||
*
|
||||
* @param expectedTaskExecution The expected value for the task execution.
|
||||
* @param actualTaskExecution The actual value for the task execution.
|
||||
* @param actualTaskExecution The actual value for the task execution.
|
||||
*/
|
||||
public static void verifyTaskExecution(TaskExecution expectedTaskExecution,
|
||||
TaskExecution actualTaskExecution) {
|
||||
assertEquals("taskExecutionId must be equal", expectedTaskExecution.getExecutionId(),
|
||||
actualTaskExecution.getExecutionId());
|
||||
assertEquals("startTime must be equal",
|
||||
expectedTaskExecution.getStartTime(),
|
||||
actualTaskExecution.getStartTime());
|
||||
assertEquals("endTime must be equal",
|
||||
expectedTaskExecution.getEndTime(),
|
||||
actualTaskExecution.getEndTime());
|
||||
assertEquals("exitCode must be equal",
|
||||
expectedTaskExecution.getExitCode(),
|
||||
actualTaskExecution.getExitCode());
|
||||
assertEquals("taskName must be equal",
|
||||
expectedTaskExecution.getTaskName(),
|
||||
actualTaskExecution.getTaskName());
|
||||
assertEquals("exitMessage must be equal",
|
||||
expectedTaskExecution.getExitMessage(),
|
||||
actualTaskExecution.getExitMessage());
|
||||
assertEquals("errorMessage must be equal",
|
||||
expectedTaskExecution.getErrorMessage(),
|
||||
actualTaskExecution.getErrorMessage());
|
||||
assertEquals("externalExecutionId must be equal",
|
||||
expectedTaskExecution.getExternalExecutionId(),
|
||||
actualTaskExecution.getExternalExecutionId());
|
||||
assertEquals("parentExecutionId must be equal",
|
||||
expectedTaskExecution.getParentExecutionId(),
|
||||
actualTaskExecution.getParentExecutionId());
|
||||
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")
|
||||
.hasSameTimeAs(expectedTaskExecution.getStartTime());
|
||||
}
|
||||
if (actualTaskExecution.getEndTime() != null) {
|
||||
assertThat(actualTaskExecution.getEndTime()).as("endTime must be equal")
|
||||
.hasSameTimeAs(expectedTaskExecution.getEndTime());
|
||||
}
|
||||
assertThat(actualTaskExecution.getExitCode()).as("exitCode must be equal")
|
||||
.isEqualTo(expectedTaskExecution.getExitCode());
|
||||
assertThat(actualTaskExecution.getTaskName()).as("taskName must be equal")
|
||||
.isEqualTo(expectedTaskExecution.getTaskName());
|
||||
assertThat(actualTaskExecution.getExitMessage()).as("exitMessage must be equal")
|
||||
.isEqualTo(expectedTaskExecution.getExitMessage());
|
||||
assertThat(actualTaskExecution.getErrorMessage()).as("errorMessage must be equal")
|
||||
.isEqualTo(expectedTaskExecution.getErrorMessage());
|
||||
assertThat(actualTaskExecution.getExternalExecutionId())
|
||||
.as("externalExecutionId must be equal")
|
||||
.isEqualTo(expectedTaskExecution.getExternalExecutionId());
|
||||
assertThat(actualTaskExecution.getParentExecutionId())
|
||||
.as("parentExecutionId must be equal")
|
||||
.isEqualTo(expectedTaskExecution.getParentExecutionId());
|
||||
|
||||
if (expectedTaskExecution.getArguments() != null) {
|
||||
assertNotNull("arguments should not be null",
|
||||
actualTaskExecution.getArguments());
|
||||
assertEquals("arguments result set count should match expected count",
|
||||
expectedTaskExecution.getArguments().size(),
|
||||
actualTaskExecution.getArguments().size());
|
||||
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 {
|
||||
assertNull("arguments should be null", actualTaskExecution.getArguments());
|
||||
assertThat(actualTaskExecution.getArguments()).as("arguments should be null")
|
||||
.isNull();
|
||||
}
|
||||
Set<String> args = new HashSet<String>();
|
||||
Set<String> args = new HashSet<>();
|
||||
for (String param : expectedTaskExecution.getArguments()) {
|
||||
args.add(param);
|
||||
}
|
||||
for (String arg : actualTaskExecution.getArguments()) {
|
||||
assertTrue("arg must exist in the repository", args.contains(arg));
|
||||
assertThat(args.contains(arg)).as("arg must exist in the repository")
|
||||
.isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user