Browse Source

Merge pull request 'DEC-15442 feat: 状态服务器适配适配腾讯云redis,插件初始化, finekit适配' (#2) from Dylan.Liu/finekit:master into master

Reviewed-on: fanruan/finekit#2
master
richie 4 years ago
parent
commit
f533f97d8f
  1. 16
      src/main/java/com/fanruan/api/cluster/state/FineCollectionsKit.java
  2. 2
      src/main/java/com/fanruan/api/cluster/state/RedisConfigKit.java
  3. 8
      src/main/java/com/fanruan/api/cluster/state/StateServerConfigKit.java
  4. 15
      src/main/java/com/fanruan/api/cluster/state/StoreTemplateKit.java
  5. 24
      src/test/java/com/fanruan/api/cluster/state/FineCollectionsKitTest.java
  6. 2
      src/test/java/com/fanruan/api/cluster/state/FineJedisPoolKitTest.java
  7. 4
      src/test/java/com/fanruan/api/cluster/state/RedisConfigKitTest.java
  8. 2
      src/test/java/com/fanruan/api/cluster/state/StandAloneJedisKitTest.java
  9. 17
      src/test/java/com/fanruan/api/cluster/state/StateServerConfigKitTest.java
  10. 39
      src/test/java/com/fanruan/api/cluster/state/StoreTemplateKitTest.java

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

@ -0,0 +1,16 @@
package com.fanruan.api.cluster.state;
import com.fr.collections.FineCollections;
import com.fr.collections.api.FineCollectionClient;
/**
* @author Dylan.Liu
* @version 10.0
* Created by Dylan.Liu on 2020/10/16
*/
public class FineCollectionsKit {
public static FineCollectionClient getClient() {
return FineCollections.getInstance().getClient();
}
}

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

@ -14,7 +14,6 @@ public class RedisConfigKit {
* @return Redis 里表名的统一的前缀
*/
public static String getTableNamePrefix() {
return RedisConfig.getInstance().getTableNamePrefix();
}
@ -23,7 +22,6 @@ public class RedisConfigKit {
* @return Redis 里过期 key 删除间隔时间
*/
public static int getExpireStateRemoveInterval() {
return RedisConfig.getInstance().getExpireStateRemoveInterval();
}
}

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

@ -16,7 +16,6 @@ public class StateServerConfigKit {
* @return 当前状态服务器类型
*/
public static String getType() {
return StateServerConfig.getInstance().getType();
}
@ -25,16 +24,18 @@ public class StateServerConfigKit {
* @param isShareMode 当前是否开启状态服务器
*/
public static void setShareMode(boolean isShareMode) {
StateServerConfig.getInstance().setShareMode(isShareMode);
}
public static boolean isShareMode() {
return StateServerConfig.getInstance().isShareMode();
}
/**
* 设置状态服务器类型
* @param type 状态服务器类型
*/
public static void setType(String type) {
StateServerConfig.getInstance().setType(type);
}
@ -43,7 +44,6 @@ public class StateServerConfigKit {
* @return StateServerConfig 类对象
*/
public static Class<? extends Configuration> getConfigClass() {
return StateServerConfig.class;
}
}

15
src/main/java/com/fanruan/api/cluster/state/StoreTemplateKit.java

@ -0,0 +1,15 @@
package com.fanruan.api.cluster.state;
import com.fr.store.impl.StoreTemplate;
/**
* @author Dylan.Liu
* @version 10.0
* Created by Dylan.Liu on 2020/10/16
*/
public class StoreTemplateKit {
public static void close(){
StoreTemplate.getInstance().close();
}
}

24
src/test/java/com/fanruan/api/cluster/state/FineCollectionsKitTest.java

@ -0,0 +1,24 @@
package com.fanruan.api.cluster.state;
import com.fr.collections.api.FineCollectionClient;
import com.fr.collections.api.FineCollectionClientWrapper;
import org.junit.Test;
import static org.easymock.EasyMock.*;
import static org.junit.Assert.*;
/**
* @author Dylan.Liu
* @version 10.0
* Created by Dylan.Liu on 2020/10/23
*/
public class FineCollectionsKitTest {
@Test
public void testGetClient() throws Exception {
// test
FineCollectionClient client = FineCollectionsKit.getClient();
assertTrue(client instanceof FineCollectionClientWrapper);
}
}

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

@ -19,7 +19,7 @@ import static org.easymock.EasyMock.mock;
public class FineJedisPoolKitTest {
@Test
public void TestSetRealClient() {
public void testSetRealClient() {
FineJedisPoolKit.setRealClient(new FineStoreWrapper() {

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

@ -13,7 +13,7 @@ import org.junit.Test;
public class RedisConfigKitTest extends Prepare {
@Test
public void TestGetTableNamePrefix() {
public void testGetTableNamePrefix() {
RedisConfig.getInstance().setTableNamePrefix("test_table name_prefix");
Assert.assertEquals("test_table name_prefix", RedisConfigKit.getTableNamePrefix());
@ -23,7 +23,7 @@ public class RedisConfigKitTest extends Prepare {
}
@Test
public void TestGetExpireStateRemoveInterval() {
public void testGetExpireStateRemoveInterval() {
RedisConfig.getInstance().setExpireStateRemoveInterval(111);
Assert.assertEquals(111, RedisConfig.getInstance().getExpireStateRemoveInterval());

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

@ -18,7 +18,7 @@ import static org.easymock.EasyMock.mock;
public class StandAloneJedisKitTest {
@Test
public void TestCreateStandAloneJedis() {
public void testCreateStandAloneJedis() {
Jedis mockJedis = mock(Jedis.class);
expect(mockJedis.type(anyObject(byte[].class))).andReturn("test_echo");

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

@ -13,7 +13,7 @@ import org.junit.Test;
public class StateServerConfigKitTest extends Prepare {
@Test
public void TestGetType() {
public void testGetType() {
StateServerConfig.getInstance().setType("test_type");
Assert.assertEquals("test_type", StateServerConfigKit.getType());
@ -23,7 +23,7 @@ public class StateServerConfigKitTest extends Prepare {
}
@Test
public void TestSetShareMode() {
public void testSetShareMode() {
StateServerConfigKit.setShareMode(true);
Assert.assertTrue(StateServerConfig.getInstance().isShareMode());
@ -33,7 +33,7 @@ public class StateServerConfigKitTest extends Prepare {
}
@Test
public void TestSetType() {
public void testSetType() {
StateServerConfigKit.setType("test_type3");
Assert.assertEquals("test_type3", StateServerConfig.getInstance().getType());
@ -43,8 +43,17 @@ public class StateServerConfigKitTest extends Prepare {
}
@Test
public void TestGetConfigClass() {
public void testGetConfigClass() {
Assert.assertEquals(StateServerConfigKit.getConfigClass(), StateServerConfig.class);
}
@Test
public void testIsShareMode() {
StateServerConfig.getInstance().setShareMode(false);
Assert.assertFalse(StateServerConfigKit.isShareMode());
StateServerConfig.getInstance().setShareMode(true);
Assert.assertTrue(StateServerConfigKit.isShareMode());
}
}

39
src/test/java/com/fanruan/api/cluster/state/StoreTemplateKitTest.java

@ -0,0 +1,39 @@
package com.fanruan.api.cluster.state;
import com.fr.ftp.client.FineSFTPClient;
import com.fr.store.impl.accessor.FineStorePool;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import static org.easymock.EasyMock.*;
import static org.junit.Assert.*;
/**
* @author Dylan.Liu
* @version 10.0
* Created by Dylan.Liu on 2020/10/23
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({FineStorePool.class})
public class StoreTemplateKitTest {
@Test
public void testClose() throws Exception {
// test
FineStorePool fineStorePool = mock(FineStorePool.class);
fineStorePool.close();
expectLastCall().times(1);
PowerMock.mockStaticPartial(FineStorePool.class, "getPool");
expect(FineStorePool.getPool()).andReturn(fineStorePool).times(1);
PowerMock.replayAll();
StoreTemplateKit.close();
PowerMock.verifyAll();
}
}
Loading…
Cancel
Save