Elffuss BraidHub

kikocis/java-driver public

Add ClusterInitTest for JAVA-854.
Changeset45816f44a013b5f2f336370ea1f03dcde5f5a3694499faed4cd6f87e936f90d7
AuthorAndrew Tolbert <andrew.tolbert@datastax.com> · 2015-11-06 12:57 -06:00
CommitterAndrew Tolbert <andrew.tolbert@datastax.com> · 2015-11-06 12:57 -06:00
Parentsead55a108ed1

Browse the files at this changeset

2 files changed

modified driver-core/src/test/java/com/datastax/driver/core/ClusterInitTest.java +38 −0
@@ -27,6 +27,7 @@
2727 import com.google.common.collect.ImmutableMap;
2828 import com.google.common.collect.ImmutableSet;
2929 import com.google.common.collect.Lists;
30+import com.google.common.collect.Maps;
3031 import com.google.common.util.concurrent.Uninterruptibles;
3132 import org.scassandra.Scassandra;
3233 import org.scassandra.http.client.PrimingClient;
@@ -220,6 +221,43 @@
220221 }
221222 }
222223
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+
223261 private void primePeerRows(Scassandra scassandra, List<FakeHost> otherHosts) throws UnknownHostException {
224262 PrimingClient primingClient = PrimingClient.builder()
225263 .withHost("localhost").withPort(scassandra.getAdminPort())
modified driver-core/src/test/java/com/datastax/driver/core/SCassandraCluster.java +16 −4
@@ -35,6 +35,7 @@
3535 * and a CCM cluster is not running at the same time.
3636 */
3737 public class SCassandraCluster {
38+ private static final Map<Integer,Map<String,Object>> EMPTY_MAP = ImmutableMap.of();
3839 private static final int BINARY_PORT = 9042;
3940 private static final int ADMIN_PORT = 9052;
4041
@@ -42,16 +43,22 @@
4243 private final List<InetAddress> addresses;
4344 private final List<PrimingClient> primingClients;
4445 private final List<ActivityClient> activityClients;
46+ private final Map<Integer,Map<String,Object>> propertyMap;
4547
4648 public SCassandraCluster(int nodeCount) {
4749 this(CCMBridge.IP_PREFIX, nodeCount);
4850 }
4951
5052 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) {
5157 scassandras = Lists.newArrayListWithCapacity(nodeCount);
5258 addresses = Lists.newArrayListWithCapacity(nodeCount);
5359 primingClients = Lists.newArrayListWithCapacity(nodeCount);
5460 activityClients = Lists.newArrayListWithCapacity(nodeCount);
61+ this.propertyMap = propertyMap;
5562
5663 for (int i = 1; i <= nodeCount; i++) {
5764 String ip = ipPrefix + i;
@@ -142,10 +149,10 @@
142149 Map<String, ?> row = ImmutableMap.<String, Object>builder()
143150 .put("peer", address)
144151 .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))))
149156 .build();
150157
151158 rows.add(row);
@@ -166,6 +173,11 @@
166173 .build());
167174 }
168175
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+
169181 static final ImmutableMap<String, ColumnTypes> SELECT_PEERS_COLUMN_TYPES =
170182 ImmutableMap.<String, ColumnTypes>builder()
171183 .put("peer", ColumnTypes.Inet)