From 15ff359b5be236eeb191c1cd0ee30804036a2958 Mon Sep 17 00:00:00 2001 From: spencergibb Date: Thu, 24 Sep 2020 11:02:52 -0400 Subject: [PATCH] Updates to use new ZookeeperTestingServer --- ...nfigDataCustomizationIntegrationTests.java | 17 +++---------- .../ZookeeperConfigDataIntegrationTests.java | 12 ++++----- ...ookeeperConfigServerBootstrapperTests.java | 25 ++++--------------- 3 files changed, 14 insertions(+), 40 deletions(-) diff --git a/spring-cloud-zookeeper-config/src/test/java/org/springframework/cloud/zookeeper/config/ZookeeperConfigDataCustomizationIntegrationTests.java b/spring-cloud-zookeeper-config/src/test/java/org/springframework/cloud/zookeeper/config/ZookeeperConfigDataCustomizationIntegrationTests.java index 0db8cbb9..02708396 100644 --- a/spring-cloud-zookeeper-config/src/test/java/org/springframework/cloud/zookeeper/config/ZookeeperConfigDataCustomizationIntegrationTests.java +++ b/spring-cloud-zookeeper-config/src/test/java/org/springframework/cloud/zookeeper/config/ZookeeperConfigDataCustomizationIntegrationTests.java @@ -23,7 +23,6 @@ import org.apache.commons.logging.LogFactory; import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.CuratorFrameworkFactory; import org.apache.curator.framework.imps.CuratorFrameworkImpl; -import org.apache.curator.test.TestingServer; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -34,10 +33,10 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.cloud.zookeeper.CuratorFactory; import org.springframework.cloud.zookeeper.ZookeeperProperties; +import org.springframework.cloud.zookeeper.test.ZookeeperTestingServer; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Configuration; import org.springframework.util.ReflectionUtils; -import org.springframework.util.SocketUtils; import static org.assertj.core.api.Assertions.assertThat; @@ -55,18 +54,13 @@ public class ZookeeperConfigDataCustomizationIntegrationTests { private ConfigurableApplicationContext context; - private TestingServer testingServer; - @Before - public void setup() throws Exception { - int port = SocketUtils.findAvailableTcpPort(); - this.testingServer = new TestingServer(port); - String connectString = "localhost:" + port; - + public void setup() { this.context = new SpringApplicationBuilder(Config.class) + .listeners(new ZookeeperTestingServer()) .web(WebApplicationType.NONE) .addBootstrapper(ZookeeperBootstrapper.fromBootstrapContext(this::curatorFramework)) - .run("--spring.config.import=zookeeper:" + connectString, + .run("--spring.config.import=zookeeper:", "--spring.application.name=testZkConfigDataIntegration", "--logging.level.org.springframework.cloud.zookeeper=DEBUG", "--spring.cloud.zookeeper.config.root=" + ROOT); @@ -77,9 +71,6 @@ public class ZookeeperConfigDataCustomizationIntegrationTests { if (context != null) { this.context.close(); } - if (testingServer != null) { - this.testingServer.close(); - } } CuratorFramework curatorFramework(BootstrapContext context) { diff --git a/spring-cloud-zookeeper-config/src/test/java/org/springframework/cloud/zookeeper/config/ZookeeperConfigDataIntegrationTests.java b/spring-cloud-zookeeper-config/src/test/java/org/springframework/cloud/zookeeper/config/ZookeeperConfigDataIntegrationTests.java index 0b0c3473..212f7a08 100644 --- a/spring-cloud-zookeeper-config/src/test/java/org/springframework/cloud/zookeeper/config/ZookeeperConfigDataIntegrationTests.java +++ b/spring-cloud-zookeeper-config/src/test/java/org/springframework/cloud/zookeeper/config/ZookeeperConfigDataIntegrationTests.java @@ -26,7 +26,6 @@ import org.apache.commons.logging.LogFactory; import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.CuratorFrameworkFactory; import org.apache.curator.retry.RetryOneTime; -import org.apache.curator.test.TestingServer; import org.apache.zookeeper.KeeperException; import org.junit.After; import org.junit.Before; @@ -39,12 +38,12 @@ import org.springframework.cloud.context.environment.EnvironmentChangeEvent; import org.springframework.cloud.context.refresh.ConfigDataContextRefresher; import org.springframework.cloud.context.refresh.ContextRefresher; import org.springframework.cloud.context.scope.refresh.RefreshScope; +import org.springframework.cloud.zookeeper.test.ZookeeperTestingServer; import org.springframework.context.ApplicationListener; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.ConfigurableEnvironment; -import org.springframework.util.SocketUtils; import static org.assertj.core.api.Assertions.assertThat; @@ -88,15 +87,14 @@ public class ZookeeperConfigDataIntegrationTests { private ConfigurableApplicationContext context; - private TestingServer testingServer; - private CuratorFramework curator; + private ZookeeperTestingServer testingServer; @Before public void setup() throws Exception { - int port = SocketUtils.findAvailableTcpPort(); - this.testingServer = new TestingServer(port); - String connectString = "localhost:" + port; + testingServer = new ZookeeperTestingServer(); + testingServer.start(); + String connectString = "localhost:" + testingServer.getPort(); this.curator = CuratorFrameworkFactory.builder() .retryPolicy(new RetryOneTime(500)).connectString(connectString).build(); this.curator.start(); diff --git a/spring-cloud-zookeeper-discovery/src/test/java/org/springframework/cloud/zookeeper/discovery/configclient/ZookeeperConfigServerBootstrapperTests.java b/spring-cloud-zookeeper-discovery/src/test/java/org/springframework/cloud/zookeeper/discovery/configclient/ZookeeperConfigServerBootstrapperTests.java index c384a5db..7c8cdc8e 100644 --- a/spring-cloud-zookeeper-discovery/src/test/java/org/springframework/cloud/zookeeper/discovery/configclient/ZookeeperConfigServerBootstrapperTests.java +++ b/spring-cloud-zookeeper-discovery/src/test/java/org/springframework/cloud/zookeeper/discovery/configclient/ZookeeperConfigServerBootstrapperTests.java @@ -18,9 +18,7 @@ package org.springframework.cloud.zookeeper.discovery.configclient; import java.util.concurrent.atomic.AtomicReference; -import org.apache.curator.test.TestingServer; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.boot.SpringBootConfiguration; @@ -28,40 +26,27 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.cloud.config.client.ConfigServerInstanceProvider; import org.springframework.cloud.zookeeper.discovery.ZookeeperDiscoveryClient; +import org.springframework.cloud.zookeeper.test.ZookeeperTestingServer; import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.util.SocketUtils; import static org.assertj.core.api.Assertions.assertThat; public class ZookeeperConfigServerBootstrapperTests { - private TestingServer testingServer; - private ConfigurableApplicationContext context; - private int port; - - @BeforeEach - public void init() throws Exception { - port = SocketUtils.findAvailableTcpPort(); - testingServer = new TestingServer(port); - } - @AfterEach - public void after() throws Exception { + public void after() { if (context != null) { context.close(); } - if (testingServer != null) { - testingServer.close(); - } } @Test public void notEnabledDoesNotAddInstanceProviderFn() { new SpringApplicationBuilder(TestConfig.class) - .properties("--server.port=0", "spring.cloud.service-registry.auto-registration.enabled=false", - "spring.cloud.zookeeper.connect-string=localhost:" + port) + .listeners(new ZookeeperTestingServer()) + .properties("--server.port=0", "spring.cloud.service-registry.auto-registration.enabled=false") .addBootstrapper(registry -> registry.addCloseListener(event -> { ConfigServerInstanceProvider.Function providerFn = event.getBootstrapContext() .get(ConfigServerInstanceProvider.Function.class); @@ -74,8 +59,8 @@ public class ZookeeperConfigServerBootstrapperTests { public void enabledAddsInstanceProviderFn() { AtomicReference bootstrapDiscoveryClient = new AtomicReference<>(); context = new SpringApplicationBuilder(TestConfig.class) + .listeners(new ZookeeperTestingServer()) .properties("--server.port=0", "spring.cloud.config.discovery.enabled=true", - "spring.cloud.zookeeper.connect-string=localhost:" + port, "spring.cloud.service-registry.auto-registration.enabled=false") .addBootstrapper(registry -> registry.addCloseListener(event -> { ConfigServerInstanceProvider.Function providerFn = event.getBootstrapContext()