This commit is contained in:
@@ -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"));
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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() {
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user