kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 738a73e7064e00e0717fcc5168a59cf26505700b76df268c6c371a3fc241bef1 |
|---|---|
| Author | Andrew Tolbert <andrew.tolbert@datastax.com> · 2016-12-06 17:10 -06:00 |
| Committer | Andrew Tolbert <andrew.tolbert@datastax.com> · 2016-12-14 17:44 -06:00 |
| Parents | b5a08ee3ce3d |
2 files changed
modified driver-core/src/test/java/com/datastax/driver/core/HeartbeatTest.java +52 −44
| @@ -63,40 +63,44 @@ | ||
| 63 | 63 | .setHeartbeatIntervalSeconds(3)) |
| 64 | 64 | .build()); |
| 65 | 65 | |
| 66 | - // Don't create any session, only the control connection will be established | |
| 67 | - cluster.init(); | |
| 68 | - | |
| 69 | - for (int i = 0; i < 5; i++) { | |
| 70 | - triggerRequestOnControlConnection(cluster); | |
| 71 | - SECONDS.sleep(1); | |
| 66 | + try { | |
| 67 | + // Don't create any session, only the control connection will be established | |
| 68 | + cluster.init(); | |
| 69 | + | |
| 70 | + for (int i = 0; i < 5; i++) { | |
| 71 | + triggerRequestOnControlConnection(cluster); | |
| 72 | + SECONDS.sleep(1); | |
| 73 | + } | |
| 74 | + assertThat(logs.getNext()).doesNotContain("sending heartbeat"); | |
| 75 | + | |
| 76 | + // Ensure heartbeat is sent after no activity. | |
| 77 | + SECONDS.sleep(4); | |
| 78 | + assertThat(logs.getNext()) | |
| 79 | + .contains("sending heartbeat") | |
| 80 | + .contains("heartbeat query succeeded"); | |
| 81 | + | |
| 82 | + // Ensure heartbeat is sent after continued inactivity. | |
| 83 | + SECONDS.sleep(4); | |
| 84 | + assertThat(logs.getNext()) | |
| 85 | + .contains("sending heartbeat") | |
| 86 | + .contains("heartbeat query succeeded"); | |
| 87 | + | |
| 88 | + // Ensure heartbeat is not sent after activity. | |
| 89 | + logs.getNext(); | |
| 90 | + for (int i = 0; i < 5; i++) { | |
| 91 | + triggerRequestOnControlConnection(cluster); | |
| 92 | + SECONDS.sleep(1); | |
| 93 | + } | |
| 94 | + assertThat(logs.getNext()).doesNotContain("sending heartbeat"); | |
| 95 | + | |
| 96 | + // Finally, ensure heartbeat is sent after inactivity. | |
| 97 | + SECONDS.sleep(4); | |
| 98 | + assertThat(logs.getNext()) | |
| 99 | + .contains("sending heartbeat") | |
| 100 | + .contains("heartbeat query succeeded"); | |
| 101 | + } finally { | |
| 102 | + cluster.close(); | |
| 72 | 103 | } |
| 73 | - assertThat(logs.getNext()).doesNotContain("sending heartbeat"); | |
| 74 | - | |
| 75 | - // Ensure heartbeat is sent after no activity. | |
| 76 | - SECONDS.sleep(4); | |
| 77 | - assertThat(logs.getNext()) | |
| 78 | - .contains("sending heartbeat") | |
| 79 | - .contains("heartbeat query succeeded"); | |
| 80 | - | |
| 81 | - // Ensure heartbeat is sent after continued inactivity. | |
| 82 | - SECONDS.sleep(4); | |
| 83 | - assertThat(logs.getNext()) | |
| 84 | - .contains("sending heartbeat") | |
| 85 | - .contains("heartbeat query succeeded"); | |
| 86 | - | |
| 87 | - // Ensure heartbeat is not sent after activity. | |
| 88 | - logs.getNext(); | |
| 89 | - for (int i = 0; i < 5; i++) { | |
| 90 | - triggerRequestOnControlConnection(cluster); | |
| 91 | - SECONDS.sleep(1); | |
| 92 | - } | |
| 93 | - assertThat(logs.getNext()).doesNotContain("sending heartbeat"); | |
| 94 | - | |
| 95 | - // Finally, ensure heartbeat is sent after inactivity. | |
| 96 | - SECONDS.sleep(4); | |
| 97 | - assertThat(logs.getNext()) | |
| 98 | - .contains("sending heartbeat") | |
| 99 | - .contains("heartbeat query succeeded"); | |
| 100 | 104 | } |
| 101 | 105 | |
| 102 | 106 | /** |
| @@ -119,18 +123,22 @@ | ||
| 119 | 123 | .setHeartbeatIntervalSeconds(0)) |
| 120 | 124 | .build()); |
| 121 | 125 | |
| 122 | - // Don't create any session, only the control connection will be established | |
| 123 | - cluster.init(); | |
| 124 | - | |
| 125 | - for (int i = 0; i < 5; i++) { | |
| 126 | - triggerRequestOnControlConnection(cluster); | |
| 127 | - SECONDS.sleep(1); | |
| 126 | + try { | |
| 127 | + // Don't create any session, only the control connection will be established | |
| 128 | + cluster.init(); | |
| 129 | + | |
| 130 | + for (int i = 0; i < 5; i++) { | |
| 131 | + triggerRequestOnControlConnection(cluster); | |
| 132 | + SECONDS.sleep(1); | |
| 133 | + } | |
| 134 | + assertThat(logs.get()).doesNotContain("sending heartbeat"); | |
| 135 | + | |
| 136 | + // Sleep for a while and ensure no heartbeat is sent. | |
| 137 | + SECONDS.sleep(32); | |
| 138 | + assertThat(logs.get()).doesNotContain("sending heartbeat"); | |
| 139 | + } finally { | |
| 140 | + cluster.close(); | |
| 128 | 141 | } |
| 129 | - assertThat(logs.get()).doesNotContain("sending heartbeat"); | |
| 130 | - | |
| 131 | - // Sleep for a while and ensure no heartbeat is sent. | |
| 132 | - SECONDS.sleep(32); | |
| 133 | - assertThat(logs.get()).doesNotContain("sending heartbeat"); | |
| 134 | 142 | } |
| 135 | 143 | |
| 136 | 144 | // Simulates activity on the control connection via the internal API |
modified driver-core/src/test/java/com/datastax/driver/core/LoadBalancingPolicyBootstrapTest.java +34 −26
| @@ -53,12 +53,16 @@ | ||
| 53 | 53 | .withLoadBalancingPolicy(policy) |
| 54 | 54 | .build()); |
| 55 | 55 | |
| 56 | - cluster.init(); | |
| 57 | - | |
| 58 | - assertThat(policy.history).containsOnly( | |
| 59 | - entry(INIT, TestUtils.findHost(cluster, 1)), | |
| 60 | - entry(INIT, TestUtils.findHost(cluster, 2)) | |
| 61 | - ); | |
| 56 | + try { | |
| 57 | + cluster.init(); | |
| 58 | + | |
| 59 | + assertThat(policy.history).containsOnly( | |
| 60 | + entry(INIT, TestUtils.findHost(cluster, 1)), | |
| 61 | + entry(INIT, TestUtils.findHost(cluster, 2)) | |
| 62 | + ); | |
| 63 | + } finally { | |
| 64 | + cluster.close(); | |
| 65 | + } | |
| 62 | 66 | } |
| 63 | 67 | |
| 64 | 68 | /** |
| @@ -95,27 +99,31 @@ | ||
| 95 | 99 | .withLoadBalancingPolicy(policy) |
| 96 | 100 | .build()); |
| 97 | 101 | |
| 98 | - cluster.init(); | |
| 99 | - | |
| 100 | - if (policy.history.contains(entry(DOWN, TestUtils.findHost(cluster, nodeToStop)))) { | |
| 101 | - // This is the situation we're testing, the control connection tried the stopped node first. | |
| 102 | - assertThat(policy.history).containsExactly( | |
| 103 | - entry(INIT, TestUtils.findHost(cluster, activeNode)), | |
| 104 | - entry(DOWN, TestUtils.findHost(cluster, nodeToStop)) | |
| 105 | - ); | |
| 106 | - break; | |
| 107 | - } else { | |
| 108 | - assertThat(policy.history).containsOnly( | |
| 109 | - entry(INIT, TestUtils.findHost(cluster, 1)), | |
| 110 | - entry(INIT, TestUtils.findHost(cluster, 2)) | |
| 111 | - ); | |
| 112 | - | |
| 113 | - logger.info("Could not get first contact point to fail, retrying"); | |
| 114 | - | |
| 102 | + try { | |
| 103 | + cluster.init(); | |
| 104 | + | |
| 105 | + if (policy.history.contains(entry(DOWN, TestUtils.findHost(cluster, nodeToStop)))) { | |
| 106 | + // This is the situation we're testing, the control connection tried the stopped node first. | |
| 107 | + assertThat(policy.history).containsExactly( | |
| 108 | + entry(INIT, TestUtils.findHost(cluster, activeNode)), | |
| 109 | + entry(DOWN, TestUtils.findHost(cluster, nodeToStop)) | |
| 110 | + ); | |
| 111 | + break; | |
| 112 | + } else { | |
| 113 | + assertThat(policy.history).containsOnly( | |
| 114 | + entry(INIT, TestUtils.findHost(cluster, 1)), | |
| 115 | + entry(INIT, TestUtils.findHost(cluster, 2)) | |
| 116 | + ); | |
| 117 | + | |
| 118 | + logger.info("Could not get first contact point to fail, retrying"); | |
| 119 | + | |
| 120 | + cluster.close(); | |
| 121 | + | |
| 122 | + ccm().start(nodeToStop); | |
| 123 | + ccm().waitForUp(nodeToStop); | |
| 124 | + } | |
| 125 | + } finally { | |
| 115 | 126 | cluster.close(); |
| 116 | - | |
| 117 | - ccm().start(nodeToStop); | |
| 118 | - ccm().waitForUp(nodeToStop); | |
| 119 | 127 | } |
| 120 | 128 | } |
| 121 | 129 |