1
0
mirror of synced 2025-12-21 08:30:11 +08:00

🐛 #1546 修复WxRedisOps问题, #1548 修复WxOpenInMemoryConfigStorage锁问题,#1305 增加商户电子发票功能

This commit is contained in:
Mario Luo
2020-05-12 18:17:17 +08:00
committed by GitHub
parent 609b38a9db
commit 058ce62a2b
25 changed files with 1078 additions and 14 deletions

View File

@@ -0,0 +1,51 @@
package me.chanjar.weixin.common.redis;
import org.testng.Assert;
import org.testng.annotations.Test;
import java.util.concurrent.TimeUnit;
public class CommonWxRedisOpsTest {
protected WxRedisOps wxRedisOps;
private String key = "access_token";
private String value = String.valueOf(System.currentTimeMillis());
@Test
public void testGetValue() {
wxRedisOps.setValue(key, value, 3, TimeUnit.SECONDS);
Assert.assertEquals(wxRedisOps.getValue(key), value);
}
@Test
public void testSetValue() {
String key = "access_token", value = String.valueOf(System.currentTimeMillis());
wxRedisOps.setValue(key, value, -1, TimeUnit.SECONDS);
wxRedisOps.setValue(key, value, 0, TimeUnit.SECONDS);
wxRedisOps.setValue(key, value, 1, TimeUnit.SECONDS);
}
@Test
public void testGetExpire() {
String key = "access_token", value = String.valueOf(System.currentTimeMillis());
wxRedisOps.setValue(key, value, -1, TimeUnit.SECONDS);
Assert.assertTrue(wxRedisOps.getExpire(key) < 0);
wxRedisOps.setValue(key, value, 4, TimeUnit.SECONDS);
Long expireSeconds = wxRedisOps.getExpire(key);
Assert.assertTrue(expireSeconds <= 4 && expireSeconds >= 0);
}
@Test
public void testExpire() {
String key = "access_token", value = String.valueOf(System.currentTimeMillis());
wxRedisOps.setValue(key, value, -1, TimeUnit.SECONDS);
wxRedisOps.expire(key, 4, TimeUnit.SECONDS);
Long expireSeconds = wxRedisOps.getExpire(key);
Assert.assertTrue(expireSeconds <= 4 && expireSeconds >= 0);
}
@Test
public void testGetLock() {
Assert.assertNotNull(wxRedisOps.getLock("access_token_lock"));
}
}

View File

@@ -0,0 +1,21 @@
package me.chanjar.weixin.common.redis;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import redis.clients.jedis.JedisPool;
public class JedisWxRedisOpsTest extends CommonWxRedisOpsTest {
JedisPool jedisPool;
@BeforeTest
public void init() {
this.jedisPool = new JedisPool("127.0.0.1", 6379);
this.wxRedisOps = new JedisWxRedisOps(jedisPool);
}
@AfterTest
public void destroy() {
this.jedisPool.close();
}
}

View File

@@ -0,0 +1,26 @@
package me.chanjar.weixin.common.redis;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
public class RedisTemplateWxRedisOpsTest extends CommonWxRedisOpsTest {
StringRedisTemplate redisTemplate;
@BeforeTest
public void init() {
JedisConnectionFactory connectionFactory = new JedisConnectionFactory();
connectionFactory.setHostName("127.0.0.1");
connectionFactory.setPort(6379);
connectionFactory.afterPropertiesSet();
StringRedisTemplate redisTemplate = new StringRedisTemplate(connectionFactory);
this.redisTemplate = redisTemplate;
this.wxRedisOps = new RedisTemplateWxRedisOps(this.redisTemplate);
}
@AfterTest
public void destroy() {
}
}

View File

@@ -0,0 +1,27 @@
package me.chanjar.weixin.common.redis;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.redisson.config.TransportMode;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
public class RedissonWxRedisOpsTest extends CommonWxRedisOpsTest {
RedissonClient redissonClient;
@BeforeTest
public void init() {
Config config = new Config();
config.useSingleServer().setAddress("redis://127.0.0.1:6379");
config.setTransportMode(TransportMode.NIO);
this.redissonClient = Redisson.create(config);
this.wxRedisOps = new RedissonWxRedisOps(this.redissonClient);
}
@AfterTest
public void destroy() {
this.redissonClient.shutdown();
}
}