Updates to use new ZookeeperTestingServer

This commit is contained in:
spencergibb
2020-09-24 11:02:52 -04:00
parent 9abe83b8d0
commit 15ff359b5b
3 changed files with 14 additions and 40 deletions

View File

@@ -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) {

View File

@@ -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();

View File

@@ -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<ZookeeperDiscoveryClient> 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()