Elffuss BraidHub

kikocis/java-driver public

JAVA-1429: Prevent heartbeats until connection is fully initialized
Changeset33790322d4e4f7489963118e6a5767ebfd99e45b552a45292842f2e38db1731a
AuthorAlexandre Dutra <alexandre.dutra@datastax.com> · 2017-03-23 12:36 +01:00
CommitterAlexandre Dutra <alexandre.dutra@datastax.com> · 2017-03-23 15:14 +01:00
Parents3f96eab68455

Browse the files at this changeset

3 files changed

modified changelog/README.md +1 −0
@@ -3,6 +3,7 @@
33 ### 3.0.8 (in progress)
44
55 - [bug] JAVA-1404: Fix min token handling in TokenRange.contains.
6+- [bug] JAVA-1429: Prevent heartbeats until connection is fully initialized.
67
78
89 ### 3.0.7
modified driver-core/src/main/java/com/datastax/driver/core/Connection.java +1 −1
@@ -1077,7 +1077,7 @@
10771077
10781078 @Override
10791079 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) {
10811081 logger.debug("{} was inactive for {} seconds, sending heartbeat", Connection.this, factory.configuration.getPoolingOptions().getHeartbeatIntervalSeconds());
10821082 write(HEARTBEAT_CALLBACK);
10831083 }
modified driver-core/src/test/java/com/datastax/driver/core/AuthenticationTest.java +46 −0
@@ -20,6 +20,9 @@
2020 import org.testng.annotations.BeforeMethod;
2121 import org.testng.annotations.Test;
2222
23+import java.net.InetSocketAddress;
24+import java.util.Timer;
25+import java.util.TimerTask;
2326 import java.util.concurrent.TimeUnit;
2427
2528 import static com.datastax.driver.core.CreateCCM.TestMode.PER_METHOD;
@@ -86,4 +89,47 @@
8689 }
8790 }
8891
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+
89135 }