diff --git a/changes/en-us/2.x.md b/changes/en-us/2.x.md index ea951fedffc..e8ffacf603b 100644 --- a/changes/en-us/2.x.md +++ b/changes/en-us/2.x.md @@ -30,6 +30,7 @@ Add changes here for all PR submitted to the 2.x branch. ### optimize: +- [[#8137](https://github.com/apache/incubator-seata/pull/8137)] server modules: spring-boot upgrade to 4.0.6 ### security: @@ -49,6 +50,7 @@ Thanks to these contributors for their code commits. Please report an unintended - [slievrly](https://github.com/slievrly) +- [xuxiaowei-com-cn](https://github.com/xuxiaowei-com-cn) - [Seol-JY](https://github.com/Seol-JY) - [lhozy](https://github.com/lhozy) - [Zhengcy05](https://github.com/Zhengcy05) diff --git a/changes/zh-cn/2.x.md b/changes/zh-cn/2.x.md index c7754065724..77a68bc3fae 100644 --- a/changes/zh-cn/2.x.md +++ b/changes/zh-cn/2.x.md @@ -29,6 +29,7 @@ ### optimize: +- [[#8137](https://github.com/apache/incubator-seata/pull/8137)] server 模块: spring-boot 升级到 4.0.6 ### security: @@ -48,6 +49,7 @@ - [slievrly](https://github.com/slievrly) +- [xuxiaowei-com-cn](https://github.com/xuxiaowei-com-cn) - [Seol-JY](https://github.com/Seol-JY) - [lhozy](https://github.com/lhozy) - [Zhengcy05](https://github.com/Zhengcy05) diff --git a/extensions/apm/pom.xml b/extensions/apm/pom.xml index 8778b913ad6..94b5a2a230c 100644 --- a/extensions/apm/pom.xml +++ b/extensions/apm/pom.xml @@ -33,6 +33,18 @@ APM extensions for Seata built with Maven - apm-seata-skywalking-plugin + - \ No newline at end of file + + + + JDK17Plus + + [17,) + + + apm-seata-skywalking-plugin + + + + diff --git a/pom.xml b/pom.xml index 05129717f49..47dfb4bc7d3 100644 --- a/pom.xml +++ b/pom.xml @@ -57,10 +57,10 @@ compressor saga sqlparser - server + integration-tx-api - test-suite/test-new-version + test-suite/test-old-version test-suite/seata-benchmark-cli json-common @@ -129,6 +129,17 @@ + + + JDK17Plus + + [17,) + + + server + test-suite/test-new-version + + JDK21Plus @@ -372,7 +383,7 @@ distribution - test-suite/test-new-version + test-suite/test-old-version diff --git a/server/pom.xml b/server/pom.xml index 9de1f407868..b7cd48a58cb 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -32,9 +32,10 @@ server for Seata built with Maven - 2.7.18 - 5.3.39 + 4.0.6 + 7.0.7 2.0 + 6.0.3 @@ -97,6 +98,10 @@ + + org.springframework.boot + spring-boot-web-server + org.springframework.boot spring-boot-starter diff --git a/server/src/main/java/org/apache/seata/server/Server.java b/server/src/main/java/org/apache/seata/server/Server.java index 9c2a579495a..279ec87f5dc 100644 --- a/server/src/main/java/org/apache/seata/server/Server.java +++ b/server/src/main/java/org/apache/seata/server/Server.java @@ -16,6 +16,7 @@ */ package org.apache.seata.server; +import jakarta.annotation.Resource; import org.apache.seata.common.XID; import org.apache.seata.common.holder.ObjectHolder; import org.apache.seata.common.thread.ThreadPoolExecutorFactory; @@ -35,7 +36,6 @@ import org.springframework.context.ConfigurableApplicationContext; import org.springframework.stereotype.Component; -import javax.annotation.Resource; import java.util.Optional; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadPoolExecutor; diff --git a/server/src/main/java/org/apache/seata/server/ServerRunner.java b/server/src/main/java/org/apache/seata/server/ServerRunner.java index 94545399a56..a363a726e78 100644 --- a/server/src/main/java/org/apache/seata/server/ServerRunner.java +++ b/server/src/main/java/org/apache/seata/server/ServerRunner.java @@ -16,19 +16,19 @@ */ package org.apache.seata.server; +import jakarta.annotation.Resource; import org.apache.seata.core.rpc.Disposable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.web.context.WebServerInitializedEvent; +import org.springframework.boot.web.server.context.WebServerInitializedEvent; import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationListener; import org.springframework.core.Ordered; import org.springframework.stereotype.Component; -import javax.annotation.Resource; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; diff --git a/server/src/main/java/org/apache/seata/server/cluster/manager/ClusterWatcherManager.java b/server/src/main/java/org/apache/seata/server/cluster/manager/ClusterWatcherManager.java index 9d1ac984ab7..1ad8ae0e833 100644 --- a/server/src/main/java/org/apache/seata/server/cluster/manager/ClusterWatcherManager.java +++ b/server/src/main/java/org/apache/seata/server/cluster/manager/ClusterWatcherManager.java @@ -31,6 +31,7 @@ import io.netty.handler.codec.http2.DefaultHttp2Headers; import io.netty.handler.codec.http2.DefaultHttp2HeadersFrame; import io.netty.handler.codec.http2.Http2Headers; +import jakarta.annotation.PostConstruct; import org.apache.seata.common.ConfigurationKeys; import org.apache.seata.common.Constants; import org.apache.seata.common.metadata.MetadataResponse; @@ -51,7 +52,6 @@ import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; -import javax.annotation.PostConstruct; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.HashSet; diff --git a/server/src/main/java/org/apache/seata/server/cluster/raft/context/SeataClusterContext.java b/server/src/main/java/org/apache/seata/server/cluster/raft/context/SeataClusterContext.java index 0f783a1b1bd..a9825707937 100644 --- a/server/src/main/java/org/apache/seata/server/cluster/raft/context/SeataClusterContext.java +++ b/server/src/main/java/org/apache/seata/server/cluster/raft/context/SeataClusterContext.java @@ -16,14 +16,13 @@ */ package org.apache.seata.server.cluster.raft.context; +import jakarta.annotation.Nonnull; +import jakarta.annotation.Nullable; import org.apache.seata.common.ConfigurationKeys; import org.apache.seata.config.ConfigurationFactory; import org.apache.seata.core.context.ContextCore; import org.apache.seata.core.context.ContextCoreLoader; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - import static org.apache.seata.common.DefaultValues.DEFAULT_SEATA_GROUP; /** diff --git a/server/src/main/java/org/apache/seata/server/config/ServerConfig.java b/server/src/main/java/org/apache/seata/server/config/ServerConfig.java index 067666e1d81..9cc7e309d7e 100644 --- a/server/src/main/java/org/apache/seata/server/config/ServerConfig.java +++ b/server/src/main/java/org/apache/seata/server/config/ServerConfig.java @@ -16,7 +16,7 @@ */ package org.apache.seata.server.config; -import org.springframework.boot.autoconfigure.web.ServerProperties; +import org.springframework.boot.web.server.autoconfigure.ServerProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/server/src/main/java/org/apache/seata/server/console/controller/BranchSessionController.java b/server/src/main/java/org/apache/seata/server/console/controller/BranchSessionController.java index 5b82b605a13..1510551dd19 100644 --- a/server/src/main/java/org/apache/seata/server/console/controller/BranchSessionController.java +++ b/server/src/main/java/org/apache/seata/server/console/controller/BranchSessionController.java @@ -16,6 +16,7 @@ */ package org.apache.seata.server.console.controller; +import jakarta.annotation.Resource; import org.apache.seata.common.result.SingleResult; import org.apache.seata.server.console.service.BranchSessionService; import org.slf4j.Logger; @@ -25,8 +26,6 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import javax.annotation.Resource; - /** * Branch Session Controller */ diff --git a/server/src/main/java/org/apache/seata/server/console/controller/GlobalLockController.java b/server/src/main/java/org/apache/seata/server/console/controller/GlobalLockController.java index fb7e3054f0c..ec37b3b2104 100644 --- a/server/src/main/java/org/apache/seata/server/console/controller/GlobalLockController.java +++ b/server/src/main/java/org/apache/seata/server/console/controller/GlobalLockController.java @@ -16,6 +16,7 @@ */ package org.apache.seata.server.console.controller; +import jakarta.annotation.Resource; import org.apache.seata.common.result.PageResult; import org.apache.seata.common.result.SingleResult; import org.apache.seata.server.console.entity.param.GlobalLockParam; @@ -29,8 +30,6 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import javax.annotation.Resource; - /** * Global Lock Controller */ diff --git a/server/src/main/java/org/apache/seata/server/console/controller/GlobalSessionController.java b/server/src/main/java/org/apache/seata/server/console/controller/GlobalSessionController.java index a7703bc4100..48c5531c47b 100644 --- a/server/src/main/java/org/apache/seata/server/console/controller/GlobalSessionController.java +++ b/server/src/main/java/org/apache/seata/server/console/controller/GlobalSessionController.java @@ -16,6 +16,7 @@ */ package org.apache.seata.server.console.controller; +import jakarta.annotation.Resource; import org.apache.seata.common.result.PageResult; import org.apache.seata.common.result.SingleResult; import org.apache.seata.server.console.entity.param.GlobalSessionParam; @@ -30,8 +31,6 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import javax.annotation.Resource; - /** * Global Session Controller */ diff --git a/server/src/main/java/org/apache/seata/server/console/impl/db/GlobalSessionDBServiceImpl.java b/server/src/main/java/org/apache/seata/server/console/impl/db/GlobalSessionDBServiceImpl.java index 16e772e7d14..1acaf087917 100644 --- a/server/src/main/java/org/apache/seata/server/console/impl/db/GlobalSessionDBServiceImpl.java +++ b/server/src/main/java/org/apache/seata/server/console/impl/db/GlobalSessionDBServiceImpl.java @@ -16,6 +16,7 @@ */ package org.apache.seata.server.console.impl.db; +import jakarta.annotation.Resource; import org.apache.seata.common.ConfigurationKeys; import org.apache.seata.common.exception.StoreException; import org.apache.seata.common.loader.EnhancedServiceLoader; @@ -36,7 +37,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.stereotype.Component; -import javax.annotation.Resource; import javax.sql.DataSource; import java.sql.Connection; import java.sql.PreparedStatement; diff --git a/server/src/main/java/org/apache/seata/server/controller/ClusterController.java b/server/src/main/java/org/apache/seata/server/controller/ClusterController.java index b3f124bebc3..ef875f0eca6 100644 --- a/server/src/main/java/org/apache/seata/server/controller/ClusterController.java +++ b/server/src/main/java/org/apache/seata/server/controller/ClusterController.java @@ -18,6 +18,7 @@ import com.alipay.sofa.jraft.RouteTable; import com.alipay.sofa.jraft.conf.Configuration; +import jakarta.annotation.Resource; import org.apache.seata.common.metadata.MetadataResponse; import org.apache.seata.common.result.Result; import org.apache.seata.common.rpc.http.HttpContext; @@ -31,7 +32,6 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import javax.annotation.Resource; import java.util.Map; @RestController diff --git a/server/src/main/java/org/apache/seata/server/instance/AbstractSeataInstanceStrategy.java b/server/src/main/java/org/apache/seata/server/instance/AbstractSeataInstanceStrategy.java index fd739519013..48dc7ef50c0 100644 --- a/server/src/main/java/org/apache/seata/server/instance/AbstractSeataInstanceStrategy.java +++ b/server/src/main/java/org/apache/seata/server/instance/AbstractSeataInstanceStrategy.java @@ -16,6 +16,9 @@ */ package org.apache.seata.server.instance; +import jakarta.annotation.PostConstruct; +import jakarta.annotation.PreDestroy; +import jakarta.annotation.Resource; import org.apache.seata.common.metadata.Instance; import org.apache.seata.common.thread.ThreadPoolExecutorFactory; import org.apache.seata.core.protocol.Version; @@ -25,12 +28,9 @@ import org.apache.seata.spring.boot.autoconfigure.properties.registry.RegistryProperties; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.boot.autoconfigure.web.ServerProperties; +import org.springframework.boot.web.server.autoconfigure.ServerProperties; import org.springframework.context.ApplicationContext; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; -import javax.annotation.Resource; import java.util.Arrays; import java.util.Optional; import java.util.concurrent.ScheduledExecutorService; diff --git a/server/src/main/java/org/apache/seata/server/instance/RaftServerInstanceStrategy.java b/server/src/main/java/org/apache/seata/server/instance/RaftServerInstanceStrategy.java index 230933baa4d..a231e648306 100644 --- a/server/src/main/java/org/apache/seata/server/instance/RaftServerInstanceStrategy.java +++ b/server/src/main/java/org/apache/seata/server/instance/RaftServerInstanceStrategy.java @@ -17,6 +17,7 @@ package org.apache.seata.server.instance; import com.alipay.sofa.jraft.entity.PeerId; +import jakarta.annotation.Resource; import org.apache.seata.common.XID; import org.apache.seata.common.holder.ObjectHolder; import org.apache.seata.common.metadata.ClusterRole; @@ -36,8 +37,6 @@ import org.springframework.core.env.PropertySource; import org.springframework.scheduling.annotation.Async; -import javax.annotation.Resource; - import static org.apache.seata.common.ConfigurationKeys.META_PREFIX; import static org.apache.seata.common.Constants.OBJECT_KEY_SPRING_CONFIGURABLE_ENVIRONMENT; diff --git a/server/src/main/java/org/apache/seata/server/storage/redis/JedisPooledFactory.java b/server/src/main/java/org/apache/seata/server/storage/redis/JedisPooledFactory.java index 583f30275e6..e9ce9a004ef 100644 --- a/server/src/main/java/org/apache/seata/server/storage/redis/JedisPooledFactory.java +++ b/server/src/main/java/org/apache/seata/server/storage/redis/JedisPooledFactory.java @@ -26,10 +26,10 @@ import org.slf4j.LoggerFactory; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; -import redis.clients.jedis.JedisPoolAbstract; import redis.clients.jedis.JedisPoolConfig; import redis.clients.jedis.JedisSentinelPool; import redis.clients.jedis.Protocol; +import redis.clients.jedis.util.Pool; import java.util.Arrays; import java.util.HashSet; @@ -47,7 +47,7 @@ public class JedisPooledFactory { */ protected static final Logger LOGGER = LoggerFactory.getLogger(JedisPooledFactory.class); - private static volatile JedisPoolAbstract jedisPool = null; + private static volatile Pool jedisPool = null; private static final String HOST = "127.0.0.1"; @@ -63,11 +63,11 @@ public class JedisPooledFactory { * * @return redisPool */ - public static JedisPoolAbstract getJedisPoolInstance(JedisPoolAbstract... jedisPools) { + public static Pool getJedisPoolInstance(Pool... jedisPools) { if (jedisPool == null) { synchronized (JedisPooledFactory.class) { if (jedisPool == null) { - JedisPoolAbstract tempJedisPool = null; + Pool tempJedisPool = null; if (jedisPools != null && jedisPools.length > 0) { tempJedisPool = jedisPools[0]; } else { diff --git a/server/src/main/java/org/apache/seata/server/storage/redis/store/RedisTransactionStoreManager.java b/server/src/main/java/org/apache/seata/server/storage/redis/store/RedisTransactionStoreManager.java index f5d14070943..c27ebc1dae3 100644 --- a/server/src/main/java/org/apache/seata/server/storage/redis/store/RedisTransactionStoreManager.java +++ b/server/src/main/java/org/apache/seata/server/storage/redis/store/RedisTransactionStoreManager.java @@ -54,7 +54,6 @@ import java.util.Map; import java.util.Objects; import java.util.Optional; -import java.util.Set; import java.util.function.Function; import java.util.stream.Collectors; @@ -500,7 +499,7 @@ public List readSortByTimeoutBeginSessions(boolean withBranchSess // queryCount final long queryCount = Math.min(logQueryLimit, countGlobalSessions); try (Jedis jedis = JedisPooledFactory.getJedisInstance()) { - Set values = jedis.zrangeByScore( + List values = jedis.zrangeByScore( REDIS_SEATA_BEGIN_TRANSACTIONS_KEY, 0, System.currentTimeMillis(), 0, (int) queryCount); List> rep; try (Pipeline pipeline = jedis.pipelined()) { diff --git a/server/src/main/resources/logback-spring.xml b/server/src/main/resources/logback-spring.xml index 880cb910115..a303251e67e 100644 --- a/server/src/main/resources/logback-spring.xml +++ b/server/src/main/resources/logback-spring.xml @@ -155,6 +155,12 @@ + + + + + + diff --git a/server/src/test/java/org/apache/seata/server/LoaderConfTest.java b/server/src/test/java/org/apache/seata/server/LoaderConfTest.java index 811615dcf00..1125715a825 100644 --- a/server/src/test/java/org/apache/seata/server/LoaderConfTest.java +++ b/server/src/test/java/org/apache/seata/server/LoaderConfTest.java @@ -16,12 +16,13 @@ */ package org.apache.seata.server; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.springframework.context.ApplicationContext; import org.springframework.core.env.Environment; +import static org.junit.jupiter.api.Assertions.assertEquals; + /** * */ @@ -42,10 +43,10 @@ public static void initSessionManager(ApplicationContext context) throws Excepti @Test public void checkConf() { String nacosServerAddr = environment.resolveRequiredPlaceholders("${seata.config.nacos.serverAddr:localhost}"); - Assertions.assertEquals(nacosServerAddr, "127.0.0.1:8848"); + assertEquals("127.0.0.1:8848", nacosServerAddr); String nacosNamespace = environment.resolveRequiredPlaceholders("${seata.config.nacos.namespace:seata-group}"); - Assertions.assertEquals(nacosNamespace, "seata-test"); + assertEquals("seata-test", nacosNamespace); String undologSaveDays = environment.resolveRequiredPlaceholders("${seata.server.undo.log-save-days:7}"); - Assertions.assertEquals(undologSaveDays, "2"); + assertEquals("2", undologSaveDays); } } diff --git a/server/src/test/java/org/apache/seata/server/console/impl/db/BranchSessionDBServiceImplTest.java b/server/src/test/java/org/apache/seata/server/console/impl/db/BranchSessionDBServiceImplTest.java index 7d34b978acb..b8d2ef935f6 100644 --- a/server/src/test/java/org/apache/seata/server/console/impl/db/BranchSessionDBServiceImplTest.java +++ b/server/src/test/java/org/apache/seata/server/console/impl/db/BranchSessionDBServiceImplTest.java @@ -24,8 +24,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.util.ReflectionTestUtils; import javax.sql.DataSource; @@ -49,7 +49,7 @@ class BranchSessionDBServiceImplTest extends BaseSpringBootTest { @Autowired private BranchSessionDBServiceImpl branchSessionDBService; - @MockBean + @MockitoBean private DataSource dataSource; private Connection connection; diff --git a/server/src/test/java/org/apache/seata/server/console/impl/db/GlobalLockDBServiceImplTest.java b/server/src/test/java/org/apache/seata/server/console/impl/db/GlobalLockDBServiceImplTest.java index 6c60f7aac9e..03e8fb675d1 100644 --- a/server/src/test/java/org/apache/seata/server/console/impl/db/GlobalLockDBServiceImplTest.java +++ b/server/src/test/java/org/apache/seata/server/console/impl/db/GlobalLockDBServiceImplTest.java @@ -27,8 +27,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.util.ReflectionTestUtils; import javax.sql.DataSource; @@ -52,7 +52,7 @@ class GlobalLockDBServiceImplTest extends BaseSpringBootTest { @Autowired private GlobalLockDBServiceImpl globalLockDBService; - @MockBean + @MockitoBean private DataSource dataSource; private Connection connection; diff --git a/server/src/test/java/org/apache/seata/server/console/impl/db/GlobalSessionDBServiceImplTest.java b/server/src/test/java/org/apache/seata/server/console/impl/db/GlobalSessionDBServiceImplTest.java index c91abfcdf4d..3b29ea43110 100644 --- a/server/src/test/java/org/apache/seata/server/console/impl/db/GlobalSessionDBServiceImplTest.java +++ b/server/src/test/java/org/apache/seata/server/console/impl/db/GlobalSessionDBServiceImplTest.java @@ -27,8 +27,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.util.ReflectionTestUtils; import javax.sql.DataSource; @@ -51,10 +51,10 @@ class GlobalSessionDBServiceImplTest extends BaseSpringBootTest { @Autowired private GlobalSessionDBServiceImpl globalSessionDBService; - @MockBean + @MockitoBean private DataSource dataSource; - @MockBean + @MockitoBean private BranchSessionService branchSessionService; private Connection connection; diff --git a/server/src/test/java/org/apache/seata/server/instance/RaftServerInstanceStrategyTest.java b/server/src/test/java/org/apache/seata/server/instance/RaftServerInstanceStrategyTest.java index d5d59d94fbf..07d9f63603c 100644 --- a/server/src/test/java/org/apache/seata/server/instance/RaftServerInstanceStrategyTest.java +++ b/server/src/test/java/org/apache/seata/server/instance/RaftServerInstanceStrategyTest.java @@ -40,7 +40,7 @@ import org.mockito.MockedStatic; import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.boot.autoconfigure.web.ServerProperties; +import org.springframework.boot.web.server.autoconfigure.ServerProperties; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.MapPropertySource; import org.springframework.core.env.MutablePropertySources; diff --git a/server/src/test/java/org/apache/seata/server/lock/LockManagerTest.java b/server/src/test/java/org/apache/seata/server/lock/LockManagerTest.java index e045d0437ed..568d56dad53 100644 --- a/server/src/test/java/org/apache/seata/server/lock/LockManagerTest.java +++ b/server/src/test/java/org/apache/seata/server/lock/LockManagerTest.java @@ -16,6 +16,7 @@ */ package org.apache.seata.server.lock; +import jakarta.annotation.Resource; import org.apache.seata.common.result.PageResult; import org.apache.seata.common.store.SessionMode; import org.apache.seata.common.util.CollectionUtils; @@ -38,7 +39,6 @@ import org.junit.jupiter.params.provider.MethodSource; import org.springframework.context.ApplicationContext; -import javax.annotation.Resource; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Collection; diff --git a/server/src/test/java/org/apache/seata/server/logging/AppenderTest.java b/server/src/test/java/org/apache/seata/server/logging/AppenderTest.java index 894959e499a..bf9a1a3fd2a 100644 --- a/server/src/test/java/org/apache/seata/server/logging/AppenderTest.java +++ b/server/src/test/java/org/apache/seata/server/logging/AppenderTest.java @@ -24,33 +24,37 @@ import org.apache.seata.server.BaseSpringBootTest; import org.apache.seata.server.logging.logback.appender.MetricLogbackAppender; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import org.slf4j.impl.StaticLoggerBinder; +import org.slf4j.LoggerFactory; +import org.springframework.test.context.TestPropertySource; import java.lang.reflect.Field; import java.util.Iterator; +@TestPropertySource( + properties = { + "logging.extend.logstash-appender.enabled=true", + "logging.extend.kafka-appender.enabled=true", + "logging.extend.kafka-appender.topic=test", + "logging.extend.metric-appender.enabled=true" + }) public class AppenderTest extends BaseSpringBootTest { - @BeforeAll - public static void init() { - System.setProperty("logging.extend.logstash-appender.enabled", "true"); - System.setProperty("logging.extend.kafka-appender.enabled", "true"); - System.setProperty("logging.extend.kafka-appender.topic", "test"); - System.setProperty("logging.extend.metric-appender.enabled", "true"); - } - @Test public void testAppenderEnabled() { - LoggerContext lc = (LoggerContext) StaticLoggerBinder.getSingleton().getLoggerFactory(); + LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); Iterator> appenderIterator = lc.getLogger("ROOT").iteratorForAppenders(); + boolean kafkaFound = false; + boolean metricFound = false; + boolean logstashFound = false; + while (appenderIterator.hasNext()) { Appender appender = appenderIterator.next(); if (appender.getName().equals("KAFKA")) { KafkaAppender kafkaAppender = (KafkaAppender) appender; + kafkaFound = true; try { // use reflection to obtain the "protect topic" fields of the abstract class inherited by the @@ -69,12 +73,18 @@ public void testAppenderEnabled() { if (appender.getName().equals("METRIC")) { Assertions.assertInstanceOf(MetricLogbackAppender.class, appender); + metricFound = true; } if (appender.getName().equals("LOGSTASH")) { Assertions.assertInstanceOf(LogstashTcpSocketAppender.class, appender); + logstashFound = true; } } + + Assertions.assertTrue(kafkaFound); + Assertions.assertTrue(metricFound); + Assertions.assertTrue(logstashFound); } private static Field getDeclaredFieldRecursive(Class clazz, String fieldName) throws NoSuchFieldException { diff --git a/server/src/test/java/org/apache/seata/server/session/FileSessionManagerTest.java b/server/src/test/java/org/apache/seata/server/session/FileSessionManagerTest.java index f4c22f7b448..77de755c649 100644 --- a/server/src/test/java/org/apache/seata/server/session/FileSessionManagerTest.java +++ b/server/src/test/java/org/apache/seata/server/session/FileSessionManagerTest.java @@ -16,6 +16,7 @@ */ package org.apache.seata.server.session; +import jakarta.annotation.Resource; import org.apache.commons.lang3.time.DateUtils; import org.apache.seata.common.XID; import org.apache.seata.common.loader.EnhancedServiceLoader; @@ -43,7 +44,6 @@ import org.junit.jupiter.params.provider.MethodSource; import org.springframework.context.ApplicationContext; -import javax.annotation.Resource; import java.io.IOException; import java.text.ParseException; import java.text.SimpleDateFormat; diff --git a/server/src/test/java/org/apache/seata/server/session/redis/RedisQueryConsolTest.java b/server/src/test/java/org/apache/seata/server/session/redis/RedisQueryConsolTest.java index b21babacd0c..19602acecd7 100644 --- a/server/src/test/java/org/apache/seata/server/session/redis/RedisQueryConsolTest.java +++ b/server/src/test/java/org/apache/seata/server/session/redis/RedisQueryConsolTest.java @@ -17,6 +17,7 @@ package org.apache.seata.server.session.redis; import com.alibaba.fastjson.JSON; +import jakarta.annotation.Resource; import org.apache.seata.common.result.PageResult; import org.apache.seata.server.BaseSpringBootTest; import org.apache.seata.server.console.entity.param.GlobalLockParam; @@ -28,8 +29,6 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledIfSystemProperty; -import javax.annotation.Resource; - /** */ @EnabledIfSystemProperty(named = "redisCaseEnabled", matches = "true") diff --git a/server/src/test/java/org/apache/seata/server/storage/redis/JedisPooledFactoryTest.java b/server/src/test/java/org/apache/seata/server/storage/redis/JedisPooledFactoryTest.java index 2f82489552b..e794766bd8b 100644 --- a/server/src/test/java/org/apache/seata/server/storage/redis/JedisPooledFactoryTest.java +++ b/server/src/test/java/org/apache/seata/server/storage/redis/JedisPooledFactoryTest.java @@ -24,8 +24,8 @@ import org.junit.jupiter.api.condition.EnabledIfSystemProperty; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; -import redis.clients.jedis.JedisPoolAbstract; import redis.clients.jedis.JedisPoolConfig; +import redis.clients.jedis.util.Pool; import java.lang.reflect.Field; @@ -37,7 +37,7 @@ public void setUp() throws Exception { // Reset the singleton jedisPool field to null before each test to ensure test isolation Field jedisPoolField = JedisPooledFactory.class.getDeclaredField("jedisPool"); jedisPoolField.setAccessible(true); - JedisPoolAbstract existingPool = (JedisPoolAbstract) jedisPoolField.get(null); + Pool existingPool = (Pool) jedisPoolField.get(null); // Close existing pool if present to prevent resource leaks if (existingPool != null) { @@ -53,7 +53,7 @@ public void tearDown() throws Exception { // Clean up resources after each test Field jedisPoolField = JedisPooledFactory.class.getDeclaredField("jedisPool"); jedisPoolField.setAccessible(true); - JedisPoolAbstract pool = (JedisPoolAbstract) jedisPoolField.get(null); + Pool pool = (Pool) jedisPoolField.get(null); if (pool != null) { pool.close(); @@ -72,7 +72,7 @@ public void testGetJedisPoolInstanceWithProvidedPool() { JedisPool jedisPool = new JedisPool(poolConfig, "127.0.0.1", 6379, 60000); - JedisPoolAbstract poolInstance = JedisPooledFactory.getJedisPoolInstance(jedisPool); + Pool poolInstance = JedisPooledFactory.getJedisPoolInstance(jedisPool); Assertions.assertNotNull(poolInstance); Assertions.assertEquals(jedisPool, poolInstance); @@ -86,8 +86,8 @@ public void testGetJedisPoolInstanceSingleton() { JedisPool jedisPool = new JedisPool(poolConfig, "127.0.0.1", 6379, 60000); - JedisPoolAbstract instance1 = JedisPooledFactory.getJedisPoolInstance(jedisPool); - JedisPoolAbstract instance2 = JedisPooledFactory.getJedisPoolInstance(); + Pool instance1 = JedisPooledFactory.getJedisPoolInstance(jedisPool); + Pool instance2 = JedisPooledFactory.getJedisPoolInstance(); Assertions.assertNotNull(instance1); Assertions.assertNotNull(instance2); diff --git a/server/src/test/java/org/apache/seata/server/storage/redis/store/RedisTransactionStoreManagerTest.java b/server/src/test/java/org/apache/seata/server/storage/redis/store/RedisTransactionStoreManagerTest.java index 3ad93bfeee4..ed4c2961ceb 100644 --- a/server/src/test/java/org/apache/seata/server/storage/redis/store/RedisTransactionStoreManagerTest.java +++ b/server/src/test/java/org/apache/seata/server/storage/redis/store/RedisTransactionStoreManagerTest.java @@ -29,7 +29,6 @@ import java.util.List; import java.util.Map; -import java.util.Set; @EnabledIfSystemProperty(named = "redisCaseEnabled", matches = "true") public class RedisTransactionStoreManagerTest extends BaseSpringBootTest { @@ -254,7 +253,7 @@ public void testInsertGlobalTransactionDO() throws Exception { Assertions.assertTrue(statusList.contains("testGlobalXid:111")); // Verify timeout sorted set - Set timeoutSet = jedis.zrangeByScore("SEATA_BEGIN_TRANSACTIONS", 0, Double.MAX_VALUE); + List timeoutSet = jedis.zrangeByScore("SEATA_BEGIN_TRANSACTIONS", 0, Double.MAX_VALUE); Assertions.assertTrue(timeoutSet.contains(globalKey)); // Cleanup @@ -292,7 +291,7 @@ public void testDeleteGlobalTransactionDO() throws Exception { List statusList = jedis.lrange(statusKey, 0, -1); Assertions.assertFalse(statusList.contains("testGlobalXid:222")); - Set timeoutSet = jedis.zrangeByScore("SEATA_BEGIN_TRANSACTIONS", 0, Double.MAX_VALUE); + List timeoutSet = jedis.zrangeByScore("SEATA_BEGIN_TRANSACTIONS", 0, Double.MAX_VALUE); Assertions.assertFalse(timeoutSet.contains(globalKey)); } }