fix:使用springboot来封装

上级 bd3706d5
...@@ -16,6 +16,11 @@ ...@@ -16,6 +16,11 @@
<artifactId>spring-boot-starter</artifactId> <artifactId>spring-boot-starter</artifactId>
<version>2.0.6.RELEASE</version> <version>2.0.6.RELEASE</version>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
......
...@@ -32,7 +32,7 @@ public class CuratorTest_02_Create { ...@@ -32,7 +32,7 @@ public class CuratorTest_02_Create {
public void testCreate2() throws Exception { public void testCreate2() throws Exception {
//基本创建 //基本创建
//如果创建节点,没有指定数据,则默认将当前客户端的ip作为数据存储 //如果创建节点,没有指定数据,则默认将当前客户端的ip作为数据存储
String path = client.create().forPath("/app5"); String path = client.create().forPath("/app34");
System.out.println(path); System.out.println(path);
} }
} }
\ No newline at end of file
...@@ -3,7 +3,10 @@ package com.kwan.shuyu.crud; ...@@ -3,7 +3,10 @@ package com.kwan.shuyu.crud;
import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.CuratorFramework;
import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.CreateMode;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
/** /**
* 设置节点的类型 * 设置节点的类型
...@@ -12,6 +15,8 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -12,6 +15,8 @@ import org.springframework.beans.factory.annotation.Autowired;
* @version : 2.2.0 * @version : 2.2.0
* @date : 2023/5/15 09:54 * @date : 2023/5/15 09:54
*/ */
@SpringBootTest
@RunWith(SpringRunner.class)
public class CuratorTest_03_Create { public class CuratorTest_03_Create {
@Autowired @Autowired
......
...@@ -2,7 +2,10 @@ package com.kwan.shuyu.crud; ...@@ -2,7 +2,10 @@ package com.kwan.shuyu.crud;
import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.CuratorFramework;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
/** /**
* 创建多级节点 * 创建多级节点
...@@ -11,6 +14,8 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -11,6 +14,8 @@ import org.springframework.beans.factory.annotation.Autowired;
* @version : 2.2.0 * @version : 2.2.0
* @date : 2023/5/15 09:54 * @date : 2023/5/15 09:54
*/ */
@SpringBootTest
@RunWith(SpringRunner.class)
public class CuratorTest_04_Create { public class CuratorTest_04_Create {
@Autowired @Autowired
......
...@@ -2,7 +2,10 @@ package com.kwan.shuyu.crud; ...@@ -2,7 +2,10 @@ package com.kwan.shuyu.crud;
import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.CuratorFramework;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
/** /**
* 查询数据 * 查询数据
...@@ -11,6 +14,8 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -11,6 +14,8 @@ import org.springframework.beans.factory.annotation.Autowired;
* @version : 2.2.0 * @version : 2.2.0
* @date : 2023/5/15 09:54 * @date : 2023/5/15 09:54
*/ */
@SpringBootTest
@RunWith(SpringRunner.class)
public class CuratorTest_05_Get { public class CuratorTest_05_Get {
@Autowired @Autowired
...@@ -25,7 +30,7 @@ public class CuratorTest_05_Get { ...@@ -25,7 +30,7 @@ public class CuratorTest_05_Get {
@Test @Test
public void testGet1() throws Exception { public void testGet1() throws Exception {
//1. 查询数据:get //1. 查询数据:get
byte[] data = client.getData().forPath("/app1"); byte[] data = client.getData().forPath("/app5");
System.out.println(new String(data)); System.out.println(new String(data));
} }
} }
\ No newline at end of file
...@@ -2,7 +2,10 @@ package com.kwan.shuyu.crud; ...@@ -2,7 +2,10 @@ package com.kwan.shuyu.crud;
import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.CuratorFramework;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.List; import java.util.List;
...@@ -13,6 +16,8 @@ import java.util.List; ...@@ -13,6 +16,8 @@ import java.util.List;
* @version : 2.2.0 * @version : 2.2.0
* @date : 2023/5/15 09:54 * @date : 2023/5/15 09:54
*/ */
@SpringBootTest
@RunWith(SpringRunner.class)
public class CuratorTest_06_Get { public class CuratorTest_06_Get {
@Autowired @Autowired
......
...@@ -3,7 +3,10 @@ package com.kwan.shuyu.crud; ...@@ -3,7 +3,10 @@ package com.kwan.shuyu.crud;
import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.CuratorFramework;
import org.apache.zookeeper.data.Stat; import org.apache.zookeeper.data.Stat;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
/** /**
* 查询节点状态信息 * 查询节点状态信息
...@@ -12,6 +15,8 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -12,6 +15,8 @@ import org.springframework.beans.factory.annotation.Autowired;
* @version : 2.2.0 * @version : 2.2.0
* @date : 2023/5/15 09:54 * @date : 2023/5/15 09:54
*/ */
@SpringBootTest
@RunWith(SpringRunner.class)
public class CuratorTest_07_Get { public class CuratorTest_07_Get {
@Autowired @Autowired
......
...@@ -2,7 +2,10 @@ package com.kwan.shuyu.crud; ...@@ -2,7 +2,10 @@ package com.kwan.shuyu.crud;
import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.CuratorFramework;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
/** /**
* 基本修改数据 * 基本修改数据
...@@ -11,6 +14,8 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -11,6 +14,8 @@ import org.springframework.beans.factory.annotation.Autowired;
* @version : 2.2.0 * @version : 2.2.0
* @date : 2023/5/15 09:54 * @date : 2023/5/15 09:54
*/ */
@SpringBootTest
@RunWith(SpringRunner.class)
public class CuratorTest_08_Set { public class CuratorTest_08_Set {
@Autowired @Autowired
......
...@@ -3,7 +3,10 @@ package com.kwan.shuyu.crud; ...@@ -3,7 +3,10 @@ package com.kwan.shuyu.crud;
import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.CuratorFramework;
import org.apache.zookeeper.data.Stat; import org.apache.zookeeper.data.Stat;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
/** /**
* 根据版本修改 * 根据版本修改
...@@ -12,6 +15,8 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -12,6 +15,8 @@ import org.springframework.beans.factory.annotation.Autowired;
* @version : 2.2.0 * @version : 2.2.0
* @date : 2023/5/15 09:54 * @date : 2023/5/15 09:54
*/ */
@SpringBootTest
@RunWith(SpringRunner.class)
public class CuratorTest_09_Set { public class CuratorTest_09_Set {
@Autowired @Autowired
......
...@@ -2,7 +2,10 @@ package com.kwan.shuyu.crud; ...@@ -2,7 +2,10 @@ package com.kwan.shuyu.crud;
import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.CuratorFramework;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
/** /**
* 删除单个节点 * 删除单个节点
...@@ -11,6 +14,8 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -11,6 +14,8 @@ import org.springframework.beans.factory.annotation.Autowired;
* @version : 2.2.0 * @version : 2.2.0
* @date : 2023/5/15 09:54 * @date : 2023/5/15 09:54
*/ */
@SpringBootTest
@RunWith(SpringRunner.class)
public class CuratorTest_10_Delete { public class CuratorTest_10_Delete {
@Autowired @Autowired
......
...@@ -2,7 +2,10 @@ package com.kwan.shuyu.crud; ...@@ -2,7 +2,10 @@ package com.kwan.shuyu.crud;
import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.CuratorFramework;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
/** /**
* 删除带有子节点的节点 * 删除带有子节点的节点
...@@ -11,6 +14,8 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -11,6 +14,8 @@ import org.springframework.beans.factory.annotation.Autowired;
* @version : 2.2.0 * @version : 2.2.0
* @date : 2023/5/15 09:54 * @date : 2023/5/15 09:54
*/ */
@SpringBootTest
@RunWith(SpringRunner.class)
public class CuratorTest_11_Delete { public class CuratorTest_11_Delete {
@Autowired @Autowired
......
...@@ -2,7 +2,10 @@ package com.kwan.shuyu.crud; ...@@ -2,7 +2,10 @@ package com.kwan.shuyu.crud;
import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.CuratorFramework;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
/** /**
* 必须成功的删除:为了防止网络抖动。本质就是重试。 * 必须成功的删除:为了防止网络抖动。本质就是重试。
...@@ -11,6 +14,8 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -11,6 +14,8 @@ import org.springframework.beans.factory.annotation.Autowired;
* @version : 2.2.0 * @version : 2.2.0
* @date : 2023/5/15 09:54 * @date : 2023/5/15 09:54
*/ */
@SpringBootTest
@RunWith(SpringRunner.class)
public class CuratorTest_12_Delete { public class CuratorTest_12_Delete {
@Autowired @Autowired
......
...@@ -4,7 +4,10 @@ import org.apache.curator.framework.CuratorFramework; ...@@ -4,7 +4,10 @@ import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.api.BackgroundCallback; import org.apache.curator.framework.api.BackgroundCallback;
import org.apache.curator.framework.api.CuratorEvent; import org.apache.curator.framework.api.CuratorEvent;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
/** /**
* 删除回调:inBackground * 删除回调:inBackground
...@@ -13,6 +16,8 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -13,6 +16,8 @@ import org.springframework.beans.factory.annotation.Autowired;
* @version : 2.2.0 * @version : 2.2.0
* @date : 2023/5/15 09:54 * @date : 2023/5/15 09:54
*/ */
@SpringBootTest
@RunWith(SpringRunner.class)
public class CuratorTest_13_Delete { public class CuratorTest_13_Delete {
@Autowired @Autowired
......
...@@ -4,7 +4,10 @@ import org.apache.curator.framework.CuratorFramework; ...@@ -4,7 +4,10 @@ import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.recipes.cache.NodeCache; import org.apache.curator.framework.recipes.cache.NodeCache;
import org.apache.curator.framework.recipes.cache.NodeCacheListener; import org.apache.curator.framework.recipes.cache.NodeCacheListener;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
/** /**
* Watcher监听 * Watcher监听
...@@ -13,6 +16,8 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -13,6 +16,8 @@ import org.springframework.beans.factory.annotation.Autowired;
* @version : 2.2.0 * @version : 2.2.0
* @date : 2023/5/15 10:29 * @date : 2023/5/15 10:29
*/ */
@SpringBootTest
@RunWith(SpringRunner.class)
public class Watcher_01_NodeCache { public class Watcher_01_NodeCache {
@Autowired @Autowired
......
...@@ -5,7 +5,10 @@ import org.apache.curator.framework.recipes.cache.PathChildrenCache; ...@@ -5,7 +5,10 @@ import org.apache.curator.framework.recipes.cache.PathChildrenCache;
import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent; import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent;
import org.apache.curator.framework.recipes.cache.PathChildrenCacheListener; import org.apache.curator.framework.recipes.cache.PathChildrenCacheListener;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
/** /**
* Watcher监听 * Watcher监听
...@@ -14,6 +17,8 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -14,6 +17,8 @@ import org.springframework.beans.factory.annotation.Autowired;
* @version : 2.2.0 * @version : 2.2.0
* @date : 2023/5/15 10:29 * @date : 2023/5/15 10:29
*/ */
@SpringBootTest
@RunWith(SpringRunner.class)
public class Watcher_02_PathChildrenCache { public class Watcher_02_PathChildrenCache {
@Autowired @Autowired
......
...@@ -5,7 +5,10 @@ import org.apache.curator.framework.recipes.cache.TreeCache; ...@@ -5,7 +5,10 @@ import org.apache.curator.framework.recipes.cache.TreeCache;
import org.apache.curator.framework.recipes.cache.TreeCacheEvent; import org.apache.curator.framework.recipes.cache.TreeCacheEvent;
import org.apache.curator.framework.recipes.cache.TreeCacheListener; import org.apache.curator.framework.recipes.cache.TreeCacheListener;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
/** /**
* Watcher监听 * Watcher监听
...@@ -14,6 +17,8 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -14,6 +17,8 @@ import org.springframework.beans.factory.annotation.Autowired;
* @version : 2.2.0 * @version : 2.2.0
* @date : 2023/5/15 10:29 * @date : 2023/5/15 10:29
*/ */
@SpringBootTest
@RunWith(SpringRunner.class)
public class Watcher_03_TreeCache { public class Watcher_03_TreeCache {
@Autowired @Autowired
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册