Repaired overriding of connection string from EnsembleProvider
fixes gh-86
This commit is contained in:
committed by
Spencer Gibb
parent
8cfa7334a2
commit
26aea48b9d
@@ -63,11 +63,10 @@ public class ZookeeperAutoConfiguration {
|
||||
CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder();
|
||||
if (this.ensembleProvider != null) {
|
||||
builder.ensembleProvider(this.ensembleProvider);
|
||||
} else {
|
||||
builder.connectString(properties.getConnectString());
|
||||
}
|
||||
CuratorFramework curator = builder
|
||||
.retryPolicy(retryPolicy)
|
||||
.connectString(properties.getConnectString())
|
||||
.build();
|
||||
CuratorFramework curator = builder.retryPolicy(retryPolicy).build();
|
||||
curator.start();
|
||||
log.trace("blocking until connected to zookeeper for " + properties.getBlockUntilConnectedWait() + properties.getBlockUntilConnectedUnit());
|
||||
curator.blockUntilConnected(properties.getBlockUntilConnectedWait(), properties.getBlockUntilConnectedUnit());
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package org.springframework.cloud.zookeeper;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
|
||||
import org.apache.curator.ensemble.EnsembleProvider;
|
||||
import org.apache.curator.ensemble.fixed.FixedEnsembleProvider;
|
||||
import org.apache.curator.framework.CuratorFramework;
|
||||
import org.apache.curator.test.TestingServer;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @author Konrad Kamil Dobrzyński
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = { ZookeeperAutoConfigurationEnsembleTests.TestConfig.class, ZookeeperAutoConfiguration.class })
|
||||
public class ZookeeperAutoConfigurationEnsembleTests {
|
||||
|
||||
@Autowired(required = false) CuratorFramework curator;
|
||||
|
||||
@Autowired TestingServer testingServer;
|
||||
|
||||
@Test
|
||||
public void should_successfully_inject_Curator_with_ensemble_connection_string() {
|
||||
assertEquals(testingServer.getConnectString(), curator.getZookeeperClient().getCurrentConnectionString());
|
||||
assertNotEquals(TestConfig.DUMMY_CONNECTION_STRING, curator.getZookeeperClient().getCurrentConnectionString());
|
||||
}
|
||||
|
||||
static class TestConfig {
|
||||
|
||||
static final String DUMMY_CONNECTION_STRING = "dummy-connection-string:2111";
|
||||
|
||||
@Bean
|
||||
EnsembleProvider ensembleProvider(TestingServer testingServer){
|
||||
return new FixedEnsembleProvider(testingServer.getConnectString());
|
||||
}
|
||||
|
||||
@Bean
|
||||
ZookeeperProperties zookeeperProperties() {
|
||||
ZookeeperProperties properties = new ZookeeperProperties();
|
||||
properties.setConnectString(DUMMY_CONNECTION_STRING);
|
||||
return properties;
|
||||
}
|
||||
|
||||
@Bean(destroyMethod = "close") TestingServer testingServer() throws Exception {
|
||||
return new TestingServer();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user