kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | a09129ebe89a3d35cfbd0346ea1579cd919ddbadc6d42b0d76719d37261055a2 |
|---|---|
| Author | Alexandre Dutra <alexandre.dutra@datastax.com> · 2016-01-16 18:47 +01:00 |
| Committer | Alexandre Dutra <alexandre.dutra@datastax.com> · 2016-01-16 18:47 +01:00 |
| Parents | 542f59d6e0ec, 446aa287b841 |
47 files changed
modified driver-core/src/main/java/com/datastax/driver/core/PoolingOptions.java +19 −1
| @@ -50,7 +50,21 @@ | ||
| 50 | 50 | */ |
| 51 | 51 | public class PoolingOptions { |
| 52 | 52 | |
| 53 | - static final int UNSET = Integer.MIN_VALUE; | |
| 53 | + /** | |
| 54 | + * The value returned for connection options when they have not been set by the client, and the protocol version | |
| 55 | + * is not known yet. | |
| 56 | + * <p/> | |
| 57 | + * Once a {@code PoolingOptions} object is associated to a {@link Cluster} and that cluster initializes, the | |
| 58 | + * protocol version will be detected, and connection options will take their default values for that protocol | |
| 59 | + * version. | |
| 60 | + * <p/> | |
| 61 | + * The methods that may return this value are: | |
| 62 | + * {@link #getCoreConnectionsPerHost(HostDistance)}, | |
| 63 | + * {@link #getMaxConnectionsPerHost(HostDistance)}, | |
| 64 | + * {@link #getNewConnectionThreshold(HostDistance)}, | |
| 65 | + * {@link #getMaxRequestsPerConnection(HostDistance)}. | |
| 66 | + */ | |
| 67 | + public static final int UNSET = Integer.MIN_VALUE; | |
| 54 | 68 | |
| 55 | 69 | private static final Map<ProtocolVersion, Map<String, Integer>> DEFAULTS = ImmutableMap.<ProtocolVersion, Map<String, Integer>>of( |
| 56 | 70 | ProtocolVersion.V2, ImmutableMap.<String, Integer>builder() |
| @@ -139,6 +153,7 @@ | ||
| 139 | 153 | public synchronized PoolingOptions setCoreConnectionsPerHost(HostDistance distance, int newCoreConnections) { |
| 140 | 154 | if (distance == HostDistance.IGNORED) |
| 141 | 155 | throw new IllegalArgumentException("Cannot set core connections per host for " + distance + " hosts"); |
| 156 | + Preconditions.checkArgument(newCoreConnections >= 0, "core number of connections must be positive"); | |
| 142 | 157 | |
| 143 | 158 | if (maxConnections[distance.ordinal()] != UNSET) |
| 144 | 159 | checkConnectionsPerHostOrder(newCoreConnections, maxConnections[distance.ordinal()], distance); |
| @@ -182,6 +197,7 @@ | ||
| 182 | 197 | public synchronized PoolingOptions setMaxConnectionsPerHost(HostDistance distance, int newMaxConnections) { |
| 183 | 198 | if (distance == HostDistance.IGNORED) |
| 184 | 199 | throw new IllegalArgumentException("Cannot set max connections per host for " + distance + " hosts"); |
| 200 | + Preconditions.checkArgument(newMaxConnections >= 0, "max number of connections must be positive"); | |
| 185 | 201 | |
| 186 | 202 | if (coreConnections[distance.ordinal()] != UNSET) |
| 187 | 203 | checkConnectionsPerHostOrder(coreConnections[distance.ordinal()], newMaxConnections, distance); |
| @@ -206,6 +222,8 @@ | ||
| 206 | 222 | public synchronized PoolingOptions setConnectionsPerHost(HostDistance distance, int core, int max) { |
| 207 | 223 | if (distance == HostDistance.IGNORED) |
| 208 | 224 | throw new IllegalArgumentException("Cannot set connections per host for " + distance + " hosts"); |
| 225 | + Preconditions.checkArgument(core >= 0, "core number of connections must be positive"); | |
| 226 | + Preconditions.checkArgument(max >= 0, "max number of connections must be positive"); | |
| 209 | 227 | |
| 210 | 228 | checkConnectionsPerHostOrder(core, max, distance); |
| 211 | 229 | coreConnections[distance.ordinal()] = core; |
modified driver-core/src/test/java/com/datastax/driver/core/AuthenticationTest.java +3 −3
| @@ -50,7 +50,7 @@ | ||
| 50 | 50 | PlainTextAuthProvider authProvider = spy(new PlainTextAuthProvider("cassandra", "cassandra")); |
| 51 | 51 | Cluster cluster = Cluster.builder() |
| 52 | 52 | .addContactPointsWithPorts(getInitialContactPoints()) |
| 53 | - .withAddressTranslator(getAddressTranslator()) | |
| 53 | + .withPort(ccm.getBinaryPort()) | |
| 54 | 54 | .withAuthProvider(authProvider) |
| 55 | 55 | .build(); |
| 56 | 56 | cluster.connect(); |
| @@ -61,7 +61,7 @@ | ||
| 61 | 61 | public void should_fail_to_connect_with_wrong_credentials() throws InterruptedException { |
| 62 | 62 | Cluster cluster = register(Cluster.builder() |
| 63 | 63 | .addContactPointsWithPorts(getInitialContactPoints()) |
| 64 | - .withAddressTranslator(getAddressTranslator()) | |
| 64 | + .withPort(ccm.getBinaryPort()) | |
| 65 | 65 | .withCredentials("bogus", "bogus") |
| 66 | 66 | .build()); |
| 67 | 67 | cluster.connect(); |
| @@ -71,7 +71,7 @@ | ||
| 71 | 71 | public void should_fail_to_connect_without_credentials() throws InterruptedException { |
| 72 | 72 | Cluster cluster = register(Cluster.builder() |
| 73 | 73 | .addContactPointsWithPorts(getInitialContactPoints()) |
| 74 | - .withAddressTranslator(getAddressTranslator()) | |
| 74 | + .withPort(ccm.getBinaryPort()) | |
| 75 | 75 | .build()); |
| 76 | 76 | cluster.connect(); |
| 77 | 77 | } |
added driver-core/src/test/java/com/datastax/driver/core/CCMAccess.java +219 −0
| @@ -0,0 +1,219 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (C) 2012-2015 DataStax Inc. | |
| 3 | + * | |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | + * you may not use this file except in compliance with the License. | |
| 6 | + * You may obtain a copy of the License at | |
| 7 | + * | |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | + * | |
| 10 | + * Unless required by applicable law or agreed to in writing, software | |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | + * See the License for the specific language governing permissions and | |
| 14 | + * limitations under the License. | |
| 15 | + */ | |
| 16 | +package com.datastax.driver.core; | |
| 17 | + | |
| 18 | +import java.io.Closeable; | |
| 19 | +import java.io.File; | |
| 20 | +import java.net.InetSocketAddress; | |
| 21 | +import java.util.Map; | |
| 22 | + | |
| 23 | +public interface CCMAccess extends Closeable { | |
| 24 | + | |
| 25 | + // Inspection methods | |
| 26 | + | |
| 27 | + /** | |
| 28 | + * @return The CCM cluster name. | |
| 29 | + */ | |
| 30 | + String getClusterName(); | |
| 31 | + | |
| 32 | + /** | |
| 33 | + * Returns the Cassandra version of this CCM cluster. | |
| 34 | + * <p/> | |
| 35 | + * By default the version is equal to {@link CCMBridge#getCassandraVersion()}. | |
| 36 | + * | |
| 37 | + * @return The version of this CCM cluster. | |
| 38 | + */ | |
| 39 | + VersionNumber getVersion(); | |
| 40 | + | |
| 41 | + /** | |
| 42 | + * @return The config directory for this CCM cluster. | |
| 43 | + */ | |
| 44 | + File getCcmDir(); | |
| 45 | + | |
| 46 | + /** | |
| 47 | + * @return The cluster directory for this CCM cluster. | |
| 48 | + */ | |
| 49 | + File getClusterDir(); | |
| 50 | + | |
| 51 | + /** | |
| 52 | + * @param n the node number, starting with 1. | |
| 53 | + * @return The node directory for this CCM cluster. | |
| 54 | + */ | |
| 55 | + File getNodeDir(int n); | |
| 56 | + | |
| 57 | + /** | |
| 58 | + * @param n the node number, starting with 1. | |
| 59 | + * @return The node config directory for this CCM cluster. | |
| 60 | + */ | |
| 61 | + File getNodeConfDir(int n); | |
| 62 | + | |
| 63 | + /** | |
| 64 | + * @return The storage port for this CCM cluster. | |
| 65 | + */ | |
| 66 | + int getStoragePort(); | |
| 67 | + | |
| 68 | + /** | |
| 69 | + * @return The thrift port for this CCM cluster. | |
| 70 | + */ | |
| 71 | + int getThriftPort(); | |
| 72 | + | |
| 73 | + /** | |
| 74 | + * @return The binary port for this CCM cluster. | |
| 75 | + */ | |
| 76 | + int getBinaryPort(); | |
| 77 | + | |
| 78 | + /** | |
| 79 | + * Signals that logs for this CCM cluster should be kept after the cluster is stopped. | |
| 80 | + */ | |
| 81 | + void setKeepLogs(boolean keepLogs); | |
| 82 | + | |
| 83 | + /** | |
| 84 | + * Returns the address of the {@code nth} host in the CCM cluster (counting from 1, i.e., | |
| 85 | + * {@code addressOfNode(1)} returns the address of the first node. | |
| 86 | + * <p/> | |
| 87 | + * In multi-DC setups, nodes are numbered in ascending order of their datacenter number. | |
| 88 | + * E.g. with 2 DCs and 3 nodes in each DC, the first node in DC 2 is number 4. | |
| 89 | + * | |
| 90 | + * @return the address of the {@code nth} host in the cluster. | |
| 91 | + */ | |
| 92 | + InetSocketAddress addressOfNode(int n); | |
| 93 | + | |
| 94 | + | |
| 95 | + // Methods altering the whole cluster | |
| 96 | + | |
| 97 | + /** | |
| 98 | + * Starts the cluster. | |
| 99 | + */ | |
| 100 | + void start(); | |
| 101 | + | |
| 102 | + /** | |
| 103 | + * Stops the cluster. | |
| 104 | + */ | |
| 105 | + void stop(); | |
| 106 | + | |
| 107 | + /** | |
| 108 | + * Aggressively stops the cluster. | |
| 109 | + */ | |
| 110 | + void forceStop(); | |
| 111 | + | |
| 112 | + /** | |
| 113 | + * Alias for {@link #stop()}. | |
| 114 | + */ | |
| 115 | + @Override | |
| 116 | + void close(); | |
| 117 | + | |
| 118 | + /** | |
| 119 | + * Removes this CCM cluster and deletes all of its files. | |
| 120 | + */ | |
| 121 | + void remove(); | |
| 122 | + | |
| 123 | + /** | |
| 124 | + * Updates the config files for all nodes in the CCM cluster. | |
| 125 | + */ | |
| 126 | + void updateConfig(Map<String, Object> configs); | |
| 127 | + | |
| 128 | + /** | |
| 129 | + * Updates the DSE config files for all nodes in the CCM cluster. | |
| 130 | + */ | |
| 131 | + void updateDSEConfig(Map<String, Object> configs); | |
| 132 | + | |
| 133 | + | |
| 134 | + // Methods altering nodes | |
| 135 | + | |
| 136 | + /** | |
| 137 | + * Starts the {@code nth} host in the CCM cluster. | |
| 138 | + * | |
| 139 | + * @param n the node number (starting from 1). | |
| 140 | + */ | |
| 141 | + void start(int n); | |
| 142 | + | |
| 143 | + /** | |
| 144 | + * Stops the {@code nth} host in the CCM cluster. | |
| 145 | + * | |
| 146 | + * @param n the node number (starting from 1). | |
| 147 | + */ | |
| 148 | + void stop(int n); | |
| 149 | + | |
| 150 | + /** | |
| 151 | + * Aggressively stops the {@code nth} host in the CCM cluster. | |
| 152 | + * | |
| 153 | + * @param n the node number (starting from 1). | |
| 154 | + */ | |
| 155 | + void forceStop(int n); | |
| 156 | + | |
| 157 | + /** | |
| 158 | + * Removes the {@code nth} host in the CCM cluster. | |
| 159 | + * | |
| 160 | + * @param n the node number (starting from 1). | |
| 161 | + */ | |
| 162 | + void remove(int n); | |
| 163 | + | |
| 164 | + /** | |
| 165 | + * Adds the {@code nth} host in the CCM cluster. | |
| 166 | + * | |
| 167 | + * @param n the node number (starting from 1). | |
| 168 | + */ | |
| 169 | + void add(int n); | |
| 170 | + | |
| 171 | + /** | |
| 172 | + * Adds the {@code nth} host in the CCM cluster. | |
| 173 | + * | |
| 174 | + * @param n the node number (starting from 1). | |
| 175 | + */ | |
| 176 | + void add(int dc, int n); | |
| 177 | + | |
| 178 | + /** | |
| 179 | + * Decommissions the {@code nth} host in the CCM cluster. | |
| 180 | + * | |
| 181 | + * @param n the node number (starting from 1). | |
| 182 | + */ | |
| 183 | + void decommision(int n); | |
| 184 | + | |
| 185 | + /** | |
| 186 | + * Updates the {@code nth} host's config file in the CCM cluster. | |
| 187 | + * | |
| 188 | + * @param n the node number (starting from 1). | |
| 189 | + */ | |
| 190 | + void updateNodeConfig(int n, String key, Object value); | |
| 191 | + | |
| 192 | + /** | |
| 193 | + * Updates the {@code nth} host's config file in the CCM cluster. | |
| 194 | + * | |
| 195 | + * @param n the node number (starting from 1). | |
| 196 | + */ | |
| 197 | + void updateNodeConfig(int n, Map<String, Object> configs); | |
| 198 | + | |
| 199 | + /** | |
| 200 | + * Sets the workload for the {@code nth} host in the CCM cluster. | |
| 201 | + * | |
| 202 | + * @param n the node number (starting from 1). | |
| 203 | + */ | |
| 204 | + void setWorkload(int n, String workload); | |
| 205 | + | |
| 206 | + | |
| 207 | + // Methods blocking until nodes are up or down | |
| 208 | + | |
| 209 | + /** | |
| 210 | + * Waits for a host to be up by pinging the TCP socket directly, without using the Java driver's API. | |
| 211 | + */ | |
| 212 | + void waitForUp(int node); | |
| 213 | + | |
| 214 | + /** | |
| 215 | + * Waits for a host to be down by pinging the TCP socket directly, without using the Java driver's API. | |
| 216 | + */ | |
| 217 | + void waitForDown(int node); | |
| 218 | + | |
| 219 | +} |
modified driver-core/src/test/java/com/datastax/driver/core/CCMBridge.java +70 −93
| @@ -15,10 +15,10 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import com.datastax.driver.core.policies.AddressTranslator; | |
| 19 | 18 | import com.google.common.base.Joiner; |
| 20 | 19 | import com.google.common.base.Throwables; |
| 21 | 20 | import com.google.common.collect.ImmutableMap; |
| 21 | +import com.google.common.collect.ImmutableSet; | |
| 22 | 22 | import com.google.common.collect.Maps; |
| 23 | 23 | import com.google.common.io.ByteStreams; |
| 24 | 24 | import com.google.common.io.Closer; |
| @@ -35,13 +35,13 @@ | ||
| 35 | 35 | import static com.datastax.driver.core.TestUtils.executeNoFail; |
| 36 | 36 | import static com.datastax.driver.core.TestUtils.findAvailablePort; |
| 37 | 37 | |
| 38 | -public class CCMBridge implements Closeable { | |
| 38 | +public class CCMBridge implements CCMAccess { | |
| 39 | 39 | |
| 40 | 40 | private static final Logger logger = LoggerFactory.getLogger(CCMBridge.class); |
| 41 | 41 | |
| 42 | 42 | private static final String CASSANDRA_VERSION; |
| 43 | 43 | |
| 44 | - private static final String CASSANDRA_INSTALL_ARGS; | |
| 44 | + private static final Set<String> CASSANDRA_INSTALL_ARGS; | |
| 45 | 45 | |
| 46 | 46 | private static final boolean IS_DSE; |
| 47 | 47 | |
| @@ -137,23 +137,20 @@ | ||
| 137 | 137 | // otherwise if there is a value, parse as boolean. |
| 138 | 138 | IS_DSE = dseProperty != null && (dseProperty.isEmpty() || Boolean.parseBoolean(dseProperty)); |
| 139 | 139 | |
| 140 | - StringBuilder installArgs = new StringBuilder(); | |
| 140 | + ImmutableSet.Builder<String> installArgs = ImmutableSet.builder(); | |
| 141 | 141 | if (installDirectory != null && !installDirectory.trim().isEmpty()) { |
| 142 | - installArgs.append("--install-dir="); | |
| 143 | - installArgs.append(new File(installDirectory).getAbsolutePath()); | |
| 142 | + installArgs.add("--install-dir=" + new File(installDirectory).getAbsolutePath()); | |
| 144 | 143 | } else if (branch != null && !branch.trim().isEmpty()) { |
| 145 | - installArgs.append("-v git:"); | |
| 146 | - installArgs.append(branch.trim().replaceAll("\"", "")); | |
| 144 | + installArgs.add("-v git:" + branch.trim().replaceAll("\"", "")); | |
| 147 | 145 | } else { |
| 148 | - installArgs.append("-v "); | |
| 149 | - installArgs.append(CASSANDRA_VERSION); | |
| 146 | + installArgs.add("-v " + CASSANDRA_VERSION); | |
| 150 | 147 | } |
| 151 | 148 | |
| 152 | 149 | if (IS_DSE) { |
| 153 | - installArgs.append(" --dse"); | |
| 150 | + installArgs.add("--dse"); | |
| 154 | 151 | } |
| 155 | 152 | |
| 156 | - CASSANDRA_INSTALL_ARGS = installArgs.toString(); | |
| 153 | + CASSANDRA_INSTALL_ARGS = installArgs.build(); | |
| 157 | 154 | |
| 158 | 155 | // Inherit the current environment. |
| 159 | 156 | Map<String, String> envMap = Maps.newHashMap(new ProcessBuilder().environment()); |
| @@ -181,10 +178,10 @@ | ||
| 181 | 178 | ENVIRONMENT_MAP = ImmutableMap.copyOf(envMap); |
| 182 | 179 | |
| 183 | 180 | if (CCMBridge.isDSE()) { |
| 184 | - logger.info("Tests requiring CCM will use DSE version {} (C* {}, install arguments: {})", | |
| 181 | + logger.info("Tests requiring CCM will by default use DSE version {} (C* {}, install arguments: {})", | |
| 185 | 182 | CCMBridge.getDSEVersion(), CCMBridge.getCassandraVersion(), CCMBridge.getInstallArguments()); |
| 186 | 183 | } else { |
| 187 | - logger.info("Tests requiring CCM will use Cassandra version {} (install arguments: {})", | |
| 184 | + logger.info("Tests requiring CCM will by default use Cassandra version {} (install arguments: {})", | |
| 188 | 185 | CCMBridge.getCassandraVersion(), CCMBridge.getInstallArguments()); |
| 189 | 186 | } |
| 190 | 187 | } |
| @@ -216,13 +213,11 @@ | ||
| 216 | 213 | |
| 217 | 214 | private final String jvmArgs; |
| 218 | 215 | |
| 219 | - private final int initialNumberOfNodes; | |
| 220 | - | |
| 221 | 216 | private boolean keepLogs = false; |
| 222 | 217 | |
| 223 | 218 | private boolean closed = false; |
| 224 | 219 | |
| 225 | - private CCMBridge(String clusterName, boolean isDSE, VersionNumber version, int storagePort, int thriftPort, int binaryPort, String jvmArgs, int initialNumberOfNodes) { | |
| 220 | + private CCMBridge(String clusterName, boolean isDSE, VersionNumber version, int storagePort, int thriftPort, int binaryPort, String jvmArgs) { | |
| 226 | 221 | this.clusterName = clusterName; |
| 227 | 222 | this.version = version; |
| 228 | 223 | this.storagePort = storagePort; |
| @@ -230,7 +225,6 @@ | ||
| 230 | 225 | this.binaryPort = binaryPort; |
| 231 | 226 | this.isDSE = isDSE; |
| 232 | 227 | this.jvmArgs = jvmArgs; |
| 233 | - this.initialNumberOfNodes = initialNumberOfNodes; | |
| 234 | 228 | this.ccmDir = Files.createTempDir(); |
| 235 | 229 | } |
| 236 | 230 | |
| @@ -287,7 +281,7 @@ | ||
| 287 | 281 | /** |
| 288 | 282 | * @return The install arguments to pass to CCM when creating the cluster. |
| 289 | 283 | */ |
| 290 | - public static String getInstallArguments() { | |
| 284 | + public static Set<String> getInstallArguments() { | |
| 291 | 285 | return CASSANDRA_INSTALL_ARGS; |
| 292 | 286 | } |
| 293 | 287 | |
| @@ -295,97 +289,57 @@ | ||
| 295 | 289 | return new Builder(); |
| 296 | 290 | } |
| 297 | 291 | |
| 298 | - /** | |
| 299 | - * Returns the address of the {@code nth} host in the CCM cluster (counting from 1, i.e., | |
| 300 | - * {@code getHostAddress(1)} returns the address of the first node. | |
| 301 | - * <p/> | |
| 302 | - * In multi-DC setups, nodes are numbered in ascending order of their datacenter number. | |
| 303 | - * E.g. with 2 DCs and 3 nodes in each DC, the first node in DC 2 is number 4. | |
| 304 | - * | |
| 305 | - * @return the address of the {@code nth} host in the cluster. | |
| 306 | - */ | |
| 307 | - public InetSocketAddress addressOfNode(int n) { | |
| 308 | - return new InetSocketAddress(TestUtils.ipOfNode(n), binaryPort); | |
| 292 | + @Override | |
| 293 | + public String getClusterName() { | |
| 294 | + return clusterName; | |
| 309 | 295 | } |
| 310 | 296 | |
| 311 | - /** | |
| 312 | - * Returns an {@link AddressTranslator} to use when tests must manually create | |
| 313 | - * {@link Cluster} instances. | |
| 314 | - * <p/> | |
| 315 | - * This translator is necessary because hosts in this cluster do not necessarily use standard ports. | |
| 316 | - * | |
| 317 | - * @return an {@link AddressTranslator} to use when tests must manually create | |
| 318 | - * {@link Cluster} instances. | |
| 319 | - */ | |
| 320 | - public AddressTranslator addressTranslator() { | |
| 321 | - return new AddressTranslator() { | |
| 322 | - @Override | |
| 323 | - public InetSocketAddress translate(InetSocketAddress address) { | |
| 324 | - return new InetSocketAddress(address.getAddress(), getBinaryPort()); | |
| 325 | - } | |
| 326 | - | |
| 327 | - @Override | |
| 328 | - public void init(Cluster cluster) { | |
| 329 | - | |
| 330 | - } | |
| 331 | - | |
| 332 | - @Override | |
| 333 | - public void close() { | |
| 334 | - | |
| 335 | - } | |
| 336 | - }; | |
| 297 | + @Override | |
| 298 | + public InetSocketAddress addressOfNode(int n) { | |
| 299 | + return new InetSocketAddress(TestUtils.ipOfNode(n), binaryPort); | |
| 337 | 300 | } |
| 338 | 301 | |
| 339 | - /** | |
| 340 | - * Returns the Cassandra version of this CCM cluster. | |
| 341 | - * <p/> | |
| 342 | - * By default the version is equal to {@link #getCassandraVersion()}. | |
| 343 | - * | |
| 344 | - * @return The version of this CCM cluster. | |
| 345 | - */ | |
| 302 | + @Override | |
| 346 | 303 | public VersionNumber getVersion() { |
| 347 | 304 | return version; |
| 348 | 305 | } |
| 349 | 306 | |
| 350 | - /** | |
| 351 | - * The number of nodes that were initially created with this CCM instance. | |
| 352 | - * <p/> | |
| 353 | - * This does not account for nodes created or removed during the cluster's lifecycle. | |
| 354 | - * | |
| 355 | - * @return The number of nodes that were initially created with this CCM instance. | |
| 356 | - */ | |
| 357 | - public int getInitialNumberOfNodes() { | |
| 358 | - return initialNumberOfNodes; | |
| 359 | - } | |
| 360 | - | |
| 307 | + @Override | |
| 361 | 308 | public File getCcmDir() { |
| 362 | 309 | return ccmDir; |
| 363 | 310 | } |
| 364 | 311 | |
| 312 | + @Override | |
| 365 | 313 | public File getClusterDir() { |
| 366 | 314 | return new File(ccmDir, clusterName); |
| 367 | 315 | } |
| 368 | 316 | |
| 317 | + @Override | |
| 369 | 318 | public File getNodeDir(int n) { |
| 370 | 319 | return new File(getClusterDir(), "node" + n); |
| 371 | 320 | } |
| 372 | 321 | |
| 322 | + @Override | |
| 373 | 323 | public File getNodeConfDir(int n) { |
| 374 | 324 | return new File(getNodeDir(n), "conf"); |
| 375 | 325 | } |
| 376 | 326 | |
| 327 | + @Override | |
| 377 | 328 | public int getStoragePort() { |
| 378 | 329 | return storagePort; |
| 379 | 330 | } |
| 380 | 331 | |
| 332 | + @Override | |
| 381 | 333 | public int getThriftPort() { |
| 382 | 334 | return thriftPort; |
| 383 | 335 | } |
| 384 | 336 | |
| 337 | + @Override | |
| 385 | 338 | public int getBinaryPort() { |
| 386 | 339 | return binaryPort; |
| 387 | 340 | } |
| 388 | 341 | |
| 342 | + @Override | |
| 389 | 343 | public void setKeepLogs(boolean keepLogs) { |
| 390 | 344 | this.keepLogs = keepLogs; |
| 391 | 345 | } |
| @@ -421,11 +375,13 @@ | ||
| 421 | 375 | logger.debug("Closed: " + this); |
| 422 | 376 | } |
| 423 | 377 | |
| 378 | + @Override | |
| 424 | 379 | public void start() { |
| 425 | 380 | logger.debug("Starting: " + this); |
| 426 | 381 | execute(CCM_COMMAND + " start --wait-other-notice --wait-for-binary-proto" + jvmArgs); |
| 427 | 382 | } |
| 428 | 383 | |
| 384 | + @Override | |
| 429 | 385 | public synchronized void stop() { |
| 430 | 386 | if (closed) |
| 431 | 387 | return; |
| @@ -434,6 +390,7 @@ | ||
| 434 | 390 | closed = true; |
| 435 | 391 | } |
| 436 | 392 | |
| 393 | + @Override | |
| 437 | 394 | public synchronized void forceStop() { |
| 438 | 395 | if (closed) |
| 439 | 396 | return; |
| @@ -442,36 +399,43 @@ | ||
| 442 | 399 | closed = true; |
| 443 | 400 | } |
| 444 | 401 | |
| 402 | + @Override | |
| 445 | 403 | public void start(int n) { |
| 446 | 404 | logger.debug(String.format("Starting: node %s (%s%s:%s) in %s", n, TestUtils.IP_PREFIX, n, binaryPort, this)); |
| 447 | 405 | execute(CCM_COMMAND + " node%d start --wait-other-notice --wait-for-binary-proto" + jvmArgs, n); |
| 448 | 406 | } |
| 449 | 407 | |
| 408 | + @Override | |
| 450 | 409 | public void stop(int n) { |
| 451 | 410 | logger.debug(String.format("Stopping: node %s (%s%s:%s) in %s", n, TestUtils.IP_PREFIX, n, binaryPort, this)); |
| 452 | 411 | execute(CCM_COMMAND + " node%d stop", n); |
| 453 | 412 | } |
| 454 | 413 | |
| 414 | + @Override | |
| 455 | 415 | public void forceStop(int n) { |
| 456 | 416 | logger.debug(String.format("Force stopping: node %s (%s%s:%s) in %s", n, TestUtils.IP_PREFIX, n, binaryPort, this)); |
| 457 | 417 | execute(CCM_COMMAND + " node%d stop --not-gently", n); |
| 458 | 418 | } |
| 459 | 419 | |
| 420 | + @Override | |
| 460 | 421 | public synchronized void remove() { |
| 461 | 422 | stop(); |
| 462 | 423 | logger.debug("Removing: " + this); |
| 463 | 424 | execute(CCM_COMMAND + " remove"); |
| 464 | 425 | } |
| 465 | 426 | |
| 427 | + @Override | |
| 466 | 428 | public void remove(int n) { |
| 467 | 429 | logger.debug(String.format("Removing: node %s (%s%s:%s) from %s", n, TestUtils.IP_PREFIX, n, binaryPort, this)); |
| 468 | 430 | execute(CCM_COMMAND + " node%d remove", n); |
| 469 | 431 | } |
| 470 | 432 | |
| 433 | + @Override | |
| 471 | 434 | public void add(int n) { |
| 472 | 435 | add(1, n); |
| 473 | 436 | } |
| 474 | 437 | |
| 438 | + @Override | |
| 475 | 439 | public void add(int dc, int n) { |
| 476 | 440 | logger.debug(String.format("Adding: node %s (%s%s:%s) to %s", n, TestUtils.IP_PREFIX, n, binaryPort, this)); |
| 477 | 441 | String thriftItf = TestUtils.ipOfNode(n) + ":" + thriftPort; |
| @@ -482,11 +446,13 @@ | ||
| 482 | 446 | n, dc, TestUtils.IP_PREFIX, n, thriftItf, storageItf, binaryItf, TestUtils.findAvailablePort(), remoteLogItf); |
| 483 | 447 | } |
| 484 | 448 | |
| 485 | - public void decommissionNode(int n) { | |
| 449 | + @Override | |
| 450 | + public void decommision(int n) { | |
| 486 | 451 | logger.debug(String.format("Decommissioning: node %s (%s%s:%s) from %s", n, TestUtils.IP_PREFIX, n, binaryPort, this)); |
| 487 | 452 | execute(CCM_COMMAND + " node%d decommission", n); |
| 488 | 453 | } |
| 489 | 454 | |
| 455 | + @Override | |
| 490 | 456 | public void updateConfig(Map<String, Object> configs) { |
| 491 | 457 | StringBuilder confStr = new StringBuilder(); |
| 492 | 458 | for (Map.Entry<String, Object> entry : configs.entrySet()) { |
| @@ -499,6 +465,7 @@ | ||
| 499 | 465 | execute(CCM_COMMAND + " updateconf " + confStr); |
| 500 | 466 | } |
| 501 | 467 | |
| 468 | + @Override | |
| 502 | 469 | public void updateDSEConfig(Map<String, Object> configs) { |
| 503 | 470 | StringBuilder confStr = new StringBuilder(); |
| 504 | 471 | for (Map.Entry<String, Object> entry : configs.entrySet()) { |
| @@ -511,10 +478,12 @@ | ||
| 511 | 478 | execute(CCM_COMMAND + " updatedseconf " + confStr); |
| 512 | 479 | } |
| 513 | 480 | |
| 481 | + @Override | |
| 514 | 482 | public void updateNodeConfig(int n, String key, Object value) { |
| 515 | 483 | updateNodeConfig(n, ImmutableMap.<String, Object>builder().put(key, value).build()); |
| 516 | 484 | } |
| 517 | 485 | |
| 486 | + @Override | |
| 518 | 487 | public void updateNodeConfig(int n, Map<String, Object> configs) { |
| 519 | 488 | StringBuilder confStr = new StringBuilder(); |
| 520 | 489 | for (Map.Entry<String, Object> entry : configs.entrySet()) { |
| @@ -527,6 +496,7 @@ | ||
| 527 | 496 | execute(CCM_COMMAND + " node%s updateconf %s", n, confStr); |
| 528 | 497 | } |
| 529 | 498 | |
| 499 | + @Override | |
| 530 | 500 | public void setWorkload(int node, String workload) { |
| 531 | 501 | execute(CCM_COMMAND + " node%d setworkload %s", node, workload); |
| 532 | 502 | } |
| @@ -633,6 +603,12 @@ | ||
| 633 | 603 | return "CCM cluster " + clusterName; |
| 634 | 604 | } |
| 635 | 605 | |
| 606 | + @Override | |
| 607 | + protected void finalize() throws Throwable { | |
| 608 | + close(); | |
| 609 | + super.finalize(); | |
| 610 | + } | |
| 611 | + | |
| 636 | 612 | /** |
| 637 | 613 | * use {@link #builder()} to get an instance |
| 638 | 614 | */ |
| @@ -642,8 +618,8 @@ | ||
| 642 | 618 | int[] nodes = {1}; |
| 643 | 619 | private boolean start = true; |
| 644 | 620 | private boolean isDSE = isDSE(); |
| 645 | - private String cassandraVersion = getCassandraVersion(); | |
| 646 | - private Set<String> createOptions = new LinkedHashSet<String>(); | |
| 621 | + private String version = getCassandraVersion(); | |
| 622 | + private Set<String> createOptions = new HashSet<String>(getInstallArguments()); | |
| 647 | 623 | private Set<String> jvmArgs = new LinkedHashSet<String>(); |
| 648 | 624 | private final Map<String, Object> cassandraConfiguration = Maps.newHashMap(); |
| 649 | 625 | private final Map<String, Object> dseConfiguration = Maps.newHashMap(); |
| @@ -701,6 +677,7 @@ | ||
| 701 | 677 | * Sets this cluster to be a DSE cluster (defaults to {@link #isDSE()} if this is never called). |
| 702 | 678 | */ |
| 703 | 679 | public Builder withDSE() { |
| 680 | + this.createOptions.add("--dse"); | |
| 704 | 681 | this.isDSE = true; |
| 705 | 682 | return this; |
| 706 | 683 | } |
| @@ -710,8 +687,17 @@ | ||
| 710 | 687 | * <p/> |
| 711 | 688 | * Defaults to {@link #getCassandraVersion()}. |
| 712 | 689 | */ |
| 713 | - public Builder withVersion(String cassandraVersion) { | |
| 714 | - this.cassandraVersion = cassandraVersion; | |
| 690 | + public Builder withVersion(String version) { | |
| 691 | + Iterator<String> it = createOptions.iterator(); | |
| 692 | + while (it.hasNext()) { | |
| 693 | + String option = it.next(); | |
| 694 | + // remove any version previously set and | |
| 695 | + // install-dir, which is incompatible | |
| 696 | + if (option.startsWith("-v ") || option.startsWith("--install-dir")) | |
| 697 | + it.remove(); | |
| 698 | + } | |
| 699 | + this.createOptions.add("-v " + version); | |
| 700 | + this.version = version; | |
| 715 | 701 | return this; |
| 716 | 702 | } |
| 717 | 703 | |
| @@ -766,15 +752,11 @@ | ||
| 766 | 752 | |
| 767 | 753 | public CCMBridge build() { |
| 768 | 754 | // be careful NOT to alter internal state (hashCode/equals) during build! |
| 769 | - int initialNumberOfNodes = 0; | |
| 770 | - for (int nodesPerDc : nodes) { | |
| 771 | - initialNumberOfNodes += nodesPerDc; | |
| 772 | - } | |
| 773 | 755 | int storagePort = this.storagePort == -1 ? findAvailablePort() : this.storagePort; |
| 774 | 756 | int thriftPort = this.thriftPort == -1 ? findAvailablePort() : this.thriftPort; |
| 775 | 757 | int binaryPort = this.binaryPort == -1 ? findAvailablePort() : this.binaryPort; |
| 776 | - VersionNumber version = VersionNumber.parse(cassandraVersion); | |
| 777 | - final CCMBridge ccm = new CCMBridge(clusterName, isDSE, version, storagePort, thriftPort, binaryPort, joinJvmArgs(), initialNumberOfNodes); | |
| 758 | + VersionNumber version = VersionNumber.parse(this.version); | |
| 759 | + final CCMBridge ccm = new CCMBridge(clusterName, isDSE, version, storagePort, thriftPort, binaryPort, joinJvmArgs()); | |
| 778 | 760 | Runtime.getRuntime().addShutdownHook(new Thread() { |
| 779 | 761 | @Override |
| 780 | 762 | public void run() { |
| @@ -809,10 +791,6 @@ | ||
| 809 | 791 | result.append(" ").append(clusterName); |
| 810 | 792 | result.append(" -i ").append(TestUtils.IP_PREFIX); |
| 811 | 793 | result.append(" "); |
| 812 | - if (cassandraVersion != null) | |
| 813 | - result.append("-v ").append(cassandraVersion); | |
| 814 | - else | |
| 815 | - result.append(CASSANDRA_INSTALL_ARGS); | |
| 816 | 794 | if (nodes.length > 0) { |
| 817 | 795 | result.append(" -n "); |
| 818 | 796 | for (int i = 0; i < nodes.length; i++) { |
| @@ -822,8 +800,7 @@ | ||
| 822 | 800 | result.append(node); |
| 823 | 801 | } |
| 824 | 802 | } |
| 825 | - if (!createOptions.isEmpty()) | |
| 826 | - result.append(" ").append(Joiner.on(" ").join(createOptions)); | |
| 803 | + result.append(" ").append(Joiner.on(" ").join(createOptions)); | |
| 827 | 804 | return result.toString(); |
| 828 | 805 | } |
| 829 | 806 | |
| @@ -893,7 +870,7 @@ | ||
| 893 | 870 | if (!jvmArgs.equals(builder.jvmArgs)) return false; |
| 894 | 871 | if (!dseConfiguration.equals(builder.dseConfiguration)) return false; |
| 895 | 872 | if (!cassandraConfiguration.equals(builder.cassandraConfiguration)) return false; |
| 896 | - return cassandraVersion.equals(builder.cassandraVersion); | |
| 873 | + return version.equals(builder.version); | |
| 897 | 874 | } |
| 898 | 875 | |
| 899 | 876 | @Override |
| @@ -909,7 +886,7 @@ | ||
| 909 | 886 | result = 31 * result + thriftPort; |
| 910 | 887 | result = 31 * result + binaryPort; |
| 911 | 888 | result = 31 * result + storagePort; |
| 912 | - result = 31 * result + cassandraVersion.hashCode(); | |
| 889 | + result = 31 * result + version.hashCode(); | |
| 913 | 890 | return result; |
| 914 | 891 | } |
| 915 | 892 | } |
modified driver-core/src/test/java/com/datastax/driver/core/CCMConfig.java +7 −0
| @@ -43,6 +43,10 @@ | ||
| 43 | 43 | /** |
| 44 | 44 | * The C* or DSE version to use; defaults to the version defined by |
| 45 | 45 | * the System property {@code cassandra.version}. |
| 46 | + * <p/> | |
| 47 | + * Note that setting this property completely | |
| 48 | + * overrides the System properties {@code cassandra.version} | |
| 49 | + * and {@code cassandra.directory}. | |
| 46 | 50 | * |
| 47 | 51 | * @return The C* or DSE version to use |
| 48 | 52 | * @see CCMBridge#getCassandraVersion() |
| @@ -51,6 +55,9 @@ | ||
| 51 | 55 | |
| 52 | 56 | /** |
| 53 | 57 | * Whether to launch a DSE instance rather than an OSS C*. |
| 58 | + * <p/> | |
| 59 | + * Note that setting this property completely | |
| 60 | + * overrides the System property {@code dse}. | |
| 54 | 61 | * |
| 55 | 62 | * @return {@code true} to launch a DSE instance, {@code false} to launch an OSS C* instance (default). |
| 56 | 63 | */ |
modified driver-core/src/test/java/com/datastax/driver/core/CCMTestsSupport.java +294 −59
| @@ -16,17 +16,19 @@ | ||
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | 18 | import com.datastax.driver.core.CreateCCM.TestMode; |
| 19 | -import com.datastax.driver.core.policies.AddressTranslator; | |
| 20 | 19 | import com.google.common.base.Throwables; |
| 21 | 20 | import com.google.common.cache.*; |
| 22 | 21 | import com.google.common.collect.Lists; |
| 23 | 22 | import com.google.common.io.Closer; |
| 23 | +import com.google.common.util.concurrent.MoreExecutors; | |
| 24 | +import com.google.common.util.concurrent.ThreadFactoryBuilder; | |
| 24 | 25 | import org.slf4j.Logger; |
| 25 | 26 | import org.slf4j.LoggerFactory; |
| 26 | 27 | import org.testng.ITestResult; |
| 27 | 28 | import org.testng.annotations.*; |
| 28 | 29 | |
| 29 | 30 | import java.io.Closeable; |
| 31 | +import java.io.File; | |
| 30 | 32 | import java.io.IOException; |
| 31 | 33 | import java.lang.annotation.Annotation; |
| 32 | 34 | import java.lang.reflect.Constructor; |
| @@ -35,8 +37,7 @@ | ||
| 35 | 37 | import java.lang.reflect.ParameterizedType; |
| 36 | 38 | import java.net.InetSocketAddress; |
| 37 | 39 | import java.util.*; |
| 38 | -import java.util.concurrent.Callable; | |
| 39 | -import java.util.concurrent.ExecutionException; | |
| 40 | +import java.util.concurrent.*; | |
| 40 | 41 | import java.util.concurrent.atomic.AtomicInteger; |
| 41 | 42 | |
| 42 | 43 | import static com.datastax.driver.core.CreateCCM.TestMode.PER_CLASS; |
| @@ -53,6 +54,166 @@ | ||
| 53 | 54 | |
| 54 | 55 | private static final List<String> TEST_GROUPS = Lists.newArrayList("isolated", "short", "long", "stress", "duration"); |
| 55 | 56 | |
| 57 | + | |
| 58 | + private static class ReadOnlyCCMBridge implements CCMAccess { | |
| 59 | + | |
| 60 | + private final CCMAccess delegate; | |
| 61 | + | |
| 62 | + private ReadOnlyCCMBridge(CCMAccess delegate) { | |
| 63 | + this.delegate = delegate; | |
| 64 | + } | |
| 65 | + | |
| 66 | + @Override | |
| 67 | + public String getClusterName() { | |
| 68 | + return delegate.getClusterName(); | |
| 69 | + } | |
| 70 | + | |
| 71 | + @Override | |
| 72 | + public InetSocketAddress addressOfNode(int n) { | |
| 73 | + return delegate.addressOfNode(n); | |
| 74 | + } | |
| 75 | + | |
| 76 | + @Override | |
| 77 | + public VersionNumber getVersion() { | |
| 78 | + return delegate.getVersion(); | |
| 79 | + } | |
| 80 | + | |
| 81 | + @Override | |
| 82 | + public File getCcmDir() { | |
| 83 | + return delegate.getCcmDir(); | |
| 84 | + } | |
| 85 | + | |
| 86 | + @Override | |
| 87 | + public File getClusterDir() { | |
| 88 | + return delegate.getClusterDir(); | |
| 89 | + } | |
| 90 | + | |
| 91 | + @Override | |
| 92 | + public File getNodeDir(int n) { | |
| 93 | + return delegate.getNodeDir(n); | |
| 94 | + } | |
| 95 | + | |
| 96 | + @Override | |
| 97 | + public File getNodeConfDir(int n) { | |
| 98 | + return delegate.getNodeConfDir(n); | |
| 99 | + } | |
| 100 | + | |
| 101 | + @Override | |
| 102 | + public int getStoragePort() { | |
| 103 | + return delegate.getStoragePort(); | |
| 104 | + } | |
| 105 | + | |
| 106 | + @Override | |
| 107 | + public int getThriftPort() { | |
| 108 | + return delegate.getThriftPort(); | |
| 109 | + } | |
| 110 | + | |
| 111 | + @Override | |
| 112 | + public int getBinaryPort() { | |
| 113 | + return delegate.getBinaryPort(); | |
| 114 | + } | |
| 115 | + | |
| 116 | + @Override | |
| 117 | + public void setKeepLogs(boolean keepLogs) { | |
| 118 | + delegate.setKeepLogs(keepLogs); | |
| 119 | + } | |
| 120 | + | |
| 121 | + @Override | |
| 122 | + public void close() { | |
| 123 | + throw new UnsupportedOperationException("This CCM cluster is read-only"); | |
| 124 | + } | |
| 125 | + | |
| 126 | + @Override | |
| 127 | + public void start() { | |
| 128 | + throw new UnsupportedOperationException("This CCM cluster is read-only"); | |
| 129 | + } | |
| 130 | + | |
| 131 | + @Override | |
| 132 | + public void stop() { | |
| 133 | + throw new UnsupportedOperationException("This CCM cluster is read-only"); | |
| 134 | + } | |
| 135 | + | |
| 136 | + @Override | |
| 137 | + public void forceStop() { | |
| 138 | + throw new UnsupportedOperationException("This CCM cluster is read-only"); | |
| 139 | + } | |
| 140 | + | |
| 141 | + @Override | |
| 142 | + public void remove() { | |
| 143 | + throw new UnsupportedOperationException("This CCM cluster is read-only"); | |
| 144 | + } | |
| 145 | + | |
| 146 | + @Override | |
| 147 | + public void start(int n) { | |
| 148 | + throw new UnsupportedOperationException("This CCM cluster is read-only"); | |
| 149 | + } | |
| 150 | + | |
| 151 | + @Override | |
| 152 | + public void stop(int n) { | |
| 153 | + throw new UnsupportedOperationException("This CCM cluster is read-only"); | |
| 154 | + } | |
| 155 | + | |
| 156 | + @Override | |
| 157 | + public void forceStop(int n) { | |
| 158 | + throw new UnsupportedOperationException("This CCM cluster is read-only"); | |
| 159 | + } | |
| 160 | + | |
| 161 | + @Override | |
| 162 | + public void remove(int n) { | |
| 163 | + throw new UnsupportedOperationException("This CCM cluster is read-only"); | |
| 164 | + } | |
| 165 | + | |
| 166 | + @Override | |
| 167 | + public void add(int n) { | |
| 168 | + throw new UnsupportedOperationException("This CCM cluster is read-only"); | |
| 169 | + } | |
| 170 | + | |
| 171 | + @Override | |
| 172 | + public void add(int dc, int n) { | |
| 173 | + throw new UnsupportedOperationException("This CCM cluster is read-only"); | |
| 174 | + } | |
| 175 | + | |
| 176 | + @Override | |
| 177 | + public void decommision(int n) { | |
| 178 | + throw new UnsupportedOperationException("This CCM cluster is read-only"); | |
| 179 | + } | |
| 180 | + | |
| 181 | + @Override | |
| 182 | + public void updateConfig(Map<String, Object> configs) { | |
| 183 | + throw new UnsupportedOperationException("This CCM cluster is read-only"); | |
| 184 | + } | |
| 185 | + | |
| 186 | + @Override | |
| 187 | + public void updateDSEConfig(Map<String, Object> configs) { | |
| 188 | + throw new UnsupportedOperationException("This CCM cluster is read-only"); | |
| 189 | + } | |
| 190 | + | |
| 191 | + @Override | |
| 192 | + public void updateNodeConfig(int n, String key, Object value) { | |
| 193 | + throw new UnsupportedOperationException("This CCM cluster is read-only"); | |
| 194 | + } | |
| 195 | + | |
| 196 | + @Override | |
| 197 | + public void updateNodeConfig(int n, Map<String, Object> configs) { | |
| 198 | + throw new UnsupportedOperationException("This CCM cluster is read-only"); | |
| 199 | + } | |
| 200 | + | |
| 201 | + @Override | |
| 202 | + public void setWorkload(int node, String workload) { | |
| 203 | + throw new UnsupportedOperationException("This CCM cluster is read-only"); | |
| 204 | + } | |
| 205 | + | |
| 206 | + @Override | |
| 207 | + public void waitForUp(int node) { | |
| 208 | + throw new UnsupportedOperationException("This CCM cluster is read-only"); | |
| 209 | + } | |
| 210 | + | |
| 211 | + @Override | |
| 212 | + public void waitForDown(int node) { | |
| 213 | + throw new UnsupportedOperationException("This CCM cluster is read-only"); | |
| 214 | + } | |
| 215 | + } | |
| 216 | + | |
| 56 | 217 | private static class CCMTestConfig { |
| 57 | 218 | |
| 58 | 219 | private final List<CCMConfig> annotations; |
| @@ -110,6 +271,7 @@ | ||
| 110 | 271 | @SuppressWarnings("SimplifiableIfStatement") |
| 111 | 272 | private Map<String, Object> config() { |
| 112 | 273 | Map<String, Object> config = new HashMap<String, Object>(); |
| 274 | + config.put("start_rpc", false); | |
| 113 | 275 | for (int i = annotations.size() - 1; i == 0; i--) { |
| 114 | 276 | CCMConfig ann = annotations.get(i); |
| 115 | 277 | addConfigOptions(ann.config(), config); |
| @@ -205,8 +367,7 @@ | ||
| 205 | 367 | |
| 206 | 368 | private CCMBridge.Builder ccmBuilder() { |
| 207 | 369 | if (ccmBuilder == null) { |
| 208 | - ccmBuilder = CCMBridge.builder() | |
| 209 | - .withNodes(numberOfNodes()); | |
| 370 | + ccmBuilder = CCMBridge.builder().withNodes(numberOfNodes()); | |
| 210 | 371 | if (version() != null) |
| 211 | 372 | ccmBuilder.withVersion(version()); |
| 212 | 373 | if (dse()) |
| @@ -286,31 +447,115 @@ | ||
| 286 | 447 | } |
| 287 | 448 | } |
| 288 | 449 | |
| 450 | + private int weight() { | |
| 451 | + int weight = 0; | |
| 452 | + weight += totalNodes() - 1; | |
| 453 | + weight += config().size() - 1; | |
| 454 | + weight += dseConfig().size(); | |
| 455 | + weight += dse() ? 1 : 0; | |
| 456 | + weight += jvmArgs().size(); | |
| 457 | + weight += startOptions().size(); | |
| 458 | + weight += ssl() ? 1 : 0; | |
| 459 | + weight += auth() ? 1 : 0; | |
| 460 | + weight += version() != null ? 1 : 0; | |
| 461 | + return weight; | |
| 462 | + } | |
| 463 | + | |
| 464 | + private int totalNodes() { | |
| 465 | + int nodes = 0; | |
| 466 | + for (int nodesPerDc : numberOfNodes()) { | |
| 467 | + nodes += nodesPerDc; | |
| 468 | + } | |
| 469 | + return nodes; | |
| 470 | + } | |
| 471 | + } | |
| 472 | + | |
| 473 | + private static class CCMTestContextKey { | |
| 474 | + | |
| 475 | + private final CCMBridge.Builder builder; | |
| 476 | + | |
| 477 | + private final int weight; | |
| 478 | + | |
| 479 | + private CCMTestContextKey(CCMBridge.Builder builder, int weight) { | |
| 480 | + this.builder = builder; | |
| 481 | + this.weight = weight; | |
| 482 | + } | |
| 483 | + | |
| 484 | + @Override | |
| 485 | + public boolean equals(Object o) { | |
| 486 | + if (this == o) return true; | |
| 487 | + if (o == null || getClass() != o.getClass()) return false; | |
| 488 | + CCMTestContextKey that = (CCMTestContextKey) o; | |
| 489 | + return builder.equals(that.builder); | |
| 490 | + } | |
| 491 | + | |
| 492 | + @Override | |
| 493 | + public int hashCode() { | |
| 494 | + return builder.hashCode(); | |
| 495 | + } | |
| 496 | + } | |
| 497 | + | |
| 498 | + private static class CCMTestContext implements Runnable { | |
| 499 | + | |
| 500 | + private CCMAccess ccm; | |
| 501 | + | |
| 502 | + private final AtomicInteger refCount = new AtomicInteger(1); | |
| 503 | + | |
| 504 | + private volatile boolean evicted = false; | |
| 505 | + | |
| 506 | + private CCMTestContext(CCMAccess ccm) { | |
| 507 | + this(ccm, false); | |
| 508 | + } | |
| 509 | + | |
| 510 | + public CCMTestContext(CCMAccess ccm, boolean evicted) { | |
| 511 | + this.ccm = ccm; | |
| 512 | + this.evicted = evicted; | |
| 513 | + } | |
| 514 | + | |
| 515 | + @Override | |
| 516 | + public void run() { | |
| 517 | + if (ccm != null) | |
| 518 | + ccm.close(); | |
| 519 | + ccm = null; | |
| 520 | + } | |
| 521 | + | |
| 522 | + private void markEvicted() { | |
| 523 | + evicted = true; | |
| 524 | + } | |
| 525 | + | |
| 526 | + private void maybeClose() { | |
| 527 | + if (refCount.get() <= 0 && evicted) | |
| 528 | + POOL.execute(this); | |
| 529 | + } | |
| 289 | 530 | } |
| 290 | 531 | |
| 291 | - private static class CCMTestContextLoader extends CacheLoader<CCMBridge.Builder, CCMBridge> { | |
| 532 | + private static class CCMTestContextLoader extends CacheLoader<CCMTestContextKey, CCMTestContext> { | |
| 292 | 533 | |
| 293 | 534 | @Override |
| 294 | - public CCMBridge load(CCMBridge.Builder builder) { | |
| 295 | - return builder.build(); | |
| 535 | + public CCMTestContext load(CCMTestContextKey key) { | |
| 536 | + return new CCMTestContext(key.builder.build()); | |
| 296 | 537 | } |
| 297 | 538 | |
| 298 | 539 | } |
| 299 | 540 | |
| 300 | - private static class CCMTestContextWeigher implements Weigher<CCMBridge.Builder, CCMBridge> { | |
| 541 | + private static class CCMTestContextWeigher implements Weigher<CCMTestContextKey, CCMTestContext> { | |
| 542 | + | |
| 301 | 543 | @Override |
| 302 | - public int weigh(CCMBridge.Builder key, CCMBridge value) { | |
| 303 | - return value.getInitialNumberOfNodes(); | |
| 544 | + public int weigh(CCMTestContextKey key, CCMTestContext value) { | |
| 545 | + return key.weight; | |
| 304 | 546 | } |
| 547 | + | |
| 305 | 548 | } |
| 306 | 549 | |
| 307 | - private static class CCMTestContextRemovalListener implements RemovalListener<CCMBridge.Builder, CCMBridge> { | |
| 550 | + private static class CCMTestContextRemovalListener implements RemovalListener<CCMTestContextKey, CCMTestContext> { | |
| 308 | 551 | |
| 309 | 552 | @Override |
| 310 | - public void onRemoval(RemovalNotification<CCMBridge.Builder, CCMBridge> notification) { | |
| 311 | - if (notification.getValue() != null) { | |
| 312 | - LOGGER.debug("Evicting: " + notification.getValue()); | |
| 313 | - notification.getValue().close(); | |
| 553 | + public void onRemoval(RemovalNotification<CCMTestContextKey, CCMTestContext> notification) { | |
| 554 | + CCMTestContext context = notification.getValue(); | |
| 555 | + if (context != null && context.ccm != null) { | |
| 556 | + LOGGER.debug("Evicting: {} because of {}", context.ccm, notification.getCause()); | |
| 557 | + context.markEvicted(); | |
| 558 | + context.maybeClose(); | |
| 314 | 559 | } |
| 315 | 560 | } |
| 316 | 561 | |
| @@ -319,7 +564,11 @@ | ||
| 319 | 564 | /** |
| 320 | 565 | * A LoadingCache that stores running CCM clusters. |
| 321 | 566 | */ |
| 322 | - private static final LoadingCache<CCMBridge.Builder, CCMBridge> CACHE; | |
| 567 | + private static final LoadingCache<CCMTestContextKey, CCMTestContext> CACHE; | |
| 568 | + | |
| 569 | + private static final ExecutorService POOL = MoreExecutors.getExitingExecutorService( | |
| 570 | + (ThreadPoolExecutor) Executors.newFixedThreadPool(2, | |
| 571 | + new ThreadFactoryBuilder().setNameFormat("ccm-removal-%d").build())); | |
| 323 | 572 | |
| 324 | 573 | static { |
| 325 | 574 | long maximumWeight; |
| @@ -329,14 +578,16 @@ | ||
| 329 | 578 | if (freeMemoryMB < 1000) |
| 330 | 579 | LOGGER.warn("Available memory below 1GB: {}MB, CCM clusters might fail to start", freeMemoryMB); |
| 331 | 580 | // CCM nodes are started with -Xms500M -Xmx500M |
| 332 | - // leave at least 500 MB out, with a minimum of 1 node and a maximum of 10 nodes | |
| 333 | - maximumWeight = Math.min(10, Math.max(1, (freeMemoryMB / 500) - 1)); | |
| 581 | + // so 1 "slot" is roughly 500MB | |
| 582 | + // leave at least 2 slots out, with a minimum of 1 slot and a maximum of 6 slots | |
| 583 | + long slotsAvailable = (freeMemoryMB / 500) - 2; | |
| 584 | + maximumWeight = Math.min(6, Math.max(1, slotsAvailable)); | |
| 334 | 585 | } else { |
| 335 | 586 | maximumWeight = Integer.parseInt(numberOfNodes); |
| 336 | 587 | } |
| 337 | 588 | LOGGER.info("Maximum number of running CCM nodes: {}", maximumWeight); |
| 338 | 589 | CACHE = CacheBuilder.newBuilder() |
| 339 | - .initialCapacity(1) | |
| 590 | + .initialCapacity(3) | |
| 340 | 591 | .maximumWeight(maximumWeight) |
| 341 | 592 | .weigher(new CCMTestContextWeigher()) |
| 342 | 593 | .removalListener(new CCMTestContextRemovalListener()) |
| @@ -347,7 +598,9 @@ | ||
| 347 | 598 | |
| 348 | 599 | private CCMTestConfig ccmTestConfig; |
| 349 | 600 | |
| 350 | - protected CCMBridge ccm; | |
| 601 | + private CCMTestContext ccmTestContext; | |
| 602 | + | |
| 603 | + protected CCMAccess ccm; | |
| 351 | 604 | |
| 352 | 605 | protected Cluster cluster; |
| 353 | 606 | |
| @@ -540,36 +793,6 @@ | ||
| 540 | 793 | return contactPoints; |
| 541 | 794 | } |
| 542 | 795 | |
| 543 | - /** | |
| 544 | - * Returns the address of the {@code nth} host in the CCM cluster (counting from 1, i.e., | |
| 545 | - * {@code getHostAddress(1)} returns the address of the first node. | |
| 546 | - * <p/> | |
| 547 | - * In multi-DC setups, nodes are numbered in ascending order of their datacenter number. | |
| 548 | - * E.g. with 2 DCs and 3 nodes in each DC, the first node in DC 2 is number 4. | |
| 549 | - * <p/> | |
| 550 | - * This method should not be called before the test has started, nor after the test is finished. | |
| 551 | - * | |
| 552 | - * @return the address of the {@code nth} host in the cluster. | |
| 553 | - */ | |
| 554 | - public InetSocketAddress getHostAddress(int n) { | |
| 555 | - return ccm.addressOfNode(n); | |
| 556 | - } | |
| 557 | - | |
| 558 | - /** | |
| 559 | - * Returns an {@link AddressTranslator} to use when tests must manually create | |
| 560 | - * {@link Cluster} instances. | |
| 561 | - * <p/> | |
| 562 | - * This translator is necessary because hosts create with this class do not use standard ports. | |
| 563 | - * <p/> | |
| 564 | - * This method should not be called before the test has started, nor after the test is finished. | |
| 565 | - * | |
| 566 | - * @return an {@link AddressTranslator} to use when tests must manually create | |
| 567 | - * {@link Cluster} instances. | |
| 568 | - */ | |
| 569 | - public AddressTranslator getAddressTranslator() { | |
| 570 | - return ccm.addressTranslator(); | |
| 571 | - } | |
| 572 | - | |
| 573 | 796 | /** |
| 574 | 797 | * Registers the given {@link Closeable} to be closed at the end of the current test method. |
| 575 | 798 | * <p/> |
| @@ -590,22 +813,32 @@ | ||
| 590 | 813 | if (ccmTestConfig.createCcm()) { |
| 591 | 814 | if (ccmTestConfig.dirtiesContext()) { |
| 592 | 815 | ccm = ccmTestConfig.ccmBuilder().build(); |
| 816 | + ccmTestContext = new CCMTestContext(ccm, true); | |
| 593 | 817 | LOGGER.debug("Using dedicated {}", ccm); |
| 594 | 818 | } else { |
| 595 | - CCMBridge.Builder key = ccmTestConfig.ccmBuilder(); | |
| 596 | - ccm = CACHE.getIfPresent(key); | |
| 597 | - if (ccm != null) { | |
| 819 | + CCMBridge.Builder builder = ccmTestConfig.ccmBuilder(); | |
| 820 | + int weight = ccmTestConfig.weight(); | |
| 821 | + CCMTestContextKey key = new CCMTestContextKey(builder, weight); | |
| 822 | + CCMAccess ccm; | |
| 823 | + ccmTestContext = CACHE.getIfPresent(key); | |
| 824 | + if (ccmTestContext != null) { | |
| 825 | + ccmTestContext.refCount.incrementAndGet(); | |
| 826 | + ccm = ccmTestContext.ccm; | |
| 598 | 827 | LOGGER.debug("Reusing {}", ccm); |
| 599 | 828 | } else { |
| 600 | 829 | try { |
| 601 | - ccm = CACHE.get(ccmTestConfig.ccmBuilder()); | |
| 830 | + ccmTestContext = CACHE.get(key); | |
| 831 | + ccm = ccmTestContext.ccm; | |
| 602 | 832 | LOGGER.debug("Using newly-created {}", ccm); |
| 603 | 833 | } catch (ExecutionException e) { |
| 604 | - Throwables.propagate(e); | |
| 834 | + throw Throwables.propagate(e); | |
| 605 | 835 | } |
| 606 | 836 | } |
| 837 | + this.ccm = new ReadOnlyCCMBridge(ccm); | |
| 607 | 838 | } |
| 839 | + assert ccmTestContext != null; | |
| 608 | 840 | assert ccm != null; |
| 841 | + | |
| 609 | 842 | } |
| 610 | 843 | } |
| 611 | 844 | |
| @@ -615,7 +848,7 @@ | ||
| 615 | 848 | // add contact points only if the provided builder didn't do so |
| 616 | 849 | if (builder.getContactPoints().isEmpty()) |
| 617 | 850 | builder.addContactPointsWithPorts(getInitialContactPoints()); |
| 618 | - builder.withAddressTranslator(ccm.addressTranslator()); | |
| 851 | + builder.withPort(ccm.getBinaryPort()); | |
| 619 | 852 | cluster = register(builder.build()); |
| 620 | 853 | cluster.init(); |
| 621 | 854 | } |
| @@ -656,10 +889,12 @@ | ||
| 656 | 889 | } |
| 657 | 890 | |
| 658 | 891 | private void closeTestContext() { |
| 659 | - if (ccmTestConfig != null && ccm != null && ccmTestConfig.dirtiesContext()) { | |
| 660 | - ccm.close(); | |
| 892 | + if (ccmTestContext != null) { | |
| 893 | + ccmTestContext.refCount.decrementAndGet(); | |
| 894 | + ccmTestContext.maybeClose(); | |
| 661 | 895 | } |
| 662 | 896 | ccmTestConfig = null; |
| 897 | + ccmTestContext = null; | |
| 663 | 898 | ccm = null; |
| 664 | 899 | } |
| 665 | 900 |
modified driver-core/src/test/java/com/datastax/driver/core/ClusterInitTest.java +2 −2
| @@ -231,8 +231,8 @@ | ||
| 231 | 231 | .forcePeerInfo(1, 2, "release_version", "1.2.19") |
| 232 | 232 | .build(); |
| 233 | 233 | Cluster cluster = Cluster.builder() |
| 234 | - .addContactPointsWithPorts(scassandraCluster.address(1)) | |
| 235 | - .withAddressTranslator(scassandraCluster.addressTranslator()) | |
| 234 | + .addContactPoints(scassandraCluster.address(1).getAddress()) | |
| 235 | + .withPort(scassandraCluster.getBinaryPort()) | |
| 236 | 236 | .withNettyOptions(nonQuietClusterCloseOptions) |
| 237 | 237 | .build(); |
| 238 | 238 |
modified driver-core/src/test/java/com/datastax/driver/core/ControlConnectionTest.java +11 −11
| @@ -61,8 +61,8 @@ | ||
| 61 | 61 | |
| 62 | 62 | // We pass only the first host as contact point, so we know the control connection will be on this host |
| 63 | 63 | cluster = register(Cluster.builder() |
| 64 | - .addContactPointsWithPorts(getHostAddress(1)) | |
| 65 | - .withAddressTranslator(getAddressTranslator()) | |
| 64 | + .addContactPoints(ccm.addressOfNode(1).getAddress()) | |
| 65 | + .withPort(ccm.getBinaryPort()) | |
| 66 | 66 | .withReconnectionPolicy(reconnectionPolicy) |
| 67 | 67 | .withLoadBalancingPolicy(loadBalancingPolicy) |
| 68 | 68 | .build()); |
| @@ -88,11 +88,11 @@ | ||
| 88 | 88 | @CassandraVersion(major = 2.1) |
| 89 | 89 | public void should_parse_UDT_definitions_when_using_default_protocol_version() { |
| 90 | 90 | Cluster cluster; |
| 91 | - InetSocketAddress firstHost = getHostAddress(1); | |
| 91 | + InetSocketAddress firstHost = ccm.addressOfNode(1); | |
| 92 | 92 | // First driver instance: create UDT |
| 93 | 93 | cluster = register(Cluster.builder() |
| 94 | 94 | .addContactPointsWithPorts(firstHost) |
| 95 | - .withAddressTranslator(getAddressTranslator()) | |
| 95 | + .withPort(ccm.getBinaryPort()) | |
| 96 | 96 | .build()); |
| 97 | 97 | Session session = cluster.connect(); |
| 98 | 98 | session.execute("create keyspace ks WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}"); |
| @@ -118,10 +118,10 @@ | ||
| 118 | 118 | @Test(groups = "long") |
| 119 | 119 | @CCMConfig(numberOfNodes = 3) |
| 120 | 120 | public void should_reestablish_if_control_node_decommissioned() throws InterruptedException { |
| 121 | - InetSocketAddress firstHost = getHostAddress(1); | |
| 121 | + InetSocketAddress firstHost = ccm.addressOfNode(1); | |
| 122 | 122 | Cluster cluster = register(Cluster.builder() |
| 123 | 123 | .addContactPointsWithPorts(firstHost) |
| 124 | - .withAddressTranslator(getAddressTranslator()) | |
| 124 | + .withPort(ccm.getBinaryPort()) | |
| 125 | 125 | .withQueryOptions(nonDebouncingQueryOptions()) |
| 126 | 126 | .build()); |
| 127 | 127 | cluster.init(); |
| @@ -131,7 +131,7 @@ | ||
| 131 | 131 | assertThat(controlHost).isEqualTo(firstHost.getAddress()); |
| 132 | 132 | |
| 133 | 133 | // Decommission the node. |
| 134 | - ccm.decommissionNode(1); | |
| 134 | + ccm.decommision(1); | |
| 135 | 135 | |
| 136 | 136 | // Ensure that the new control connection is not null and it's host is not equal to the decommissioned node. |
| 137 | 137 | Host newHost = cluster.manager.controlConnection.connectedHost(); |
| @@ -161,15 +161,15 @@ | ||
| 161 | 161 | scassandras.init(); |
| 162 | 162 | |
| 163 | 163 | try { |
| 164 | - Collection<InetSocketAddress> contactPoints = newArrayList(); | |
| 164 | + Collection<InetAddress> contactPoints = newArrayList(); | |
| 165 | 165 | for (int i = 1; i <= hostCount; i++) { |
| 166 | - contactPoints.add(scassandras.address(i)); | |
| 166 | + contactPoints.add(scassandras.address(i).getAddress()); | |
| 167 | 167 | } |
| 168 | 168 | final HashMultiset<InetAddress> occurrencesByHost = HashMultiset.create(hostCount); |
| 169 | 169 | for (int i = 0; i < iterations; i++) { |
| 170 | 170 | Cluster cluster = Cluster.builder() |
| 171 | - .addContactPointsWithPorts(contactPoints) | |
| 172 | - .withAddressTranslator(scassandras.addressTranslator()) | |
| 171 | + .addContactPoints(contactPoints) | |
| 172 | + .withPort(scassandras.getBinaryPort()) | |
| 173 | 173 | .withNettyOptions(nonQuietClusterCloseOptions) |
| 174 | 174 | .build(); |
| 175 | 175 |
modified driver-core/src/test/java/com/datastax/driver/core/CustomPayloadTest.java +1 −1
| @@ -241,7 +241,7 @@ | ||
| 241 | 241 | try { |
| 242 | 242 | v3cluster = Cluster.builder() |
| 243 | 243 | .addContactPointsWithPorts(getInitialContactPoints()) |
| 244 | - .withAddressTranslator(getAddressTranslator()) | |
| 244 | + .withPort(ccm.getBinaryPort()) | |
| 245 | 245 | .withProtocolVersion(V3) |
| 246 | 246 | .build() |
| 247 | 247 | .init(); |
added driver-core/src/test/java/com/datastax/driver/core/DseCCMClusterTest.java +71 −0
| @@ -0,0 +1,71 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (C) 2012-2015 DataStax Inc. | |
| 3 | + * | |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | + * you may not use this file except in compliance with the License. | |
| 6 | + * You may obtain a copy of the License at | |
| 7 | + * | |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | + * | |
| 10 | + * Unless required by applicable law or agreed to in writing, software | |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | + * See the License for the specific language governing permissions and | |
| 14 | + * limitations under the License. | |
| 15 | + */ | |
| 16 | +package com.datastax.driver.core; | |
| 17 | + | |
| 18 | +import org.testng.annotations.Test; | |
| 19 | + | |
| 20 | +/** | |
| 21 | + * A simple test to validate DSE setups. | |
| 22 | + * <p/> | |
| 23 | + * <h3>Running all tests against DSE</h3> | |
| 24 | + * <p/> | |
| 25 | + * To run tests globally against DSE, set the system property {@code dse} | |
| 26 | + * to {@code true}. | |
| 27 | + * <p/> | |
| 28 | + * When this flag is provided, it is assumed a DSE version is passed under | |
| 29 | + * the system property {@code cassandra.version}. | |
| 30 | + * A mapping for determining C* version from DSE version is described in {@link CCMBridge}. | |
| 31 | + * <p/> | |
| 32 | + * Example usages: | |
| 33 | + * <p/> | |
| 34 | + * DSE 4.8.3: | |
| 35 | + * <pre> | |
| 36 | + * -Ddse -Dcassandra.version=4.8.3 | |
| 37 | + * -Ddse=true -Dcassandra.version=4.8.3 | |
| 38 | + * </pre> | |
| 39 | + * <p/> | |
| 40 | + * Custom local install of DSE 5.0 (using {@code cassandra.directory} instead of {@code cassandra.version}): | |
| 41 | + * <pre> | |
| 42 | + * -Dcassandra.version=5.0 -Ddse -Dcassandra.directory=/path/to/dse | |
| 43 | + * </pre> | |
| 44 | + * <p/> | |
| 45 | + * <h3>Running a specific test against DSE</h3> | |
| 46 | + * <p/> | |
| 47 | + * Set the following properties on the test: | |
| 48 | + * <pre>{@code @CCMConfig(dse = true, version = "4.8.3")}</pre> | |
| 49 | + * | |
| 50 | + * <h3>Supplying DSE credentials</h3> | |
| 51 | + * | |
| 52 | + * Rather than adding system properties for DSE credentials, | |
| 53 | + * DSE tests rely on a recent change in CCM to support providing | |
| 54 | + * credentials via {@code $HOME/.ccm/.dse.ini}. | |
| 55 | + * | |
| 56 | + * The contents of this file need to be formed in this way: | |
| 57 | + * <pre> | |
| 58 | + * [dse_credentials] | |
| 59 | + * dse_username = myusername | |
| 60 | + * dse_password = mypassword | |
| 61 | + * </pre> | |
| 62 | + */ | |
| 63 | +@Test(enabled = false) | |
| 64 | +@CCMConfig(dse = true, version = "4.8.3") | |
| 65 | +public class DseCCMClusterTest extends CCMTestsSupport { | |
| 66 | + | |
| 67 | + @Test(groups = "short") | |
| 68 | + public void should_conenct_to_dse() throws InterruptedException { | |
| 69 | + } | |
| 70 | + | |
| 71 | +} |
modified driver-core/src/test/java/com/datastax/driver/core/EventDebouncerIntegrationTest.java +2 −2
| @@ -44,8 +44,8 @@ | ||
| 44 | 44 | public void should_wait_until_load_balancing_policy_is_fully_initialized() throws InterruptedException { |
| 45 | 45 | TestLoadBalancingPolicy policy = new TestLoadBalancingPolicy(); |
| 46 | 46 | final Cluster cluster = register(createClusterBuilderNoDebouncing() |
| 47 | - .addContactPointsWithPorts(getHostAddress(1)) | |
| 48 | - .withAddressTranslator(getAddressTranslator()) | |
| 47 | + .addContactPoints(ccm.addressOfNode(1).getAddress()) | |
| 48 | + .withPort(ccm.getBinaryPort()) | |
| 49 | 49 | .withLoadBalancingPolicy(policy).build()); |
| 50 | 50 | new Thread() { |
| 51 | 51 | @Override |
modified driver-core/src/test/java/com/datastax/driver/core/HeartbeatTest.java +4 −4
| @@ -57,8 +57,8 @@ | ||
| 57 | 57 | @Test(groups = "long") |
| 58 | 58 | public void should_send_heartbeat_when_connection_is_inactive() throws InterruptedException { |
| 59 | 59 | Cluster cluster = register(Cluster.builder() |
| 60 | - .addContactPointsWithPorts(getHostAddress(1)) | |
| 61 | - .withAddressTranslator(getAddressTranslator()) | |
| 60 | + .addContactPoints(ccm.addressOfNode(1).getAddress()) | |
| 61 | + .withPort(ccm.getBinaryPort()) | |
| 62 | 62 | .withPoolingOptions(new PoolingOptions() |
| 63 | 63 | .setHeartbeatIntervalSeconds(3)) |
| 64 | 64 | .build()); |
| @@ -113,8 +113,8 @@ | ||
| 113 | 113 | @Test(groups = "long") |
| 114 | 114 | public void should_not_send_heartbeat_when_disabled() throws InterruptedException { |
| 115 | 115 | Cluster cluster = register(Cluster.builder() |
| 116 | - .addContactPointsWithPorts(getHostAddress(1)) | |
| 117 | - .withAddressTranslator(getAddressTranslator()) | |
| 116 | + .addContactPoints(ccm.addressOfNode(1).getAddress()) | |
| 117 | + .withPort(ccm.getBinaryPort()) | |
| 118 | 118 | .withPoolingOptions(new PoolingOptions() |
| 119 | 119 | .setHeartbeatIntervalSeconds(0)) |
| 120 | 120 | .build()); |
modified driver-core/src/test/java/com/datastax/driver/core/HostConnectionPoolMultiTest.java +2 −2
| @@ -53,8 +53,8 @@ | ||
| 53 | 53 | PoolingOptions poolingOptions = new PoolingOptions().setConnectionsPerHost(LOCAL, core, max); |
| 54 | 54 | SocketOptions socketOptions = new SocketOptions().setReadTimeoutMillis(1000); |
| 55 | 55 | cluster = Cluster.builder() |
| 56 | - .addContactPointsWithPorts(scassandra.address(1)) | |
| 57 | - .withAddressTranslator(scassandra.addressTranslator()) | |
| 56 | + .addContactPoints(scassandra.address(1).getAddress()) | |
| 57 | + .withPort(scassandra.getBinaryPort()) | |
| 58 | 58 | .withQueryOptions(nonDebouncingQueryOptions()) |
| 59 | 59 | .withPoolingOptions(poolingOptions) |
| 60 | 60 | .withSocketOptions(socketOptions) |
modified driver-core/src/test/java/com/datastax/driver/core/LoadBalancingPolicyBootstrapTest.java +2 −2
| @@ -49,7 +49,7 @@ | ||
| 49 | 49 | |
| 50 | 50 | Cluster cluster = register(Cluster.builder() |
| 51 | 51 | .addContactPointsWithPorts(getInitialContactPoints()) |
| 52 | - .withAddressTranslator(ccm.addressTranslator()) | |
| 52 | + .withPort(ccm.getBinaryPort()) | |
| 53 | 53 | .withLoadBalancingPolicy(policy) |
| 54 | 54 | .build()); |
| 55 | 55 | |
| @@ -91,7 +91,7 @@ | ||
| 91 | 91 | HistoryPolicy policy = new HistoryPolicy(new RoundRobinPolicy()); |
| 92 | 92 | Cluster cluster = register(Cluster.builder() |
| 93 | 93 | .addContactPointsWithPorts(getInitialContactPoints()) |
| 94 | - .withAddressTranslator(ccm.addressTranslator()) | |
| 94 | + .withPort(ccm.getBinaryPort()) | |
| 95 | 95 | .withLoadBalancingPolicy(policy) |
| 96 | 96 | .build()); |
| 97 | 97 |
modified driver-core/src/test/java/com/datastax/driver/core/MetadataTest.java +3 −3
| @@ -55,8 +55,8 @@ | ||
| 55 | 55 | @CCMConfig(numberOfNodes = 3, dirtiesContext = true, createCluster = false) |
| 56 | 56 | public void should_update_metadata_on_topology_change() { |
| 57 | 57 | Cluster cluster = register(Cluster.builder() |
| 58 | - .addContactPointsWithPorts(getHostAddress(1)) | |
| 59 | - .withAddressTranslator(getAddressTranslator()) | |
| 58 | + .addContactPoints(ccm.addressOfNode(1).getAddress()) | |
| 59 | + .withPort(ccm.getBinaryPort()) | |
| 60 | 60 | .withQueryOptions(nonDebouncingQueryOptions()) |
| 61 | 61 | .build()); |
| 62 | 62 | Session session = cluster.connect(); |
| @@ -73,7 +73,7 @@ | ||
| 73 | 73 | Host host3 = TestUtils.findHost(cluster, 3); |
| 74 | 74 | Token host3Token = tokensForHost.get(host3); |
| 75 | 75 | |
| 76 | - ccm.decommissionNode(3); | |
| 76 | + ccm.decommision(3); | |
| 77 | 77 | ccm.remove(3); |
| 78 | 78 | |
| 79 | 79 | // Ensure that the token ranges were updated, there should only be 2 ranges now. |
modified driver-core/src/test/java/com/datastax/driver/core/MetricsTest.java +2 −2
| @@ -126,7 +126,7 @@ | ||
| 126 | 126 | public void metrics_should_be_null_when_metrics_disabled() throws Exception { |
| 127 | 127 | Cluster cluster = register(Cluster.builder() |
| 128 | 128 | .addContactPointsWithPorts(getInitialContactPoints()) |
| 129 | - .withAddressTranslator(getAddressTranslator()) | |
| 129 | + .withPort(ccm.getBinaryPort()) | |
| 130 | 130 | .withoutMetrics() |
| 131 | 131 | .build()); |
| 132 | 132 | try { |
| @@ -151,7 +151,7 @@ | ||
| 151 | 151 | public void should_be_no_jmx_mbean_when_jmx_is_disabled() throws Exception { |
| 152 | 152 | Cluster cluster = register(Cluster.builder() |
| 153 | 153 | .addContactPointsWithPorts(getInitialContactPoints()) |
| 154 | - .withAddressTranslator(getAddressTranslator()) | |
| 154 | + .withPort(ccm.getBinaryPort()) | |
| 155 | 155 | .withoutJMXReporting() |
| 156 | 156 | .build()); |
| 157 | 157 | try { |
modified driver-core/src/test/java/com/datastax/driver/core/MissingRpcAddressTest.java +4 −4
| @@ -42,8 +42,8 @@ | ||
| 42 | 42 | deleteNode2RpcAddressFromNode1(); |
| 43 | 43 | // Use only one contact point to make sure that the control connection is on node1 |
| 44 | 44 | Cluster cluster = register(Cluster.builder() |
| 45 | - .addContactPointsWithPorts(getHostAddress(1)) | |
| 46 | - .withAddressTranslator(getAddressTranslator()) | |
| 45 | + .addContactPoints(ccm.addressOfNode(1).getAddress()) | |
| 46 | + .withPort(ccm.getBinaryPort()) | |
| 47 | 47 | .build()); |
| 48 | 48 | cluster.connect(); |
| 49 | 49 | |
| @@ -54,10 +54,10 @@ | ||
| 54 | 54 | |
| 55 | 55 | // Artificially modify the system tables to simulate the missing rpc_address. |
| 56 | 56 | private void deleteNode2RpcAddressFromNode1() throws Exception { |
| 57 | - InetSocketAddress firstHost = getHostAddress(1); | |
| 57 | + InetSocketAddress firstHost = ccm.addressOfNode(1); | |
| 58 | 58 | Cluster cluster = register(Cluster.builder() |
| 59 | 59 | .addContactPointsWithPorts(singleton(firstHost)) |
| 60 | - .withAddressTranslator(getAddressTranslator()) | |
| 60 | + .withPort(ccm.getBinaryPort()) | |
| 61 | 61 | // ensure we will only connect to node1 |
| 62 | 62 | .withLoadBalancingPolicy(new WhiteListPolicy(Policies.defaultLoadBalancingPolicy(), |
| 63 | 63 | Lists.newArrayList(firstHost))) |
modified driver-core/src/test/java/com/datastax/driver/core/NettyOptionsTest.java +1 −1
| @@ -64,7 +64,7 @@ | ||
| 64 | 64 | }).when(nettyOptions).afterChannelInitialized(any(SocketChannel.class)); |
| 65 | 65 | cluster = Cluster.builder() |
| 66 | 66 | .addContactPointsWithPorts(ccm.addressOfNode(1)) |
| 67 | - .withAddressTranslator(ccm.addressTranslator()) | |
| 67 | + .withPort(ccm.getBinaryPort()) | |
| 68 | 68 | .withPoolingOptions(new PoolingOptions() |
| 69 | 69 | .setConnectionsPerHost(HostDistance.LOCAL, coreConnections, coreConnections) |
| 70 | 70 | ) |
modified driver-core/src/test/java/com/datastax/driver/core/NodeRefreshDebouncerTest.java +2 −2
| @@ -43,8 +43,8 @@ | ||
| 43 | 43 | int refreshNodeInterval = 30000; |
| 44 | 44 | QueryOptions queryOptions = new QueryOptions().setRefreshNodeIntervalMillis(refreshNodeInterval); |
| 45 | 45 | Cluster cluster = register(Cluster.builder() |
| 46 | - .addContactPointsWithPorts(getHostAddress(1)) | |
| 47 | - .withAddressTranslator(getAddressTranslator()) | |
| 46 | + .addContactPoints(ccm.addressOfNode(1).getAddress()) | |
| 47 | + .withPort(ccm.getBinaryPort()) | |
| 48 | 48 | .withQueryOptions(queryOptions) |
| 49 | 49 | .build()); |
| 50 | 50 | cluster.connect(); |
modified driver-core/src/test/java/com/datastax/driver/core/PoolingOptionsTest.java +44 −0
| @@ -93,5 +93,49 @@ | ||
| 93 | 93 | assertThat(options.getCoreConnectionsPerHost(LOCAL)).isEqualTo(10); |
| 94 | 94 | assertThat(options.getMaxConnectionsPerHost(LOCAL)).isEqualTo(15); |
| 95 | 95 | } |
| 96 | + | |
| 97 | + @Test(groups = "unit") | |
| 98 | + public void should_leave_connection_options_unset_until_protocol_version_known() { | |
| 99 | + PoolingOptions options = new PoolingOptions(); | |
| 100 | + | |
| 101 | + assertThat(options.getCoreConnectionsPerHost(LOCAL)).isEqualTo(PoolingOptions.UNSET); | |
| 102 | + assertThat(options.getCoreConnectionsPerHost(REMOTE)).isEqualTo(PoolingOptions.UNSET); | |
| 103 | + assertThat(options.getMaxConnectionsPerHost(LOCAL)).isEqualTo(PoolingOptions.UNSET); | |
| 104 | + assertThat(options.getMaxConnectionsPerHost(REMOTE)).isEqualTo(PoolingOptions.UNSET); | |
| 105 | + assertThat(options.getNewConnectionThreshold(LOCAL)).isEqualTo(PoolingOptions.UNSET); | |
| 106 | + assertThat(options.getNewConnectionThreshold(REMOTE)).isEqualTo(PoolingOptions.UNSET); | |
| 107 | + assertThat(options.getMaxRequestsPerConnection(LOCAL)).isEqualTo(PoolingOptions.UNSET); | |
| 108 | + assertThat(options.getMaxRequestsPerConnection(REMOTE)).isEqualTo(PoolingOptions.UNSET); | |
| 109 | + } | |
| 110 | + | |
| 111 | + @Test(groups = "unit") | |
| 112 | + public void should_reject_negative_connection_options_even_when_protocol_version_unknown() { | |
| 113 | + PoolingOptions options = new PoolingOptions(); | |
| 114 | + | |
| 115 | + try { | |
| 116 | + options.setCoreConnectionsPerHost(LOCAL, -1); | |
| 117 | + fail("expected an IllegalArgumentException"); | |
| 118 | + } catch (IllegalArgumentException e) { /*expected*/ } | |
| 119 | + try { | |
| 120 | + options.setMaxConnectionsPerHost(LOCAL, -1); | |
| 121 | + fail("expected an IllegalArgumentException"); | |
| 122 | + } catch (IllegalArgumentException e) { /*expected*/ } | |
| 123 | + try { | |
| 124 | + options.setConnectionsPerHost(LOCAL, -1, 1); | |
| 125 | + fail("expected an IllegalArgumentException"); | |
| 126 | + } catch (IllegalArgumentException e) { /*expected*/ } | |
| 127 | + try { | |
| 128 | + options.setConnectionsPerHost(LOCAL, -2, -1); | |
| 129 | + fail("expected an IllegalArgumentException"); | |
| 130 | + } catch (IllegalArgumentException e) { /*expected*/ } | |
| 131 | + try { | |
| 132 | + options.setNewConnectionThreshold(LOCAL, -1); | |
| 133 | + fail("expected an IllegalArgumentException"); | |
| 134 | + } catch (IllegalArgumentException e) { /*expected*/ } | |
| 135 | + try { | |
| 136 | + options.setMaxRequestsPerConnection(LOCAL, -1); | |
| 137 | + fail("expected an IllegalArgumentException"); | |
| 138 | + } catch (IllegalArgumentException e) { /*expected*/ } | |
| 139 | + } | |
| 96 | 140 | } |
| 97 | 141 |
modified driver-core/src/test/java/com/datastax/driver/core/PreparedStatementTest.java +3 −3
| @@ -407,7 +407,7 @@ | ||
| 407 | 407 | public void should_fail_when_prepared_on_another_cluster() throws Exception { |
| 408 | 408 | Cluster otherCluster = Cluster.builder() |
| 409 | 409 | .addContactPointsWithPorts(getInitialContactPoints()) |
| 410 | - .withAddressTranslator(getAddressTranslator()) | |
| 410 | + .withPort(ccm.getBinaryPort()) | |
| 411 | 411 | .build(); |
| 412 | 412 | try { |
| 413 | 413 | PreparedStatement pst = otherCluster.connect().prepare("select * from system.peers where inet = ?"); |
| @@ -434,7 +434,7 @@ | ||
| 434 | 434 | public void should_not_allow_unbound_value_on_bound_statement_when_protocol_lesser_than_v4() { |
| 435 | 435 | Cluster cluster = Cluster.builder() |
| 436 | 436 | .addContactPointsWithPorts(getInitialContactPoints()) |
| 437 | - .withAddressTranslator(getAddressTranslator()) | |
| 437 | + .withPort(ccm.getBinaryPort()) | |
| 438 | 438 | .withProtocolVersion(TestUtils.getDesiredProtocolVersion(ProtocolVersion.V3)) |
| 439 | 439 | .build(); |
| 440 | 440 | Session session = cluster.connect(); |
| @@ -467,7 +467,7 @@ | ||
| 467 | 467 | public void should_not_allow_unbound_value_on_batch_statement_when_protocol_lesser_than_v4() { |
| 468 | 468 | Cluster cluster = Cluster.builder() |
| 469 | 469 | .addContactPointsWithPorts(getInitialContactPoints()) |
| 470 | - .withAddressTranslator(getAddressTranslator()) | |
| 470 | + .withPort(ccm.getBinaryPort()) | |
| 471 | 471 | .withProtocolVersion(TestUtils.getDesiredProtocolVersion(ProtocolVersion.V3)) |
| 472 | 472 | .build(); |
| 473 | 473 | Session session = cluster.connect(); |
modified driver-core/src/test/java/com/datastax/driver/core/QueryOptionsTest.java +2 −2
| @@ -49,8 +49,8 @@ | ||
| 49 | 49 | queryOptions = new QueryOptions(); |
| 50 | 50 | loadBalancingPolicy = new SortingLoadBalancingPolicy(); |
| 51 | 51 | cluster = Cluster.builder() |
| 52 | - .addContactPointsWithPorts(scassandra.address(2)) | |
| 53 | - .withAddressTranslator(scassandra.addressTranslator()) | |
| 52 | + .addContactPoints(scassandra.address(2).getAddress()) | |
| 53 | + .withPort(scassandra.getBinaryPort()) | |
| 54 | 54 | .withLoadBalancingPolicy(loadBalancingPolicy) |
| 55 | 55 | .withQueryOptions(queryOptions) |
| 56 | 56 | .withNettyOptions(nonQuietClusterCloseOptions) |
modified driver-core/src/test/java/com/datastax/driver/core/RecommissionedNodeTest.java +8 −8
| @@ -51,8 +51,8 @@ | ||
| 51 | 51 | |
| 52 | 52 | // Now start the driver that will connect to node2 and node3, and consider node1 down |
| 53 | 53 | mainCluster = Cluster.builder() |
| 54 | - .addContactPointsWithPorts(mainCcm.addressOfNode(2)) | |
| 55 | - .withAddressTranslator(mainCcm.addressTranslator()) | |
| 54 | + .addContactPoints(mainCcm.addressOfNode(2).getAddress()) | |
| 55 | + .withPort(mainCcm.getBinaryPort()) | |
| 56 | 56 | .withQueryOptions(nonDebouncingQueryOptions()).build(); |
| 57 | 57 | mainCluster.connect(); |
| 58 | 58 | waitForCountUpHosts(mainCluster, 2); |
| @@ -80,8 +80,8 @@ | ||
| 80 | 80 | |
| 81 | 81 | // Start the driver, the control connection will be on node2 |
| 82 | 82 | mainCluster = Cluster.builder() |
| 83 | - .addContactPointsWithPorts(mainCcm.addressOfNode(2)) | |
| 84 | - .withAddressTranslator(mainCcm.addressTranslator()) | |
| 83 | + .addContactPoints(mainCcm.addressOfNode(2).getAddress()) | |
| 84 | + .withPort(mainCcm.getBinaryPort()) | |
| 85 | 85 | .withQueryOptions(nonDebouncingQueryOptions()).build(); |
| 86 | 86 | mainCluster.connect(); |
| 87 | 87 | waitForCountUpHosts(mainCluster, 1); |
| @@ -118,8 +118,8 @@ | ||
| 118 | 118 | |
| 119 | 119 | // Start the driver, it should only connect to node 2 |
| 120 | 120 | mainCluster = Cluster.builder() |
| 121 | - .addContactPointsWithPorts(mainCcm.addressOfNode(2)) | |
| 122 | - .withAddressTranslator(mainCcm.addressTranslator()) | |
| 121 | + .addContactPoints(mainCcm.addressOfNode(2).getAddress()) | |
| 122 | + .withPort(mainCcm.getBinaryPort()) | |
| 123 | 123 | .withQueryOptions(nonDebouncingQueryOptions()).build(); |
| 124 | 124 | |
| 125 | 125 | // When we first initialize the Cluster, all hosts are marked UP |
| @@ -154,8 +154,8 @@ | ||
| 154 | 154 | |
| 155 | 155 | // Start the driver, it should only connect to node 2 |
| 156 | 156 | mainCluster = Cluster.builder() |
| 157 | - .addContactPointsWithPorts(mainCcm.addressOfNode(2)) | |
| 158 | - .withAddressTranslator(mainCcm.addressTranslator()) | |
| 157 | + .addContactPoints(mainCcm.addressOfNode(2).getAddress()) | |
| 158 | + .withPort(mainCcm.getBinaryPort()) | |
| 159 | 159 | .withQueryOptions(nonDebouncingQueryOptions()).build(); |
| 160 | 160 | |
| 161 | 161 | // Create a session. This will try to open a pool to node 1 and find that it doesn't support protocol version. |
modified driver-core/src/test/java/com/datastax/driver/core/ReconnectionTest.java +5 −5
| @@ -51,7 +51,7 @@ | ||
| 51 | 51 | public void should_reconnect_after_full_connectivity_loss() throws InterruptedException { |
| 52 | 52 | Cluster cluster = register(Cluster.builder() |
| 53 | 53 | .addContactPointsWithPorts(ccm.addressOfNode(1)) |
| 54 | - .withAddressTranslator(ccm.addressTranslator()) | |
| 54 | + .withPort(ccm.getBinaryPort()) | |
| 55 | 55 | .withReconnectionPolicy(new ConstantReconnectionPolicy(reconnectionDelayMillis)) |
| 56 | 56 | .build()); |
| 57 | 57 | cluster.connect(); |
| @@ -90,7 +90,7 @@ | ||
| 90 | 90 | CountingAuthProvider authProvider = new CountingAuthProvider("cassandra", "cassandra"); |
| 91 | 91 | Cluster cluster = register(Cluster.builder() |
| 92 | 92 | .addContactPointsWithPorts(ccm.addressOfNode(1)) |
| 93 | - .withAddressTranslator(ccm.addressTranslator()) | |
| 93 | + .withPort(ccm.getBinaryPort()) | |
| 94 | 94 | // Start with the correct auth so that we can initialize the server |
| 95 | 95 | .withAuthProvider(authProvider) |
| 96 | 96 | .withReconnectionPolicy(reconnectionPolicy) |
| @@ -131,7 +131,7 @@ | ||
| 131 | 131 | |
| 132 | 132 | Cluster cluster = register(Cluster.builder() |
| 133 | 133 | .addContactPointsWithPorts(ccm.addressOfNode(1)) |
| 134 | - .withAddressTranslator(ccm.addressTranslator()) | |
| 134 | + .withPort(ccm.getBinaryPort()) | |
| 135 | 135 | .withReconnectionPolicy(reconnectionPolicy).build()); |
| 136 | 136 | cluster.connect(); |
| 137 | 137 | |
| @@ -159,7 +159,7 @@ | ||
| 159 | 159 | TogglabePolicy loadBalancingPolicy = new TogglabePolicy(new RoundRobinPolicy()); |
| 160 | 160 | Cluster cluster = register(Cluster.builder() |
| 161 | 161 | .addContactPointsWithPorts(ccm.addressOfNode(1)) |
| 162 | - .withAddressTranslator(ccm.addressTranslator()) | |
| 162 | + .withPort(ccm.getBinaryPort()) | |
| 163 | 163 | .withLoadBalancingPolicy(loadBalancingPolicy) |
| 164 | 164 | .withReconnectionPolicy(new ConstantReconnectionPolicy(reconnectionDelayMillis)) |
| 165 | 165 | .build()); |
| @@ -215,7 +215,7 @@ | ||
| 215 | 215 | SocketOptions socketOptions = spy(new SocketOptions()); |
| 216 | 216 | Cluster cluster = register(Cluster.builder() |
| 217 | 217 | .addContactPointsWithPorts(ccm.addressOfNode(1)) |
| 218 | - .withAddressTranslator(ccm.addressTranslator()) | |
| 218 | + .withPort(ccm.getBinaryPort()) | |
| 219 | 219 | .withReconnectionPolicy(new ConstantReconnectionPolicy(5000)) |
| 220 | 220 | .withLoadBalancingPolicy(loadBalancingPolicy) |
| 221 | 221 | .withSocketOptions(socketOptions) |
modified driver-core/src/test/java/com/datastax/driver/core/RefreshConnectedHostTest.java +1 −1
| @@ -43,7 +43,7 @@ | ||
| 43 | 43 | PoolingOptions poolingOptions = Mockito.spy(new PoolingOptions()); |
| 44 | 44 | cluster = register(Cluster.builder() |
| 45 | 45 | .addContactPointsWithPorts(ccm.addressOfNode(1)) |
| 46 | - .withAddressTranslator(ccm.addressTranslator()) | |
| 46 | + .withPort(ccm.getBinaryPort()) | |
| 47 | 47 | .withPoolingOptions(poolingOptions) |
| 48 | 48 | .withLoadBalancingPolicy(loadBalancingPolicy) |
| 49 | 49 | .withReconnectionPolicy(new ConstantReconnectionPolicy(1000)) |
modified driver-core/src/test/java/com/datastax/driver/core/SSLEncryptionTest.java +4 −2
| @@ -23,7 +23,9 @@ | ||
| 23 | 23 | import static com.datastax.driver.core.Assertions.assertThat; |
| 24 | 24 | import static com.datastax.driver.core.CCMBridge.DEFAULT_CLIENT_TRUSTSTORE_FILE; |
| 25 | 25 | import static com.datastax.driver.core.CCMBridge.DEFAULT_CLIENT_TRUSTSTORE_PASSWORD; |
| 26 | +import static com.datastax.driver.core.CreateCCM.TestMode.PER_METHOD; | |
| 26 | 27 | |
| 28 | +@CreateCCM(PER_METHOD) | |
| 27 | 29 | @CCMConfig(auth = false) |
| 28 | 30 | public class SSLEncryptionTest extends SSLTestBase { |
| 29 | 31 | |
| @@ -73,7 +75,7 @@ | ||
| 73 | 75 | public void should_not_connect_without_ssl_but_node_uses_ssl() throws Exception { |
| 74 | 76 | Cluster cluster = register(Cluster.builder() |
| 75 | 77 | .addContactPointsWithPorts(this.getInitialContactPoints()) |
| 76 | - .withAddressTranslator(ccm.addressTranslator()) | |
| 78 | + .withPort(ccm.getBinaryPort()) | |
| 77 | 79 | .build()); |
| 78 | 80 | cluster.connect(); |
| 79 | 81 | } |
| @@ -92,7 +94,7 @@ | ||
| 92 | 94 | public void should_reconnect_with_ssl_on_node_up(SslImplementation sslImplementation) throws Exception { |
| 93 | 95 | Cluster cluster = register(Cluster.builder() |
| 94 | 96 | .addContactPointsWithPorts(this.getInitialContactPoints()) |
| 95 | - .withAddressTranslator(ccm.addressTranslator()) | |
| 97 | + .withPort(ccm.getBinaryPort()) | |
| 96 | 98 | .withSSL(getSSLOptions(sslImplementation, true, true)) |
| 97 | 99 | .build()); |
| 98 | 100 |
modified driver-core/src/test/java/com/datastax/driver/core/SSLTestBase.java +2 −2
| @@ -56,7 +56,7 @@ | ||
| 56 | 56 | protected void connectWithSSLOptions(SSLOptions sslOptions) throws Exception { |
| 57 | 57 | Cluster cluster = register(Cluster.builder() |
| 58 | 58 | .addContactPointsWithPorts(this.getInitialContactPoints()) |
| 59 | - .withAddressTranslator(ccm.addressTranslator()) | |
| 59 | + .withPort(ccm.getBinaryPort()) | |
| 60 | 60 | .withSSL(sslOptions) |
| 61 | 61 | .build()); |
| 62 | 62 | cluster.connect(); |
| @@ -74,7 +74,7 @@ | ||
| 74 | 74 | protected void connectWithSSL() throws Exception { |
| 75 | 75 | Cluster cluster = register(Cluster.builder() |
| 76 | 76 | .addContactPointsWithPorts(this.getInitialContactPoints()) |
| 77 | - .withAddressTranslator(ccm.addressTranslator()) | |
| 77 | + .withPort(ccm.getBinaryPort()) | |
| 78 | 78 | .withSSL() |
| 79 | 79 | .build()); |
| 80 | 80 | cluster.connect(); |
modified driver-core/src/test/java/com/datastax/driver/core/ScassandraCluster.java +4 −32
| @@ -17,7 +17,6 @@ | ||
| 17 | 17 | |
| 18 | 18 | import com.beust.jcommander.internal.Lists; |
| 19 | 19 | import com.beust.jcommander.internal.Maps; |
| 20 | -import com.datastax.driver.core.policies.AddressTranslator; | |
| 21 | 20 | import com.google.common.collect.ImmutableList; |
| 22 | 21 | import com.google.common.collect.ImmutableMap; |
| 23 | 22 | import com.google.common.collect.ImmutableSet; |
| @@ -115,6 +114,10 @@ | ||
| 115 | 114 | return -1; |
| 116 | 115 | } |
| 117 | 116 | |
| 117 | + public int getBinaryPort() { | |
| 118 | + return binaryPort; | |
| 119 | + } | |
| 120 | + | |
| 118 | 121 | public InetSocketAddress address(int node) { |
| 119 | 122 | return new InetSocketAddress(ipPrefix + node, binaryPort); |
| 120 | 123 | } |
| @@ -127,37 +130,6 @@ | ||
| 127 | 130 | return new InetSocketAddress(ipPrefix + ipSuffix, binaryPort); |
| 128 | 131 | } |
| 129 | 132 | |
| 130 | - /** | |
| 131 | - * Returns an {@link AddressTranslator} to use when tests must manually create | |
| 132 | - * {@link Cluster} instances. | |
| 133 | - * <p/> | |
| 134 | - * This translator is necessary because hosts create with this class do not use standard ports. | |
| 135 | - * <p/> | |
| 136 | - * This method should not be called before the test has started, nor after the test is finished. | |
| 137 | - * | |
| 138 | - * @return an {@link AddressTranslator} to use when tests must manually create | |
| 139 | - * {@link Cluster} instances. | |
| 140 | - */ | |
| 141 | - public AddressTranslator addressTranslator() { | |
| 142 | - return new AddressTranslator() { | |
| 143 | - @Override | |
| 144 | - public InetSocketAddress translate(InetSocketAddress address) { | |
| 145 | - return new InetSocketAddress(address.getAddress(), binaryPort); | |
| 146 | - } | |
| 147 | - | |
| 148 | - @Override | |
| 149 | - public void init(Cluster cluster) { | |
| 150 | - | |
| 151 | - } | |
| 152 | - | |
| 153 | - @Override | |
| 154 | - public void close() { | |
| 155 | - | |
| 156 | - } | |
| 157 | - }; | |
| 158 | - } | |
| 159 | - | |
| 160 | - | |
| 161 | 133 | public Host host(Cluster cluster, int dc, int node) { |
| 162 | 134 | InetAddress address = address(dc, node).getAddress(); |
| 163 | 135 | for (Host host : cluster.getMetadata().getAllHosts()) { |
modified driver-core/src/test/java/com/datastax/driver/core/SchemaChangesCCTest.java +2 −2
| @@ -57,14 +57,14 @@ | ||
| 57 | 57 | Cluster.builder() |
| 58 | 58 | .withLoadBalancingPolicy(lbPolicy) |
| 59 | 59 | .addContactPointsWithPorts(ccm.addressOfNode(1)) |
| 60 | - .withAddressTranslator(ccm.addressTranslator()) | |
| 60 | + .withPort(ccm.getBinaryPort()) | |
| 61 | 61 | .build()); |
| 62 | 62 | // Put cluster2 control connection on node 2 so it doesn't go down (to prevent noise for debugging). |
| 63 | 63 | Cluster cluster2 = register( |
| 64 | 64 | Cluster.builder() |
| 65 | 65 | .withLoadBalancingPolicy(lbPolicy) |
| 66 | 66 | .addContactPointsWithPorts(ccm.addressOfNode(2)) |
| 67 | - .withAddressTranslator(ccm.addressTranslator()) | |
| 67 | + .withPort(ccm.getBinaryPort()) | |
| 68 | 68 | .build()); |
| 69 | 69 | SchemaChangeListener listener = mock(SchemaChangeListener.class); |
| 70 | 70 |
modified driver-core/src/test/java/com/datastax/driver/core/SessionLeakTest.java +4 −4
| @@ -40,8 +40,8 @@ | ||
| 40 | 40 | channelMonitor = new SocketChannelMonitor(); |
| 41 | 41 | channelMonitor.reportAtFixedInterval(1, TimeUnit.SECONDS); |
| 42 | 42 | cluster = register(Cluster.builder() |
| 43 | - .addContactPointsWithPorts(getHostAddress(1)) | |
| 44 | - .withAddressTranslator(getAddressTranslator()) | |
| 43 | + .addContactPoints(ccm.addressOfNode(1).getAddress()) | |
| 44 | + .withPort(ccm.getBinaryPort()) | |
| 45 | 45 | .withNettyOptions(channelMonitor.nettyOptions()) |
| 46 | 46 | .withQueryOptions(nonDebouncingQueryOptions()) |
| 47 | 47 | .build()); |
| @@ -97,8 +97,8 @@ | ||
| 97 | 97 | channelMonitor = new SocketChannelMonitor(); |
| 98 | 98 | channelMonitor.reportAtFixedInterval(1, TimeUnit.SECONDS); |
| 99 | 99 | cluster = register(Cluster.builder() |
| 100 | - .addContactPointsWithPorts(getHostAddress(1)) | |
| 101 | - .withAddressTranslator(getAddressTranslator()) | |
| 100 | + .addContactPoints(ccm.addressOfNode(1).getAddress()) | |
| 101 | + .withPort(ccm.getBinaryPort()) | |
| 102 | 102 | .withNettyOptions(channelMonitor.nettyOptions()) |
| 103 | 103 | .build()); |
| 104 | 104 | cluster.init(); |
modified driver-core/src/test/java/com/datastax/driver/core/SpeculativeExecutionTest.java +4 −4
| @@ -51,8 +51,8 @@ | ||
| 51 | 51 | |
| 52 | 52 | loadBalancingPolicy = new SortingLoadBalancingPolicy(); |
| 53 | 53 | cluster = Cluster.builder() |
| 54 | - .addContactPointsWithPorts(scassandras.address(2)) | |
| 55 | - .withAddressTranslator(scassandras.addressTranslator()) | |
| 54 | + .addContactPoints(scassandras.address(2).getAddress()) | |
| 55 | + .withPort(scassandras.getBinaryPort()) | |
| 56 | 56 | .withProtocolVersion(ProtocolVersion.V2) // Scassandra does not support V3 nor V4 yet |
| 57 | 57 | .withLoadBalancingPolicy(loadBalancingPolicy) |
| 58 | 58 | .withSpeculativeExecutionPolicy(new ConstantSpeculativeExecutionPolicy(speculativeExecutionDelay, 1)) |
| @@ -203,8 +203,8 @@ | ||
| 203 | 203 | SpeculativeExecutionPolicy mockPolicy = mock(SpeculativeExecutionPolicy.class); |
| 204 | 204 | |
| 205 | 205 | Cluster cluster = Cluster.builder() |
| 206 | - .addContactPointsWithPorts(scassandras.address(2)) | |
| 207 | - .withAddressTranslator(scassandras.addressTranslator()) | |
| 206 | + .addContactPoints(scassandras.address(2).getAddress()) | |
| 207 | + .withPort(scassandras.getBinaryPort()) | |
| 208 | 208 | // Scassandra does not support V3 nor V4 yet, and V4 may cause the server to crash |
| 209 | 209 | .withProtocolVersion(ProtocolVersion.V2) |
| 210 | 210 | .withSpeculativeExecutionPolicy(mockPolicy) |
modified driver-core/src/test/java/com/datastax/driver/core/StateListenerTest.java +1 −1
| @@ -51,7 +51,7 @@ | ||
| 51 | 51 | listener.waitForEvent(); |
| 52 | 52 | |
| 53 | 53 | listener.setExpectedEvent(REMOVE); |
| 54 | - ccm.decommissionNode(2); | |
| 54 | + ccm.decommision(2); | |
| 55 | 55 | listener.waitForEvent(); |
| 56 | 56 | } |
| 57 | 57 |
modified driver-core/src/test/java/com/datastax/driver/core/TestUtils.java +2 −2
| @@ -776,12 +776,12 @@ | ||
| 776 | 776 | /** |
| 777 | 777 | * @return a {@link Cluster} instance that connects only to the control host of the given cluster. |
| 778 | 778 | */ |
| 779 | - public static Cluster buildControlCluster(Cluster cluster, CCMBridge ccm) { | |
| 779 | + public static Cluster buildControlCluster(Cluster cluster, CCMAccess ccm) { | |
| 780 | 780 | Host controlHost = cluster.manager.controlConnection.connectedHost(); |
| 781 | 781 | List<InetSocketAddress> singleAddress = Collections.singletonList(controlHost.getSocketAddress()); |
| 782 | 782 | return Cluster.builder() |
| 783 | 783 | .addContactPointsWithPorts(singleAddress) |
| 784 | - .withAddressTranslator(ccm.addressTranslator()) | |
| 784 | + .withPort(ccm.getBinaryPort()) | |
| 785 | 785 | .withLoadBalancingPolicy(new WhiteListPolicy(new RoundRobinPolicy(), singleAddress)) |
| 786 | 786 | .build(); |
| 787 | 787 | } |
modified driver-core/src/test/java/com/datastax/driver/core/TypeCodecTupleIntegrationTest.java +2 −2
| @@ -94,7 +94,7 @@ | ||
| 94 | 94 | CodecRegistry codecRegistry = new CodecRegistry(); |
| 95 | 95 | Cluster cluster = register(Cluster.builder() |
| 96 | 96 | .addContactPointsWithPorts(getInitialContactPoints()) |
| 97 | - .withAddressTranslator(getAddressTranslator()) | |
| 97 | + .withPort(ccm.getBinaryPort()) | |
| 98 | 98 | .withCodecRegistry(codecRegistry) |
| 99 | 99 | .build()); |
| 100 | 100 | Session session = cluster.connect(keyspace); |
| @@ -124,7 +124,7 @@ | ||
| 124 | 124 | CodecRegistry codecRegistry = new CodecRegistry(); |
| 125 | 125 | Cluster cluster = register(Cluster.builder() |
| 126 | 126 | .addContactPointsWithPorts(getInitialContactPoints()) |
| 127 | - .withAddressTranslator(getAddressTranslator()) | |
| 127 | + .withPort(ccm.getBinaryPort()) | |
| 128 | 128 | .withCodecRegistry(codecRegistry) |
| 129 | 129 | .build()); |
| 130 | 130 | Session session = cluster.connect(keyspace); |
modified driver-core/src/test/java/com/datastax/driver/core/TypeCodecUDTIntegrationTest.java +1 −1
| @@ -79,7 +79,7 @@ | ||
| 79 | 79 | CodecRegistry codecRegistry = new CodecRegistry(); |
| 80 | 80 | Cluster cluster = register(Cluster.builder() |
| 81 | 81 | .addContactPointsWithPorts(getInitialContactPoints()) |
| 82 | - .withAddressTranslator(getAddressTranslator()) | |
| 82 | + .withPort(ccm.getBinaryPort()) | |
| 83 | 83 | .withCodecRegistry(codecRegistry) |
| 84 | 84 | .build()); |
| 85 | 85 | Session session = cluster.connect(keyspace); |
modified driver-core/src/test/java/com/datastax/driver/core/UnresolvedUserTypeTest.java +1 −1
| @@ -69,7 +69,7 @@ | ||
| 69 | 69 | // The parsing logic should sort them to make sure they are loaded in the right order. |
| 70 | 70 | Cluster newCluster = register(Cluster.builder() |
| 71 | 71 | .addContactPointsWithPorts(getInitialContactPoints()) |
| 72 | - .withAddressTranslator(getAddressTranslator()) | |
| 72 | + .withPort(ccm.getBinaryPort()) | |
| 73 | 73 | .build()); |
| 74 | 74 | checkUserTypes(newCluster.getMetadata()); |
| 75 | 75 | } |
modified driver-core/src/test/java/com/datastax/driver/core/exceptions/ExceptionsScassandraTest.java +2 −2
| @@ -48,8 +48,8 @@ | ||
| 48 | 48 | @BeforeMethod(groups = "short") |
| 49 | 49 | public void beforeMethod() { |
| 50 | 50 | cluster = Cluster.builder() |
| 51 | - .addContactPointsWithPorts(scassandras.address(1)) | |
| 52 | - .withAddressTranslator(scassandras.addressTranslator()) | |
| 51 | + .addContactPoints(scassandras.address(1).getAddress()) | |
| 52 | + .withPort(scassandras.getBinaryPort()) | |
| 53 | 53 | .withRetryPolicy(FallthroughRetryPolicy.INSTANCE) |
| 54 | 54 | .build(); |
| 55 | 55 | session = cluster.connect(); |
modified driver-core/src/test/java/com/datastax/driver/core/exceptions/ExceptionsTest.java +4 −4
| @@ -66,8 +66,8 @@ | ||
| 66 | 66 | assertEquals(e.getKeyspace(), keyspace.toLowerCase()); |
| 67 | 67 | assertEquals(e.getTable(), null); |
| 68 | 68 | assertEquals(e.wasTableCreation(), false); |
| 69 | - assertEquals(e.getHost(), getHostAddress(1).getAddress()); | |
| 70 | - assertEquals(e.getAddress(), getHostAddress(1)); | |
| 69 | + assertEquals(e.getHost(), ccm.addressOfNode(1).getAddress()); | |
| 70 | + assertEquals(e.getAddress(), ccm.addressOfNode(1)); | |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | session.execute(cqlCommands[1]); |
| @@ -80,8 +80,8 @@ | ||
| 80 | 80 | assertEquals(e.getKeyspace(), keyspace.toLowerCase()); |
| 81 | 81 | assertEquals(e.getTable(), table.toLowerCase()); |
| 82 | 82 | assertEquals(e.wasTableCreation(), true); |
| 83 | - assertEquals(e.getHost(), getHostAddress(1).getAddress()); | |
| 84 | - assertEquals(e.getAddress(), getHostAddress(1)); | |
| 83 | + assertEquals(e.getHost(), ccm.addressOfNode(1).getAddress()); | |
| 84 | + assertEquals(e.getAddress(), ccm.addressOfNode(1)); | |
| 85 | 85 | } |
| 86 | 86 | } |
| 87 | 87 |
modified driver-core/src/test/java/com/datastax/driver/core/policies/AbstractRetryPolicyIntegrationTest.java +2 −2
| @@ -77,8 +77,8 @@ | ||
| 77 | 77 | scassandras.init(); |
| 78 | 78 | |
| 79 | 79 | cluster = Cluster.builder() |
| 80 | - .addContactPointsWithPorts(scassandras.address(1)) | |
| 81 | - .withAddressTranslator(scassandras.addressTranslator()) | |
| 80 | + .addContactPoints(scassandras.address(1).getAddress()) | |
| 81 | + .withPort(scassandras.getBinaryPort()) | |
| 82 | 82 | .withRetryPolicy(retryPolicy) |
| 83 | 83 | .withLoadBalancingPolicy(new SortingLoadBalancingPolicy()) |
| 84 | 84 | // Scassandra does not support V3 nor V4 yet, and V4 may cause the server to crash |
modified driver-core/src/test/java/com/datastax/driver/core/policies/CloseableLoadBalancingPolicyTest.java +1 −1
| @@ -41,7 +41,7 @@ | ||
| 41 | 41 | public Cluster.Builder createClusterBuilder() { |
| 42 | 42 | policy = new CloseMonitoringPolicy(Policies.defaultLoadBalancingPolicy()); |
| 43 | 43 | return Cluster.builder() |
| 44 | - .addContactPointsWithPorts(getHostAddress(1)) | |
| 44 | + .addContactPoints(ccm.addressOfNode(1).getAddress()) | |
| 45 | 45 | .withLoadBalancingPolicy(policy); |
| 46 | 46 | } |
| 47 | 47 |
modified driver-core/src/test/java/com/datastax/driver/core/policies/DCAwareRoundRobinPolicyTest.java +22 −22
| @@ -81,8 +81,8 @@ | ||
| 81 | 81 | // given: a 10 node 2 DC cluster. |
| 82 | 82 | ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(5, 5).build(); |
| 83 | 83 | Cluster cluster = builder() |
| 84 | - .addContactPointsWithPorts(sCluster.address(1, 1)) | |
| 85 | - .withAddressTranslator(sCluster.addressTranslator()) | |
| 84 | + .addContactPoints(sCluster.address(1, 1).getAddress()) | |
| 85 | + .withPort(sCluster.getBinaryPort()) | |
| 86 | 86 | .withLoadBalancingPolicy(DCAwareRoundRobinPolicy.builder().withLocalDc(datacenter(1)).build()) |
| 87 | 87 | .build(); |
| 88 | 88 | try { |
| @@ -114,8 +114,8 @@ | ||
| 114 | 114 | // given: a 10 node 2 DC cluster with DC policy with 2 remote hosts. |
| 115 | 115 | ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(5, 5).build(); |
| 116 | 116 | Cluster cluster = builder() |
| 117 | - .addContactPointsWithPorts(sCluster.address(1, 1)) | |
| 118 | - .withAddressTranslator(sCluster.addressTranslator()) | |
| 117 | + .addContactPoints(sCluster.address(1, 1).getAddress()) | |
| 118 | + .withPort(sCluster.getBinaryPort()) | |
| 119 | 119 | .withLoadBalancingPolicy(DCAwareRoundRobinPolicy.builder().withLocalDc(datacenter(1)).withUsedHostsPerRemoteDc(2).build()) |
| 120 | 120 | .build(); |
| 121 | 121 | |
| @@ -157,8 +157,8 @@ | ||
| 157 | 157 | // given: a 10 node 2 DC cluster with DC policy with 2 remote hosts. |
| 158 | 158 | ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(5, 5).build(); |
| 159 | 159 | Cluster cluster = builder() |
| 160 | - .addContactPointsWithPorts(sCluster.address(1, 1)) | |
| 161 | - .withAddressTranslator(sCluster.addressTranslator()) | |
| 160 | + .addContactPoints(sCluster.address(1, 1).getAddress()) | |
| 161 | + .withPort(sCluster.getBinaryPort()) | |
| 162 | 162 | .withLoadBalancingPolicy(DCAwareRoundRobinPolicy.builder().withUsedHostsPerRemoteDc(2).build()) |
| 163 | 163 | .build(); |
| 164 | 164 | |
| @@ -201,8 +201,8 @@ | ||
| 201 | 201 | // a local consistency level. |
| 202 | 202 | ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(2, 2).build(); |
| 203 | 203 | Cluster cluster = builder() |
| 204 | - .addContactPointsWithPorts(sCluster.address(1, 1)) | |
| 205 | - .withAddressTranslator(sCluster.addressTranslator()) | |
| 204 | + .addContactPoints(sCluster.address(1, 1).getAddress()) | |
| 205 | + .withPort(sCluster.getBinaryPort()) | |
| 206 | 206 | .withLoadBalancingPolicy(DCAwareRoundRobinPolicy.builder().withUsedHostsPerRemoteDc(2).build()) |
| 207 | 207 | .build(); |
| 208 | 208 | |
| @@ -247,8 +247,8 @@ | ||
| 247 | 247 | // a local consistency level. |
| 248 | 248 | ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(2, 2).build(); |
| 249 | 249 | Cluster cluster = builder() |
| 250 | - .addContactPointsWithPorts(sCluster.address(1, 1)) | |
| 251 | - .withAddressTranslator(sCluster.addressTranslator()) | |
| 250 | + .addContactPoints(sCluster.address(1, 1).getAddress()) | |
| 251 | + .withPort(sCluster.getBinaryPort()) | |
| 252 | 252 | .withLoadBalancingPolicy(DCAwareRoundRobinPolicy.builder() |
| 253 | 253 | .allowRemoteDCsForLocalConsistencyLevel() |
| 254 | 254 | .withUsedHostsPerRemoteDc(2).build()) |
| @@ -293,8 +293,8 @@ | ||
| 293 | 293 | DCAwareRoundRobinPolicy.builder().withUsedHostsPerRemoteDc(2).build(), |
| 294 | 294 | Lists.newArrayList(datacenter(2))); |
| 295 | 295 | Cluster cluster = builder() |
| 296 | - .addContactPointsWithPorts(sCluster.address(1, 1)) | |
| 297 | - .withAddressTranslator(sCluster.addressTranslator()) | |
| 296 | + .addContactPoints(sCluster.address(1, 1).getAddress()) | |
| 297 | + .withPort(sCluster.getBinaryPort()) | |
| 298 | 298 | .withLoadBalancingPolicy(loadBalancingPolicy) |
| 299 | 299 | .build(); |
| 300 | 300 | |
| @@ -347,8 +347,8 @@ | ||
| 347 | 347 | DCAwareRoundRobinPolicy.builder().withUsedHostsPerRemoteDc(2).build(), |
| 348 | 348 | Lists.newArrayList(datacenter(1), datacenter(2))); |
| 349 | 349 | Cluster cluster = builder() |
| 350 | - .addContactPointsWithPorts(sCluster.address(1, 1)) | |
| 351 | - .withAddressTranslator(sCluster.addressTranslator()) | |
| 350 | + .addContactPoints(sCluster.address(1, 1).getAddress()) | |
| 351 | + .withPort(sCluster.getBinaryPort()) | |
| 352 | 352 | .withLoadBalancingPolicy(loadBalancingPolicy) |
| 353 | 353 | .build(); |
| 354 | 354 | |
| @@ -399,8 +399,8 @@ | ||
| 399 | 399 | DCAwareRoundRobinPolicy policy = spy(DCAwareRoundRobinPolicy.builder().build()); |
| 400 | 400 | ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(2, 2).build(); |
| 401 | 401 | Cluster cluster = builder() |
| 402 | - .addContactPointsWithPorts(sCluster.address(1, 1)) | |
| 403 | - .withAddressTranslator(sCluster.addressTranslator()) | |
| 402 | + .addContactPoints(sCluster.address(1, 1).getAddress()) | |
| 403 | + .withPort(sCluster.getBinaryPort()) | |
| 404 | 404 | .withLoadBalancingPolicy(policy) |
| 405 | 405 | .build(); |
| 406 | 406 | |
| @@ -439,8 +439,8 @@ | ||
| 439 | 439 | DCAwareRoundRobinPolicy policy = spy(DCAwareRoundRobinPolicy.builder().build()); |
| 440 | 440 | ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(2, 2).build(); |
| 441 | 441 | Cluster cluster = builder() |
| 442 | - .addContactPointsWithPorts(sCluster.address(1, 1), sCluster.address(2, 1)) | |
| 443 | - .withAddressTranslator(sCluster.addressTranslator()) | |
| 442 | + .addContactPoints(sCluster.address(1, 1).getAddress(), sCluster.address(2, 1).getAddress()) | |
| 443 | + .withPort(sCluster.getBinaryPort()) | |
| 444 | 444 | .withLoadBalancingPolicy(policy) |
| 445 | 445 | .build(); |
| 446 | 446 | |
| @@ -478,8 +478,8 @@ | ||
| 478 | 478 | ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(2, 2).build(); |
| 479 | 479 | DCAwareRoundRobinPolicy policy = spy(DCAwareRoundRobinPolicy.builder().withLocalDc(datacenter(1)).build()); |
| 480 | 480 | Cluster cluster = builder() |
| 481 | - .addContactPointsWithPorts(sCluster.address(1, 1)) | |
| 482 | - .withAddressTranslator(sCluster.addressTranslator()) | |
| 481 | + .addContactPoints(sCluster.address(1, 1).getAddress()) | |
| 482 | + .withPort(sCluster.getBinaryPort()) | |
| 483 | 483 | .withLoadBalancingPolicy(policy) |
| 484 | 484 | .build(); |
| 485 | 485 | |
| @@ -518,8 +518,8 @@ | ||
| 518 | 518 | ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(2, 2).build(); |
| 519 | 519 | DCAwareRoundRobinPolicy policy = spy(DCAwareRoundRobinPolicy.builder().withLocalDc(datacenter(3)).build()); |
| 520 | 520 | Cluster cluster = builder() |
| 521 | - .addContactPointsWithPorts(sCluster.address(1, 1), sCluster.address(2, 1)) | |
| 522 | - .withAddressTranslator(sCluster.addressTranslator()) | |
| 521 | + .addContactPoints(sCluster.address(1, 1).getAddress(), sCluster.address(2, 1).getAddress()) | |
| 522 | + .withPort(sCluster.getBinaryPort()) | |
| 523 | 523 | .withLoadBalancingPolicy(policy) |
| 524 | 524 | .build(); |
| 525 | 525 |
modified driver-core/src/test/java/com/datastax/driver/core/policies/DefaultRetryPolicyIntegrationTest.java +2 −2
| @@ -113,8 +113,8 @@ | ||
| 113 | 113 | Collections.singletonList(host1.getSocketAddress())); |
| 114 | 114 | |
| 115 | 115 | Cluster whiteListedCluster = Cluster.builder() |
| 116 | - .addContactPointsWithPorts(scassandras.address(1)) | |
| 117 | - .withAddressTranslator(scassandras.addressTranslator()) | |
| 116 | + .addContactPoints(scassandras.address(1).getAddress()) | |
| 117 | + .withPort(scassandras.getBinaryPort()) | |
| 118 | 118 | // Scassandra does not support V3 nor V4 yet, and V4 may cause the server to crash |
| 119 | 119 | .withProtocolVersion(ProtocolVersion.V2) |
| 120 | 120 | .withRetryPolicy(retryPolicy) |
modified driver-core/src/test/java/com/datastax/driver/core/policies/RoundRobinPolicyTest.java +6 −6
| @@ -59,8 +59,8 @@ | ||
| 59 | 59 | ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(5).build(); |
| 60 | 60 | |
| 61 | 61 | Cluster cluster = Cluster.builder() |
| 62 | - .addContactPointsWithPorts(sCluster.address(1)) | |
| 63 | - .withAddressTranslator(sCluster.addressTranslator()) | |
| 62 | + .addContactPoints(sCluster.address(1).getAddress()) | |
| 63 | + .withPort(sCluster.getBinaryPort()) | |
| 64 | 64 | .withLoadBalancingPolicy(new RoundRobinPolicy()) |
| 65 | 65 | .withNettyOptions(nonQuietClusterCloseOptions) |
| 66 | 66 | .build(); |
| @@ -95,8 +95,8 @@ | ||
| 95 | 95 | ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(2, 2, 2, 2, 2).build(); |
| 96 | 96 | |
| 97 | 97 | Cluster cluster = Cluster.builder() |
| 98 | - .addContactPointsWithPorts(sCluster.address(1)) | |
| 99 | - .withAddressTranslator(sCluster.addressTranslator()) | |
| 98 | + .addContactPoints(sCluster.address(1).getAddress()) | |
| 99 | + .withPort(sCluster.getBinaryPort()) | |
| 100 | 100 | .withLoadBalancingPolicy(new RoundRobinPolicy()) |
| 101 | 101 | .withNettyOptions(nonQuietClusterCloseOptions) |
| 102 | 102 | .build(); |
| @@ -134,8 +134,8 @@ | ||
| 134 | 134 | ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(1, 1).build(); |
| 135 | 135 | |
| 136 | 136 | Cluster cluster = Cluster.builder() |
| 137 | - .addContactPointsWithPorts(sCluster.address(1)) | |
| 138 | - .withAddressTranslator(sCluster.addressTranslator()) | |
| 137 | + .addContactPoints(sCluster.address(1).getAddress()) | |
| 138 | + .withPort(sCluster.getBinaryPort()) | |
| 139 | 139 | .withLoadBalancingPolicy(new RoundRobinPolicy()) |
| 140 | 140 | .withNettyOptions(nonQuietClusterCloseOptions) |
| 141 | 141 | .build(); |
modified driver-core/src/test/java/com/datastax/driver/core/policies/TokenAwarePolicyTest.java +10 −10
| @@ -70,8 +70,8 @@ | ||
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | Cluster cluster = Cluster.builder() |
| 73 | - .addContactPointsWithPorts(sCluster.address(1)) | |
| 74 | - .withAddressTranslator(sCluster.addressTranslator()) | |
| 73 | + .addContactPoints(sCluster.address(1).getAddress()) | |
| 74 | + .withPort(sCluster.getBinaryPort()) | |
| 75 | 75 | .withNettyOptions(nonQuietClusterCloseOptions) |
| 76 | 76 | .withLoadBalancingPolicy(loadBalancingPolicy) |
| 77 | 77 | .build(); |
| @@ -140,8 +140,8 @@ | ||
| 140 | 140 | .withSimpleKeyspace("keyspace", 1) |
| 141 | 141 | .build(); |
| 142 | 142 | Cluster cluster = Cluster.builder() |
| 143 | - .addContactPointsWithPorts(sCluster.address(1)) | |
| 144 | - .withAddressTranslator(sCluster.addressTranslator()) | |
| 143 | + .addContactPoints(sCluster.address(1).getAddress()) | |
| 144 | + .withPort(sCluster.getBinaryPort()) | |
| 145 | 145 | .withNettyOptions(nonQuietClusterCloseOptions) |
| 146 | 146 | .withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy())) |
| 147 | 147 | .build(); |
| @@ -185,8 +185,8 @@ | ||
| 185 | 185 | .withNetworkTopologyKeyspace("keyspace", ImmutableMap.of(1, 1, 2, 1)) |
| 186 | 186 | .build(); |
| 187 | 187 | Cluster cluster = Cluster.builder() |
| 188 | - .addContactPointsWithPorts(sCluster.address(1)) | |
| 189 | - .withAddressTranslator(sCluster.addressTranslator()) | |
| 188 | + .addContactPoints(sCluster.address(1).getAddress()) | |
| 189 | + .withPort(sCluster.getBinaryPort()) | |
| 190 | 190 | .withNettyOptions(nonQuietClusterCloseOptions) |
| 191 | 191 | .withLoadBalancingPolicy(new TokenAwarePolicy(DCAwareRoundRobinPolicy.builder() |
| 192 | 192 | .withLocalDc(ScassandraCluster.datacenter(2)) |
| @@ -232,10 +232,10 @@ | ||
| 232 | 232 | .withSimpleKeyspace("keyspace", 2) |
| 233 | 233 | .build(); |
| 234 | 234 | Cluster cluster = Cluster.builder() |
| 235 | - .addContactPointsWithPorts(sCluster.address(2)) | |
| 236 | - .withAddressTranslator(sCluster.addressTranslator()) | |
| 235 | + .addContactPoints(sCluster.address(2).getAddress()) | |
| 236 | + .withPort(sCluster.getBinaryPort()) | |
| 237 | 237 | .withNettyOptions(nonQuietClusterCloseOptions) |
| 238 | - // Don't shuffle replicas just to keep test deterministic. | |
| 238 | + // Don't shuffle replicas just to keep test deterministic. | |
| 239 | 239 | .withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy(), false)) |
| 240 | 240 | .build(); |
| 241 | 241 | |
| @@ -324,7 +324,7 @@ | ||
| 324 | 324 | Cluster cluster = Cluster.builder() |
| 325 | 325 | .withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy())) |
| 326 | 326 | .addContactPointsWithPorts(ccm.addressOfNode(1)) |
| 327 | - .withAddressTranslator(ccm.addressTranslator()) | |
| 327 | + .withPort(ccm.getBinaryPort()) | |
| 328 | 328 | .build(); |
| 329 | 329 | |
| 330 | 330 | try { |
modified driver-core/src/test/java/com/datastax/driver/core/policies/WhiteListPolicyTest.java +2 −2
| @@ -53,8 +53,8 @@ | ||
| 53 | 53 | List<InetSocketAddress> whiteList = Lists.newArrayList(sCluster.address(3), sCluster.address(5)); |
| 54 | 54 | |
| 55 | 55 | Cluster cluster = Cluster.builder() |
| 56 | - .addContactPointsWithPorts(sCluster.address(5)) | |
| 57 | - .withAddressTranslator(sCluster.addressTranslator()) | |
| 56 | + .addContactPoints(sCluster.address(5).getAddress()) | |
| 57 | + .withPort(sCluster.getBinaryPort()) | |
| 58 | 58 | .withLoadBalancingPolicy(new WhiteListPolicy(new RoundRobinPolicy(), whiteList)) |
| 59 | 59 | .withNettyOptions(nonQuietClusterCloseOptions) |
| 60 | 60 | .build(); |
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperUDTTest.java +1 −1
| @@ -310,7 +310,7 @@ | ||
| 310 | 310 | // Create a separate Cluster/Session to start with a CodecRegistry from scratch (so not already registered). |
| 311 | 311 | Cluster cluster = register(Cluster.builder() |
| 312 | 312 | .addContactPointsWithPorts(getInitialContactPoints()) |
| 313 | - .withAddressTranslator(getAddressTranslator()) | |
| 313 | + .withPort(ccm.getBinaryPort()) | |
| 314 | 314 | .build()); |
| 315 | 315 | CodecRegistry registry = cluster.getConfiguration().getCodecRegistry(); |
| 316 | 316 | Session session = cluster.connect(keyspace); |
modified driver-mapping/src/test/java/com/datastax/driver/mapping/UDTFieldMapperTest.java +4 −4
| @@ -40,7 +40,7 @@ | ||
| 40 | 40 | ccm = CCMBridge.builder().build(); |
| 41 | 41 | cluster = Cluster.builder() |
| 42 | 42 | .addContactPointsWithPorts(ccm.addressOfNode(1)) |
| 43 | - .withAddressTranslator(ccm.addressTranslator()) | |
| 43 | + .withPort(ccm.getBinaryPort()) | |
| 44 | 44 | .build(); |
| 45 | 45 | Session session1 = cluster.connect(); |
| 46 | 46 | session1.execute("create schema if not exists java_509 " + |
| @@ -56,7 +56,7 @@ | ||
| 56 | 56 | // Create entities with another connection |
| 57 | 57 | cluster = Cluster.builder() |
| 58 | 58 | .addContactPointsWithPorts(ccm.addressOfNode(1)) |
| 59 | - .withAddressTranslator(ccm.addressTranslator()) | |
| 59 | + .withPort(ccm.getBinaryPort()) | |
| 60 | 60 | .build(); |
| 61 | 61 | Session session2 = cluster.newSession(); |
| 62 | 62 | Mapper<MyHashWithKeyspace> hashMapper = new MappingManager(session2).mapper(MyHashWithKeyspace.class); |
| @@ -93,7 +93,7 @@ | ||
| 93 | 93 | ccm = CCMBridge.builder().build(); |
| 94 | 94 | cluster = Cluster.builder() |
| 95 | 95 | .addContactPointsWithPorts(ccm.addressOfNode(1)) |
| 96 | - .withAddressTranslator(ccm.addressTranslator()) | |
| 96 | + .withPort(ccm.getBinaryPort()) | |
| 97 | 97 | .build(); |
| 98 | 98 | Session session1 = cluster.connect(); |
| 99 | 99 | session1.execute("create schema if not exists java_509 " + |
| @@ -110,7 +110,7 @@ | ||
| 110 | 110 | // Create entities with another connection |
| 111 | 111 | cluster = Cluster.builder() |
| 112 | 112 | .addContactPointsWithPorts(ccm.addressOfNode(1)) |
| 113 | - .withAddressTranslator(ccm.addressTranslator()) | |
| 113 | + .withPort(ccm.getBinaryPort()) | |
| 114 | 114 | .build(); |
| 115 | 115 | Session session2 = cluster.newSession(); |
| 116 | 116 |