Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.apache.pulsar.tests.TestRetrySupport;
import org.assertj.core.util.Files;
import org.testng.annotations.AfterClass;
Expand Down Expand Up @@ -91,6 +93,10 @@ public Object[][] distributedImplementations() {
}

private synchronized String getEtcdClusterConnectString() {
String etcdUrl = System.getProperty("pulsar.metadatastore.etcd.url");
if(StringUtils.isNotBlank(etcdUrl)){
return etcdUrl;
}
if (etcdCluster == null) {
etcdCluster = EtcdClusterExtension.builder().withClusterName("test").withNodes(1).withSsl(false).build()
.cluster();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.stream.Collectors;
import lombok.Cleanup;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.pulsar.metadata.api.MetadataStore;
import org.apache.pulsar.metadata.api.MetadataStoreConfig;
import org.apache.pulsar.metadata.api.MetadataStoreFactory;
Expand All @@ -43,10 +44,6 @@ public class EtcdMetadataStoreTest {

@Test
public void testCluster() throws Exception {
@Cleanup
EtcdCluster etcdCluster = EtcdClusterExtension.builder().withClusterName("test-cluster").withNodes(3)
.withSsl(false).build().cluster();
etcdCluster.start();

EtcdConfig etcdConfig = EtcdConfig.builder().useTls(false)
.tlsProvider(null)
Expand All @@ -56,8 +53,8 @@ public void testCluster() throws Exception {
Path etcdConfigPath = Files.createTempFile("etcd_config_cluster", ".yml");
new ObjectMapper(new YAMLFactory()).writeValue(etcdConfigPath.toFile(), etcdConfig);

String metadataURL =
"etcd:" + etcdCluster.clientEndpoints().stream().map(URI::toString).collect(Collectors.joining(","));
String metadataURL = getEtcdClusterConnectString(EtcdClusterExtension.builder().withClusterName("test-cluster").withNodes(3)
.withSsl(false));

@Cleanup
MetadataStore store = MetadataStoreFactory.create(metadataURL,
Expand All @@ -71,10 +68,6 @@ public void testCluster() throws Exception {

@Test
public void testClusterWithTls() throws Exception {
@Cleanup
EtcdCluster etcdCluster = EtcdClusterExtension.builder().withClusterName("test-cluster").withNodes(3)
.withSsl(true).build().cluster();
etcdCluster.start();

EtcdConfig etcdConfig = EtcdConfig.builder().useTls(true)
.tlsProvider(null)
Expand All @@ -87,8 +80,8 @@ public void testClusterWithTls() throws Exception {
Path etcdConfigPath = Files.createTempFile("etcd_config_cluster_ssl", ".yml");
new ObjectMapper(new YAMLFactory()).writeValue(etcdConfigPath.toFile(), etcdConfig);

String metadataURL =
"etcd:" + etcdCluster.clientEndpoints().stream().map(URI::toString).collect(Collectors.joining(","));
String metadataURL = getEtcdClusterConnectString(EtcdClusterExtension.builder().withClusterName("test-cluster").withNodes(3)
.withSsl(true));

@Cleanup
MetadataStore store = MetadataStoreFactory.create(metadataURL,
Expand All @@ -102,10 +95,6 @@ public void testClusterWithTls() throws Exception {

@Test
public void testTlsInstance() throws Exception {
@Cleanup
EtcdCluster etcdCluster = EtcdClusterExtension.builder().withClusterName("test-tls").withNodes(1)
.withSsl(true).build().cluster();
etcdCluster.start();

EtcdConfig etcdConfig = EtcdConfig.builder().useTls(true)
.tlsProvider(null)
Expand All @@ -117,8 +106,8 @@ public void testTlsInstance() throws Exception {
Path etcdConfigPath = Files.createTempFile("etcd_config", ".yml");
new ObjectMapper(new YAMLFactory()).writeValue(etcdConfigPath.toFile(), etcdConfig);

String metadataURL =
"etcd:" + etcdCluster.clientEndpoints().stream().map(URI::toString).collect(Collectors.joining(","));
String metadataURL = getEtcdClusterConnectString(EtcdClusterExtension.builder().withClusterName("test-tls").withNodes(1)
.withSsl(true));

@Cleanup
MetadataStore store = MetadataStoreFactory.create(metadataURL,
Expand All @@ -128,4 +117,19 @@ public void testTlsInstance() throws Exception {

assertTrue(store.exists("/test").join());
}


private synchronized String getEtcdClusterConnectString(EtcdClusterExtension.Builder builder) {
String etcdUrl = System.getProperty("pulsar.metadatastore.etcd.url");
if(!StringUtils.isBlank(etcdUrl)){
return "etcd:"+etcdUrl;
}
@Cleanup
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @Cleanup should call the close(), which seems to cause the etcd cluster to shutdown after calling the getEtcdClusterConnectString().

EtcdCluster etcdCluster = builder.build().cluster();
etcdCluster.start();
String metadataURL =
"etcd:" + etcdCluster.clientEndpoints().stream().map(URI::toString).collect(Collectors.joining(","));
return metadataURL;
}

}