Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
黄志磊
committed
Jan 16, 2016
1 parent
d5825b6
commit 12f03fd
Showing
8 changed files
with
305 additions
and
306 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
222 changes: 109 additions & 113 deletions
222
mpush-tools/src/test/java/com/shinemo/mpush/tools/redis/RedisGroupManageTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,113 +1,109 @@ | ||
//package com.shinemo.mpush.tools.redis; | ||
// | ||
//import java.util.Date; | ||
//import java.util.List; | ||
// | ||
//import com.shinemo.mpush.tools.redis.listener.MessageListener; | ||
//import com.shinemo.mpush.tools.zk.ZKPath; | ||
// | ||
//import org.apache.commons.lang3.builder.ToStringBuilder; | ||
//import org.apache.commons.lang3.builder.ToStringStyle; | ||
//import org.junit.Before; | ||
//import org.junit.Test; | ||
// | ||
//import com.shinemo.mpush.tools.MPushUtil; | ||
//import com.shinemo.mpush.tools.redis.manage.RedisManage; | ||
//import com.shinemo.mpush.tools.redis.pubsub.Subscriber; | ||
//import com.shinemo.mpush.tools.spi.ServiceContainer; | ||
//import com.shinemo.mpush.tools.zk.ServerApp; | ||
//import com.shinemo.mpush.tools.zk.manage.ServerManage; | ||
// | ||
//public class RedisGroupManageTest { | ||
// | ||
// ServerApp app = new ServerApp(MPushUtil.getLocalIp(), 3000); | ||
// ServerManage manage = new ServerManage(app, ZKPath.REDIS_SERVER); | ||
// List<RedisGroup> groupList = null; | ||
// | ||
// RedisNode node = new RedisNode("127.0.0.1", 6379, "ShineMoIpo"); | ||
// RedisNode node2 = new RedisNode("127.0.0.1", 6380, "ShineMoIpo"); | ||
// | ||
// RedisRegister redisRegister = ServiceContainer.getInstance(RedisRegister.class); | ||
// | ||
// @Before | ||
// public void init() { | ||
// manage.start(); | ||
// groupList = redisRegister.getGroupList(); | ||
// } | ||
// | ||
// @Test | ||
// public void testGetRedisGroup() { | ||
// for (RedisGroup group : groupList) { | ||
// for (RedisNode node : group.getRedisNodeList()) { | ||
// System.out.println(group + ToStringBuilder.reflectionToString(node, ToStringStyle.MULTI_LINE_STYLE)); | ||
// } | ||
// | ||
// } | ||
// } | ||
// | ||
// @Test | ||
// public void testAdd() { | ||
// User user = RedisManage.get("huang2", User.class); | ||
// if (user == null) { | ||
// user = new User("hi", 10, new Date()); | ||
// RedisManage.set("huang2", user); | ||
// user = RedisManage.get("huang2", User.class); | ||
// } | ||
// System.out.println(ToStringBuilder.reflectionToString(user, ToStringStyle.MULTI_LINE_STYLE)); | ||
// | ||
// User nowUser = RedisUtil.get(node, "huang2", User.class); | ||
// System.out.println("node1:" + ToStringBuilder.reflectionToString(nowUser)); | ||
// | ||
// nowUser = RedisUtil.get(node2, "huang2", User.class); | ||
// System.out.println("node2:" + ToStringBuilder.reflectionToString(nowUser)); | ||
// | ||
// RedisManage.del("huang2"); | ||
// | ||
// nowUser = RedisUtil.get(node2, "huang2", User.class); | ||
// if (nowUser == null) { | ||
// System.out.println("node2 nowUser is null"); | ||
// } else { | ||
// System.out.println("node2:" + ToStringBuilder.reflectionToString(nowUser)); | ||
// } | ||
// | ||
// nowUser = RedisUtil.get(node, "huang2", User.class); | ||
// System.out.println("node:" + ToStringBuilder.reflectionToString(nowUser)); | ||
// | ||
// } | ||
// | ||
// @Test | ||
// public void testPub() { | ||
// for (int i = 0; i < 20; i++) { | ||
// User user = new User("pub" + i, 10, new Date()); | ||
// RedisManage.publish("channel1", user); | ||
// RedisManage.publish("channel2", user); | ||
// } | ||
// } | ||
// | ||
// @Test | ||
// public void testSub() { | ||
// RedisManage.subscribe(new MessageListener() { | ||
// @Override | ||
// public void onMessage(String channel, String message) { | ||
// System.out.printf("on message channel=%s, message=%s%n", channel, message); | ||
// } | ||
// }, "channel1", "channel2"); | ||
// try { | ||
// Thread.sleep(Integer.MAX_VALUE); | ||
// } catch (InterruptedException e) { | ||
// e.printStackTrace(); | ||
// } | ||
// } | ||
// | ||
// @Test | ||
// public void testSub2() { | ||
// RedisManage.subscribe(new Subscriber(), "channel1", "channel2"); | ||
// try { | ||
// Thread.sleep(Integer.MAX_VALUE); | ||
// } catch (InterruptedException e) { | ||
// e.printStackTrace(); | ||
// } | ||
// } | ||
// | ||
// | ||
//} | ||
package com.shinemo.mpush.tools.redis; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
|
||
import com.shinemo.mpush.tools.redis.listener.MessageListener; | ||
|
||
import org.apache.commons.lang3.builder.ToStringBuilder; | ||
import org.apache.commons.lang3.builder.ToStringStyle; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import com.shinemo.mpush.tools.MPushUtil; | ||
import com.shinemo.mpush.tools.redis.manage.RedisManage; | ||
import com.shinemo.mpush.tools.redis.pubsub.Subscriber; | ||
import com.shinemo.mpush.tools.spi.ServiceContainer; | ||
import com.shinemo.mpush.tools.zk.ServerApp; | ||
|
||
public class RedisGroupManageTest { | ||
|
||
ServerApp app = new ServerApp(MPushUtil.getLocalIp(), 3000); | ||
List<RedisGroup> groupList = null; | ||
|
||
RedisNode node = new RedisNode("127.0.0.1", 6379, "ShineMoIpo"); | ||
RedisNode node2 = new RedisNode("127.0.0.1", 6380, "ShineMoIpo"); | ||
|
||
RedisRegister redisRegister = ServiceContainer.getInstance(RedisRegister.class); | ||
|
||
@Before | ||
public void init() { | ||
groupList = redisRegister.getGroupList(); | ||
} | ||
|
||
@Test | ||
public void testGetRedisGroup() { | ||
for (RedisGroup group : groupList) { | ||
for (RedisNode node : group.getRedisNodeList()) { | ||
System.out.println(group + ToStringBuilder.reflectionToString(node, ToStringStyle.MULTI_LINE_STYLE)); | ||
} | ||
|
||
} | ||
} | ||
|
||
@Test | ||
public void testAdd() { | ||
User user = RedisManage.get("huang2", User.class); | ||
if (user == null) { | ||
user = new User("hi", 10, new Date()); | ||
RedisManage.set("huang2", user); | ||
user = RedisManage.get("huang2", User.class); | ||
} | ||
System.out.println(ToStringBuilder.reflectionToString(user, ToStringStyle.MULTI_LINE_STYLE)); | ||
|
||
User nowUser = RedisUtil.get(node, "huang2", User.class); | ||
System.out.println("node1:" + ToStringBuilder.reflectionToString(nowUser)); | ||
|
||
nowUser = RedisUtil.get(node2, "huang2", User.class); | ||
System.out.println("node2:" + ToStringBuilder.reflectionToString(nowUser)); | ||
|
||
RedisManage.del("huang2"); | ||
|
||
nowUser = RedisUtil.get(node2, "huang2", User.class); | ||
if (nowUser == null) { | ||
System.out.println("node2 nowUser is null"); | ||
} else { | ||
System.out.println("node2:" + ToStringBuilder.reflectionToString(nowUser)); | ||
} | ||
|
||
nowUser = RedisUtil.get(node, "huang2", User.class); | ||
System.out.println("node:" + ToStringBuilder.reflectionToString(nowUser)); | ||
|
||
} | ||
|
||
@Test | ||
public void testPub() { | ||
for (int i = 0; i < 20; i++) { | ||
User user = new User("pub" + i, 10, new Date()); | ||
RedisManage.publish("channel1", user); | ||
RedisManage.publish("channel2", user); | ||
} | ||
} | ||
|
||
@Test | ||
public void testSub() { | ||
RedisManage.subscribe(new MessageListener() { | ||
@Override | ||
public void onMessage(String channel, String message) { | ||
System.out.printf("on message channel=%s, message=%s%n", channel, message); | ||
} | ||
}, "channel1", "channel2"); | ||
try { | ||
Thread.sleep(Integer.MAX_VALUE); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
@Test | ||
public void testSub2() { | ||
RedisManage.subscribe(new Subscriber(), "channel1", "channel2"); | ||
try { | ||
Thread.sleep(Integer.MAX_VALUE); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.