Updated project to use Spring Boot 3.0

Resolves issues:
TASK-810
TASK-812
TASK-813
This commit is contained in:
Glenn Renfro
2022-01-07 17:38:50 -05:00
parent a95b420315
commit 02b44227d4
30 changed files with 184 additions and 143 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2019 the original author or authors.
* Copyright 2015-2022 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,9 +16,9 @@
package org.springframework.cloud.task.configuration;
import javax.persistence.EntityManager;
import javax.sql.DataSource;
import jakarta.persistence.EntityManager;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2019 the original author or authors.
* Copyright 2015-2022 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,14 @@
package org.springframework.cloud.task.repository.support;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import javax.sql.DataSource;
import org.springframework.jdbc.support.DatabaseMetaDataCallback;
import org.springframework.jdbc.support.JdbcUtils;
import org.springframework.jdbc.support.MetaDataAccessException;
import org.springframework.util.StringUtils;
@@ -107,15 +110,27 @@ public enum DatabaseType {
* @throws MetaDataAccessException thrown if failure occurs on metadata lookup.
*/
public static DatabaseType fromMetaData(DataSource dataSource)
throws MetaDataAccessException {
throws SQLException, MetaDataAccessException {
String databaseProductName = JdbcUtils
.extractDatabaseMetaData(dataSource, "getDatabaseProductName").toString();
.extractDatabaseMetaData(dataSource, new DatabaseMetaDataCallback() {
@Override
public Object processMetaData(DatabaseMetaData dbmd) throws SQLException, MetaDataAccessException {
return dbmd.getDatabaseProductName();
}
}).toString();
if (StringUtils.hasText(databaseProductName)
&& !databaseProductName.equals("DB2/Linux")
&& databaseProductName.startsWith("DB2")) {
String databaseProductVersion = JdbcUtils
.extractDatabaseMetaData(dataSource, "getDatabaseProductVersion")
.toString();
.extractDatabaseMetaData(dataSource, new DatabaseMetaDataCallback() {
@Override
public Object processMetaData(DatabaseMetaData dbmd) throws SQLException, MetaDataAccessException {
return dbmd.getDatabaseProductVersion();
}
}).toString();
if (databaseProductVersion.startsWith("ARI")) {
databaseProductName = "DB2VSE";
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2021 the original author or authors.
* Copyright 2015-2022 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.
@@ -132,6 +132,9 @@ public class TaskExecutionDaoFactoryBean implements FactoryBean<TaskExecutionDao
catch (MetaDataAccessException e) {
throw new IllegalStateException(e);
}
catch (SQLException e) {
throw new IllegalStateException(e);
}
((JdbcTaskExecutionDao) this.dao).setTaskIncrementer(incrementerFactory
.getIncrementer(databaseType, this.tablePrefix + "SEQ"));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2019 the original author or authors.
* Copyright 2015-2022 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,6 +16,8 @@
package org.springframework.cloud.task.repository.support;
import java.sql.SQLException;
import javax.sql.DataSource;
import org.apache.commons.logging.Log;
@@ -89,6 +91,9 @@ public final class TaskRepositoryInitializer implements InitializingBean {
catch (MetaDataAccessException ex) {
throw new IllegalStateException("Unable to detect database type", ex);
}
catch (SQLException ex) {
throw new IllegalStateException("Unable to detect database type", ex);
}
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017-2019 the original author or authors.
* Copyright 2017-2022 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,9 +16,9 @@
package org.springframework.cloud.task.configuration;
import javax.persistence.EntityManager;
import javax.sql.DataSource;
import jakarta.persistence.EntityManager;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -68,7 +68,7 @@ public class DefaultTaskConfigurerTests {
DefaultTaskConfigurer defaultTaskConfigurer = new DefaultTaskConfigurer(
this.dataSource, TaskProperties.DEFAULT_TABLE_PREFIX, localContext);
assertThat(defaultTaskConfigurer.getTransactionManager().getClass().getName())
.isEqualTo("org.springframework.orm.jpa.JpaTransactionManager");
.isEqualTo("org.springframework.jdbc.datasource.DataSourceTransactionManager");
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2019 the original author or authors.
* Copyright 2016-2022 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,6 +16,7 @@
package org.springframework.cloud.task.listener;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Date;
@@ -139,7 +140,7 @@ public class TaskExecutionListenerTests {
.getBean(
AfterTaskErrorAnnotationConfiguration.AnnotatedTaskListener.class);
this.context.publishEvent(new ApplicationReadyEvent(new SpringApplication(),
new String[0], this.context));
new String[0], this.context, Duration.ofSeconds(50)));
assertThat(taskExecutionListener.isTaskStartup()).isTrue();
assertThat(taskExecutionListener.isTaskEnd()).isTrue();
@@ -162,7 +163,7 @@ public class TaskExecutionListenerTests {
.getBean(
DefaultTaskListenerConfiguration.TestTaskExecutionListener.class);
this.context.publishEvent(new ApplicationReadyEvent(new SpringApplication(),
new String[0], this.context));
new String[0], this.context, Duration.ofSeconds(50)));
TaskExecution taskExecution = new TaskExecution(0, 0, "wombat", new Date(),
new Date(), null, new ArrayList<>(), null, null);
@@ -184,7 +185,7 @@ public class TaskExecutionListenerTests {
this.context.publishEvent(new ApplicationFailedEvent(application, new String[0],
this.context, exception));
this.context.publishEvent(
new ApplicationReadyEvent(application, new String[0], this.context));
new ApplicationReadyEvent(application, new String[0], this.context, Duration.ofSeconds(50)));
TaskExecution taskExecution = new TaskExecution(0, 1, "wombat", new Date(),
new Date(), null, new ArrayList<>(), null, null);
@@ -215,7 +216,7 @@ public class TaskExecutionListenerTests {
DefaultAnnotationConfiguration.AnnotatedTaskListener annotatedListener = this.context
.getBean(DefaultAnnotationConfiguration.AnnotatedTaskListener.class);
this.context.publishEvent(new ApplicationReadyEvent(new SpringApplication(),
new String[0], this.context));
new String[0], this.context, Duration.ofSeconds(50)));
TaskExecution taskExecution = new TaskExecution(0, 0, "wombat", new Date(),
new Date(), null, new ArrayList<>(), null, null);
@@ -236,7 +237,7 @@ public class TaskExecutionListenerTests {
this.context.publishEvent(new ApplicationFailedEvent(application, new String[0],
this.context, exception));
this.context.publishEvent(
new ApplicationReadyEvent(application, new String[0], this.context));
new ApplicationReadyEvent(application, new String[0], this.context, Duration.ofSeconds(50)));
TaskExecution taskExecution = new TaskExecution(0, 1, "wombat", new Date(),
new Date(), null, new ArrayList<>(), null, null);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2019 the original author or authors.
* Copyright 2015-2022 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,6 +16,7 @@
package org.springframework.cloud.task.listener;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -109,7 +110,7 @@ public class TaskLifecycleListenerTests {
this.taskExplorer = this.context.getBean(TaskExplorer.class);
this.context.publishEvent(new ApplicationReadyEvent(new SpringApplication(),
new String[0], this.context));
new String[0], this.context, Duration.ofSeconds(50)));
verifyTaskExecution(0, true, 0);
}
@@ -123,7 +124,7 @@ public class TaskLifecycleListenerTests {
this.context.publishEvent(new ApplicationFailedEvent(application, new String[0],
this.context, exception));
this.context.publishEvent(
new ApplicationReadyEvent(application, new String[0], this.context));
new ApplicationReadyEvent(application, new String[0], this.context, Duration.ofSeconds(50)));
verifyTaskExecution(0, true, 1, exception, null);
}
@@ -142,7 +143,7 @@ public class TaskLifecycleListenerTests {
this.context.publishEvent(new ApplicationFailedEvent(application, new String[0],
this.context, exception));
this.context.publishEvent(
new ApplicationReadyEvent(application, new String[0], this.context));
new ApplicationReadyEvent(application, new String[0], this.context, Duration.ofSeconds(50)));
verifyTaskExecution(0, true, exitCode, exception, null);
assertThat(TestListener.getStartupOrderList().size()).isEqualTo(2);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2019 the original author or authors.
* Copyright 2015-2022 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.
@@ -174,6 +174,9 @@ public final class TestDBUtils {
catch (MetaDataAccessException e) {
throw new IllegalStateException(e);
}
catch (SQLException ex) {
throw new IllegalStateException("Unable to detect database type", ex);
}
return incrementerFactory.getIncrementer(databaseType, "TASK_SEQ");
}