This is an automated email from the ASF dual-hosted git repository. btellier pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 6a4ad33402ffd5d1ed16ddcc7a786f9e0e14ed97 Author: Benoit Tellier <[email protected]> AuthorDate: Wed Oct 2 12:17:10 2019 +0700 JAMES-2904 Remove ClusterBuilder complicated host/port options Rely only on Host objects --- .../backends/cassandra/init/ClusterBuilder.java | 40 +++------------------- .../james/backends/cassandra/CassandraCluster.java | 3 +- .../cassandra/init/ClusterBuilderTest.java | 4 +-- .../SessionWithInitializedTablesFactoryTest.java | 5 ++- 4 files changed, 10 insertions(+), 42 deletions(-) diff --git a/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/ClusterBuilder.java b/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/ClusterBuilder.java index 681992a..e41c6d6 100644 --- a/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/ClusterBuilder.java +++ b/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/ClusterBuilder.java @@ -47,8 +47,6 @@ public class ClusterBuilder { private Optional<String> username; private Optional<String> password; - private Optional<String> host; - private Optional<Integer> port; private Optional<Collection<Host>> servers; private Optional<QueryLoggerConfiguration> queryLogger; @@ -62,8 +60,6 @@ public class ClusterBuilder { password = Optional.empty(); useSsl = Optional.empty(); - host = Optional.empty(); - port = Optional.empty(); servers = Optional.empty(); queryLogger = Optional.empty(); @@ -92,18 +88,6 @@ public class ClusterBuilder { return this; } - public ClusterBuilder host(String host) { - this.host = Optional.of(host); - - return this; - } - - public ClusterBuilder port(int port) { - this.port = Optional.of(port); - - return this; - } - public ClusterBuilder useSsl(boolean useSsl) { this.useSsl = Optional.of(useSsl); @@ -149,15 +133,13 @@ public class ClusterBuilder { } public Cluster build() { - Preconditions.checkState(!(servers.isPresent() && host.isPresent()), "You can't specify a list of servers and a host at the same time"); - Preconditions.checkState(!(servers.isPresent() && port.isPresent()), "You can't specify a list of servers and a port at the same time"); Preconditions.checkState(username.isPresent() == password.isPresent(), "If you specify username, you must specify password"); Cluster.Builder clusterBuilder = Cluster.builder() .withoutJMXReporting(); - getServers().forEach( - (server) -> clusterBuilder.addContactPoint(server.getHostName()).withPort(server.getPort()) - ); + getServers().forEach(server -> clusterBuilder + .addContactPoint(server.getHostName()) + .withPort(server.getPort())); username.map(username -> password.map(password -> @@ -190,19 +172,7 @@ public class ClusterBuilder { } private Collection<Host> getServers() { - return servers.orElse(getServersFromHostAndPort()); - } - - private Collection<Host> getServersFromHostAndPort() { - String host = this.host.orElseGet(() -> { - LOGGER.info("No cassandra host specified. Falling back to {}", DEFAULT_CLUSTER_IP); - return DEFAULT_CLUSTER_IP; - }); - int port = this.port.orElseGet(() -> { - LOGGER.info("No cassandra port specified. Falling back to {}", DEFAULT_CASSANDRA_PORT); - return DEFAULT_CASSANDRA_PORT; - }); - - return ImmutableList.of(Host.from(host, port)); + return servers.orElse(ImmutableList.of( + Host.from(DEFAULT_CLUSTER_IP, DEFAULT_CASSANDRA_PORT))); } } diff --git a/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/CassandraCluster.java b/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/CassandraCluster.java index aff80b4..9a6d412 100644 --- a/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/CassandraCluster.java +++ b/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/CassandraCluster.java @@ -58,8 +58,7 @@ public final class CassandraCluster implements AutoCloseable { this.module = module; try { cluster = ClusterBuilder.builder() - .host(host.getHostName()) - .port(host.getPort()) + .servers(host) .build(); ClusterConfiguration clusterConfiguration = ClusterConfiguration.builder() .host(host) diff --git a/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/init/ClusterBuilderTest.java b/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/init/ClusterBuilderTest.java index 9c440f4..4ad3db7 100644 --- a/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/init/ClusterBuilderTest.java +++ b/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/init/ClusterBuilderTest.java @@ -20,6 +20,7 @@ package org.apache.james.backends.cassandra.init; import static org.assertj.core.api.Assertions.assertThat; +import org.apache.james.util.Host; import org.junit.jupiter.api.Test; import com.datastax.driver.core.Cluster; @@ -30,8 +31,7 @@ class ClusterBuilderTest { @Test void consistencyLevelShouldBeEqualToQuorum() { Cluster cluster = ClusterBuilder.builder() - .host("localhost") - .port(ClusterBuilder.DEFAULT_CASSANDRA_PORT) + .servers(Host.from("localhost", ClusterBuilder.DEFAULT_CASSANDRA_PORT)) .build(); ConsistencyLevel consistencyLevel = cluster.getConfiguration() diff --git a/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/init/SessionWithInitializedTablesFactoryTest.java b/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/init/SessionWithInitializedTablesFactoryTest.java index 13a4f53..ea6fd49 100644 --- a/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/init/SessionWithInitializedTablesFactoryTest.java +++ b/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/init/SessionWithInitializedTablesFactoryTest.java @@ -123,9 +123,8 @@ class SessionWithInitializedTablesFactoryTest { private static Supplier<Session> createSession(DockerCassandraExtension.DockerCassandra cassandraServer) { Host host = cassandraServer.getHost(); Cluster cluster = ClusterBuilder.builder() - .host(host.getHostName()) - .port(host.getPort()) - .build(); + .servers(host) + .build(); ClusterConfiguration clusterConfiguration = ClusterConfiguration.builder() .host(host) .keyspace(KEYSPACE) --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
