kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 2de341b4b9f76fba195022d85d9a53c68255bc564ba93581fb49ddf02e56971d |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2015-06-17 17:14 +02:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2015-06-17 17:14 +02:00 |
| Parents | 86b5308050bb, fd4d807e5ca8 |
9 files changed
modified README.md +0 −2
| @@ -51,8 +51,6 @@ | ||
| 51 | 51 | - driver-examples: example applications using the other modules which are |
| 52 | 52 | only meant for demonstration purposes. |
| 53 | 53 | |
| 54 | -Please refer to the README of each module for more information. | |
| 55 | - | |
| 56 | 54 | **Community:** |
| 57 | 55 | |
| 58 | 56 | - JIRA: https://datastax-oss.atlassian.net/browse/JAVA |
modified changelog/README.md +12 −0
| @@ -219,6 +219,18 @@ | ||
| 219 | 219 | - [bug] Make metadata parsing more lenient (JAVA-377, JAVA-391) |
| 220 | 220 | |
| 221 | 221 | |
| 222 | +### 2.0.11 (in progress) | |
| 223 | + | |
| 224 | +- [bug] Fix SpeculativeExecutionPolicy.init() and close() are never called (JAVA-796) | |
| 225 | + | |
| 226 | +Merged from 2.0.10_fixes branch: | |
| 227 | + | |
| 228 | +- [improvement] Use Netty's pooled ByteBufAllocator by default (JAVA-756) | |
| 229 | +- [improvement] Expose "unsafe" paging state API (JAVA-759) | |
| 230 | +- [bug] Fix getObject by name (JAVA-767) | |
| 231 | +- [bug] Prevent race during pool initialization (JAVA-768) | |
| 232 | + | |
| 233 | + | |
| 222 | 234 | ### 2.0.10.1 |
| 223 | 235 | |
| 224 | 236 | - [improvement] Use Netty's pooled ByteBufAllocator by default (JAVA-756) |
modified driver-core/src/main/java/com/datastax/driver/core/Cluster.java +45 −8
| @@ -281,14 +281,16 @@ | ||
| 281 | 281 | long timeout = getConfiguration().getSocketOptions().getConnectTimeoutMillis(); |
| 282 | 282 | Session session = connect(); |
| 283 | 283 | try { |
| 284 | - ResultSetFuture future = session.executeAsync("USE " + keyspace); | |
| 285 | - // Note: using the connection timeout isn't perfectly correct, we should probably change that someday | |
| 286 | - Uninterruptibles.getUninterruptibly(future, timeout, TimeUnit.MILLISECONDS); | |
| 287 | - return session; | |
| 288 | - } catch (TimeoutException e) { | |
| 289 | - throw new DriverInternalError(String.format("No responses after %d milliseconds while setting current keyspace. This should not happen, unless you have setup a very low connection timeout.", timeout)); | |
| 290 | - } catch (ExecutionException e) { | |
| 291 | - throw DefaultResultSetFuture.extractCauseFromExecutionException(e); | |
| 284 | + try { | |
| 285 | + ResultSetFuture future = session.executeAsync("USE " + keyspace); | |
| 286 | + // Note: using the connection timeout isn't perfectly correct, we should probably change that someday | |
| 287 | + Uninterruptibles.getUninterruptibly(future, timeout, TimeUnit.MILLISECONDS); | |
| 288 | + return session; | |
| 289 | + } catch (TimeoutException e) { | |
| 290 | + throw new DriverInternalError(String.format("No responses after %d milliseconds while setting current keyspace. This should not happen, unless you have setup a very low connection timeout.", timeout)); | |
| 291 | + } catch (ExecutionException e) { | |
| 292 | + throw DefaultResultSetFuture.extractCauseFromExecutionException(e); | |
| 293 | + } | |
| 292 | 294 | } catch (RuntimeException e) { |
| 293 | 295 | session.close(); |
| 294 | 296 | throw e; |
| @@ -789,6 +791,38 @@ | ||
| 789 | 791 | return this; |
| 790 | 792 | } |
| 791 | 793 | |
| 794 | + /** | |
| 795 | + * Adds a contact point - or many if it host resolves to multiple <code>InetAddress</code>s (A records). | |
| 796 | + * <p> | |
| 797 | + * | |
| 798 | + * If the host name points to a dns records with multiple a-records, all InetAddresses | |
| 799 | + * returned will be used. Make sure that all resulting <code>InetAddress</code>s returned | |
| 800 | + * points to the same cluster and datacenter. | |
| 801 | + * <p> | |
| 802 | + * See {@link Builder#addContactPoint} for more details on contact | |
| 803 | + * points and thrown exceptions | |
| 804 | + * | |
| 805 | + * @param address address of the nodes to look up InetAddresses from to add as contact points. | |
| 806 | + * @return this Builder. | |
| 807 | + * | |
| 808 | + * | |
| 809 | + * @see Builder#addContactPoint | |
| 810 | + */ | |
| 811 | + public Builder addContactPoints(String address) { | |
| 812 | + // We explicitely check for nulls because InetAdress.getByName() will happily | |
| 813 | + // accept it and use localhost (while a null here almost likely mean a user error, | |
| 814 | + // not "connect to localhost") | |
| 815 | + if (address == null) | |
| 816 | + throw new NullPointerException(); | |
| 817 | + | |
| 818 | + try { | |
| 819 | + addContactPoints(InetAddress.getAllByName(address)); | |
| 820 | + } catch (UnknownHostException e) { | |
| 821 | + throw new IllegalArgumentException(e.getMessage()); | |
| 822 | + } | |
| 823 | + return this; | |
| 824 | + } | |
| 825 | + | |
| 792 | 826 | /** |
| 793 | 827 | * Adds contact points. |
| 794 | 828 | * <p> |
| @@ -1292,6 +1326,7 @@ | ||
| 1292 | 1326 | // Now that the control connection is ready, we have all the information we need about the nodes (datacenter, |
| 1293 | 1327 | // rack...) to initialize the load balancing policy |
| 1294 | 1328 | loadBalancingPolicy().init(Cluster.this, contactPointHosts); |
| 1329 | + speculativeRetryPolicy().init(Cluster.this); | |
| 1295 | 1330 | for (Host host : downContactPointHosts) { |
| 1296 | 1331 | loadBalancingPolicy().onDown(host); |
| 1297 | 1332 | for (Host.StateListener listener : listeners) |
| @@ -1417,6 +1452,8 @@ | ||
| 1417 | 1452 | if (loadBalancingPolicy instanceof CloseableLoadBalancingPolicy) |
| 1418 | 1453 | ((CloseableLoadBalancingPolicy)loadBalancingPolicy).close(); |
| 1419 | 1454 | |
| 1455 | + speculativeRetryPolicy().close(); | |
| 1456 | + | |
| 1420 | 1457 | AddressTranslater translater = configuration.getPolicies().getAddressTranslater(); |
| 1421 | 1458 | if (translater instanceof CloseableAddressTranslater) |
| 1422 | 1459 | ((CloseableAddressTranslater)translater).close(); |
modified driver-core/src/main/java/com/datastax/driver/core/QueryTrace.java +1 −1
| @@ -232,7 +232,7 @@ | ||
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | if (tries > MAX_TRIES) |
| 235 | - throw new TraceRetrievalException(String.format("Unable to retrieve complete query trace after %d tries", MAX_TRIES)); | |
| 235 | + throw new TraceRetrievalException(String.format("Unable to retrieve complete query trace for id %s after %d tries", traceId, MAX_TRIES)); | |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | /** |
modified driver-core/src/main/java/com/datastax/driver/core/SessionManager.java +5 −3
| @@ -471,7 +471,11 @@ | ||
| 471 | 471 | defaultTimestamp = cluster.getConfiguration().getPolicies().getTimestampGenerator().next(); |
| 472 | 472 | } |
| 473 | 473 | |
| 474 | - return makeRequestMessage(statement, consistency, serialConsistency, pagingState, defaultTimestamp); | |
| 474 | + Message.Request request = makeRequestMessage(statement, consistency, serialConsistency, pagingState, defaultTimestamp); | |
| 475 | + if (statement.isTracing()) | |
| 476 | + request.setTracingRequested(); | |
| 477 | + | |
| 478 | + return request; | |
| 475 | 479 | } |
| 476 | 480 | |
| 477 | 481 | Message.Request makeRequestMessage(Statement statement, ConsistencyLevel cl, ConsistencyLevel scl, ByteBuffer pagingState, long defaultTimestamp) { |
| @@ -591,8 +595,6 @@ | ||
| 591 | 595 | } |
| 592 | 596 | |
| 593 | 597 | ResultSetFuture executeQuery(Message.Request msg, Statement statement) { |
| 594 | - if (statement.isTracing()) | |
| 595 | - msg.setTracingRequested(); | |
| 596 | 598 | |
| 597 | 599 | DefaultResultSetFuture future = new DefaultResultSetFuture(this, configuration().getProtocolOptions().getProtocolVersionEnum(), msg); |
| 598 | 600 | execute(future, statement); |
modified driver-core/src/test/java/com/datastax/driver/core/CCMBridge.java +52 −26
| @@ -83,6 +83,11 @@ | ||
| 83 | 83 | */ |
| 84 | 84 | private static final Map<String,String> ENVIRONMENT_MAP; |
| 85 | 85 | |
| 86 | + /** | |
| 87 | + * The command to use to launch CCM | |
| 88 | + */ | |
| 89 | + private static final String CCM_COMMAND; | |
| 90 | + | |
| 86 | 91 | static { |
| 87 | 92 | // Inherit the current environment. |
| 88 | 93 | Map<String,String> envMap = Maps.newHashMap(new ProcessBuilder().environment()); |
| @@ -93,8 +98,15 @@ | ||
| 93 | 98 | if(existingPath == null) { |
| 94 | 99 | existingPath = ""; |
| 95 | 100 | } |
| 96 | - envMap.put("PATH", ccmPath + ":" + existingPath); | |
| 101 | + envMap.put("PATH", ccmPath + File.pathSeparator + existingPath); | |
| 102 | + } | |
| 103 | + | |
| 104 | + if (isWindows()) { | |
| 105 | + CCM_COMMAND = "cmd /c ccm.py"; | |
| 106 | + } else { | |
| 107 | + CCM_COMMAND = "ccm"; | |
| 97 | 108 | } |
| 109 | + | |
| 98 | 110 | // If ccm.java.home is set, override the JAVA_HOME variable with it. |
| 99 | 111 | String ccmJavaHome = System.getProperty("ccm.java.home"); |
| 100 | 112 | if(ccmJavaHome != null) { |
| @@ -103,6 +115,19 @@ | ||
| 103 | 115 | ENVIRONMENT_MAP = ImmutableMap.copyOf(envMap); |
| 104 | 116 | } |
| 105 | 117 | |
| 118 | + /** | |
| 119 | + * Checks if the operating system is a Windows one | |
| 120 | + * @return <code>true</code> if the operating system is a Windows one, <code>false</code> otherwise. | |
| 121 | + */ | |
| 122 | + private static boolean isWindows() { | |
| 123 | + | |
| 124 | + String osName = System.getProperty("os.name"); | |
| 125 | + if (osName == null) { | |
| 126 | + return false; | |
| 127 | + } | |
| 128 | + return osName.startsWith("Windows"); | |
| 129 | + } | |
| 130 | + | |
| 106 | 131 | static final File CASSANDRA_DIR; |
| 107 | 132 | static final String CASSANDRA_VERSION; |
| 108 | 133 | |
| @@ -170,7 +195,7 @@ | ||
| 170 | 195 | checkArgument(!"current".equals(name.toLowerCase()), |
| 171 | 196 | "cluster can't be called \"current\""); |
| 172 | 197 | CCMBridge bridge = new CCMBridge(); |
| 173 | - bridge.execute("ccm create %s -b -i %s %s " + Joiner.on(" ").join(options), name, IP_PREFIX, CASSANDRA_VERSION); | |
| 198 | + bridge.execute(CCM_COMMAND + " create %s -b -i %s %s " + Joiner.on(" ").join(options), name, IP_PREFIX, CASSANDRA_VERSION); | |
| 174 | 199 | return bridge; |
| 175 | 200 | } |
| 176 | 201 | |
| @@ -178,7 +203,7 @@ | ||
| 178 | 203 | checkArgument(!"current".equals(name.toLowerCase()), |
| 179 | 204 | "cluster can't be called \"current\""); |
| 180 | 205 | CCMBridge bridge = new CCMBridge(); |
| 181 | - bridge.execute("ccm create %s -n %d -s -i %s -b %s " + Joiner.on(" ").join(options), name, nbNodes, IP_PREFIX, CASSANDRA_VERSION); | |
| 206 | + bridge.execute(CCM_COMMAND + " create %s -n %d -s -i %s -b %s " + Joiner.on(" ").join(options), name, nbNodes, IP_PREFIX, CASSANDRA_VERSION); | |
| 182 | 207 | return bridge; |
| 183 | 208 | } |
| 184 | 209 | |
| @@ -186,7 +211,7 @@ | ||
| 186 | 211 | checkArgument(!"current".equals(name.toLowerCase()), |
| 187 | 212 | "cluster can't be called \"current\""); |
| 188 | 213 | CCMBridge bridge = new CCMBridge(); |
| 189 | - bridge.execute("ccm create %s -n %d -s -i %s -b -v %s ", name, nbNodes, IP_PREFIX, cassandraVersion); | |
| 214 | + bridge.execute(CCM_COMMAND + " create %s -n %d -s -i %s -b -v %s ", name, nbNodes, IP_PREFIX, cassandraVersion); | |
| 190 | 215 | return bridge; |
| 191 | 216 | } |
| 192 | 217 | |
| @@ -194,7 +219,7 @@ | ||
| 194 | 219 | checkArgument(!"current".equals(name.toLowerCase()), |
| 195 | 220 | "cluster can't be called \"current\""); |
| 196 | 221 | CCMBridge bridge = new CCMBridge(); |
| 197 | - bridge.execute("ccm create %s -n %d:%d -s -i %s -b %s", name, nbNodesDC1, nbNodesDC2, IP_PREFIX, CASSANDRA_VERSION); | |
| 222 | + bridge.execute(CCM_COMMAND + " create %s -n %d:%d -s -i %s -b %s", name, nbNodesDC1, nbNodesDC2, IP_PREFIX, CASSANDRA_VERSION); | |
| 198 | 223 | return bridge; |
| 199 | 224 | } |
| 200 | 225 | |
| @@ -207,55 +232,55 @@ | ||
| 207 | 232 | } |
| 208 | 233 | |
| 209 | 234 | public void start() { |
| 210 | - execute("ccm start --wait-other-notice --wait-for-binary-proto"); | |
| 235 | + execute(CCM_COMMAND + " start --wait-other-notice --wait-for-binary-proto"); | |
| 211 | 236 | } |
| 212 | 237 | |
| 213 | 238 | public void stop() { |
| 214 | - execute("ccm stop"); | |
| 239 | + execute(CCM_COMMAND + " stop"); | |
| 215 | 240 | } |
| 216 | 241 | |
| 217 | 242 | public void forceStop() { |
| 218 | - execute("ccm stop --not-gently"); | |
| 243 | + execute(CCM_COMMAND + " stop --not-gently"); | |
| 219 | 244 | } |
| 220 | 245 | |
| 221 | 246 | public void start(int n) { |
| 222 | 247 | logger.info("Starting: " + IP_PREFIX + n); |
| 223 | - execute("ccm node%d start --wait-other-notice --wait-for-binary-proto", n); | |
| 248 | + execute(CCM_COMMAND + " node%d start --wait-other-notice --wait-for-binary-proto", n); | |
| 224 | 249 | } |
| 225 | 250 | |
| 226 | 251 | public void start(int n, String option) { |
| 227 | 252 | logger.info("Starting: " + IP_PREFIX + n + " with " + option); |
| 228 | - execute("ccm node%d start --wait-other-notice --wait-for-binary-proto --jvm_arg=%s", n, option); | |
| 253 | + execute(CCM_COMMAND + " node%d start --wait-other-notice --wait-for-binary-proto --jvm_arg=%s", n, option); | |
| 229 | 254 | } |
| 230 | 255 | |
| 231 | 256 | public void stop(int n) { |
| 232 | 257 | logger.info("Stopping: " + IP_PREFIX + n); |
| 233 | - execute("ccm node%d stop", n); | |
| 258 | + execute(CCM_COMMAND + " node%d stop", n); | |
| 234 | 259 | } |
| 235 | 260 | |
| 236 | 261 | public void stop(String clusterName) { |
| 237 | 262 | logger.info("Stopping Cluster : "+clusterName); |
| 238 | - execute("ccm stop "+clusterName); | |
| 263 | + execute(CCM_COMMAND + " stop "+clusterName); | |
| 239 | 264 | } |
| 240 | 265 | |
| 241 | 266 | public void forceStop(int n) { |
| 242 | 267 | logger.info("Force stopping: " + IP_PREFIX + n); |
| 243 | - execute("ccm node%d stop --not-gently", n); | |
| 268 | + execute(CCM_COMMAND + " node%d stop --not-gently", n); | |
| 244 | 269 | } |
| 245 | 270 | |
| 246 | 271 | public void remove() { |
| 247 | 272 | stop(); |
| 248 | - execute("ccm remove"); | |
| 273 | + execute(CCM_COMMAND + " remove"); | |
| 249 | 274 | } |
| 250 | 275 | |
| 251 | 276 | public void remove(String clusterName) { |
| 252 | 277 | stop(clusterName); |
| 253 | - execute("ccm remove " + clusterName); | |
| 278 | + execute(CCM_COMMAND + " remove " + clusterName); | |
| 254 | 279 | } |
| 255 | 280 | |
| 256 | 281 | public void remove(int n) { |
| 257 | 282 | logger.info("Removing: " + IP_PREFIX + n); |
| 258 | - execute("ccm node%d remove", n); | |
| 283 | + execute(CCM_COMMAND + " node%d remove", n); | |
| 259 | 284 | } |
| 260 | 285 | |
| 261 | 286 | public void bootstrapNode(int n) { |
| @@ -264,10 +289,10 @@ | ||
| 264 | 289 | |
| 265 | 290 | public void bootstrapNode(int n, String dc) { |
| 266 | 291 | if (dc == null) |
| 267 | - execute("ccm add node%d -i %s%d -j %d -r %d -b -s", n, IP_PREFIX, n, 7000 + 100 * n, 8000 + 100 * n); | |
| 292 | + execute(CCM_COMMAND + " add node%d -i %s%d -j %d -r %d -b -s", n, IP_PREFIX, n, 7000 + 100 * n, 8000 + 100 * n); | |
| 268 | 293 | else |
| 269 | - execute("ccm add node%d -i %s%d -j %d -b -d %s -s", n, IP_PREFIX, n, 7000 + 100 * n, dc); | |
| 270 | - execute("ccm node%d start --wait-other-notice --wait-for-binary-proto", n); | |
| 294 | + execute(CCM_COMMAND + " add node%d -i %s%d -j %d -b -d %s -s", n, IP_PREFIX, n, 7000 + 100 * n, dc); | |
| 295 | + execute(CCM_COMMAND + " node%d start --wait-other-notice --wait-for-binary-proto", n); | |
| 271 | 296 | } |
| 272 | 297 | |
| 273 | 298 | public void bootstrapNodeWithPorts(int n, int thriftPort, int storagePort, int binaryPort, int jmxPort, int remoteDebugPort) { |
| @@ -275,13 +300,13 @@ | ||
| 275 | 300 | String storageItf = IP_PREFIX + n + ":" + storagePort; |
| 276 | 301 | String binaryItf = IP_PREFIX + n + ":" + binaryPort; |
| 277 | 302 | String remoteLogItf = IP_PREFIX + n + ":" + remoteDebugPort; |
| 278 | - execute("ccm add node%d -i %s%d -b -t %s -l %s --binary-itf %s -j %d -r %s -s", | |
| 303 | + execute(CCM_COMMAND + " add node%d -i %s%d -b -t %s -l %s --binary-itf %s -j %d -r %s -s", | |
| 279 | 304 | n, IP_PREFIX, n, thriftItf, storageItf, binaryItf, jmxPort, remoteLogItf); |
| 280 | - execute("ccm node%d start --wait-other-notice --wait-for-binary-proto", n); | |
| 305 | + execute(CCM_COMMAND + " node%d start --wait-other-notice --wait-for-binary-proto", n); | |
| 281 | 306 | } |
| 282 | 307 | |
| 283 | 308 | public void decommissionNode(int n) { |
| 284 | - execute("ccm node%d decommission", n); | |
| 309 | + execute(CCM_COMMAND + " node%d decommission", n); | |
| 285 | 310 | } |
| 286 | 311 | |
| 287 | 312 | public void updateConfig(String name, String value) { |
| @@ -293,16 +318,17 @@ | ||
| 293 | 318 | for (Map.Entry<String, String> entry : configs.entrySet()) { |
| 294 | 319 | confStr.append(entry.getKey() + ":" + entry.getValue() + " "); |
| 295 | 320 | } |
| 296 | - execute("ccm updateconf " + confStr); | |
| 321 | + execute(CCM_COMMAND + " updateconf " + confStr); | |
| 297 | 322 | } |
| 298 | 323 | |
| 299 | 324 | public void populate(int n) { |
| 300 | - execute("ccm populate -n %d -i %s", n, IP_PREFIX); | |
| 325 | + execute(CCM_COMMAND + " populate -n %d -i %s", n, IP_PREFIX); | |
| 301 | 326 | } |
| 302 | 327 | |
| 303 | 328 | private void execute(String command, Object... args) { |
| 329 | + | |
| 330 | + String fullCommand = String.format(command, args) + " --config-dir=" + ccmDir; | |
| 304 | 331 | try { |
| 305 | - String fullCommand = String.format(command, args) + " --config-dir=" + ccmDir; | |
| 306 | 332 | logger.debug("Executing: " + fullCommand); |
| 307 | 333 | CommandLine cli = CommandLine.parse(fullCommand); |
| 308 | 334 | Executor executor = new DefaultExecutor(); |
| @@ -327,7 +353,7 @@ | ||
| 327 | 353 | throw new RuntimeException(); |
| 328 | 354 | } |
| 329 | 355 | } catch (IOException e) { |
| 330 | - throw new RuntimeException(e); | |
| 356 | + throw new RuntimeException(String.format("The command %s failed to execute", fullCommand), e); | |
| 331 | 357 | } |
| 332 | 358 | } |
| 333 | 359 |
modified driver-core/src/test/java/com/datastax/driver/core/SessionLeakTest.java +53 −7
| @@ -25,17 +25,19 @@ | ||
| 25 | 25 | import com.google.common.collect.Lists; |
| 26 | 26 | import org.testng.annotations.Test; |
| 27 | 27 | |
| 28 | +import static org.assertj.core.api.Assertions.fail; | |
| 29 | + | |
| 30 | +import com.datastax.driver.core.exceptions.InvalidQueryException; | |
| 28 | 31 | import com.datastax.driver.core.utils.SocketChannelMonitor; |
| 29 | 32 | |
| 30 | 33 | import static com.datastax.driver.core.Assertions.assertThat; |
| 31 | 34 | |
| 32 | - | |
| 33 | 35 | public class SessionLeakTest { |
| 34 | 36 | |
| 35 | 37 | Cluster cluster; |
| 36 | 38 | List<InetSocketAddress> nodes = Lists.newArrayList( |
| 37 | - new InetSocketAddress(CCMBridge.IP_PREFIX + '1', 9042), | |
| 38 | - new InetSocketAddress(CCMBridge.IP_PREFIX + '2', 9042)); | |
| 39 | + new InetSocketAddress(CCMBridge.IP_PREFIX + '1', 9042), | |
| 40 | + new InetSocketAddress(CCMBridge.IP_PREFIX + '2', 9042)); | |
| 39 | 41 | SocketChannelMonitor channelMonitor; |
| 40 | 42 | |
| 41 | 43 | @Test(groups = "short") |
| @@ -47,9 +49,9 @@ | ||
| 47 | 49 | channelMonitor.reportAtFixedInterval(1, TimeUnit.SECONDS); |
| 48 | 50 | try { |
| 49 | 51 | cluster = Cluster.builder() |
| 50 | - .addContactPointsWithPorts(Collections.singletonList( | |
| 51 | - new InetSocketAddress(CCMBridge.IP_PREFIX + '1', 9042))) | |
| 52 | - .withNettyOptions(channelMonitor.nettyOptions()).build(); | |
| 52 | + .addContactPointsWithPorts(Collections.singletonList( | |
| 53 | + new InetSocketAddress(CCMBridge.IP_PREFIX + '1', 9042))) | |
| 54 | + .withNettyOptions(channelMonitor.nettyOptions()).build(); | |
| 53 | 55 | |
| 54 | 56 | cluster.init(); |
| 55 | 57 | |
| @@ -88,7 +90,51 @@ | ||
| 88 | 90 | assertThat(cluster.manager.sessions.size()).isEqualTo(0); |
| 89 | 91 | assertOpenConnections(1); |
| 90 | 92 | } finally { |
| 91 | - if(cluster != null){ | |
| 93 | + if (cluster != null) { | |
| 94 | + cluster.close(); | |
| 95 | + } | |
| 96 | + if (ccmBridge != null) { | |
| 97 | + ccmBridge.remove(); | |
| 98 | + } | |
| 99 | + // Ensure no channels remain open. | |
| 100 | + channelMonitor.stop(); | |
| 101 | + channelMonitor.report(); | |
| 102 | + assertThat(channelMonitor.openChannels(nodes).size()).isEqualTo(0); | |
| 103 | + } | |
| 104 | + } | |
| 105 | + | |
| 106 | + @Test(groups = "short") | |
| 107 | + public void should_not_leak_session_when_wrong_keyspace() throws Exception { | |
| 108 | + // Checking for JAVA-806 | |
| 109 | + CCMBridge ccmBridge; | |
| 110 | + ccmBridge = CCMBridge.create("test", 1); | |
| 111 | + channelMonitor = new SocketChannelMonitor(); | |
| 112 | + channelMonitor.reportAtFixedInterval(1, TimeUnit.SECONDS); | |
| 113 | + try { | |
| 114 | + cluster = Cluster.builder() | |
| 115 | + .addContactPointsWithPorts(Collections.singletonList( | |
| 116 | + new InetSocketAddress(CCMBridge.IP_PREFIX + '1', 9042))) | |
| 117 | + .withNettyOptions(channelMonitor.nettyOptions()).build(); | |
| 118 | + | |
| 119 | + cluster.init(); | |
| 120 | + | |
| 121 | + assertThat(cluster.manager.sessions.size()).isEqualTo(0); | |
| 122 | + // Should be 1 control connection after initialization. | |
| 123 | + assertOpenConnections(1); | |
| 124 | + | |
| 125 | + cluster.connect("wrong_keyspace"); | |
| 126 | + | |
| 127 | + fail("Should not have connected to a wrong keyspace"); | |
| 128 | + | |
| 129 | + } catch (InvalidQueryException e) { | |
| 130 | + | |
| 131 | + // ok | |
| 132 | + | |
| 133 | + } finally { | |
| 134 | + | |
| 135 | + assertThat(cluster.manager.sessions.size()).isEqualTo(0); | |
| 136 | + | |
| 137 | + if (cluster != null) { | |
| 92 | 138 | cluster.close(); |
| 93 | 139 | } |
| 94 | 140 | if (ccmBridge != null) { |
added driver-core/src/test/java/com/datastax/driver/core/TracingTest.java +73 −0
| @@ -0,0 +1,73 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (C) 2012-2015 DataStax Inc. | |
| 3 | + * | |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | + * you may not use this file except in compliance with the License. | |
| 6 | + * You may obtain a copy of the License at | |
| 7 | + * | |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | + * | |
| 10 | + * Unless required by applicable law or agreed to in writing, software | |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | + * See the License for the specific language governing permissions and | |
| 14 | + * limitations under the License. | |
| 15 | + */ | |
| 16 | +package com.datastax.driver.core; | |
| 17 | + | |
| 18 | +import java.util.Collection; | |
| 19 | +import java.util.Collections; | |
| 20 | +import java.util.List; | |
| 21 | +import java.util.UUID; | |
| 22 | + | |
| 23 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 24 | +import org.testng.annotations.BeforeClass; | |
| 25 | +import org.testng.annotations.Test; | |
| 26 | + | |
| 27 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 28 | + | |
| 29 | +@CassandraVersion(major=2.0) | |
| 30 | +public class TracingTest extends CCMBridge.PerClassSingleNodeCluster { | |
| 31 | + | |
| 32 | + public static final String KEY = "tracing_test"; | |
| 33 | + | |
| 34 | + @Override | |
| 35 | + protected Collection<String> getTableDefinitions() { | |
| 36 | + return Collections.singletonList("CREATE TABLE test (k text, v int, PRIMARY KEY (k, v))"); | |
| 37 | + } | |
| 38 | + | |
| 39 | + @BeforeClass(groups = "short") | |
| 40 | + public void initData() { | |
| 41 | + for (int i = 0; i < 100; i++) { | |
| 42 | + session.execute(String.format("INSERT INTO test (k, v) VALUES ('%s', %d)", KEY, i)); | |
| 43 | + } | |
| 44 | + } | |
| 45 | + | |
| 46 | + /** | |
| 47 | + * Validates that for each page the {@link ExecutionInfo} will have a different tracing ID. | |
| 48 | + * | |
| 49 | + * @test_category tracing | |
| 50 | + * @expected_result {@link ResultSet} where all the {@link ExecutionInfo} will contains a different tracing ID and | |
| 51 | + * that the events can be retrieved for the last query. | |
| 52 | + */ | |
| 53 | + @Test(groups = "short") | |
| 54 | + public void should_have_a_different_tracingId_for_each_page() { | |
| 55 | + SimpleStatement st = new SimpleStatement(String.format("SELECT v FROM test WHERE k='%s'", KEY)); | |
| 56 | + ResultSet result = session.execute(st.setFetchSize(40).enableTracing()); | |
| 57 | + result.all(); | |
| 58 | + | |
| 59 | + List<ExecutionInfo> executions = result.getAllExecutionInfo(); | |
| 60 | + | |
| 61 | + UUID previousTraceId = null; | |
| 62 | + for (ExecutionInfo executionInfo : executions) { | |
| 63 | + QueryTrace queryTrace = executionInfo.getQueryTrace(); | |
| 64 | + assertThat(queryTrace).isNotNull(); | |
| 65 | + assertThat(queryTrace.getTraceId()).isNotEqualTo(previousTraceId); | |
| 66 | + previousTraceId = queryTrace.getTraceId(); | |
| 67 | + } | |
| 68 | + | |
| 69 | + assertThat(result.getExecutionInfo().getQueryTrace().getEvents()).isNotNull() | |
| 70 | + .isNotEmpty(); | |
| 71 | + } | |
| 72 | +} | |
| 73 | + |
modified features/native_protocol/README.md +1 −1
| @@ -7,7 +7,7 @@ | ||
| 7 | 7 | aspect is that some features are only available with specific protocol |
| 8 | 8 | versions. |
| 9 | 9 | |
| 10 | -[native_spec]: https://git-wip-us.apache.org/repos/asf?p=cassandra.git;a=tree;f=doc;hb=HEAD | |
| 10 | +[native_spec]: https://github.com/apache/cassandra/tree/trunk/doc | |
| 11 | 11 | |
| 12 | 12 | ### Compatibility matrix |
| 13 | 13 |