当前位置: 首页 > wzjs >正文

做地铁建设的公司网站陕西建筑工程网

做地铁建设的公司网站,陕西建筑工程网,徐州做网站的公司招聘,国内一家做国外酒店团购的网站概述 使用curator framework框架去操作zookeeper时,我们知道因其的方法风格是那种流式的编写风格,所以我们在写单元测试的时候要把链接zookeeper的操作给mock掉,那么着实是不太好写单测。不过好在curator framework有一个专门用于测试的模块…

概述

使用curator framework框架去操作zookeeper时,我们知道因其的方法风格是那种流式的编写风格,所以我们在写单元测试的时候要把链接zookeeper的操作给mock掉,那么着实是不太好写单测。不过好在curator framework有一个专门用于测试的模块,可以让我们在单测运行之前就在本地启动一个zookeeper server实例,以便于让单测可以直接连接本地的zookeeper实例创建curator client,便于做单元测试。

实现

引入依赖

            <dependency><groupId>org.apache.curator</groupId><artifactId>curator-framework</artifactId><version>4.3.0</version></dependency><dependency><groupId>org.apache.curator</groupId><artifactId>curator-test</artifactId><version>4.3.0</version><scope>test</scope></dependency><dependency><groupId>org.apache.zookeeper</groupId><artifactId>zookeeper</artifactId><version>3.4.14</version></dependency>

启动zookeeper

    private static TestingServer zkServer;@BeforeClasspublic static void startZkServer() throws Exception {zkServer = new TestingServer(true);zkServer.start();}

创建curator framework client

    private CuratorFramework zkClient;@BeforeAllpublic CuratorFramework createCuratorClient() {zkClient = CuratorFrameworkFactory.builder()//本地启动的zookeeper实例端口,跑单测用.connectString(zkServer.getConnectString()).retryPolicy(new RetryNTimes(5, 1000)).connectionTimeoutMs(40 * 1000).sessionTimeoutMs(5 * 1000).build();zkClient.start();}

单元测试-创建临时节点

    @Testpublic void test_createEphemeral() {String path = "/zk/test";createEphemeral(path);List<String> childrens = getChildren("/zk");Assert.assertEquals(1, childrens.size());}private void createEphemeral(String path) {try {zkClient.create().withMode(CreateMode.EPHEMERAL).forPath(path);} catch (NodeExistsException e) {logger.warn("ZNode " + path + " already exists.", e);throw new IllegalStateException(e.getMessage(), e);} catch (Exception e) {throw new IllegalStateException(e.getMessage(), e);}}private List<String> getChildren(String path) {try {return zkClient.getChildren().forPath(path);} catch (NoNodeException e) {return new ArrayList<>();} catch (Exception e) {throw new IllegalStateException(e.getMessage(), e);}}

单测完毕后关闭zookeeper server

@AfterClass
public static void closeZkServer() throws IOException {zkServer.close();
}


文章转载自:

http://00000000.Lpqgq.cn
http://00000000.Lpqgq.cn
http://00000000.Lpqgq.cn
http://00000000.Lpqgq.cn
http://00000000.Lpqgq.cn
http://00000000.Lpqgq.cn
http://00000000.Lpqgq.cn
http://00000000.Lpqgq.cn
http://00000000.Lpqgq.cn
http://00000000.Lpqgq.cn
http://00000000.Lpqgq.cn
http://00000000.Lpqgq.cn
http://00000000.Lpqgq.cn
http://00000000.Lpqgq.cn
http://00000000.Lpqgq.cn
http://00000000.Lpqgq.cn
http://00000000.Lpqgq.cn
http://00000000.Lpqgq.cn
http://00000000.Lpqgq.cn
http://00000000.Lpqgq.cn
http://00000000.Lpqgq.cn
http://00000000.Lpqgq.cn
http://00000000.Lpqgq.cn
http://00000000.Lpqgq.cn
http://00000000.Lpqgq.cn
http://00000000.Lpqgq.cn
http://00000000.Lpqgq.cn
http://00000000.Lpqgq.cn
http://00000000.Lpqgq.cn
http://00000000.Lpqgq.cn
http://www.dtcms.com/wzjs/619932.html

相关文章:

  • 什么网站可以找人做软件四库一平台查询系统
  • 做怎样的企业网站推广网站的几种方法
  • 新光途网站建设简约好看的网站模板
  • 无锡教育论坛网站建设wordpress 标签云集
  • 房屋中介做网站的wordpress最多支持多少会员
  • 网站太卡怎么优化制作一个收费网站要多少钱
  • 深圳有做网站最近价格如何把自己做的网站分享给别人用
  • 延吉网站开发公司有哪些蓝希菏泽网站建设
  • 苏州网站建设书生商友建设网站招聘
  • 网站做优化的必要性外贸网站设计注意事项
  • 优化科技seo点击排名源码
  • 厦网站建设培训学校空壳网站清理通知
  • 阿里云可以做网站如何做营销活动
  • 快速网站优化服务公众号seo排名优化
  • 网站建设优化服务新闻连云港权威网站优化服务
  • 毅冰做外贸是哪个网站在手机上怎么做微电影网站吗
  • 金阊seo网站优化软件邢台网站优化公司
  • 网站建设肆金手指排名2武昌网站建设哪家便宜
  • wordpress站长统计插件手机上那个网站做农产品推广比较好
  • 网站设计公司合肥vi形象设计企业vi设计公司
  • led网站模板软件开发外包公司哪个好
  • 手机怎么访问wap网站重庆网站制作公司电话
  • 关于医院网站建设的通知企业官方网站的作用
  • 邯郸做seo网站优化跨境电商有哪些平台
  • 陶瓷 网站模板wordpress有中文版没
  • 常州哪些网站公司做的好处自媒体平台有哪些赚钱
  • 有没有做黑市网站大气装饰公司网站源码
  • 网站建设的空间选择网站建设要求
  • 个人怎么做一个网站成都建设局官网
  • 网站建设与优化及覆盖率方案江苏省建设网站