Browse Source

DEC-11271 Redis 哨兵插件不应该直接依赖非接口和非开放抽象类

pull/30/head
Dylan.Liu 5 years ago
parent
commit
b1a1c313ad
  1. 33
      src/main/java/com/fanruan/api/cluster/state/BaseRedisCollectionConfig.java
  2. 23
      src/main/java/com/fanruan/api/cluster/state/BaseRedisCollectionsClient.java
  3. 16
      src/main/java/com/fanruan/api/cluster/state/BaseRedisLock.java
  4. 16
      src/main/java/com/fanruan/api/cluster/state/BaseRedisStore.java
  5. 17
      src/main/java/com/fanruan/api/cluster/state/DetectorConstantsKit.java
  6. 21
      src/main/java/com/fanruan/api/cluster/state/FineJedisPoolKit.java
  7. 29
      src/main/java/com/fanruan/api/cluster/state/RedisConfigKit.java
  8. 26
      src/main/java/com/fanruan/api/cluster/state/StandAloneJedisKit.java
  9. 49
      src/main/java/com/fanruan/api/cluster/state/StateServerConfigKit.java
  10. 4
      src/test/java/com/fanruan/api/ModulePrepare.java
  11. 57
      src/test/java/com/fanruan/api/cluster/state/FineJedisPoolKitTest.java
  12. 34
      src/test/java/com/fanruan/api/cluster/state/RedisConfigKitTest.java
  13. 31
      src/test/java/com/fanruan/api/cluster/state/StandAloneJedisKitTest.java
  14. 50
      src/test/java/com/fanruan/api/cluster/state/StateServerConfigKitTest.java

33
src/main/java/com/fanruan/api/cluster/state/BaseRedisCollectionConfig.java

@ -0,0 +1,33 @@
package com.fanruan.api.cluster.state;
import com.fr.collections.api.Codec;
import com.fr.collections.config.redis.RedisCollectionConfig;
/**
* Redis 集合相关配置
* @author Dylan.Liu
* @version 10.0
* Created by Dylan.Liu on 2019/12/3
*/
public class BaseRedisCollectionConfig extends RedisCollectionConfig {
public BaseRedisCollectionConfig(Codec codec, String host, int port) {
super(codec, host, port);
}
public BaseRedisCollectionConfig(String host, int port, String password) {
super(host, port, password);
}
public BaseRedisCollectionConfig() {
super();
}
public BaseRedisCollectionConfig(String host, int port) {
super(host, port);
}
}

23
src/main/java/com/fanruan/api/cluster/state/BaseRedisCollectionsClient.java

@ -0,0 +1,23 @@
package com.fanruan.api.cluster.state;
import com.fr.collections.cluster.client.RedisCollectionsClient;
import com.fr.collections.config.redis.RedisCollectionConfig;
/**
* 集群集合客户端
* @author Dylan.Liu
* @version 10.0
* Created by Dylan.Liu on 2019/12/3
*/
public class BaseRedisCollectionsClient extends RedisCollectionsClient {
public BaseRedisCollectionsClient() {
super();
}
public BaseRedisCollectionsClient(RedisCollectionConfig config) {
super(config);
}
}

16
src/main/java/com/fanruan/api/cluster/state/BaseRedisLock.java

@ -0,0 +1,16 @@
package com.fanruan.api.cluster.state;
import com.fr.store.impl.redis.RedisLock;
/**
* Redis
* @author Dylan.Liu
* @version 10.0
* Created by Dylan.Liu on 2019/12/3
*/
public class BaseRedisLock extends RedisLock {
public BaseRedisLock() {
super();
}
}

16
src/main/java/com/fanruan/api/cluster/state/BaseRedisStore.java

@ -0,0 +1,16 @@
package com.fanruan.api.cluster.state;
import com.fr.store.RedisStore;
/**
* Redis Store
* @author Dylan.Liu
* @version 10.0
* Created by Dylan.Liu on 2019/12/3
*/
public class BaseRedisStore extends RedisStore {
public BaseRedisStore(String tableNamePrefix, int expireStateRemoveInterval) {
super(tableNamePrefix, expireStateRemoveInterval);
}
}

17
src/main/java/com/fanruan/api/cluster/state/DetectorConstantsKit.java

@ -0,0 +1,17 @@
package com.fanruan.api.cluster.state;
import com.fr.store.detector.utils.DetectorUtils;
/**
* @author Dylan.Liu
* @version 10.0
* Created by Dylan.Liu on 2019/12/3
*/
public class DetectorConstantsKit {
/**
* 状态服务器的前端密码显示
* 如果密码是 DEFAULT_PWD(******) 则从数据库取真实密码
*/
public static final String DEFAULT_PWD = DetectorUtils.DEFAULT_PWD;
}

21
src/main/java/com/fanruan/api/cluster/state/FineJedisPoolKit.java

@ -0,0 +1,21 @@
package com.fanruan.api.cluster.state;
import com.fr.store.impl.redis.accessor.FineJedisPool;
import com.fr.store.impl.redis.accessor.FineJedisWrapper;
/**
* @author Dylan.Liu
* @version 10.0
* Created by Dylan.Liu on 2019/12/3
*/
public class FineJedisPoolKit {
/**
* 设置提供真实资源的 Jedis 包装对象
* @param jedisWrapper Jedis 包装对象
*/
public static void setRealClient(FineJedisWrapper jedisWrapper) {
FineJedisPool.getInstance().setRealClient(jedisWrapper);
}
}

29
src/main/java/com/fanruan/api/cluster/state/RedisConfigKit.java

@ -0,0 +1,29 @@
package com.fanruan.api.cluster.state;
import com.fr.store.impl.redis.RedisConfig;
/**
* @author Dylan.Liu
* @version 10.0
* Created by Dylan.Liu on 2019/12/3
*/
public class RedisConfigKit {
/**
* 获取 Redis 里表名的统一的前缀
* @return Redis 里表名的统一的前缀
*/
public static String getTableNamePrefix() {
return RedisConfig.getInstance().getTableNamePrefix();
}
/**
* 获取 Redis 里过期 key 删除间隔时间
* @return Redis 里过期 key 删除间隔时间
*/
public static int getExpireStateRemoveInterval() {
return RedisConfig.getInstance().getExpireStateRemoveInterval();
}
}

26
src/main/java/com/fanruan/api/cluster/state/StandAloneJedisKit.java

@ -0,0 +1,26 @@
package com.fanruan.api.cluster.state;
import com.fr.store.impl.redis.accessor.FineJedis;
import com.fr.store.impl.redis.accessor.StandAloneJedis;
import com.fr.third.redis.clients.jedis.Jedis;
/**
* @author Dylan.Liu
* @version 10.0
* Created by Dylan.Liu on 2019/12/3
*/
public class StandAloneJedisKit {
/**
* 创建单机版 Jedis Api集合
* @param jedis Jedis 资源
* @return 单机版 Jedis Api集合
*/
public static FineJedis createStandAloneJedis(Jedis jedis) {
if (jedis == null) {
throw new NullPointerException("jedis is null");
}
return new StandAloneJedis(jedis);
}
}

49
src/main/java/com/fanruan/api/cluster/state/StateServerConfigKit.java

@ -0,0 +1,49 @@
package com.fanruan.api.cluster.state;
import com.fr.config.Configuration;
import com.fr.store.StateServerConfig;
/**
* 状态服务器配置
* @author Dylan.Liu
* @version 10.0
* Created by Dylan.Liu on 2019/12/3
*/
public class StateServerConfigKit {
/**
* 获取当前状态服务器类型
* @return 当前状态服务器类型
*/
public static String getType() {
return StateServerConfig.getInstance().getType();
}
/**
* 获取当前是否开启状态服务器
* @param isShareMode 当前是否开启状态服务器
*/
public static void setShareMode(boolean isShareMode) {
StateServerConfig.getInstance().setShareMode(isShareMode);
}
/**
* 设置状态服务器类型
* @param type 状态服务器类型
*/
public static void setType(String type) {
StateServerConfig.getInstance().setType(type);
}
/**
* 获取 StateServerConfig 类对象
* @return StateServerConfig 类对象
*/
public static Class<? extends Configuration> getConfigClass() {
return StateServerConfig.class;
}
}

4
src/test/java/com/fanruan/api/ModulePrepare.java

@ -12,7 +12,7 @@ import com.fr.report.ReportActivator;
import com.fr.report.RestrictionActivator; import com.fr.report.RestrictionActivator;
import com.fr.report.module.ReportBaseActivator; import com.fr.report.module.ReportBaseActivator;
import com.fr.scheduler.SchedulerActivator; import com.fr.scheduler.SchedulerActivator;
import com.fr.store.StateServerActivator; import com.fr.store.StateServiceActivator;
import com.fr.workspace.simple.SimpleWork; import com.fr.workspace.simple.SimpleWork;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
@ -31,7 +31,7 @@ public class ModulePrepare {
new BaseDBActivator(), new BaseDBActivator(),
new ConfigurationActivator(), new ConfigurationActivator(),
new StandaloneModeActivator(), new StandaloneModeActivator(),
new StateServerActivator(), new StateServiceActivator(),
new SchedulerActivator(), new SchedulerActivator(),
new ReportBaseActivator(), new ReportBaseActivator(),
new RestrictionActivator(), new RestrictionActivator(),

57
src/test/java/com/fanruan/api/cluster/state/FineJedisPoolKitTest.java

@ -0,0 +1,57 @@
package com.fanruan.api.cluster.state;
import com.fr.store.impl.redis.accessor.FineJedis;
import com.fr.store.impl.redis.accessor.FineJedisPool;
import com.fr.store.impl.redis.accessor.FineJedisWrapper;
import org.easymock.EasyMock;
import org.junit.Assert;
import org.junit.Test;
import static org.easymock.EasyMock.anyObject;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.mock;
/**
* @author Dylan.Liu
* @version 10.0
* Created by Dylan.Liu on 2019/12/3
*/
public class FineJedisPoolKitTest {
@Test
public void TestSetRealClient() {
FineJedisPoolKit.setRealClient(new FineJedisWrapper() {
@Override
public FineJedis getResource() {
return null;
}
@Override
public void destroy() {
}
});
Assert.assertNull(FineJedisPool.getInstance().getResource());
FineJedis mockFineJedis = mock(FineJedis.class);
expect(mockFineJedis.type(anyObject())).andReturn("TestFineJedis");
EasyMock.replay(mockFineJedis);
FineJedisPoolKit.setRealClient(new FineJedisWrapper() {
@Override
public FineJedis getResource() {
return mockFineJedis;
}
@Override
public void destroy() {
}
});
Assert.assertEquals("TestFineJedis", FineJedisPool.getInstance().getResource().type(new byte[]{}));
}
}

34
src/test/java/com/fanruan/api/cluster/state/RedisConfigKitTest.java

@ -0,0 +1,34 @@
package com.fanruan.api.cluster.state;
import com.fanruan.api.Prepare;
import com.fr.store.impl.redis.RedisConfig;
import org.junit.Assert;
import org.junit.Test;
/**
* @author Dylan.Liu
* @version 10.0
* Created by Dylan.Liu on 2019/12/3
*/
public class RedisConfigKitTest extends Prepare {
@Test
public void TestGetTableNamePrefix() {
RedisConfig.getInstance().setTableNamePrefix("test_table name_prefix");
Assert.assertEquals("test_table name_prefix", RedisConfigKit.getTableNamePrefix());
RedisConfig.getInstance().setTableNamePrefix("test_table name_prefix2");
Assert.assertEquals("test_table name_prefix2", RedisConfigKit.getTableNamePrefix());
}
@Test
public void TestGetExpireStateRemoveInterval() {
RedisConfig.getInstance().setExpireStateRemoveInterval(111);
Assert.assertEquals(111, RedisConfig.getInstance().getExpireStateRemoveInterval());
RedisConfig.getInstance().setExpireStateRemoveInterval(222);
Assert.assertEquals(222, RedisConfig.getInstance().getExpireStateRemoveInterval());
}
}

31
src/test/java/com/fanruan/api/cluster/state/StandAloneJedisKitTest.java

@ -0,0 +1,31 @@
package com.fanruan.api.cluster.state;
import com.fr.store.impl.redis.accessor.FineJedis;
import com.fr.third.redis.clients.jedis.Jedis;
import org.easymock.EasyMock;
import org.junit.Assert;
import org.junit.Test;
import static org.easymock.EasyMock.anyObject;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.mock;
/**
* @author Dylan.Liu
* @version 10.0
* Created by Dylan.Liu on 2019/12/3
*/
public class StandAloneJedisKitTest {
@Test
public void TestCreateStandAloneJedis() {
Jedis mockJedis = mock(Jedis.class);
expect(mockJedis.type(anyObject(byte[].class))).andReturn("test_echo");
EasyMock.replay(mockJedis);
FineJedis standAloneJedis = StandAloneJedisKit.createStandAloneJedis(mockJedis);
Assert.assertEquals("test_echo", standAloneJedis.type(new byte[]{}));
}
}

50
src/test/java/com/fanruan/api/cluster/state/StateServerConfigKitTest.java

@ -0,0 +1,50 @@
package com.fanruan.api.cluster.state;
import com.fanruan.api.Prepare;
import com.fr.store.StateServerConfig;
import org.junit.Assert;
import org.junit.Test;
/**
* @author Dylan.Liu
* @version 10.0
* Created by Dylan.Liu on 2019/12/3
*/
public class StateServerConfigKitTest extends Prepare {
@Test
public void TestGetType() {
StateServerConfig.getInstance().setType("test_type");
Assert.assertEquals("test_type", StateServerConfigKit.getType());
StateServerConfig.getInstance().setType("test_type2");
Assert.assertEquals("test_type2", StateServerConfigKit.getType());
}
@Test
public void TestSetShareMode() {
StateServerConfigKit.setShareMode(true);
Assert.assertTrue(StateServerConfig.getInstance().isShareMode());
StateServerConfigKit.setShareMode(false);
Assert.assertFalse(StateServerConfig.getInstance().isShareMode());
}
@Test
public void TestSetType() {
StateServerConfigKit.setType("test_type3");
Assert.assertEquals("test_type3", StateServerConfig.getInstance().getType());
StateServerConfigKit.setType("test_type4");
Assert.assertEquals("test_type4", StateServerConfig.getInstance().getType());
}
@Test
public void TestGetConfigClass() {
Assert.assertEquals(StateServerConfigKit.getConfigClass(), StateServerConfig.class);
}
}
Loading…
Cancel
Save