Skip to content

Commit

Permalink
test: support Redis integration testing (apache#6466)
Browse files Browse the repository at this point in the history
  • Loading branch information
funky-eyes authored Apr 17, 2024
1 parent e72babb commit bd7ad85
Show file tree
Hide file tree
Showing 16 changed files with 38 additions and 107 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ jobs:
# job 1: Test based on java 8 and 17. Do not checkstyle.
build:
name: "build"
services:
redis:
image: redis:7.2
ports:
- 6379:6379
options: --health-cmd="redis-cli ping" --health-interval=10s --health-timeout=5s --health-retries=3
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand All @@ -34,7 +40,7 @@ jobs:
run: |
./mvnw -T 4C clean test \
-Dcheckstyle.skip=false -Dpmd.skip=false -Dlicense.skip=false \
-Dmaven.git-commit-id.skip=true \
-Dmaven.git-commit-id.skip=true -DredisCaseEnabled=true \
-e -B -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn;
# step 4.2
- name: "Test with Maven and Java${{ matrix.java }}"
Expand Down
1 change: 1 addition & 0 deletions changes/en-us/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ Add changes here for all PR submitted to the 2.x branch.
- [[#6325](https://github.com/apache/incubator-seata/pull/6325)] fix mockServerTest fail cause using same port with seata-server
- [[#6430](https://github.com/apache/incubator-seata/pull/6430)] increase common module unit test coverage
- [[#6456](https://github.com/apache/incubator-seata/pull/6456)] adjust the test cases related to dynamic configuration
- [[#6466](https://github.com/apache/incubator-seata/pull/6466)] support redis integration testing

### refactor:

Expand Down
1 change: 1 addition & 0 deletions changes/zh-cn/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
- [[#6325](https://github.com/apache/incubator-seata/pull/6325)] 修复mock-server相关测试用例
- [[#6430](https://github.com/apache/incubator-seata/pull/6430)] 增加 common 模块单元测试覆盖率
- [[#6456](https://github.com/apache/incubator-seata/pull/6456)] 调整动态配置监听测试用例
- [[#6466](https://github.com/apache/incubator-seata/pull/6466)] 支持redis的集成测试

### refactor:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,23 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

class FileConfigurationTest {


Logger logger = LoggerFactory.getLogger(FileConfigurationTest.class);

@BeforeEach
void setUp() {
System.setProperty("file.listener.enabled", "true");
ConfigurationCache.clear();
}

@AfterEach
void tearDown() {
ConfigurationCache.clear();
System.setProperty("file.listener.enabled", "true");
}

@Test
Expand All @@ -48,13 +51,14 @@ void addConfigListener() throws InterruptedException {
fileConfig.addConfigListener(dataId, (CachedConfigurationChangeListener)event -> {
Assertions.assertEquals(Boolean.parseBoolean(event.getNewValue()),
!Boolean.parseBoolean(event.getOldValue()));
System.out.println("oldValue:" + event.getOldValue() + ",newValue:" + event.getNewValue());
logger.info("dataId: {}, oldValue: {}, newValue: {}", event.getDataId(), event.getOldValue(),
event.getNewValue());
countDownLatch.countDown();
});
System.setProperty(dataId, String.valueOf(!value));
countDownLatch.await(10, TimeUnit.SECONDS);
System.out.println(fileConfig.getBoolean(dataId));
System.out.println(value);
countDownLatch.await(60, TimeUnit.SECONDS);
logger.info("dataId: {}, oldValue: {}", dataId, value);
logger.info("dataId: {}, currenValue: {}", dataId, fileConfig.getBoolean(dataId));
Assertions.assertNotEquals(fileConfig.getBoolean(dataId), value);
//wait for loop safety, loop time is LISTENER_CONFIG_INTERVAL=1s
CountDownLatch countDownLatch2 = new CountDownLatch(1);
Expand Down
6 changes: 0 additions & 6 deletions dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
<apache-zookeeper.version>3.7.2</apache-zookeeper.version>
<curator-test.version>5.1.0</curator-test.version>
<spring-context-support.version>1.0.2</spring-context-support.version>
<mock-jedis.version>0.3.1</mock-jedis.version>
<apollo-client.version>2.0.1</apollo-client.version>
<eureka-clients.version>1.10.18</eureka-clients.version>
<jettison.version>1.5.4</jettison.version>
Expand Down Expand Up @@ -416,11 +415,6 @@
<artifactId>jedis</artifactId>
<version>${jedis.version}</version>
</dependency>
<dependency>
<groupId>com.github.microwww</groupId>
<artifactId>redis-server</artifactId>
<version>${mock-jedis.version}</version>
</dependency>
<dependency>
<groupId>com.netflix.eureka</groupId>
<artifactId>eureka-client</artifactId>
Expand Down
5 changes: 0 additions & 5 deletions discovery/seata-discovery-redis/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,5 @@
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</dependency>
<dependency>
<groupId>com.github.microwww</groupId>
<artifactId>redis-server</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
*/
package org.apache.seata.discovery.registry.redis;

import com.github.microwww.redis.RedisServer;
import org.apache.seata.common.util.NetUtil;
import org.apache.seata.config.Configuration;
import org.apache.seata.config.ConfigurationFactory;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
import org.mockito.MockedStatic;
import org.mockito.internal.util.collections.Sets;

Expand All @@ -38,23 +39,19 @@
import static org.mockito.Mockito.when;


@EnabledIfSystemProperty(named = "redisCaseEnabled", matches = "true")
public class RedisRegisterServiceImplTest {

private static RedisRegistryServiceImpl redisRegistryService;

private static RedisServer server;


@BeforeAll
public static void init() throws IOException {
System.setProperty("config.type", "file");
System.setProperty("config.file.name", "file.conf");
System.setProperty("txServiceGroup", "default_tx_group");
System.setProperty("service.vgroupMapping.default_tx_group", "default");
System.setProperty("registry.redis.serverAddr", "127.0.0.1:6789");
System.setProperty("registry.redis.serverAddr", "127.0.0.1:6379");
System.setProperty("registry.redis.cluster", "default");
RedisServer server = new RedisServer();
server.listener("127.0.0.1", 6789);
redisRegistryService = RedisRegistryServiceImpl.getInstance();
}

Expand Down Expand Up @@ -103,14 +100,4 @@ public void testRemoveServerAddressByPushEmptyProtection()
Assertions.assertEquals(0, CLUSTER_ADDRESS_MAP.get("cluster").size());
}

@AfterAll
public static void afterAll() {
if (server != null) {
try {
server.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
6 changes: 0 additions & 6 deletions server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,6 @@
<artifactId>jedis</artifactId>
</dependency>

<dependency>
<groupId>com.github.microwww</groupId>
<artifactId>redis-server</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
import org.apache.seata.core.model.LockStatus;
import org.apache.seata.server.lock.LockManager;
import org.apache.seata.server.session.BranchSession;
import org.apache.seata.server.session.redis.MockRedisServer;
import org.apache.seata.server.storage.redis.JedisPooledFactory;
import org.apache.seata.server.storage.redis.lock.RedisLockManager;
import org.apache.seata.server.storage.redis.lock.RedisLocker;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
import redis.clients.jedis.Jedis;
Expand All @@ -40,6 +40,7 @@
/**
*/
@SpringBootTest
@EnabledIfSystemProperty(named = "redisCaseEnabled", matches = "true")
public class RedisLockManagerTest {
static LockManager lockManager = null;

Expand All @@ -54,11 +55,10 @@ public class RedisLockManagerTest {
*/
@BeforeAll
public static void start(ApplicationContext context) throws IOException {
MockRedisServer.getInstance();
JedisPoolConfig poolConfig = new JedisPoolConfig();
poolConfig.setMinIdle(1);
poolConfig.setMaxIdle(10);
JedisPooledFactory.getJedisPoolInstance(new JedisPool(poolConfig, "127.0.0.1", 6789, 60000)).getResource();
JedisPooledFactory.getJedisPoolInstance(new JedisPool(poolConfig, "127.0.0.1", 6379, 60000)).getResource();
lockManager = new RedisLockManagerForTest();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
import org.apache.seata.common.loader.EnhancedServiceLoader;
import org.apache.seata.core.lock.Locker;
import org.apache.seata.server.session.BranchSession;
import org.apache.seata.server.session.redis.MockRedisServer;
import org.apache.seata.server.storage.redis.lock.RedisLockManager;
import org.apache.seata.server.storage.redis.lock.RedisLuaLocker;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;

Expand All @@ -34,6 +34,7 @@
*
*/
@SpringBootTest
@EnabledIfSystemProperty(named = "redisCaseEnabled", matches = "true")
public class RedisLuaLockManagerTest extends RedisLockManagerTest {

/**
Expand All @@ -46,7 +47,6 @@ public class RedisLuaLockManagerTest extends RedisLockManagerTest {
*/
@BeforeAll
public static void start(ApplicationContext context) throws IOException {
MockRedisServer.getInstance();
EnhancedServiceLoader.unloadAll();
lockManager = new RedisLuaLockManagerTest.RedisLockManagerForTest();
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
import redis.clients.jedis.Jedis;
Expand All @@ -40,6 +41,7 @@
*
*/
@SpringBootTest
@EnabledIfSystemProperty(named = "redisCaseEnabled", matches = "true")
public class RedisDistributedLockerTest {

private String retryRollbacking = "RetryRollbacking";
Expand All @@ -52,7 +54,6 @@ public class RedisDistributedLockerTest {
@BeforeAll
public static void start(ApplicationContext context) throws IOException {
EnhancedServiceLoader.unload(DistributedLocker.class);
MockRedisServer.getInstance();
DistributedLockerFactory.cleanLocker();
distributedLocker = DistributedLockerFactory.getDistributedLocker(StoreMode.REDIS.getName());
jedis = JedisPooledFactory.getJedisInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.seata.server.storage.redis.store.RedisLuaTransactionStoreManager;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;

Expand All @@ -31,6 +32,7 @@
*
*/
@SpringBootTest
@EnabledIfSystemProperty(named = "redisCaseEnabled", matches = "true")
public class RedisLuaTransactionStoreManagerTest extends RedisTransactionStoreManagerTest {

/**
Expand All @@ -43,7 +45,6 @@ public class RedisLuaTransactionStoreManagerTest extends RedisTransactionStoreMa
*/
@BeforeAll
public static void start(ApplicationContext context) throws IOException {
MockRedisServer.getInstance();
EnhancedServiceLoader.unloadAll();
redisTransactionStoreManager = new RedisLuaTransactionStoreManager();
RedisSessionManager redisSessionManager = new RedisSessionManager();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@
import org.apache.seata.server.console.vo.GlobalLockVO;
import org.apache.seata.server.console.vo.GlobalSessionVO;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
import org.springframework.boot.test.context.SpringBootTest;

/**
*/
@SpringBootTest
@EnabledIfSystemProperty(named = "redisCaseEnabled", matches = "true")
public class RedisQueryConsolTest {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.test.context.SpringBootTest;
Expand All @@ -48,14 +49,14 @@
/**
*/
@SpringBootTest
@EnabledIfSystemProperty(named = "redisCaseEnabled", matches = "true")
public class RedisSessionManagerTest {

private static final Logger LOGGER = LoggerFactory.getLogger(RedisSessionManagerTest.class);
private static SessionManager sessionManager = null;

@BeforeAll
public static void start(ApplicationContext context) throws IOException {
MockRedisServer.getInstance();
EnhancedServiceLoader.unloadAll();
RedisTransactionStoreManager transactionStoreManager = RedisTransactionStoreManager.getInstance();
RedisSessionManager redisSessionManager = new RedisSessionManager();
Expand Down
Loading

0 comments on commit bd7ad85

Please sign in to comment.