perf[orm]: 简化测试用例

This commit is contained in:
jaysunxiao
2021-07-10 11:39:04 +08:00
parent dedecdbb25
commit 2be46dfce9
32 changed files with 52 additions and 92 deletions
@@ -120,8 +120,7 @@ public class BioServerTest {
Thread clienThread = new Thread(serverChannel);
listClient.add(serverChannel);
clienThread.start();
System.out
.println("server started! Connect to client successfully");
System.out.println("server started! Connect to client successfully");
}
} catch (IOException e) {
@@ -49,7 +49,6 @@ public class EchoServerTest {
EventLoopGroup bossGroup = new NioEventLoopGroup();//服务端接受客户端连接
EventLoopGroup workerGroup = new NioEventLoopGroup();//SocketChannel的网络读写
try {
System.out.println("sdfs");
ServerBootstrap bootstrap = new ServerBootstrap();
bootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
.option(ChannelOption.SO_BACKLOG, 100).handler(new LoggingHandler(LogLevel.INFO))
@@ -59,7 +58,6 @@ public class EchoServerTest {
ChannelFuture future = bootstrap.bind(port).sync();
//等待服务端监听端口关闭
future.channel().closeFuture().sync();
System.out.println("sdfs");
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
@@ -23,7 +23,7 @@ public class EchoClientHandler extends ChannelInboundHandlerAdapter {
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
System.out.println("hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh");
System.out.println(StringUtils.format("received msg [{}]", msg));
}
@Override
@@ -1,29 +0,0 @@
package com.zfoo.net.zookeeper;
/**
* 引子和趣闻:
* Zookeeper名字的由来是比较有趣的,下面的片段摘抄自《从PAXOS到ZOOKEEPER分布式一致性原理与实践》一书:
* Zookeeper最早起源于雅虎的研究院的一个研究小组。在当时,研究人员发现,在雅虎内部很多大型的系统需要依赖一个类似的系统进行分布式协调,
* 但是这些系统往往存在分布式单点问题。所以雅虎的开发人员就试图开发一个通用的无单点问题的分布式协调框架。
* 在立项初期,考虑到很多项目都是用动物的名字来命名的(例如著名的Pig项目),雅虎的工程师希望给这个项目也取一个动物的名字。
* 时任研究院的首席科学家Raghu Ramakrishnan开玩笑说:再这样下去,我们这儿就变成动物园了。
* 此话一出,大家纷纷表示就叫动物园管理员吧——因为各个以动物命名的分布式组件放在一起,雅虎的整个分布式系统看上去就像一个大型的动物园了,
* 而Zookeeper正好用来进行分布式环境的协调——于是,Zookeeper的名字由此诞生了。
* <p>
* Curator无疑是Zookeeper客户端中的瑞士军刀,它译作"馆长"或者''管理者'',不知道是不是开发小组有意而为之,
* 笔者猜测有可能这样命名的原因是说明Curator就是Zookeeper的馆长(脑洞有点大:Curator就是动物园的园长)。
* <p>
* curator-framework:对zookeeper的底层api的一些封装
* curator-client:提供一些客户端的操作,例如重试策略等
* curator-recipes:封装了一些高级特性,如:Cache事件监听、选举、分布式锁、分布式计数器、分布式Barrier等
*
* @author jaysunxiao
* @version 1.0
* @since 2018-04-03 15:29
*/
public abstract class ZookeeperConstantTest {
public static String URL = "localhost:2181";
}
@@ -1,6 +1,5 @@
package com.zfoo.net.zookeeper.base.create;
import com.zfoo.net.zookeeper.ZookeeperConstantTest;
import org.apache.zookeeper.*;
import org.apache.zookeeper.Watcher.Event.EventType;
import org.apache.zookeeper.Watcher.Event.KeeperState;
@@ -20,7 +19,7 @@ public class CreateNodeASyncTest {
// 异步创建一个节点
@Test
public void test() throws IOException, InterruptedException {
ZooKeeper zookeeper = new ZooKeeper(ZookeeperConstantTest.URL, 5000, new CreateNodeASyncWatcher());
ZooKeeper zookeeper = new ZooKeeper("localhost:2181", 5000, new CreateNodeASyncWatcher());
System.out.println(zookeeper.getState());
@@ -1,6 +1,5 @@
package com.zfoo.net.zookeeper.base.create;
import com.zfoo.net.zookeeper.ZookeeperConstantTest;
import org.apache.zookeeper.*;
import org.apache.zookeeper.Watcher.Event.EventType;
import org.apache.zookeeper.Watcher.Event.KeeperState;
@@ -26,7 +25,7 @@ public class CreateNodeSyncAuthTest {
@Test
public void test() throws IOException, InterruptedException {
zookeeper = new ZooKeeper(ZookeeperConstantTest.URL, 5000, new CreateNodeSyncAuthWatcher());
zookeeper = new ZooKeeper("localhost:2181", 5000, new CreateNodeSyncAuthWatcher());
System.out.println(zookeeper.getState());
Thread.sleep(Integer.MAX_VALUE);
}
@@ -1,6 +1,5 @@
package com.zfoo.net.zookeeper.base.create;
import com.zfoo.net.zookeeper.ZookeeperConstantTest;
import org.apache.zookeeper.*;
import org.apache.zookeeper.Watcher.Event.EventType;
import org.apache.zookeeper.Watcher.Event.KeeperState;
@@ -21,7 +20,7 @@ public class CreateNodeSyncTest {
@Test
public void test() throws IOException, InterruptedException, KeeperException {
// 这个创建zookeeper的链接是异步的
ZooKeeper zookeeper = new ZooKeeper(ZookeeperConstantTest.URL, 5000, new CreateNodeSyncWatcher());
ZooKeeper zookeeper = new ZooKeeper("localhost:2181", 5000, new CreateNodeSyncWatcher());
System.out.println(zookeeper.getState());
@@ -1,6 +1,5 @@
package com.zfoo.net.zookeeper.base.delete;
import com.zfoo.net.zookeeper.ZookeeperConstantTest;
import org.apache.zookeeper.AsyncCallback;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
@@ -21,7 +20,7 @@ public class DeleteNodeASyncTest {
@Test
public void test() throws IOException, InterruptedException {
ZooKeeper zooKeeper = new ZooKeeper(ZookeeperConstantTest.URL, 5000, new DeleteNodeASyncWatcher());
ZooKeeper zooKeeper = new ZooKeeper("localhost:2181", 5000, new DeleteNodeASyncWatcher());
System.out.println(zooKeeper.getState().toString());
connectedSemaphore.await();
@@ -1,6 +1,5 @@
package com.zfoo.net.zookeeper.base.delete;
import com.zfoo.net.zookeeper.ZookeeperConstantTest;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
@@ -20,7 +19,7 @@ public class DeleteNodeSyncTest {
@Test
public void test() throws IOException, InterruptedException, KeeperException {
ZooKeeper zooKeeper = new ZooKeeper(ZookeeperConstantTest.URL, 5000, new DeleteNodeSyncWatcher());
ZooKeeper zooKeeper = new ZooKeeper("localhost:2181", 5000, new DeleteNodeSyncWatcher());
System.out.println(zooKeeper.getState().toString());
connectedSemaphore.await();
@@ -1,6 +1,5 @@
package com.zfoo.net.zookeeper.base.query;
import com.zfoo.net.zookeeper.ZookeeperConstantTest;
import org.apache.zookeeper.AsyncCallback;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
@@ -21,7 +20,7 @@ public class GetChildrenASyncTest {
@Test
public void test() throws IOException, InterruptedException {
zooKeeper = new ZooKeeper(ZookeeperConstantTest.URL, 5000, new GetChildrenASyncWatcher());
zooKeeper = new ZooKeeper("localhost:2181", 5000, new GetChildrenASyncWatcher());
System.out.println(zooKeeper.getState().toString());
Thread.sleep(Integer.MAX_VALUE);
}
@@ -1,6 +1,6 @@
package com.zfoo.net.zookeeper.base.query;
import com.zfoo.net.zookeeper.ZookeeperConstantTest;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
@@ -22,7 +22,7 @@ public class GetChildrenSyncTest {
@Test
public void test() throws IOException, InterruptedException, KeeperException {
zk = new ZooKeeper(ZookeeperConstantTest.URL, 5000, new GetChildrenSyncWatcher());
zk = new ZooKeeper("localhost:2181", 5000, new GetChildrenSyncWatcher());
System.out.println(zk.getState().toString());
connectedSemaphore.await();
@@ -1,6 +1,6 @@
package com.zfoo.net.zookeeper.base.query;
import com.zfoo.net.zookeeper.ZookeeperConstantTest;
import org.apache.zookeeper.*;
import org.apache.zookeeper.Watcher.Event.EventType;
import org.apache.zookeeper.Watcher.Event.KeeperState;
@@ -21,7 +21,7 @@ public class GetDataASyncTest {
// ZooKeeper API 获取节点数据内容,使用异步(async)接口。
@Test
public void test() throws IOException, InterruptedException, KeeperException {
zk = new ZooKeeper(ZookeeperConstantTest.URL, 5000, new GetDataASyncWatcher());
zk = new ZooKeeper("localhost:2181", 5000, new GetDataASyncWatcher());
System.out.println(zk.getState().toString());
String path = "/node_test";
@@ -1,6 +1,6 @@
package com.zfoo.net.zookeeper.base.query;
import com.zfoo.net.zookeeper.ZookeeperConstantTest;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
@@ -22,7 +22,7 @@ public class GetDataSyncTest {
@Test
public void test() throws IOException, InterruptedException {
zooKeeper = new ZooKeeper(ZookeeperConstantTest.URL, 5000, new GetDataASyncWatcher());
zooKeeper = new ZooKeeper("localhost:2181", 5000, new GetDataASyncWatcher());
System.out.println(zooKeeper.getState().toString());
Thread.sleep(Integer.MAX_VALUE);
}
@@ -1,6 +1,6 @@
package com.zfoo.net.zookeeper.base.query;
import com.zfoo.net.zookeeper.ZookeeperConstantTest;
import org.apache.zookeeper.AsyncCallback;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
@@ -21,7 +21,7 @@ public class NodeExistsASyncTest {
@Test
public void test() throws IOException, InterruptedException {
zooKeeper = new ZooKeeper(ZookeeperConstantTest.URL, 5000, new NodeExistsASynccWatcher());
zooKeeper = new ZooKeeper("localhost:2181", 5000, new NodeExistsASynccWatcher());
System.out.println(zooKeeper.getState().toString());
Thread.sleep(Integer.MAX_VALUE);
}
@@ -1,6 +1,6 @@
package com.zfoo.net.zookeeper.base.query;
import com.zfoo.net.zookeeper.ZookeeperConstantTest;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.Watcher.Event.EventType;
@@ -19,7 +19,7 @@ public class NodeExistsSyncTest {
@Test
public void test() throws IOException, InterruptedException {
zooKeeper = new ZooKeeper(ZookeeperConstantTest.URL, 5000, new NodeExistsSyncWatcher());
zooKeeper = new ZooKeeper("localhost:2181", 5000, new NodeExistsSyncWatcher());
System.out.println(zooKeeper.getState().toString());
Thread.sleep(Integer.MAX_VALUE);
}
@@ -1,6 +1,6 @@
package com.zfoo.net.zookeeper.base.update;
import com.zfoo.net.zookeeper.ZookeeperConstantTest;
import org.apache.zookeeper.AsyncCallback;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
@@ -21,7 +21,7 @@ public class UpdateNodeASyncTest {
@Test
public void test() throws IOException, InterruptedException {
zooKeeper = new ZooKeeper(ZookeeperConstantTest.URL, 5000, new UpdateNodeASyncWatcher());
zooKeeper = new ZooKeeper("localhost:2181", 5000, new UpdateNodeASyncWatcher());
System.out.println(zooKeeper.getState().toString());
Thread.sleep(Integer.MAX_VALUE);
}
@@ -1,6 +1,6 @@
package com.zfoo.net.zookeeper.base.update;
import com.zfoo.net.zookeeper.ZookeeperConstantTest;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
@@ -20,7 +20,7 @@ public class UpdateNodeSyncTest {
@Test
public void test() throws IOException, InterruptedException {
zooKeeper = new ZooKeeper(ZookeeperConstantTest.URL, 5000, new UpdateNodeSyncWatcher());
zooKeeper = new ZooKeeper("localhost:2181", 5000, new UpdateNodeSyncWatcher());
System.out.println(zooKeeper.getState().toString());
Thread.sleep(Integer.MAX_VALUE);
}
@@ -1,6 +1,6 @@
package com.zfoo.net.zookeeper.curator.cache;
import com.zfoo.net.zookeeper.ZookeeperConstantTest;
import com.zfoo.util.ThreadUtils;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
@@ -20,7 +20,7 @@ import org.junit.Test;
public class PathCacheTest {
private static CuratorFramework curator = CuratorFrameworkFactory.builder()
.connectString(ZookeeperConstantTest.URL)
.connectString("localhost:2181")
.sessionTimeoutMs(5000)
.retryPolicy(new ExponentialBackoffRetry(1000, 3))
// .retryPolicy(new RetryNTimes(1, 1000))
@@ -1,6 +1,6 @@
package com.zfoo.net.zookeeper.curator.cache;
import com.zfoo.net.zookeeper.ZookeeperConstantTest;
import com.zfoo.util.ThreadUtils;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
@@ -21,7 +21,7 @@ import org.junit.Test;
public class TreeCacheTest {
private static CuratorFramework curator = CuratorFrameworkFactory.builder()
.connectString(ZookeeperConstantTest.URL)
.connectString("localhost:2181")
.sessionTimeoutMs(5000)
.retryPolicy(new ExponentialBackoffRetry(1000, 3))
// .retryPolicy(new RetryNTimes(1, 1000))
@@ -1,6 +1,6 @@
package com.zfoo.net.zookeeper.curator.create;
import com.zfoo.net.zookeeper.ZookeeperConstantTest;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.framework.api.BackgroundCallback;
@@ -23,7 +23,7 @@ import java.util.concurrent.Executors;
public class CreateNodeASyncTest {
private static CuratorFramework curator = CuratorFrameworkFactory.builder()
.connectString(ZookeeperConstantTest.URL)
.connectString("localhost:2181")
.sessionTimeoutMs(5000)
.retryPolicy(new ExponentialBackoffRetry(1000, 3))
.build();
@@ -1,6 +1,6 @@
package com.zfoo.net.zookeeper.curator.create;
import com.zfoo.net.zookeeper.ZookeeperConstantTest;
import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
@@ -25,7 +25,7 @@ public class CreateNodeAuthTest {
CuratorFramework curator = CuratorFrameworkFactory
.builder()
.connectString(ZookeeperConstantTest.URL)
.connectString("localhost:2181")
.sessionTimeoutMs(5000)
.connectionTimeoutMs(5000)
.retryPolicy(retryPolicy)
@@ -58,7 +58,7 @@ public class CreateNodeAuthTest {
CuratorFramework curator = CuratorFrameworkFactory
.builder()
.connectString(ZookeeperConstantTest.URL)
.connectString("localhost:2181")
.sessionTimeoutMs(5000)
.authorization("digest", "jaysunxiao:123456".getBytes()) // 授权访问
.connectionTimeoutMs(5000)
@@ -1,6 +1,5 @@
package com.zfoo.net.zookeeper.curator.create;
import com.zfoo.net.zookeeper.ZookeeperConstantTest;
import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
@@ -24,7 +23,7 @@ public class CreateNodeSyncTest {
CuratorFramework client = CuratorFrameworkFactory
.builder()
.connectString(ZookeeperConstantTest.URL)
.connectString("localhost:2181")
.sessionTimeoutMs(5000)
.connectionTimeoutMs(5000)
.retryPolicy(retryPolicy)
@@ -1,6 +1,6 @@
package com.zfoo.net.zookeeper.curator.delete;
import com.zfoo.net.zookeeper.ZookeeperConstantTest;
import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
@@ -17,7 +17,7 @@ public class DeleteNodeTest {
CuratorFramework client = CuratorFrameworkFactory
.builder()
.connectString(ZookeeperConstantTest.URL)
.connectString("localhost:2181")
.sessionTimeoutMs(5000)
.connectionTimeoutMs(5000)
.retryPolicy(retryPolicy)
@@ -1,6 +1,6 @@
package com.zfoo.net.zookeeper.curator.query;
import com.zfoo.net.zookeeper.ZookeeperConstantTest;
import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
@@ -19,7 +19,7 @@ public class GetChildrenTest {
CuratorFramework client = CuratorFrameworkFactory
.builder()
.connectString(ZookeeperConstantTest.URL)
.connectString("localhost:2181")
.sessionTimeoutMs(5000)
.connectionTimeoutMs(5000)
.retryPolicy(retryPolicy)
@@ -1,6 +1,6 @@
package com.zfoo.net.zookeeper.curator.query;
import com.zfoo.net.zookeeper.ZookeeperConstantTest;
import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
@@ -18,7 +18,7 @@ public class GetDataTest {
CuratorFramework client = CuratorFrameworkFactory
.builder()
.connectString(ZookeeperConstantTest.URL)
.connectString("localhost:2181")
.sessionTimeoutMs(5000)
.connectionTimeoutMs(5000)
.retryPolicy(retryPolicy)
@@ -1,6 +1,6 @@
package com.zfoo.net.zookeeper.curator.query;
import com.zfoo.net.zookeeper.ZookeeperConstantTest;
import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
@@ -25,7 +25,7 @@ public class NodeExistsTest {
CuratorFramework client = CuratorFrameworkFactory
.builder()
.connectString(ZookeeperConstantTest.URL)
.connectString("localhost:2181")
.sessionTimeoutMs(5000)
.connectionTimeoutMs(5000)
.retryPolicy(retryPolicy)
@@ -53,7 +53,7 @@ public class NodeExistsTest {
CuratorFramework client = CuratorFrameworkFactory
.builder()
.connectString(ZookeeperConstantTest.URL)
.connectString("localhost:2181")
.sessionTimeoutMs(5000)
.connectionTimeoutMs(5000)
.retryPolicy(retryPolicy)
@@ -1,6 +1,5 @@
package com.zfoo.net.zookeeper.curator.update;
import com.zfoo.net.zookeeper.ZookeeperConstantTest;
import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
@@ -18,7 +17,7 @@ public class UpdateDataTest {
CuratorFramework client = CuratorFrameworkFactory
.builder()
.connectString(ZookeeperConstantTest.URL)
.connectString("localhost:2181")
.sessionTimeoutMs(5000)
.connectionTimeoutMs(5000)
.retryPolicy(retryPolicy)
@@ -1,6 +1,6 @@
package com.zfoo.net.zookeeper.recipes.atomicint;
import com.zfoo.net.zookeeper.ZookeeperConstantTest;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.framework.recipes.atomic.AtomicValue;
@@ -24,7 +24,7 @@ public class DistributedAtomicIntTest {
static String distatomicint_path = "/node_test";
static CuratorFramework curator = CuratorFrameworkFactory
.builder()
.connectString(ZookeeperConstantTest.URL)
.connectString("localhost:2181")
.retryPolicy(new ExponentialBackoffRetry(1000, 3))
.build();
@@ -1,6 +1,6 @@
package com.zfoo.net.zookeeper.recipes.distributedbarrier;
import com.zfoo.net.zookeeper.ZookeeperConstantTest;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.framework.recipes.barriers.DistributedBarrier;
@@ -30,7 +30,7 @@ public class DistributedBarrierTest {
CuratorFramework client = CuratorFrameworkFactory
.builder()
.connectString(ZookeeperConstantTest.URL)
.connectString("localhost:2181")
.retryPolicy(new ExponentialBackoffRetry(1000, 3))
.build();
client.start();
@@ -1,6 +1,6 @@
package com.zfoo.net.zookeeper.recipes.distributedlock;
import com.zfoo.net.zookeeper.ZookeeperConstantTest;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.framework.recipes.locks.InterProcessMutex;
@@ -25,7 +25,7 @@ public class DistributedLockTest {
static String lock_path = "/node";
static CuratorFramework curator = CuratorFrameworkFactory
.builder()
.connectString(ZookeeperConstantTest.URL)
.connectString("localhost:2181")
.retryPolicy(new ExponentialBackoffRetry(1000, 3))
.build();
@@ -1,6 +1,6 @@
package com.zfoo.net.zookeeper.recipes.nodecache;
import com.zfoo.net.zookeeper.ZookeeperConstantTest;
import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
@@ -20,7 +20,7 @@ public class NodeChildrenListenerTest {
CuratorFramework client = CuratorFrameworkFactory
.builder()
.connectString(ZookeeperConstantTest.URL)
.connectString("localhost:2181")
.sessionTimeoutMs(5000)
.connectionTimeoutMs(5000)
.retryPolicy(retryPolicy)
@@ -1,6 +1,6 @@
package com.zfoo.net.zookeeper.recipes.nodecache;
import com.zfoo.net.zookeeper.ZookeeperConstantTest;
import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
@@ -27,7 +27,7 @@ public class NodeListenerTest {
CuratorFramework curator = CuratorFrameworkFactory
.builder()
.connectString(ZookeeperConstantTest.URL)
.connectString("localhost:2181")
.sessionTimeoutMs(5000)
.connectionTimeoutMs(5000)
.retryPolicy(retryPolicy)