kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 45816f44a013b5f2f336370ea1f03dcde5f5a3694499faed4cd6f87e936f90d7 |
|---|---|
| Author | Andrew Tolbert <andrew.tolbert@datastax.com> · 2015-11-06 12:57 -06:00 |
| Committer | Andrew Tolbert <andrew.tolbert@datastax.com> · 2015-11-06 12:57 -06:00 |
| Parents | ead55a108ed1 |
2 files changed
modified driver-core/src/test/java/com/datastax/driver/core/ClusterInitTest.java +38 −0
| @@ -27,6 +27,7 @@ | ||
| 27 | 27 | import com.google.common.collect.ImmutableMap; |
| 28 | 28 | import com.google.common.collect.ImmutableSet; |
| 29 | 29 | import com.google.common.collect.Lists; |
| 30 | +import com.google.common.collect.Maps; | |
| 30 | 31 | import com.google.common.util.concurrent.Uninterruptibles; |
| 31 | 32 | import org.scassandra.Scassandra; |
| 32 | 33 | import org.scassandra.http.client.PrimingClient; |
| @@ -220,6 +221,43 @@ | ||
| 220 | 221 | } |
| 221 | 222 | } |
| 222 | 223 | |
| 224 | + /** | |
| 225 | + * Ensures that if a node is detected that does not support the protocol version in use on init that | |
| 226 | + * the node is not marked up and the all other hosts are appropriately marked up. | |
| 227 | + * | |
| 228 | + * @jira_ticket JAVA-854 | |
| 229 | + * @test_category host:state | |
| 230 | + */ | |
| 231 | + @Test(groups="short") | |
| 232 | + public void should_not_abort_init_if_host_does_not_support_protocol_version() { | |
| 233 | + Map<Integer,Map<String,Object>> nodeProperties = Maps.newHashMap(); | |
| 234 | + // Configure node 2 to run with an older version which uses protocol v1. | |
| 235 | + nodeProperties.put(2, ImmutableMap.<String,Object>of("release_version", "1.2.19")); | |
| 236 | + SCassandraCluster scassandraCluster = new SCassandraCluster(CCMBridge.IP_PREFIX, 5, nodeProperties); | |
| 237 | + Cluster cluster = Cluster.builder() | |
| 238 | + .addContactPoints(scassandraCluster.addresses().get(0)) | |
| 239 | + .withNettyOptions(nonQuietClusterCloseOptions) | |
| 240 | + .build(); | |
| 241 | + | |
| 242 | + try { | |
| 243 | + cluster.init(); | |
| 244 | + for(int i = 0; i < scassandraCluster.addresses().size(); i++) { | |
| 245 | + String hostAddress = scassandraCluster.addresses().get(i).getHostAddress(); | |
| 246 | + if (i == 2) { | |
| 247 | + // As this host is at an older protocol version, it should not be marked added. | |
| 248 | + assertThat(cluster).host(hostAddress).hasState(Host.State.ADDED); | |
| 249 | + } else { | |
| 250 | + // All hosts should be set as 'UP' as part of cluster.init() if they are | |
| 251 | + // in added state it's possible that cluster.init() did not fully complete. | |
| 252 | + assertThat(cluster).host(hostAddress).hasState(Host.State.UP); | |
| 253 | + } | |
| 254 | + } | |
| 255 | + } finally { | |
| 256 | + cluster.close(); | |
| 257 | + scassandraCluster.stop(); | |
| 258 | + } | |
| 259 | + } | |
| 260 | + | |
| 223 | 261 | private void primePeerRows(Scassandra scassandra, List<FakeHost> otherHosts) throws UnknownHostException { |
| 224 | 262 | PrimingClient primingClient = PrimingClient.builder() |
| 225 | 263 | .withHost("localhost").withPort(scassandra.getAdminPort()) |
modified driver-core/src/test/java/com/datastax/driver/core/SCassandraCluster.java +16 −4
| @@ -35,6 +35,7 @@ | ||
| 35 | 35 | * and a CCM cluster is not running at the same time. |
| 36 | 36 | */ |
| 37 | 37 | public class SCassandraCluster { |
| 38 | + private static final Map<Integer,Map<String,Object>> EMPTY_MAP = ImmutableMap.of(); | |
| 38 | 39 | private static final int BINARY_PORT = 9042; |
| 39 | 40 | private static final int ADMIN_PORT = 9052; |
| 40 | 41 | |
| @@ -42,16 +43,22 @@ | ||
| 42 | 43 | private final List<InetAddress> addresses; |
| 43 | 44 | private final List<PrimingClient> primingClients; |
| 44 | 45 | private final List<ActivityClient> activityClients; |
| 46 | + private final Map<Integer,Map<String,Object>> propertyMap; | |
| 45 | 47 | |
| 46 | 48 | public SCassandraCluster(int nodeCount) { |
| 47 | 49 | this(CCMBridge.IP_PREFIX, nodeCount); |
| 48 | 50 | } |
| 49 | 51 | |
| 50 | 52 | public SCassandraCluster(String ipPrefix, int nodeCount) { |
| 53 | + this(ipPrefix, nodeCount, EMPTY_MAP); | |
| 54 | + } | |
| 55 | + | |
| 56 | + public SCassandraCluster(String ipPrefix, int nodeCount, Map<Integer,Map<String,Object>> propertyMap) { | |
| 51 | 57 | scassandras = Lists.newArrayListWithCapacity(nodeCount); |
| 52 | 58 | addresses = Lists.newArrayListWithCapacity(nodeCount); |
| 53 | 59 | primingClients = Lists.newArrayListWithCapacity(nodeCount); |
| 54 | 60 | activityClients = Lists.newArrayListWithCapacity(nodeCount); |
| 61 | + this.propertyMap = propertyMap; | |
| 55 | 62 | |
| 56 | 63 | for (int i = 1; i <= nodeCount; i++) { |
| 57 | 64 | String ip = ipPrefix + i; |
| @@ -142,10 +149,10 @@ | ||
| 142 | 149 | Map<String, ?> row = ImmutableMap.<String, Object>builder() |
| 143 | 150 | .put("peer", address) |
| 144 | 151 | .put("rpc_address", address) |
| 145 | - .put("data_center", "datacenter1") | |
| 146 | - .put("rack", "rack1") | |
| 147 | - .put("release_version", "2.0.1") | |
| 148 | - .put("tokens", ImmutableSet.of(Long.toString(Long.MIN_VALUE + i))) | |
| 152 | + .put("data_center", getProperty(i, "data_center", "datacenter1")) | |
| 153 | + .put("rack", getProperty(i, "rack1", "rack1")) | |
| 154 | + .put("release_version", getProperty(i, "release_version", "2.0.1")) | |
| 155 | + .put("tokens", getProperty(i, "tokens", ImmutableSet.of(Long.toString(Long.MIN_VALUE + i)))) | |
| 149 | 156 | .build(); |
| 150 | 157 | |
| 151 | 158 | rows.add(row); |
| @@ -166,6 +173,11 @@ | ||
| 166 | 173 | .build()); |
| 167 | 174 | } |
| 168 | 175 | |
| 176 | + private Object getProperty(int node, String property, Object defaultValue) { | |
| 177 | + Map<String,Object> nodeProperties = propertyMap.get(node); | |
| 178 | + return nodeProperties != null && nodeProperties.containsKey(property) ? nodeProperties.get(property) : defaultValue; | |
| 179 | + } | |
| 180 | + | |
| 169 | 181 | static final ImmutableMap<String, ColumnTypes> SELECT_PEERS_COLUMN_TYPES = |
| 170 | 182 | ImmutableMap.<String, ColumnTypes>builder() |
| 171 | 183 | .put("peer", ColumnTypes.Inet) |