kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | a8380ffc8ab12efdc67f34bcbc40e82d4ee711742c76820d68993c3303ddb9aa |
|---|---|
| Author | Alexandre Dutra <alexandre.dutra@datastax.com> · 2017-03-24 10:41 +01:00 |
| Committer | Alexandre Dutra <alexandre.dutra@datastax.com> · 2017-03-24 10:41 +01:00 |
| Parents | 0fd0a452bfbe, fb892c5d8ff4 |
9 files changed
modified changelog/README.md +1 −0
| @@ -136,6 +136,7 @@ | ||
| 136 | 136 | ### 3.0.8 (in progress) |
| 137 | 137 | |
| 138 | 138 | - [bug] JAVA-1404: Fix min token handling in TokenRange.contains. |
| 139 | +- [bug] JAVA-1429: Prevent heartbeats until connection is fully initialized. | |
| 139 | 140 | |
| 140 | 141 | |
| 141 | 142 | ### 3.0.7 |
modified driver-core/src/main/java/com/datastax/driver/core/Connection.java +1 −1
| @@ -1077,7 +1077,7 @@ | ||
| 1077 | 1077 | |
| 1078 | 1078 | @Override |
| 1079 | 1079 | public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { |
| 1080 | - if (!isClosed() && evt instanceof IdleStateEvent && ((IdleStateEvent) evt).state() == READER_IDLE) { | |
| 1080 | + if (isInitialized && !isClosed() && evt instanceof IdleStateEvent && ((IdleStateEvent) evt).state() == READER_IDLE) { | |
| 1081 | 1081 | logger.debug("{} was inactive for {} seconds, sending heartbeat", Connection.this, factory.configuration.getPoolingOptions().getHeartbeatIntervalSeconds()); |
| 1082 | 1082 | write(HEARTBEAT_CALLBACK); |
| 1083 | 1083 | } |
modified driver-core/src/test/java/com/datastax/driver/core/AuthenticationTest.java +46 −0
| @@ -20,6 +20,9 @@ | ||
| 20 | 20 | import org.testng.annotations.BeforeMethod; |
| 21 | 21 | import org.testng.annotations.Test; |
| 22 | 22 | |
| 23 | +import java.net.InetSocketAddress; | |
| 24 | +import java.util.Timer; | |
| 25 | +import java.util.TimerTask; | |
| 23 | 26 | import java.util.concurrent.TimeUnit; |
| 24 | 27 | |
| 25 | 28 | import static com.datastax.driver.core.CreateCCM.TestMode.PER_METHOD; |
| @@ -86,4 +89,47 @@ | ||
| 86 | 89 | } |
| 87 | 90 | } |
| 88 | 91 | |
| 92 | + /** | |
| 93 | + * Ensures that authentication is possible even if the server is busy during | |
| 94 | + * SASL handshake. | |
| 95 | + * | |
| 96 | + * @jira_ticket JAVA-1429 | |
| 97 | + */ | |
| 98 | + @Test(groups = "short") | |
| 99 | + @CCMConfig(dirtiesContext = true) | |
| 100 | + public void should_connect_with_slow_server() throws InterruptedException { | |
| 101 | + Cluster cluster = Cluster.builder() | |
| 102 | + .addContactPoints(getContactPoints()) | |
| 103 | + .withPort(ccm().getBinaryPort()) | |
| 104 | + .withAuthProvider(new SlowAuthProvider()) | |
| 105 | + .withPoolingOptions(new PoolingOptions() | |
| 106 | + .setHeartbeatIntervalSeconds(1)) | |
| 107 | + .build(); | |
| 108 | + cluster.connect(); | |
| 109 | + } | |
| 110 | + | |
| 111 | + private class SlowAuthProvider extends PlainTextAuthProvider { | |
| 112 | + | |
| 113 | + public SlowAuthProvider() { | |
| 114 | + super("cassandra", "cassandra"); | |
| 115 | + } | |
| 116 | + | |
| 117 | + @Override | |
| 118 | + public Authenticator newAuthenticator(InetSocketAddress host, String authenticator) throws AuthenticationException { | |
| 119 | + simulateBusyServer(); | |
| 120 | + return super.newAuthenticator(host, authenticator); | |
| 121 | + } | |
| 122 | + | |
| 123 | + } | |
| 124 | + | |
| 125 | + private void simulateBusyServer() { | |
| 126 | + ccm().pause(1); | |
| 127 | + new Timer().schedule(new TimerTask() { | |
| 128 | + @Override | |
| 129 | + public void run() { | |
| 130 | + ccm().resume(1); | |
| 131 | + } | |
| 132 | + }, 2000); | |
| 133 | + } | |
| 134 | + | |
| 89 | 135 | } |
modified driver-core/src/test/java/com/datastax/driver/core/CCMAccess.java +14 −0
| @@ -168,6 +168,20 @@ | ||
| 168 | 168 | */ |
| 169 | 169 | void forceStop(int n); |
| 170 | 170 | |
| 171 | + /** | |
| 172 | + * Pauses the {@code nth} host in the CCM cluster. | |
| 173 | + * | |
| 174 | + * @param n the node number (starting from 1). | |
| 175 | + */ | |
| 176 | + void pause(int n); | |
| 177 | + | |
| 178 | + /** | |
| 179 | + * Resumes the {@code nth} host in the CCM cluster. | |
| 180 | + * | |
| 181 | + * @param n the node number (starting from 1). | |
| 182 | + */ | |
| 183 | + void resume(int n); | |
| 184 | + | |
| 171 | 185 | /** |
| 172 | 186 | * Removes the {@code nth} host in the CCM cluster. |
| 173 | 187 | * |
modified driver-core/src/test/java/com/datastax/driver/core/CCMBridge.java +14 −0
| @@ -521,6 +521,18 @@ | ||
| 521 | 521 | execute(CCM_COMMAND + " node%d stop --not-gently", n); |
| 522 | 522 | } |
| 523 | 523 | |
| 524 | + @Override | |
| 525 | + public void pause(int n) { | |
| 526 | + logger.debug(String.format("Pausing: node %s (%s%s:%s) in %s", n, TestUtils.IP_PREFIX, n, binaryPort, this)); | |
| 527 | + execute(CCM_COMMAND + " node%d pause", n); | |
| 528 | + } | |
| 529 | + | |
| 530 | + @Override | |
| 531 | + public void resume(int n) { | |
| 532 | + logger.debug(String.format("Resuming: node %s (%s%s:%s) in %s", n, TestUtils.IP_PREFIX, n, binaryPort, this)); | |
| 533 | + execute(CCM_COMMAND + " node%d resume", n); | |
| 534 | + } | |
| 535 | + | |
| 524 | 536 | @Override |
| 525 | 537 | public void remove(int n) { |
| 526 | 538 | logger.debug(String.format("Removing: node %s (%s%s:%s) from %s", n, TestUtils.IP_PREFIX, n, binaryPort, this)); |
| @@ -679,6 +691,7 @@ | ||
| 679 | 691 | /** |
| 680 | 692 | * Waits for a host to be up by pinging the TCP socket directly, without using the Java driver's API. |
| 681 | 693 | */ |
| 694 | + @Override | |
| 682 | 695 | public void waitForUp(int node) { |
| 683 | 696 | TestUtils.waitUntilPortIsUp(addressOfNode(node)); |
| 684 | 697 | } |
| @@ -686,6 +699,7 @@ | ||
| 686 | 699 | /** |
| 687 | 700 | * Waits for a host to be down by pinging the TCP socket directly, without using the Java driver's API. |
| 688 | 701 | */ |
| 702 | + @Override | |
| 689 | 703 | public void waitForDown(int node) { |
| 690 | 704 | TestUtils.waitUntilPortIsDown(addressOfNode(node)); |
| 691 | 705 | } |
modified driver-core/src/test/java/com/datastax/driver/core/CCMCache.java +10 −0
| @@ -165,6 +165,16 @@ | ||
| 165 | 165 | ccm.forceStop(n); |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | + @Override | |
| 169 | + public void pause(int n) { | |
| 170 | + ccm.pause(n); | |
| 171 | + } | |
| 172 | + | |
| 173 | + @Override | |
| 174 | + public void resume(int n) { | |
| 175 | + ccm.resume(n); | |
| 176 | + } | |
| 177 | + | |
| 168 | 178 | @Override |
| 169 | 179 | public void remove(int n) { |
| 170 | 180 | ccm.remove(n); |
modified driver-core/src/test/java/com/datastax/driver/core/CCMTestsSupport.java +10 −0
| @@ -177,6 +177,16 @@ | ||
| 177 | 177 | throw new UnsupportedOperationException("This CCM cluster is read-only"); |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | + @Override | |
| 181 | + public void pause(int n) { | |
| 182 | + throw new UnsupportedOperationException("This CCM cluster is read-only"); | |
| 183 | + } | |
| 184 | + | |
| 185 | + @Override | |
| 186 | + public void resume(int n) { | |
| 187 | + throw new UnsupportedOperationException("This CCM cluster is read-only"); | |
| 188 | + } | |
| 189 | + | |
| 180 | 190 | @Override |
| 181 | 191 | public void remove(int n) { |
| 182 | 192 | throw new UnsupportedOperationException("This CCM cluster is read-only"); |
modified driver-core/src/test/java/com/datastax/driver/core/HostConnectionPoolTest.java +9 −6
| @@ -18,7 +18,7 @@ | ||
| 18 | 18 | import com.codahale.metrics.Gauge; |
| 19 | 19 | import com.datastax.driver.core.exceptions.*; |
| 20 | 20 | import com.datastax.driver.core.policies.ConstantReconnectionPolicy; |
| 21 | -import com.datastax.driver.core.utils.MoreFutures; | |
| 21 | +import com.google.common.base.Function; | |
| 22 | 22 | import com.google.common.base.Predicate; |
| 23 | 23 | import com.google.common.base.Throwables; |
| 24 | 24 | import com.google.common.util.concurrent.*; |
| @@ -290,7 +290,7 @@ | ||
| 290 | 290 | int count = 0; |
| 291 | 291 | for (MockRequest queuedRequest : queuedRequests) { |
| 292 | 292 | try { |
| 293 | - Uninterruptibles.getUninterruptibly(queuedRequest.connectionFuture, 5, TimeUnit.SECONDS); | |
| 293 | + Uninterruptibles.getUninterruptibly(queuedRequest.connectionFuture, 10, TimeUnit.SECONDS); | |
| 294 | 294 | count++; |
| 295 | 295 | } catch (ExecutionException e) { |
| 296 | 296 | // 128th request should timeout since all in flight requests are used. |
| @@ -400,7 +400,6 @@ | ||
| 400 | 400 | assertThat(e.getCause()).isInstanceOf(DriverException.class); |
| 401 | 401 | assertThat(e.getCause().getMessage()).contains("Aborting attempt to set keyspace to 'newkeyspace' since there is already an in flight attempt to set keyspace to 'slowks'."); |
| 402 | 402 | } |
| 403 | - | |
| 404 | 403 | } finally { |
| 405 | 404 | MockRequest.completeAll(requests); |
| 406 | 405 | cluster.close(); |
| @@ -1242,8 +1241,8 @@ | ||
| 1242 | 1241 | |
| 1243 | 1242 | // Should create up to core connections. |
| 1244 | 1243 | verify(factory, timeout(readTimeout).times(1)).open(any(HostConnectionPool.class)); |
| 1245 | - | |
| 1246 | 1244 | assertPoolSize(pool, 1); |
| 1245 | + Uninterruptibles.getUninterruptibly(request.requestInitialized, 10, TimeUnit.SECONDS); | |
| 1247 | 1246 | request.simulateSuccessResponse(); |
| 1248 | 1247 | } finally { |
| 1249 | 1248 | cluster.close(); |
| @@ -1348,6 +1347,9 @@ | ||
| 1348 | 1347 | enum State {START, COMPLETED, FAILED, TIMED_OUT} |
| 1349 | 1348 | |
| 1350 | 1349 | final ListenableFuture<Connection> connectionFuture; |
| 1350 | + | |
| 1351 | + final ListenableFuture<Connection.ResponseHandler> requestInitialized; | |
| 1352 | + | |
| 1351 | 1353 | private volatile Connection.ResponseHandler responseHandler; |
| 1352 | 1354 | |
| 1353 | 1355 | final AtomicReference<State> state = new AtomicReference<State>(State.START); |
| @@ -1404,12 +1406,13 @@ | ||
| 1404 | 1406 | |
| 1405 | 1407 | private MockRequest(HostConnectionPool pool, int timeoutMillis, int maxQueueSize) throws ConnectionException { |
| 1406 | 1408 | this.connectionFuture = pool.borrowConnection(timeoutMillis, MILLISECONDS, maxQueueSize); |
| 1407 | - Futures.addCallback(this.connectionFuture, new MoreFutures.SuccessCallback<Connection>() { | |
| 1409 | + requestInitialized = Futures.transform(this.connectionFuture, new Function<Connection, Connection.ResponseHandler>() { | |
| 1408 | 1410 | @Override |
| 1409 | - public void onSuccess(Connection connection) { | |
| 1411 | + public Connection.ResponseHandler apply(Connection connection) { | |
| 1410 | 1412 | MockRequest thisRequest = MockRequest.this; |
| 1411 | 1413 | thisRequest.responseHandler = new Connection.ResponseHandler(connection, -1, thisRequest); |
| 1412 | 1414 | connection.dispatcher.add(thisRequest.responseHandler); |
| 1415 | + return responseHandler; | |
| 1413 | 1416 | } |
| 1414 | 1417 | }); |
| 1415 | 1418 | } |
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperSaveNullFieldsTest.java +2 −0
| @@ -17,6 +17,7 @@ | ||
| 17 | 17 | |
| 18 | 18 | import com.datastax.driver.core.BoundStatement; |
| 19 | 19 | import com.datastax.driver.core.CCMTestsSupport; |
| 20 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 20 | 21 | import com.datastax.driver.mapping.Mapper.Option; |
| 21 | 22 | import com.datastax.driver.mapping.annotations.PartitionKey; |
| 22 | 23 | import com.datastax.driver.mapping.annotations.Table; |
| @@ -40,6 +41,7 @@ | ||
| 40 | 41 | mapper = new MappingManager(session()).mapper(User.class); |
| 41 | 42 | } |
| 42 | 43 | |
| 44 | + @CassandraVersion("2.1.0") | |
| 43 | 45 | @Test(groups = "short") |
| 44 | 46 | void should_save_null_fields_if_requested() { |
| 45 | 47 | should_save_null_fields(true, Option.saveNullFields(true)); |