Elffuss BraidHub

kikocis/java-driver public

Merge pull request #621 from datastax/java852-fix

Fix checkSchemaAgreement bug introduced in JAVA-852
Changesetc3395b80b593f6c566169b840e1076992c162e5f0baecab8fdc08b9da4e1f950
AuthorOlivier Michallat <olim7t@users.noreply.github.com> · 2016-03-15 10:32 +01:00
CommitterOlivier Michallat <olim7t@users.noreply.github.com> · 2016-03-15 10:32 +01:00
Parents23c646c58e54, 172ea7610cbc

Browse the files at this changeset

5 files changed

modified driver-core/pom.xml +1 −0
@@ -381,6 +381,7 @@
381381 <include>**/SSL*Test.java</include>
382382 <include>**/UUIDsPID*.java</include>
383383 <include>**/ControlConnectionTest.java</include>
384+ <include>**/ExtendedPeerCheckDisabledTest.java</include>
384385 </includes>
385386 </configuration>
386387 </plugin>
modified driver-core/src/main/java/com/datastax/driver/core/ControlConnection.java +3 −7
@@ -427,10 +427,9 @@
427427 InetAddress peer = peersRow.getInet("peer");
428428 InetAddress addr = peersRow.getInet("rpc_address");
429429
430- // We've already called isValid on the row, which checks this
431- assert addr != null;
432-
433- if (peer.equals(connectedHost.getAddress()) || addr.equals(connectedHost.getAddress())) {
430+ if (addr == null) {
431+ return null;
432+ } else if (peer.equals(connectedHost.getAddress()) || addr.equals(connectedHost.getAddress())) {
434433 // Some DSE versions were inserting a line for the local node in peers (with mostly null values). This has been fixed, but if we
435434 // detect that's the case, ignore it as it's not really a big deal.
436435 logger.debug("System.peers on node {} has a line for itself. This is not normal but is a known problem of some DSE version. Ignoring the entry.", connectedHost);
@@ -733,9 +732,6 @@
733732
734733 for (Row row : peersFuture.get()) {
735734
736- if (!isValidPeer(row, false))
737- continue;
738-
739735 InetSocketAddress addr = addressToUseForPeerHost(row, connection.address, cluster);
740736 if (addr == null || row.isNull("schema_version"))
741737 continue;
modified driver-core/src/test/java/com/datastax/driver/core/ControlConnectionTest.java +2 −16
@@ -225,7 +225,7 @@
225225 }
226226
227227 @DataProvider
228- public Object[][] disallowedNullColumnsInPeerData() {
228+ public static Object[][] disallowedNullColumnsInPeerData() {
229229 return new Object[][]{
230230 {"host_id"},
231231 {"data_center"},
@@ -325,20 +325,6 @@
325325 }
326326 }
327327
328- /**
329- * Validates that if the com.datastax.driver.EXTENDED_PEER_CHECK system property is set to false that a peer
330- * with null values for host_id, data_center, rack, tokens is not ignored.
331- *
332- * @test_category host:metadata
333- * @jira_ticket JAVA-852
334- * @since 2.1.10
335- */
336- @Test(groups = "isolated", dataProvider = "disallowedNullColumnsInPeerData")
337- @CCMConfig(createCcm = false)
338- public void should_use_peer_if_extended_peer_check_is_disabled(String columns) {
339- System.setProperty("com.datastax.driver.EXTENDED_PEER_CHECK", "false");
340- run_with_null_peer_info(columns, true);
341- }
342328
343329 /**
344330 * Validates that if the com.datastax.driver.EXTENDED_PEER_CHECK system property is set to true that a peer
@@ -368,7 +354,7 @@
368354 run_with_null_peer_info(columns, false);
369355 }
370356
371- private void run_with_null_peer_info(String columns, boolean expectPeer2) {
357+ static void run_with_null_peer_info(String columns, boolean expectPeer2) {
372358 // given: A cluster with peer 2 having a null rack.
373359 ScassandraCluster.ScassandraClusterBuilder builder = ScassandraCluster.builder()
374360 .withNodes(3);
added driver-core/src/test/java/com/datastax/driver/core/ExtendedPeerCheckDisabledTest.java +36 −0
@@ -0,0 +1,36 @@
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+public class ExtendedPeerCheckDisabledTest {
21+
22+ /**
23+ * Validates that if the com.datastax.driver.EXTENDED_PEER_CHECK system property is set to false that a peer
24+ * with null values for host_id, data_center, rack, tokens is not ignored.
25+ *
26+ * @test_category host:metadata
27+ * @jira_ticket JAVA-852
28+ * @since 2.1.10
29+ */
30+ @Test(groups = "isolated", dataProvider = "disallowedNullColumnsInPeerData", dataProviderClass = ControlConnectionTest.class)
31+ @CCMConfig(createCcm = false)
32+ public void should_use_peer_if_extended_peer_check_is_disabled(String columns) {
33+ System.setProperty("com.datastax.driver.EXTENDED_PEER_CHECK", "false");
34+ ControlConnectionTest.run_with_null_peer_info(columns, true);
35+ }
36+}
modified driver-core/src/test/java/com/datastax/driver/core/ScassandraCluster.java +7 −1
@@ -52,6 +52,8 @@
5252
5353 private final List<Map<String, ?>> keyspaceRows;
5454
55+ private static final java.util.UUID schemaVersion = UUIDs.random();
56+
5557
5658 private final Map<Integer, Map<Integer, Map<String, Object>>> forcedPeerInfos;
5759
@@ -297,6 +299,7 @@
297299 addPeerInfo(row, dc, n + 1, "rack", getPeerInfo(dc, n + 1, "rack", "rack1"));
298300 addPeerInfo(row, dc, n + 1, "release_version", getPeerInfo(dc, n + 1, "release_version", "2.1.8"));
299301 addPeerInfo(row, dc, n + 1, "tokens", ImmutableSet.of(tokens.get(n)));
302+ addPeerInfo(row, dc, n + 1, "schema_version", schemaVersion);
300303 } else { // prime system.peers.
301304 query = "SELECT * FROM system.peers WHERE peer='" + address + "'";
302305 metadata = SELECT_PEERS;
@@ -308,6 +311,7 @@
308311 addPeerInfo(row, dc, n + 1, "release_version", getPeerInfo(dc, n + 1, "release_version", "2.1.8"));
309312 addPeerInfo(row, dc, n + 1, "tokens", ImmutableSet.of(Long.toString(tokens.get(n))));
310313 addPeerInfo(row, dc, n + 1, "host_id", UUIDs.random());
314+ addPeerInfo(row, dc, n + 1, "schema_version", schemaVersion);
311315 rows.add(row);
312316 }
313317 client.prime(PrimingRequest.queryBuilder()
@@ -379,7 +383,8 @@
379383 column("rack", TEXT),
380384 column("release_version", TEXT),
381385 column("tokens", set(TEXT)),
382- column("host_id", UUID)
386+ column("host_id", UUID),
387+ column("schema_version", UUID)
383388 };
384389
385390 public static final org.scassandra.http.client.types.ColumnMetadata[] SELECT_LOCAL = {
@@ -394,6 +399,7 @@
394399 column("rack", TEXT),
395400 column("release_version", TEXT),
396401 column("tokens", set(TEXT)),
402+ column("schema_version", UUID)
397403 };
398404
399405 static final org.scassandra.http.client.types.ColumnMetadata[] SELECT_CLUSTER_NAME = {