kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | e6290790ad2eb361f28beea853c47a32e9eb39c1a30f9678d2ce9b891a180bfd |
|---|---|
| Author | Andrew Tolbert <andrew.tolbert@datastax.com> · 2015-03-05 17:04 -06:00 |
| Committer | Andrew Tolbert <andrew.tolbert@datastax.com> · 2015-03-05 17:21 -06:00 |
| Parents | 36b017dc4f86 |
4 files changed
modified driver-core/src/main/java/com/datastax/driver/core/Connection.java +1 −3
| @@ -183,9 +183,7 @@ | ||
| 183 | 183 | |
| 184 | 184 | private UnsupportedProtocolVersionException unsupportedProtocolVersionException(int triedVersion) { |
| 185 | 185 | logger.debug("Got unsupported protocol version error from {} for version {}", address, triedVersion); |
| 186 | - UnsupportedProtocolVersionException exc = new UnsupportedProtocolVersionException(address, triedVersion); | |
| 187 | - defunct(new TransportException(address, "Cannot initialize transport", exc)); | |
| 188 | - return exc; | |
| 186 | + return new UnsupportedProtocolVersionException(address, triedVersion); | |
| 189 | 187 | } |
| 190 | 188 | |
| 191 | 189 | private void authenticateV1(Authenticator authenticator) throws ConnectionException, BusyConnectionException, ExecutionException, InterruptedException { |
modified driver-core/src/test/java/com/datastax/driver/core/CCMBridge.java +8 −0
| @@ -98,6 +98,14 @@ | ||
| 98 | 98 | return bridge; |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | + public static CCMBridge createWithCustomVersion(String name, int nbNodes, String cassandraVersion) { | |
| 102 | + checkArgument(!"current".equals(name.toLowerCase()), | |
| 103 | + "cluster can't be called \"current\""); | |
| 104 | + CCMBridge bridge = new CCMBridge(); | |
| 105 | + bridge.execute("ccm create %s -n %d -s -i %s -b -v %s ", name, nbNodes, IP_PREFIX, cassandraVersion); | |
| 106 | + return bridge; | |
| 107 | + } | |
| 108 | + | |
| 101 | 109 | public static CCMBridge create(String name, int nbNodesDC1, int nbNodesDC2) { |
| 102 | 110 | checkArgument(!"current".equals(name.toLowerCase()), |
| 103 | 111 | "cluster can't be called \"current\""); |
added driver-core/src/test/java/com/datastax/driver/core/RecommissionedNodeTest.java +163 −0
| @@ -0,0 +1,163 @@ | ||
| 1 | +package com.datastax.driver.core; | |
| 2 | + | |
| 3 | +import java.util.concurrent.TimeUnit; | |
| 4 | + | |
| 5 | +import org.slf4j.Logger; | |
| 6 | +import org.slf4j.LoggerFactory; | |
| 7 | +import org.testng.annotations.AfterMethod; | |
| 8 | +import org.testng.annotations.Test; | |
| 9 | + | |
| 10 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 11 | + | |
| 12 | +import static com.datastax.driver.core.Assertions.*; | |
| 13 | +import static com.datastax.driver.core.Host.State.DOWN; | |
| 14 | +import static com.datastax.driver.core.Host.State.UP; | |
| 15 | + | |
| 16 | +/** | |
| 17 | + * Due to C* gossip bugs, system.peers may report nodes that are gone from the cluster. | |
| 18 | + * | |
| 19 | + * This class tests scenarios where these nodes have been recommissioned to another cluster and | |
| 20 | + * come back up. The driver must detect that they are not part of the cluster anymore, and ignore them. | |
| 21 | + */ | |
| 22 | +public class RecommissionedNodeTest { | |
| 23 | + private static final Logger logger = LoggerFactory.getLogger(RecommissionedNodeTest.class); | |
| 24 | + | |
| 25 | + CCMBridge mainCcm, otherCcm; | |
| 26 | + Cluster mainCluster; | |
| 27 | + | |
| 28 | + @Test(groups = "long") | |
| 29 | + public void should_ignore_recommissioned_node_on_reconnection_attempt() throws Exception { | |
| 30 | + mainCcm = CCMBridge.create("main", 3); | |
| 31 | + // node1 will be our "recommissioned" node, for now we just stop it so that it stays in the peers table. | |
| 32 | + mainCcm.stop(1); | |
| 33 | + mainCcm.waitForDown(1); | |
| 34 | + | |
| 35 | + // Now start the driver that will connect to node2 and node3, and consider node1 down | |
| 36 | + mainCluster = Cluster.builder().addContactPoint(CCMBridge.IP_PREFIX + "2").build(); | |
| 37 | + mainCluster.connect(); | |
| 38 | + waitForCountUpHosts(mainCluster, 2); | |
| 39 | + // From that point, reconnections to node1 have been scheduled. | |
| 40 | + | |
| 41 | + // Start another ccm that will reuse node1's address | |
| 42 | + otherCcm = CCMBridge.create("other", 1); | |
| 43 | + otherCcm.waitForUp(1); | |
| 44 | + | |
| 45 | + // Give the driver the time to notice the node is back up and try to connect to it. | |
| 46 | + TimeUnit.SECONDS.sleep(32); | |
| 47 | + | |
| 48 | + assertThat(countUpHosts(mainCluster)).isEqualTo(2); | |
| 49 | + } | |
| 50 | + | |
| 51 | + @Test(groups = "long") | |
| 52 | + public void should_ignore_recommissioned_node_on_control_connection_reconnect() throws Exception { | |
| 53 | + mainCcm = CCMBridge.create("main", 2); | |
| 54 | + mainCcm.stop(1); | |
| 55 | + mainCcm.waitForDown(1); | |
| 56 | + | |
| 57 | + // Start the driver, the control connection will be on node2 | |
| 58 | + mainCluster = Cluster.builder().addContactPoint(CCMBridge.IP_PREFIX + "2").build(); | |
| 59 | + mainCluster.connect(); | |
| 60 | + waitForCountUpHosts(mainCluster, 1); | |
| 61 | + | |
| 62 | + // Start another ccm that will reuse node1's address | |
| 63 | + otherCcm = CCMBridge.create("other", 1); | |
| 64 | + otherCcm.waitForUp(1); | |
| 65 | + | |
| 66 | + // Stop node2, the control connection gets defunct | |
| 67 | + mainCcm.stop(2); | |
| 68 | + TimeUnit.SECONDS.sleep(32); | |
| 69 | + | |
| 70 | + // The driver should not try to reconnect the control connection to node1 | |
| 71 | + assertThat(mainCluster).hasClosedControlConnection(); | |
| 72 | + } | |
| 73 | + | |
| 74 | + @Test(groups = "long") | |
| 75 | + public void should_ignore_recommissioned_node_on_session_init() throws Exception { | |
| 76 | + // Simulate the bug before starting the cluster | |
| 77 | + mainCcm = CCMBridge.create("main", 2); | |
| 78 | + mainCcm.stop(1); | |
| 79 | + mainCcm.waitForDown(1); | |
| 80 | + | |
| 81 | + otherCcm = CCMBridge.create("other", 1); | |
| 82 | + otherCcm.waitForUp(1); | |
| 83 | + | |
| 84 | + // Start the driver, it should only connect to node 2 | |
| 85 | + mainCluster = Cluster.builder().addContactPoint(CCMBridge.IP_PREFIX + "2").build(); | |
| 86 | + | |
| 87 | + // When we first initialize the Cluster, all hosts are marked UP | |
| 88 | + assertThat(mainCluster).host(2).hasState(UP); | |
| 89 | + assertThat(mainCluster).host(1).hasState(UP); | |
| 90 | + | |
| 91 | + // Create a session. This will try to open a pool to node 1 and find out that the cluster name doesn't match. | |
| 92 | + mainCluster.connect(); | |
| 93 | + | |
| 94 | + // Node 1 should now be DOWN with no reconnection attempt | |
| 95 | + assertThat(mainCluster).host(1) | |
| 96 | + .hasState(DOWN) | |
| 97 | + .isNotReconnectingFromDown() | |
| 98 | + .isNotReconnectingFromSuspected(); | |
| 99 | + } | |
| 100 | + | |
| 101 | + @Test(groups = "long") | |
| 102 | + @CassandraVersion(major=2.0) | |
| 103 | + public void should_ignore_node_that_does_not_support_protocol_version_on_session_init() throws Exception { | |
| 104 | + // Simulate the bug before starting the cluster | |
| 105 | + mainCcm = CCMBridge.create("main", 2); | |
| 106 | + mainCcm.stop(1); | |
| 107 | + mainCcm.waitForDown(1); | |
| 108 | + | |
| 109 | + otherCcm = CCMBridge.createWithCustomVersion("main", 1, "1.2.19"); | |
| 110 | + otherCcm.waitForUp(1); | |
| 111 | + | |
| 112 | + // Start the driver, it should only connect to node 2 | |
| 113 | + mainCluster = Cluster.builder().addContactPoint(CCMBridge.IP_PREFIX + "2").build(); | |
| 114 | + | |
| 115 | + // Create a session. This will try to open a pool to node 1 and find that it doesn't support protocol version. | |
| 116 | + mainCluster.connect(); | |
| 117 | + | |
| 118 | + // Node 1 should now be DOWN with no reconnection attempt | |
| 119 | + assertThat(mainCluster).host(1) | |
| 120 | + .hasState(DOWN) | |
| 121 | + .isNotReconnectingFromDown() | |
| 122 | + .isNotReconnectingFromSuspected(); | |
| 123 | + } | |
| 124 | + | |
| 125 | + @AfterMethod(groups = "long") | |
| 126 | + public void teardown() { | |
| 127 | + if (mainCluster != null) | |
| 128 | + mainCluster.close(); | |
| 129 | + | |
| 130 | + if (mainCcm != null) | |
| 131 | + mainCcm.remove(); | |
| 132 | + if (otherCcm != null) | |
| 133 | + otherCcm.remove(); | |
| 134 | + } | |
| 135 | + | |
| 136 | + private static int countUpHosts(Cluster cluster) { | |
| 137 | + int ups = 0; | |
| 138 | + for (Host host : cluster.getMetadata().getAllHosts()) { | |
| 139 | + if (host.isUp()) | |
| 140 | + ups += 1; | |
| 141 | + } | |
| 142 | + return ups; | |
| 143 | + } | |
| 144 | + | |
| 145 | + private static void waitForCountUpHosts(Cluster cluster, int expectedCount) throws InterruptedException { | |
| 146 | + int maxRetries = 30; | |
| 147 | + int interval = 10; | |
| 148 | + | |
| 149 | + for (int i = 0; i <= maxRetries; i++) { | |
| 150 | + int actualCount = countUpHosts(cluster); | |
| 151 | + if (actualCount == expectedCount) | |
| 152 | + return; | |
| 153 | + | |
| 154 | + if (i == maxRetries) | |
| 155 | + fail(String.format("Up host count didn't reach %d after %d seconds", | |
| 156 | + expectedCount, i * interval)); | |
| 157 | + else | |
| 158 | + logger.debug("Counted {} up hosts after {} seconds", actualCount, i * interval); | |
| 159 | + | |
| 160 | + TimeUnit.SECONDS.sleep(interval); | |
| 161 | + } | |
| 162 | + } | |
| 163 | +} | |
| No newline at the end of the file |
deleted driver-core/src/test/java/com/datastax/driver/core/RecommissionnedNodeTest.java +0 −138
| @@ -1,138 +0,0 @@ | ||
| 1 | -package com.datastax.driver.core; | |
| 2 | - | |
| 3 | -import java.util.concurrent.TimeUnit; | |
| 4 | - | |
| 5 | -import org.slf4j.Logger; | |
| 6 | -import org.slf4j.LoggerFactory; | |
| 7 | -import org.testng.annotations.AfterMethod; | |
| 8 | -import org.testng.annotations.Test; | |
| 9 | - | |
| 10 | -import static com.datastax.driver.core.Assertions.*; | |
| 11 | -import static com.datastax.driver.core.Host.State.ADDED; | |
| 12 | -import static com.datastax.driver.core.Host.State.DOWN; | |
| 13 | -import static com.datastax.driver.core.Host.State.UP; | |
| 14 | - | |
| 15 | -/** | |
| 16 | - * Due to C* gossip bugs, system.peers may report nodes that are gone from the cluster. | |
| 17 | - * | |
| 18 | - * This class tests scenarios where these nodes have been recommissionned to another cluster and | |
| 19 | - * come back up. The driver must detect that they are not part of the cluster anymore, and ignore them. | |
| 20 | - */ | |
| 21 | -public class RecommissionnedNodeTest { | |
| 22 | - private static final Logger logger = LoggerFactory.getLogger(RecommissionnedNodeTest.class); | |
| 23 | - | |
| 24 | - CCMBridge mainCcm, otherCcm; | |
| 25 | - Cluster mainCluster; | |
| 26 | - | |
| 27 | - @Test(groups = "long") | |
| 28 | - public void should_ignore_recommissionned_node_on_reconnection_attempt() throws Exception { | |
| 29 | - mainCcm = CCMBridge.create("main", 3); | |
| 30 | - // node1 will be our "recommissionned" node, for now we just stop it so that it stays in the peers table. | |
| 31 | - mainCcm.stop(1); | |
| 32 | - mainCcm.waitForDown(1); | |
| 33 | - | |
| 34 | - // Now start the driver that will connect to node2 and node3, and consider node1 down | |
| 35 | - mainCluster = Cluster.builder().addContactPoint(CCMBridge.IP_PREFIX + "2").build(); | |
| 36 | - mainCluster.connect(); | |
| 37 | - waitForCountUpHosts(mainCluster, 2); | |
| 38 | - // From that point, reconnections to node1 have been scheduled. | |
| 39 | - | |
| 40 | - // Start another ccm that will reuse node1's address | |
| 41 | - otherCcm = CCMBridge.create("other", 1); | |
| 42 | - otherCcm.waitForUp(1); | |
| 43 | - | |
| 44 | - // Give the driver the time to notice the node is back up and try to connect to it. | |
| 45 | - TimeUnit.SECONDS.sleep(32); | |
| 46 | - | |
| 47 | - assertThat(countUpHosts(mainCluster)).isEqualTo(2); | |
| 48 | - } | |
| 49 | - | |
| 50 | - @Test(groups = "long") | |
| 51 | - public void should_ignore_recommissionned_node_on_control_connection_reconnect() throws Exception { | |
| 52 | - mainCcm = CCMBridge.create("main", 2); | |
| 53 | - mainCcm.stop(1); | |
| 54 | - mainCcm.waitForDown(1); | |
| 55 | - | |
| 56 | - // Start the driver, the control connection will be on node2 | |
| 57 | - mainCluster = Cluster.builder().addContactPoint(CCMBridge.IP_PREFIX + "2").build(); | |
| 58 | - mainCluster.connect(); | |
| 59 | - waitForCountUpHosts(mainCluster, 1); | |
| 60 | - | |
| 61 | - // Start another ccm that will reuse node1's address | |
| 62 | - otherCcm = CCMBridge.create("other", 1); | |
| 63 | - otherCcm.waitForUp(1); | |
| 64 | - | |
| 65 | - // Stop node2, the control connection gets defunct | |
| 66 | - mainCcm.stop(2); | |
| 67 | - TimeUnit.SECONDS.sleep(32); | |
| 68 | - | |
| 69 | - // The driver should not try to reconnect the control connection to node1 | |
| 70 | - assertThat(mainCluster).hasClosedControlConnection(); | |
| 71 | - } | |
| 72 | - | |
| 73 | - @Test(groups = "long") | |
| 74 | - public void should_ignore_recommissionned_node_on_session_init() throws Exception { | |
| 75 | - // Simulate the bug before starting the cluster | |
| 76 | - mainCcm = CCMBridge.create("main", 2); | |
| 77 | - mainCcm.stop(1); | |
| 78 | - mainCcm.waitForDown(1); | |
| 79 | - | |
| 80 | - otherCcm = CCMBridge.create("other", 1); | |
| 81 | - otherCcm.waitForUp(1); | |
| 82 | - | |
| 83 | - // Start the driver, it should only connect to node 2 | |
| 84 | - mainCluster = Cluster.builder().addContactPoint(CCMBridge.IP_PREFIX + "2").build(); | |
| 85 | - | |
| 86 | - // When we first initialize the Cluster, all hosts are marked UP | |
| 87 | - assertThat(mainCluster).host(2).hasState(UP); | |
| 88 | - assertThat(mainCluster).host(1).hasState(UP); | |
| 89 | - | |
| 90 | - // Create a session. This will try to open a pool to node 1 and find out that the cluster name doesn't match. | |
| 91 | - mainCluster.connect(); | |
| 92 | - | |
| 93 | - // Node 1 should now be DOWN with no reconnection attempt | |
| 94 | - assertThat(mainCluster).host(1) | |
| 95 | - .hasState(DOWN) | |
| 96 | - .isNotReconnectingFromDown() | |
| 97 | - .isNotReconnectingFromSuspected(); | |
| 98 | - } | |
| 99 | - | |
| 100 | - @AfterMethod(groups = "long") | |
| 101 | - public void teardown() { | |
| 102 | - if (mainCluster != null) | |
| 103 | - mainCluster.close(); | |
| 104 | - | |
| 105 | - if (mainCcm != null) | |
| 106 | - mainCcm.remove(); | |
| 107 | - if (otherCcm != null) | |
| 108 | - otherCcm.remove(); | |
| 109 | - } | |
| 110 | - | |
| 111 | - private static int countUpHosts(Cluster cluster) { | |
| 112 | - int ups = 0; | |
| 113 | - for (Host host : cluster.getMetadata().getAllHosts()) { | |
| 114 | - if (host.isUp()) | |
| 115 | - ups += 1; | |
| 116 | - } | |
| 117 | - return ups; | |
| 118 | - } | |
| 119 | - | |
| 120 | - private static void waitForCountUpHosts(Cluster cluster, int expectedCount) throws InterruptedException { | |
| 121 | - int maxRetries = 30; | |
| 122 | - int interval = 10; | |
| 123 | - | |
| 124 | - for (int i = 0; i <= maxRetries; i++) { | |
| 125 | - int actualCount = countUpHosts(cluster); | |
| 126 | - if (actualCount == expectedCount) | |
| 127 | - return; | |
| 128 | - | |
| 129 | - if (i == maxRetries) | |
| 130 | - fail(String.format("Up host count didn't reach %d after %d seconds", | |
| 131 | - expectedCount, i * interval)); | |
| 132 | - else | |
| 133 | - logger.debug("Counted {} up hosts after {} seconds", actualCount, i * interval); | |
| 134 | - | |
| 135 | - TimeUnit.SECONDS.sleep(interval); | |
| 136 | - } | |
| 137 | - } | |
| 138 | -} | |
| No newline at the end of the file |