kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 33790322d4e4f7489963118e6a5767ebfd99e45b552a45292842f2e38db1731a |
|---|---|
| Author | Alexandre Dutra <alexandre.dutra@datastax.com> · 2017-03-23 12:36 +01:00 |
| Committer | Alexandre Dutra <alexandre.dutra@datastax.com> · 2017-03-23 15:14 +01:00 |
| Parents | 3f96eab68455 |
3 files changed
modified changelog/README.md +1 −0
| @@ -3,6 +3,7 @@ | ||
| 3 | 3 | ### 3.0.8 (in progress) |
| 4 | 4 | |
| 5 | 5 | - [bug] JAVA-1404: Fix min token handling in TokenRange.contains. |
| 6 | +- [bug] JAVA-1429: Prevent heartbeats until connection is fully initialized. | |
| 6 | 7 | |
| 7 | 8 | |
| 8 | 9 | ### 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 | } |