From feb435fdb2fcf022b8f8db10da4e3d8176bb925a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=A6=E8=8B=B1=E6=9D=B0?= <327782001@qq.com> Date: Mon, 15 May 2023 11:25:19 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BD=BF=E7=94=A8springboot=E6=9D=A5?= =?UTF-8?q?=E5=B0=81=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 5 +++++ .../java/com/kwan/shuyu/crud/CuratorTest_02_Create.java | 2 +- .../java/com/kwan/shuyu/crud/CuratorTest_03_Create.java | 5 +++++ .../java/com/kwan/shuyu/crud/CuratorTest_04_Create.java | 5 +++++ src/test/java/com/kwan/shuyu/crud/CuratorTest_05_Get.java | 7 ++++++- src/test/java/com/kwan/shuyu/crud/CuratorTest_06_Get.java | 5 +++++ src/test/java/com/kwan/shuyu/crud/CuratorTest_07_Get.java | 5 +++++ src/test/java/com/kwan/shuyu/crud/CuratorTest_08_Set.java | 5 +++++ src/test/java/com/kwan/shuyu/crud/CuratorTest_09_Set.java | 5 +++++ .../java/com/kwan/shuyu/crud/CuratorTest_10_Delete.java | 5 +++++ .../java/com/kwan/shuyu/crud/CuratorTest_11_Delete.java | 5 +++++ .../java/com/kwan/shuyu/crud/CuratorTest_12_Delete.java | 5 +++++ .../java/com/kwan/shuyu/crud/CuratorTest_13_Delete.java | 5 +++++ .../java/com/kwan/shuyu/watch/Watcher_01_NodeCache.java | 5 +++++ .../com/kwan/shuyu/watch/Watcher_02_PathChildrenCache.java | 5 +++++ .../java/com/kwan/shuyu/watch/Watcher_03_TreeCache.java | 5 +++++ 16 files changed, 77 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index e6a7ffc..724aa9c 100644 --- a/pom.xml +++ b/pom.xml @@ -16,6 +16,11 @@ spring-boot-starter 2.0.6.RELEASE + + org.springframework.boot + spring-boot-starter-web + 2.0.1.RELEASE + org.springframework.boot spring-boot-starter-test diff --git a/src/test/java/com/kwan/shuyu/crud/CuratorTest_02_Create.java b/src/test/java/com/kwan/shuyu/crud/CuratorTest_02_Create.java index 9c37155..72efed4 100644 --- a/src/test/java/com/kwan/shuyu/crud/CuratorTest_02_Create.java +++ b/src/test/java/com/kwan/shuyu/crud/CuratorTest_02_Create.java @@ -32,7 +32,7 @@ public class CuratorTest_02_Create { public void testCreate2() throws Exception { //基本创建 //如果创建节点,没有指定数据,则默认将当前客户端的ip作为数据存储 - String path = client.create().forPath("/app5"); + String path = client.create().forPath("/app34"); System.out.println(path); } } \ No newline at end of file diff --git a/src/test/java/com/kwan/shuyu/crud/CuratorTest_03_Create.java b/src/test/java/com/kwan/shuyu/crud/CuratorTest_03_Create.java index cce4272..8a7e8f4 100644 --- a/src/test/java/com/kwan/shuyu/crud/CuratorTest_03_Create.java +++ b/src/test/java/com/kwan/shuyu/crud/CuratorTest_03_Create.java @@ -3,7 +3,10 @@ package com.kwan.shuyu.crud; import org.apache.curator.framework.CuratorFramework; import org.apache.zookeeper.CreateMode; import org.junit.Test; +import org.junit.runner.RunWith; 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; * @version : 2.2.0 * @date : 2023/5/15 09:54 */ +@SpringBootTest +@RunWith(SpringRunner.class) public class CuratorTest_03_Create { @Autowired diff --git a/src/test/java/com/kwan/shuyu/crud/CuratorTest_04_Create.java b/src/test/java/com/kwan/shuyu/crud/CuratorTest_04_Create.java index 5908e9e..f7e40cc 100644 --- a/src/test/java/com/kwan/shuyu/crud/CuratorTest_04_Create.java +++ b/src/test/java/com/kwan/shuyu/crud/CuratorTest_04_Create.java @@ -2,7 +2,10 @@ package com.kwan.shuyu.crud; import org.apache.curator.framework.CuratorFramework; import org.junit.Test; +import org.junit.runner.RunWith; 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; * @version : 2.2.0 * @date : 2023/5/15 09:54 */ +@SpringBootTest +@RunWith(SpringRunner.class) public class CuratorTest_04_Create { @Autowired diff --git a/src/test/java/com/kwan/shuyu/crud/CuratorTest_05_Get.java b/src/test/java/com/kwan/shuyu/crud/CuratorTest_05_Get.java index 82019c2..71bbcc4 100644 --- a/src/test/java/com/kwan/shuyu/crud/CuratorTest_05_Get.java +++ b/src/test/java/com/kwan/shuyu/crud/CuratorTest_05_Get.java @@ -2,7 +2,10 @@ package com.kwan.shuyu.crud; import org.apache.curator.framework.CuratorFramework; import org.junit.Test; +import org.junit.runner.RunWith; 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; * @version : 2.2.0 * @date : 2023/5/15 09:54 */ +@SpringBootTest +@RunWith(SpringRunner.class) public class CuratorTest_05_Get { @Autowired @@ -25,7 +30,7 @@ public class CuratorTest_05_Get { @Test public void testGet1() throws Exception { //1. 查询数据:get - byte[] data = client.getData().forPath("/app1"); + byte[] data = client.getData().forPath("/app5"); System.out.println(new String(data)); } } \ No newline at end of file diff --git a/src/test/java/com/kwan/shuyu/crud/CuratorTest_06_Get.java b/src/test/java/com/kwan/shuyu/crud/CuratorTest_06_Get.java index dc75673..77fbbf0 100644 --- a/src/test/java/com/kwan/shuyu/crud/CuratorTest_06_Get.java +++ b/src/test/java/com/kwan/shuyu/crud/CuratorTest_06_Get.java @@ -2,7 +2,10 @@ package com.kwan.shuyu.crud; import org.apache.curator.framework.CuratorFramework; import org.junit.Test; +import org.junit.runner.RunWith; 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; @@ -13,6 +16,8 @@ import java.util.List; * @version : 2.2.0 * @date : 2023/5/15 09:54 */ +@SpringBootTest +@RunWith(SpringRunner.class) public class CuratorTest_06_Get { @Autowired diff --git a/src/test/java/com/kwan/shuyu/crud/CuratorTest_07_Get.java b/src/test/java/com/kwan/shuyu/crud/CuratorTest_07_Get.java index 5d2b444..a7f2149 100644 --- a/src/test/java/com/kwan/shuyu/crud/CuratorTest_07_Get.java +++ b/src/test/java/com/kwan/shuyu/crud/CuratorTest_07_Get.java @@ -3,7 +3,10 @@ package com.kwan.shuyu.crud; import org.apache.curator.framework.CuratorFramework; import org.apache.zookeeper.data.Stat; import org.junit.Test; +import org.junit.runner.RunWith; 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; * @version : 2.2.0 * @date : 2023/5/15 09:54 */ +@SpringBootTest +@RunWith(SpringRunner.class) public class CuratorTest_07_Get { @Autowired diff --git a/src/test/java/com/kwan/shuyu/crud/CuratorTest_08_Set.java b/src/test/java/com/kwan/shuyu/crud/CuratorTest_08_Set.java index 278301b..f27651a 100644 --- a/src/test/java/com/kwan/shuyu/crud/CuratorTest_08_Set.java +++ b/src/test/java/com/kwan/shuyu/crud/CuratorTest_08_Set.java @@ -2,7 +2,10 @@ package com.kwan.shuyu.crud; import org.apache.curator.framework.CuratorFramework; import org.junit.Test; +import org.junit.runner.RunWith; 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; * @version : 2.2.0 * @date : 2023/5/15 09:54 */ +@SpringBootTest +@RunWith(SpringRunner.class) public class CuratorTest_08_Set { @Autowired diff --git a/src/test/java/com/kwan/shuyu/crud/CuratorTest_09_Set.java b/src/test/java/com/kwan/shuyu/crud/CuratorTest_09_Set.java index a004975..db777bd 100644 --- a/src/test/java/com/kwan/shuyu/crud/CuratorTest_09_Set.java +++ b/src/test/java/com/kwan/shuyu/crud/CuratorTest_09_Set.java @@ -3,7 +3,10 @@ package com.kwan.shuyu.crud; import org.apache.curator.framework.CuratorFramework; import org.apache.zookeeper.data.Stat; import org.junit.Test; +import org.junit.runner.RunWith; 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; * @version : 2.2.0 * @date : 2023/5/15 09:54 */ +@SpringBootTest +@RunWith(SpringRunner.class) public class CuratorTest_09_Set { @Autowired diff --git a/src/test/java/com/kwan/shuyu/crud/CuratorTest_10_Delete.java b/src/test/java/com/kwan/shuyu/crud/CuratorTest_10_Delete.java index 15ae895..6db6692 100644 --- a/src/test/java/com/kwan/shuyu/crud/CuratorTest_10_Delete.java +++ b/src/test/java/com/kwan/shuyu/crud/CuratorTest_10_Delete.java @@ -2,7 +2,10 @@ package com.kwan.shuyu.crud; import org.apache.curator.framework.CuratorFramework; import org.junit.Test; +import org.junit.runner.RunWith; 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; * @version : 2.2.0 * @date : 2023/5/15 09:54 */ +@SpringBootTest +@RunWith(SpringRunner.class) public class CuratorTest_10_Delete { @Autowired diff --git a/src/test/java/com/kwan/shuyu/crud/CuratorTest_11_Delete.java b/src/test/java/com/kwan/shuyu/crud/CuratorTest_11_Delete.java index 44693ea..1e7d6d3 100644 --- a/src/test/java/com/kwan/shuyu/crud/CuratorTest_11_Delete.java +++ b/src/test/java/com/kwan/shuyu/crud/CuratorTest_11_Delete.java @@ -2,7 +2,10 @@ package com.kwan.shuyu.crud; import org.apache.curator.framework.CuratorFramework; import org.junit.Test; +import org.junit.runner.RunWith; 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; * @version : 2.2.0 * @date : 2023/5/15 09:54 */ +@SpringBootTest +@RunWith(SpringRunner.class) public class CuratorTest_11_Delete { @Autowired diff --git a/src/test/java/com/kwan/shuyu/crud/CuratorTest_12_Delete.java b/src/test/java/com/kwan/shuyu/crud/CuratorTest_12_Delete.java index ad063b2..cf541e8 100644 --- a/src/test/java/com/kwan/shuyu/crud/CuratorTest_12_Delete.java +++ b/src/test/java/com/kwan/shuyu/crud/CuratorTest_12_Delete.java @@ -2,7 +2,10 @@ package com.kwan.shuyu.crud; import org.apache.curator.framework.CuratorFramework; import org.junit.Test; +import org.junit.runner.RunWith; 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; * @version : 2.2.0 * @date : 2023/5/15 09:54 */ +@SpringBootTest +@RunWith(SpringRunner.class) public class CuratorTest_12_Delete { @Autowired diff --git a/src/test/java/com/kwan/shuyu/crud/CuratorTest_13_Delete.java b/src/test/java/com/kwan/shuyu/crud/CuratorTest_13_Delete.java index 85aaf1a..7f74b93 100644 --- a/src/test/java/com/kwan/shuyu/crud/CuratorTest_13_Delete.java +++ b/src/test/java/com/kwan/shuyu/crud/CuratorTest_13_Delete.java @@ -4,7 +4,10 @@ import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.api.BackgroundCallback; import org.apache.curator.framework.api.CuratorEvent; import org.junit.Test; +import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; /** * 删除回调:inBackground @@ -13,6 +16,8 @@ import org.springframework.beans.factory.annotation.Autowired; * @version : 2.2.0 * @date : 2023/5/15 09:54 */ +@SpringBootTest +@RunWith(SpringRunner.class) public class CuratorTest_13_Delete { @Autowired diff --git a/src/test/java/com/kwan/shuyu/watch/Watcher_01_NodeCache.java b/src/test/java/com/kwan/shuyu/watch/Watcher_01_NodeCache.java index 357f997..e8fbd50 100644 --- a/src/test/java/com/kwan/shuyu/watch/Watcher_01_NodeCache.java +++ b/src/test/java/com/kwan/shuyu/watch/Watcher_01_NodeCache.java @@ -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.NodeCacheListener; import org.junit.Test; +import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; /** * Watcher监听 @@ -13,6 +16,8 @@ import org.springframework.beans.factory.annotation.Autowired; * @version : 2.2.0 * @date : 2023/5/15 10:29 */ +@SpringBootTest +@RunWith(SpringRunner.class) public class Watcher_01_NodeCache { @Autowired diff --git a/src/test/java/com/kwan/shuyu/watch/Watcher_02_PathChildrenCache.java b/src/test/java/com/kwan/shuyu/watch/Watcher_02_PathChildrenCache.java index 276b071..f8ccd9a 100644 --- a/src/test/java/com/kwan/shuyu/watch/Watcher_02_PathChildrenCache.java +++ b/src/test/java/com/kwan/shuyu/watch/Watcher_02_PathChildrenCache.java @@ -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.PathChildrenCacheListener; import org.junit.Test; +import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; /** * Watcher监听 @@ -14,6 +17,8 @@ import org.springframework.beans.factory.annotation.Autowired; * @version : 2.2.0 * @date : 2023/5/15 10:29 */ +@SpringBootTest +@RunWith(SpringRunner.class) public class Watcher_02_PathChildrenCache { @Autowired diff --git a/src/test/java/com/kwan/shuyu/watch/Watcher_03_TreeCache.java b/src/test/java/com/kwan/shuyu/watch/Watcher_03_TreeCache.java index 573b213..cfce9b2 100644 --- a/src/test/java/com/kwan/shuyu/watch/Watcher_03_TreeCache.java +++ b/src/test/java/com/kwan/shuyu/watch/Watcher_03_TreeCache.java @@ -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.TreeCacheListener; import org.junit.Test; +import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; /** * Watcher监听 @@ -14,6 +17,8 @@ import org.springframework.beans.factory.annotation.Autowired; * @version : 2.2.0 * @date : 2023/5/15 10:29 */ +@SpringBootTest +@RunWith(SpringRunner.class) public class Watcher_03_TreeCache { @Autowired -- GitLab