kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 56a63006452dd0e034718f83afb215424d7bdb3d8745daaddeaa151f36b8650b |
|---|---|
| Author | Andrew Tolbert <andrew.tolbert@datastax.com> · 2015-07-16 12:55 -05:00 |
| Committer | Andrew Tolbert <andrew.tolbert@datastax.com> · 2015-07-16 12:55 -05:00 |
| Parents | b4f0888fb54b |
2 files changed
modified driver-core/src/test/java/com/datastax/driver/core/AuthenticationTest.java +17 −11
| @@ -59,36 +59,42 @@ | ||
| 59 | 59 | |
| 60 | 60 | @Test(groups = "short") |
| 61 | 61 | public void should_connect_with_credentials() throws InterruptedException { |
| 62 | + Cluster cluster = Cluster.builder().addContactPoint(CCMBridge.IP_PREFIX + '1') | |
| 63 | + .withCredentials("cassandra", "cassandra") | |
| 64 | + .build(); | |
| 62 | 65 | try { |
| 63 | - Cluster.builder().addContactPoint(CCMBridge.IP_PREFIX + '1') | |
| 64 | - .withCredentials("cassandra", "cassandra") | |
| 65 | - .build() | |
| 66 | - .connect(); | |
| 66 | + cluster.connect(); | |
| 67 | 67 | } catch (NoHostAvailableException e) { |
| 68 | 68 | logger.error(e.getCustomMessage(1, true, true)); |
| 69 | + } finally { | |
| 70 | + cluster.close(); | |
| 69 | 71 | } |
| 70 | 72 | } |
| 71 | 73 | |
| 72 | 74 | @Test(groups = "short", expectedExceptions = AuthenticationException.class) |
| 73 | 75 | public void should_fail_to_connect_with_wrong_credentials() throws InterruptedException { |
| 76 | + Cluster cluster = Cluster.builder().addContactPoint(CCMBridge.IP_PREFIX + '1') | |
| 77 | + .withCredentials("bogus", "bogus") | |
| 78 | + .build(); | |
| 74 | 79 | try { |
| 75 | - Cluster.builder().addContactPoint(CCMBridge.IP_PREFIX + '1') | |
| 76 | - .withCredentials("bogus", "bogus") | |
| 77 | - .build() | |
| 78 | - .connect(); | |
| 80 | + cluster.connect(); | |
| 79 | 81 | } catch (NoHostAvailableException e) { |
| 80 | 82 | logger.error(e.getCustomMessage(1, true, true)); |
| 83 | + } finally { | |
| 84 | + cluster.close(); | |
| 81 | 85 | } |
| 82 | 86 | } |
| 83 | 87 | |
| 84 | 88 | @Test(groups = "short", expectedExceptions = AuthenticationException.class) |
| 85 | 89 | public void should_fail_to_connect_without_credentials() throws InterruptedException { |
| 90 | + Cluster cluster = Cluster.builder().addContactPoint(CCMBridge.IP_PREFIX + '1') | |
| 91 | + .build(); | |
| 86 | 92 | try { |
| 87 | - Cluster.builder().addContactPoint(CCMBridge.IP_PREFIX + '1') | |
| 88 | - .build() | |
| 89 | - .connect(); | |
| 93 | + cluster.connect(); | |
| 90 | 94 | } catch (NoHostAvailableException e) { |
| 91 | 95 | logger.error(e.getCustomMessage(1, true, true)); |
| 96 | + } finally { | |
| 97 | + cluster.close(); | |
| 92 | 98 | } |
| 93 | 99 | } |
| 94 | 100 | } |
modified driver-core/src/test/java/com/datastax/driver/core/policies/LatencyAwarePolicyTest.java +70 −58
| @@ -70,23 +70,27 @@ | ||
| 70 | 70 | Cluster.Builder builder = super.createClusterBuilder(); |
| 71 | 71 | builder.withLoadBalancingPolicy(latencyAwarePolicy); |
| 72 | 72 | Cluster cluster = builder.build(); |
| 73 | - cluster.init(); // force initialization of latency aware policy | |
| 74 | - LatencyTrackerBarrier barrier = new LatencyTrackerBarrier(1); | |
| 75 | - cluster.register(barrier); // add barrier to synchronize latency tracker threads with the current thread | |
| 76 | - Session session = cluster.connect(); | |
| 77 | - // when | |
| 78 | - session.execute(query); | |
| 79 | - // then | |
| 80 | - // wait until trackers have been notified | |
| 81 | - barrier.await(); | |
| 82 | - // make sure the updater is called at least once | |
| 83 | - latencyAwarePolicy.new Updater().run(); | |
| 84 | - LatencyAwarePolicy.Snapshot snapshot = latencyAwarePolicy.getScoresSnapshot(); | |
| 85 | - assertThat(snapshot.getAllStats()).hasSize(1); | |
| 86 | - LatencyAwarePolicy.Snapshot.Stats stats = snapshot.getStats(retrieveSingleHost(cluster)); | |
| 87 | - assertThat(stats).isNotNull(); | |
| 88 | - assertThat(stats.getMeasurementsCount()).isEqualTo(1); | |
| 89 | - assertThat(stats.getLatencyScore()).isNotEqualTo(-1); | |
| 73 | + try { | |
| 74 | + cluster.init(); // force initialization of latency aware policy | |
| 75 | + LatencyTrackerBarrier barrier = new LatencyTrackerBarrier(1); | |
| 76 | + cluster.register(barrier); // add barrier to synchronize latency tracker threads with the current thread | |
| 77 | + Session session = cluster.connect(); | |
| 78 | + // when | |
| 79 | + session.execute(query); | |
| 80 | + // then | |
| 81 | + // wait until trackers have been notified | |
| 82 | + barrier.await(); | |
| 83 | + // make sure the updater is called at least once | |
| 84 | + latencyAwarePolicy.new Updater().run(); | |
| 85 | + LatencyAwarePolicy.Snapshot snapshot = latencyAwarePolicy.getScoresSnapshot(); | |
| 86 | + assertThat(snapshot.getAllStats()).hasSize(1); | |
| 87 | + LatencyAwarePolicy.Snapshot.Stats stats = snapshot.getStats(retrieveSingleHost(cluster)); | |
| 88 | + assertThat(stats).isNotNull(); | |
| 89 | + assertThat(stats.getMeasurementsCount()).isEqualTo(1); | |
| 90 | + assertThat(stats.getLatencyScore()).isNotEqualTo(-1); | |
| 91 | + } finally { | |
| 92 | + cluster.close(); | |
| 93 | + } | |
| 90 | 94 | } |
| 91 | 95 | |
| 92 | 96 | @Test(groups = "short") |
| @@ -105,29 +109,33 @@ | ||
| 105 | 109 | Cluster.Builder builder = super.createClusterBuilder(); |
| 106 | 110 | builder.withLoadBalancingPolicy(latencyAwarePolicy); |
| 107 | 111 | Cluster cluster = builder.build(); |
| 108 | - cluster.init(); // force initialization of latency aware policy | |
| 109 | - LatencyTrackerBarrier barrier = new LatencyTrackerBarrier(1); | |
| 110 | - cluster.register(barrier); | |
| 111 | - Session session = cluster.connect(); | |
| 112 | - // when | |
| 113 | 112 | try { |
| 114 | - session.execute(query); | |
| 115 | - fail("Should have thrown NoHostAvailableException"); | |
| 116 | - } catch(NoHostAvailableException e) { | |
| 117 | - // ok | |
| 118 | - Throwable error = e.getErrors().get(hostAddress); | |
| 119 | - assertThat(error).isNotNull(); | |
| 120 | - assertThat(error).isInstanceOf(UnavailableException.class); | |
| 113 | + cluster.init(); // force initialization of latency aware policy | |
| 114 | + LatencyTrackerBarrier barrier = new LatencyTrackerBarrier(1); | |
| 115 | + cluster.register(barrier); | |
| 116 | + Session session = cluster.connect(); | |
| 117 | + // when | |
| 118 | + try { | |
| 119 | + session.execute(query); | |
| 120 | + fail("Should have thrown NoHostAvailableException"); | |
| 121 | + } catch (NoHostAvailableException e) { | |
| 122 | + // ok | |
| 123 | + Throwable error = e.getErrors().get(hostAddress); | |
| 124 | + assertThat(error).isNotNull(); | |
| 125 | + assertThat(error).isInstanceOf(UnavailableException.class); | |
| 126 | + } | |
| 127 | + // then | |
| 128 | + // wait until trackers have been notified | |
| 129 | + barrier.await(); | |
| 130 | + // make sure the updater is called at least once | |
| 131 | + latencyAwarePolicy.new Updater().run(); | |
| 132 | + LatencyAwarePolicy.Snapshot snapshot = latencyAwarePolicy.getScoresSnapshot(); | |
| 133 | + assertThat(snapshot.getAllStats()).isEmpty(); | |
| 134 | + LatencyAwarePolicy.Snapshot.Stats stats = snapshot.getStats(retrieveSingleHost(cluster)); | |
| 135 | + assertThat(stats).isNull(); | |
| 136 | + } finally { | |
| 137 | + cluster.close(); | |
| 121 | 138 | } |
| 122 | - // then | |
| 123 | - // wait until trackers have been notified | |
| 124 | - barrier.await(); | |
| 125 | - // make sure the updater is called at least once | |
| 126 | - latencyAwarePolicy.new Updater().run(); | |
| 127 | - LatencyAwarePolicy.Snapshot snapshot = latencyAwarePolicy.getScoresSnapshot(); | |
| 128 | - assertThat(snapshot.getAllStats()).isEmpty(); | |
| 129 | - LatencyAwarePolicy.Snapshot.Stats stats = snapshot.getStats(retrieveSingleHost(cluster)); | |
| 130 | - assertThat(stats).isNull(); | |
| 131 | 139 | } |
| 132 | 140 | |
| 133 | 141 | @Test(groups= "short") |
| @@ -147,28 +155,32 @@ | ||
| 147 | 155 | builder.withLoadBalancingPolicy(latencyAwarePolicy); |
| 148 | 156 | builder.withRetryPolicy(FallthroughRetryPolicy.INSTANCE); |
| 149 | 157 | Cluster cluster = builder.build(); |
| 150 | - cluster.init(); // force initialization of latency aware policy | |
| 151 | - LatencyTrackerBarrier barrier = new LatencyTrackerBarrier(1); | |
| 152 | - cluster.register(barrier); | |
| 153 | - Session session = cluster.connect(); | |
| 154 | - // when | |
| 155 | 158 | try { |
| 156 | - session.execute(query); | |
| 157 | - fail("Should have thrown ReadTimeoutException"); | |
| 158 | - } catch(ReadTimeoutException e) { | |
| 159 | - // ok | |
| 159 | + cluster.init(); // force initialization of latency aware policy | |
| 160 | + LatencyTrackerBarrier barrier = new LatencyTrackerBarrier(1); | |
| 161 | + cluster.register(barrier); | |
| 162 | + Session session = cluster.connect(); | |
| 163 | + // when | |
| 164 | + try { | |
| 165 | + session.execute(query); | |
| 166 | + fail("Should have thrown ReadTimeoutException"); | |
| 167 | + } catch (ReadTimeoutException e) { | |
| 168 | + // ok | |
| 169 | + } | |
| 170 | + // then | |
| 171 | + // wait until trackers have been notified | |
| 172 | + barrier.await(); | |
| 173 | + // make sure the updater is called at least once | |
| 174 | + latencyAwarePolicy.new Updater().run(); | |
| 175 | + LatencyAwarePolicy.Snapshot snapshot = latencyAwarePolicy.getScoresSnapshot(); | |
| 176 | + assertThat(snapshot.getAllStats()).hasSize(1); | |
| 177 | + LatencyAwarePolicy.Snapshot.Stats stats = snapshot.getStats(retrieveSingleHost(cluster)); | |
| 178 | + assertThat(stats).isNotNull(); | |
| 179 | + assertThat(stats.getMeasurementsCount()).isEqualTo(1); | |
| 180 | + assertThat(stats.getLatencyScore()).isNotEqualTo(-1); | |
| 181 | + } finally { | |
| 182 | + cluster.close(); | |
| 160 | 183 | } |
| 161 | - // then | |
| 162 | - // wait until trackers have been notified | |
| 163 | - barrier.await(); | |
| 164 | - // make sure the updater is called at least once | |
| 165 | - latencyAwarePolicy.new Updater().run(); | |
| 166 | - LatencyAwarePolicy.Snapshot snapshot = latencyAwarePolicy.getScoresSnapshot(); | |
| 167 | - assertThat(snapshot.getAllStats()).hasSize(1); | |
| 168 | - LatencyAwarePolicy.Snapshot.Stats stats = snapshot.getStats(retrieveSingleHost(cluster)); | |
| 169 | - assertThat(stats).isNotNull(); | |
| 170 | - assertThat(stats.getMeasurementsCount()).isEqualTo(1); | |
| 171 | - assertThat(stats.getLatencyScore()).isNotEqualTo(-1); | |
| 172 | 184 | } |
| 173 | 185 | |
| 174 | 186 | } |