Browse Source

Merge pull request '无 jira 任务 fix: 之前的commit无故丢失,重构内心补上' (#5) from Dylan.Liu/finekit:master into master

Reviewed-on: fanruan/finekit#5
master
richie 4 years ago
parent
commit
eaf185c3ed
  1. 17
      src/main/java/com/fanruan/api/cluster/state/BaseStandAloneStore.java
  2. 20
      src/main/java/com/fanruan/api/cluster/state/FineCollectionsKit.java
  3. 9
      src/main/java/com/fanruan/api/cluster/state/StateServerConfigKit.java
  4. 20
      src/test/java/com/fanruan/api/cluster/state/FineCollectionsKitTest.java
  5. 2
      src/test/java/com/fanruan/api/cluster/state/FineJedisPoolKitTest.java
  6. 4
      src/test/java/com/fanruan/api/cluster/state/RedisConfigKitTest.java
  7. 2
      src/test/java/com/fanruan/api/cluster/state/StandAloneJedisKitTest.java
  8. 17
      src/test/java/com/fanruan/api/cluster/state/StateServerConfigKitTest.java
  9. 38
      src/test/java/com/fanruan/api/cluster/state/StoreTemplateKitTest.java

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

@ -0,0 +1,17 @@
package com.fanruan.api.cluster.state;
import com.fr.store.impl.accessor.api.impl.StandAloneStore;
import com.fr.third.redis.clients.jedis.Jedis;
/**
* 单机<code>Redis API</code>.
*
* @author Dylan.Liu
* @version 10.0
* Created by Dylan.Liu on 2021/1/18
*/
public class BaseStandAloneStore extends StandAloneStore {
public BaseStandAloneStore(Jedis jedis) {
super(jedis);
}
}

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

@ -0,0 +1,20 @@
package com.fanruan.api.cluster.state;
import com.fr.collections.FineCollections;
/**
* @author Dylan.Liu
* @version 10.0
* Created by Dylan.Liu on 2021/1/18
*/
public class FineCollectionsKit {
public FineCollectionsKit() {}
/**
* 销毁集群集合
*/
public static void destroy() {
FineCollections.getInstance().getClient().destroy();
}
}

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

@ -29,6 +29,15 @@ public class StateServerConfigKit {
StateServerConfig.getInstance().setShareMode(isShareMode); StateServerConfig.getInstance().setShareMode(isShareMode);
} }
/**
* 是否是共享仓库
* @return 是否是共享仓库
*/
public static boolean isShareMode() {
return StateServerConfig.getInstance().isShareMode();
}
/** /**
* 设置状态服务器类型 * 设置状态服务器类型
* @param type 状态服务器类型 * @param type 状态服务器类型

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

@ -0,0 +1,20 @@
package com.fanruan.api.cluster.state;
import com.fr.collections.api.FineCollectionClient;
import com.fr.collections.api.FineCollectionClientWrapper;
import org.junit.Test;
/**
* @author Dylan.Liu
* @version 10.0
* Created by Dylan.Liu on 2021/1/19
*/
public class FineCollectionsKitTest {
@Test
public void testGetClient() throws Exception {
// test
FineCollectionsKit.destroy();
}
}

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

@ -19,7 +19,7 @@ import static org.easymock.EasyMock.mock;
public class FineJedisPoolKitTest { public class FineJedisPoolKitTest {
@Test @Test
public void TestSetRealClient() { public void testSetRealClient() {
FineJedisPoolKit.setRealClient(new FineStoreWrapper() { 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 { public class RedisConfigKitTest extends Prepare {
@Test @Test
public void TestGetTableNamePrefix() { public void testGetTableNamePrefix() {
RedisConfig.getInstance().setTableNamePrefix("test_table name_prefix"); RedisConfig.getInstance().setTableNamePrefix("test_table name_prefix");
Assert.assertEquals("test_table name_prefix", RedisConfigKit.getTableNamePrefix()); Assert.assertEquals("test_table name_prefix", RedisConfigKit.getTableNamePrefix());
@ -23,7 +23,7 @@ public class RedisConfigKitTest extends Prepare {
} }
@Test @Test
public void TestGetExpireStateRemoveInterval() { public void testGetExpireStateRemoveInterval() {
RedisConfig.getInstance().setExpireStateRemoveInterval(111); RedisConfig.getInstance().setExpireStateRemoveInterval(111);
Assert.assertEquals(111, RedisConfig.getInstance().getExpireStateRemoveInterval()); 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 { public class StandAloneJedisKitTest {
@Test @Test
public void TestCreateStandAloneJedis() { public void testCreateStandAloneJedis() {
Jedis mockJedis = mock(Jedis.class); Jedis mockJedis = mock(Jedis.class);
expect(mockJedis.type(anyObject(byte[].class))).andReturn("test_echo"); 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 { public class StateServerConfigKitTest extends Prepare {
@Test @Test
public void TestGetType() { public void testGetType() {
StateServerConfig.getInstance().setType("test_type"); StateServerConfig.getInstance().setType("test_type");
Assert.assertEquals("test_type", StateServerConfigKit.getType()); Assert.assertEquals("test_type", StateServerConfigKit.getType());
@ -23,7 +23,7 @@ public class StateServerConfigKitTest extends Prepare {
} }
@Test @Test
public void TestSetShareMode() { public void testSetShareMode() {
StateServerConfigKit.setShareMode(true); StateServerConfigKit.setShareMode(true);
Assert.assertTrue(StateServerConfig.getInstance().isShareMode()); Assert.assertTrue(StateServerConfig.getInstance().isShareMode());
@ -33,7 +33,7 @@ public class StateServerConfigKitTest extends Prepare {
} }
@Test @Test
public void TestSetType() { public void testSetType() {
StateServerConfigKit.setType("test_type3"); StateServerConfigKit.setType("test_type3");
Assert.assertEquals("test_type3", StateServerConfig.getInstance().getType()); Assert.assertEquals("test_type3", StateServerConfig.getInstance().getType());
@ -43,8 +43,17 @@ public class StateServerConfigKitTest extends Prepare {
} }
@Test @Test
public void TestGetConfigClass() { public void testGetConfigClass() {
Assert.assertEquals(StateServerConfigKit.getConfigClass(), StateServerConfig.class); 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());
}
} }

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

@ -0,0 +1,38 @@
package com.fanruan.api.cluster.state;
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 2021/1/19
*/
@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