kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | f59550660f4e59d7152ae535f53ab01b74da3d61aec6a981eae50f2348e25a36 |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2015-10-14 15:43 +02:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2015-10-27 17:59 +01:00 |
| Parents | add58104027d |
7 files changed
modified changelog/README.md +5 −0
| @@ -1,5 +1,10 @@ | ||
| 1 | 1 | ## Changelog |
| 2 | 2 | |
| 3 | +### 2.0.12 (in progress) | |
| 4 | + | |
| 5 | +- [bug] Fix Cluster.connect with a case-sensitive keyspace (JAVA-950) | |
| 6 | + | |
| 7 | + | |
| 3 | 8 | ### 2.0.11 |
| 4 | 9 | |
| 5 | 10 | - [improvement] Log streamid at the trace level on sending request and receiving response (JAVA-718) |
modified driver-core/src/main/java/com/datastax/driver/core/Cluster.java +27 −8
| @@ -26,9 +26,9 @@ | ||
| 26 | 26 | import java.util.concurrent.atomic.AtomicReference; |
| 27 | 27 | |
| 28 | 28 | import com.google.common.annotations.VisibleForTesting; |
| 29 | +import com.google.common.base.Functions; | |
| 29 | 30 | import com.google.common.base.Objects; |
| 30 | 31 | import com.google.common.base.Predicates; |
| 31 | -import com.google.common.base.Throwables; | |
| 32 | 32 | import com.google.common.collect.*; |
| 33 | 33 | import com.google.common.util.concurrent.*; |
| 34 | 34 | import org.slf4j.Logger; |
| @@ -36,6 +36,7 @@ | ||
| 36 | 36 | |
| 37 | 37 | import com.datastax.driver.core.exceptions.AuthenticationException; |
| 38 | 38 | import com.datastax.driver.core.exceptions.DriverInternalError; |
| 39 | +import com.datastax.driver.core.exceptions.InvalidQueryException; | |
| 39 | 40 | import com.datastax.driver.core.exceptions.NoHostAvailableException; |
| 40 | 41 | import com.datastax.driver.core.policies.*; |
| 41 | 42 | import com.datastax.driver.core.utils.MoreFutures; |
| @@ -221,7 +222,7 @@ | ||
| 221 | 222 | */ |
| 222 | 223 | public Session newSession() { |
| 223 | 224 | checkNotClosed(manager); |
| 224 | - return manager.newSession(null); | |
| 225 | + return manager.newSession(); | |
| 225 | 226 | } |
| 226 | 227 | |
| 227 | 228 | /** |
| @@ -272,6 +273,7 @@ | ||
| 272 | 273 | * be contacted to set the {@code keyspace}. |
| 273 | 274 | * @throws AuthenticationException if an authentication error occurs while |
| 274 | 275 | * contacting the initial contact points. |
| 276 | + * @throws InvalidQueryException if the keyspace does not exists. | |
| 275 | 277 | * @throws IllegalStateException if the Cluster was closed prior to calling |
| 276 | 278 | * this method. This can occur either directly (through {@link #close()} or |
| 277 | 279 | * {@link #closeAsync()}), or as a result of an error while initializing the |
| @@ -332,11 +334,28 @@ | ||
| 332 | 334 | * {@link #closeAsync()}), or as a result of an error while initializing the |
| 333 | 335 | * Cluster. |
| 334 | 336 | */ |
| 335 | - public ListenableFuture<Session> connectAsync(String keyspace) { | |
| 337 | + public ListenableFuture<Session> connectAsync(final String keyspace) { | |
| 336 | 338 | checkNotClosed(manager); |
| 337 | 339 | init(); |
| 338 | - AsyncInitSession session = manager.newSession(keyspace); | |
| 339 | - return session.initAsync(); | |
| 340 | + final AsyncInitSession session = manager.newSession(); | |
| 341 | + ListenableFuture<Session> sessionInitialized = session.initAsync(); | |
| 342 | + if (keyspace == null) { | |
| 343 | + return sessionInitialized; | |
| 344 | + } else { | |
| 345 | + ListenableFuture<ResultSet> keyspaceSet = Futures.transform(sessionInitialized, new AsyncFunction<Session, ResultSet>() { | |
| 346 | + @Override | |
| 347 | + public ListenableFuture<ResultSet> apply(Session session) throws Exception { | |
| 348 | + return session.executeAsync("USE " + keyspace); | |
| 349 | + } | |
| 350 | + }); | |
| 351 | + Futures.addCallback(keyspaceSet, new MoreFutures.FailureCallback<ResultSet>() { | |
| 352 | + @Override | |
| 353 | + public void onFailure(Throwable t) { | |
| 354 | + session.closeAsync(); | |
| 355 | + } | |
| 356 | + }); | |
| 357 | + return Futures.transform(keyspaceSet, Functions.<Session>constant(session)); | |
| 358 | + } | |
| 340 | 359 | } |
| 341 | 360 | |
| 342 | 361 | /** |
| @@ -1487,8 +1506,8 @@ | ||
| 1487 | 1506 | return translated == null ? sa : translated; |
| 1488 | 1507 | } |
| 1489 | 1508 | |
| 1490 | - private AsyncInitSession newSession(String keyspace) { | |
| 1491 | - SessionManager session = new SessionManager(Cluster.this, keyspace); | |
| 1509 | + private AsyncInitSession newSession() { | |
| 1510 | + SessionManager session = new SessionManager(Cluster.this); | |
| 1492 | 1511 | sessions.add(session); |
| 1493 | 1512 | return session; |
| 1494 | 1513 | } |
| @@ -1925,7 +1944,7 @@ | ||
| 1925 | 1944 | |
| 1926 | 1945 | List<ListenableFuture<Boolean>> futures = Lists.newArrayListWithCapacity(sessions.size()); |
| 1927 | 1946 | for (SessionManager s : sessions) |
| 1928 | - futures.add(s.maybeAddPool(host, reusedConnection, false)); | |
| 1947 | + futures.add(s.maybeAddPool(host, reusedConnection)); | |
| 1929 | 1948 | |
| 1930 | 1949 | try { |
| 1931 | 1950 | // Only mark the node up once all session have added their pool (if the load-balancing |
modified driver-core/src/main/java/com/datastax/driver/core/Connection.java +6 −15
| @@ -46,14 +46,11 @@ | ||
| 46 | 46 | |
| 47 | 47 | import static io.netty.handler.timeout.IdleState.ALL_IDLE; |
| 48 | 48 | |
| 49 | -import com.datastax.driver.core.exceptions.AuthenticationException; | |
| 50 | -import com.datastax.driver.core.exceptions.DriverException; | |
| 51 | -import com.datastax.driver.core.exceptions.DriverInternalError; | |
| 52 | -import com.datastax.driver.core.exceptions.InvalidQueryException; | |
| 49 | +import com.datastax.driver.core.Responses.Result.SetKeyspace; | |
| 50 | +import com.datastax.driver.core.exceptions.*; | |
| 53 | 51 | import com.datastax.driver.core.utils.MoreFutures; |
| 54 | 52 | |
| 55 | 53 | import static com.datastax.driver.core.Message.Response.Type.ERROR; |
| 56 | -import static com.datastax.driver.core.Message.Response.Type.RESULT; | |
| 57 | 54 | |
| 58 | 55 | // For LoggingHandler |
| 59 | 56 | //import org.jboss.netty.handler.logging.LoggingHandler; |
| @@ -182,7 +179,7 @@ | ||
| 182 | 179 | public ListenableFuture<Void> create(Throwable t) throws Exception { |
| 183 | 180 | SettableFuture<Void> future = SettableFuture.create(); |
| 184 | 181 | // Make sure the connection gets properly closed. |
| 185 | - if (t instanceof ClusterNameMismatchException || t instanceof UnsupportedProtocolVersionException || t instanceof SetKeyspaceException) { | |
| 182 | + if (t instanceof ClusterNameMismatchException || t instanceof UnsupportedProtocolVersionException) { | |
| 186 | 183 | // Just propagate |
| 187 | 184 | closeAsync().force(); |
| 188 | 185 | future.setException(t); |
| @@ -474,19 +471,13 @@ | ||
| 474 | 471 | return Futures.transform(future, new AsyncFunction<Message.Response, Void>() { |
| 475 | 472 | @Override |
| 476 | 473 | public ListenableFuture<Void> apply(Message.Response response) throws Exception { |
| 477 | - if (response.type == RESULT) { | |
| 478 | - Connection.this.keyspace = keyspace; | |
| 474 | + if (response instanceof SetKeyspace) { | |
| 475 | + Connection.this.keyspace = ((SetKeyspace)response).keyspace; | |
| 479 | 476 | return MoreFutures.VOID_SUCCESS; |
| 480 | 477 | } else if (response.type == ERROR) { |
| 481 | 478 | closeAsync().force(); |
| 482 | 479 | Responses.Error error = (Responses.Error)response; |
| 483 | - Exception e = error.asException(address); | |
| 484 | - if (e instanceof InvalidQueryException) { | |
| 485 | - // Most likely means that the keyspace name is wrong. Wrap that in a specific exception, because we want | |
| 486 | - // to treat it specially in case of a Session init. | |
| 487 | - e = new SetKeyspaceException(e); | |
| 488 | - } | |
| 489 | - throw e; | |
| 480 | + throw error.asException(address); | |
| 490 | 481 | } else { |
| 491 | 482 | closeAsync().force(); |
| 492 | 483 | throw new DriverInternalError("Unexpected response while setting keyspace: " + response); |
modified driver-core/src/main/java/com/datastax/driver/core/HostConnectionPool.java +1 −19
| @@ -100,8 +100,6 @@ | ||
| 100 | 100 | * pool. |
| 101 | 101 | */ |
| 102 | 102 | public ListenableFuture<Void> initAsync(Connection reusedConnection) { |
| 103 | - String keyspace = manager.poolsState.keyspace; | |
| 104 | - | |
| 105 | 103 | Executor initExecutor = manager.cluster.manager.configuration.getPoolingOptions().getInitializationExecutor(); |
| 106 | 104 | |
| 107 | 105 | // Create initial core connections |
| @@ -121,7 +119,7 @@ | ||
| 121 | 119 | } |
| 122 | 120 | reusedConnection = null; |
| 123 | 121 | connections.add(connection); |
| 124 | - connectionFutures.add(handleErrors(setKeyspaceAsync(connectionFuture, connection, keyspace), initExecutor)); | |
| 122 | + connectionFutures.add(handleErrors(connectionFuture, initExecutor)); | |
| 125 | 123 | } |
| 126 | 124 | |
| 127 | 125 | ListenableFuture<List<Void>> allConnectionsFuture = Futures.allAsList(connectionFutures); |
| @@ -170,7 +168,6 @@ | ||
| 170 | 168 | // accordingly in SessionManager#maybeAddPool. |
| 171 | 169 | Throwables.propagateIfInstanceOf(t, ClusterNameMismatchException.class); |
| 172 | 170 | Throwables.propagateIfInstanceOf(t, UnsupportedProtocolVersionException.class); |
| 173 | - Throwables.propagateIfInstanceOf(t, SetKeyspaceException.class); | |
| 174 | 171 | |
| 175 | 172 | // We don't want to swallow Errors either as they probably indicate a more serious issue (OOME...) |
| 176 | 173 | Throwables.propagateIfInstanceOf(t, Error.class); |
| @@ -181,17 +178,6 @@ | ||
| 181 | 178 | }, executor); |
| 182 | 179 | } |
| 183 | 180 | |
| 184 | - private ListenableFuture<Void> setKeyspaceAsync(ListenableFuture<Void> initFuture, final Connection connection, final String keyspace) { | |
| 185 | - return (keyspace == null) | |
| 186 | - ? initFuture | |
| 187 | - : Futures.transform(initFuture, new AsyncFunction<Void, Void>() { | |
| 188 | - @Override | |
| 189 | - public ListenableFuture<Void> apply(Void input) throws Exception { | |
| 190 | - return connection.setKeyspaceAsync(keyspace); | |
| 191 | - } | |
| 192 | - }); | |
| 193 | - } | |
| 194 | - | |
| 195 | 181 | // Clean up if we got a fatal error at construction time but still created part of the core connections |
| 196 | 182 | private void forceClose(List<Connection> connections) { |
| 197 | 183 | for (Connection connection : connections) { |
| @@ -682,10 +668,6 @@ | ||
| 682 | 668 | |
| 683 | 669 | volatile String keyspace; |
| 684 | 670 | |
| 685 | - PoolState(String keyspace) { | |
| 686 | - this.keyspace = keyspace; | |
| 687 | - } | |
| 688 | - | |
| 689 | 671 | void setKeyspace(String keyspace) { |
| 690 | 672 | this.keyspace = keyspace; |
| 691 | 673 | } |
modified driver-core/src/main/java/com/datastax/driver/core/SessionManager.java +6 −11
| @@ -21,9 +21,7 @@ | ||
| 21 | 21 | import java.util.concurrent.*; |
| 22 | 22 | import java.util.concurrent.atomic.AtomicReference; |
| 23 | 23 | |
| 24 | -import com.google.common.base.Function; | |
| 25 | 24 | import com.google.common.base.Functions; |
| 26 | -import com.google.common.base.Throwables; | |
| 27 | 25 | import com.google.common.collect.ImmutableList; |
| 28 | 26 | import com.google.common.collect.Lists; |
| 29 | 27 | import com.google.common.util.concurrent.*; |
| @@ -56,10 +54,10 @@ | ||
| 56 | 54 | private volatile boolean isClosing; |
| 57 | 55 | |
| 58 | 56 | // Package protected, only Cluster should construct that. |
| 59 | - SessionManager(Cluster cluster, String keyspace) { | |
| 57 | + SessionManager(Cluster cluster) { | |
| 60 | 58 | this.cluster = cluster; |
| 61 | 59 | this.pools = new ConcurrentHashMap<Host, HostConnectionPool>(); |
| 62 | - this.poolsState = new HostConnectionPool.PoolState(keyspace); | |
| 60 | + this.poolsState = new HostConnectionPool.PoolState(); | |
| 63 | 61 | } |
| 64 | 62 | |
| 65 | 63 | public Session init() { |
| @@ -113,7 +111,7 @@ | ||
| 113 | 111 | List<ListenableFuture<Boolean>> futures = Lists.newArrayListWithCapacity(hosts.size()); |
| 114 | 112 | for (Host host : hosts) |
| 115 | 113 | if (host.state != Host.State.DOWN) |
| 116 | - futures.add(maybeAddPool(host, null, true)); | |
| 114 | + futures.add(maybeAddPool(host, null)); | |
| 117 | 115 | return Futures.allAsList(futures); |
| 118 | 116 | } |
| 119 | 117 | |
| @@ -328,7 +326,7 @@ | ||
| 328 | 326 | } |
| 329 | 327 | |
| 330 | 328 | // Returns whether there was problem creating the pool |
| 331 | - ListenableFuture<Boolean> maybeAddPool(final Host host, Connection reusedConnection, final boolean failOnKeyspaceError) { | |
| 329 | + ListenableFuture<Boolean> maybeAddPool(final Host host, Connection reusedConnection) { | |
| 332 | 330 | final HostDistance distance = cluster.manager.loadBalancingPolicy().distance(host); |
| 333 | 331 | if (distance == HostDistance.IGNORED) |
| 334 | 332 | return Futures.immediateFuture(true); |
| @@ -361,9 +359,6 @@ | ||
| 361 | 359 | ClusterNameMismatchException e = (ClusterNameMismatchException)t; |
| 362 | 360 | cluster.manager.logClusterNameMismatch(host, e.expectedClusterName, e.actualClusterName); |
| 363 | 361 | cluster.manager.triggerOnDown(host, false); |
| 364 | - } else if ((t instanceof SetKeyspaceException) && failOnKeyspaceError) { | |
| 365 | - future.setException(t.getCause()); | |
| 366 | - return; | |
| 367 | 362 | } else { |
| 368 | 363 | logger.error("Error creating pool to " + host, t); |
| 369 | 364 | } |
| @@ -409,7 +404,7 @@ | ||
| 409 | 404 | |
| 410 | 405 | if (pool == null) { |
| 411 | 406 | if (dist != HostDistance.IGNORED && h.state == Host.State.UP) |
| 412 | - poolCreatedFutures.add(maybeAddPool(h, null, false)); | |
| 407 | + poolCreatedFutures.add(maybeAddPool(h, null)); | |
| 413 | 408 | } else if (dist != pool.hostDistance) { |
| 414 | 409 | if (dist == HostDistance.IGNORED) { |
| 415 | 410 | toRemove.add(h); |
| @@ -443,7 +438,7 @@ | ||
| 443 | 438 | if (pool == null) { |
| 444 | 439 | if (dist != HostDistance.IGNORED && h.state == Host.State.UP) |
| 445 | 440 | try { |
| 446 | - maybeAddPool(h, null, false).get(); | |
| 441 | + maybeAddPool(h, null).get(); | |
| 447 | 442 | } catch (ExecutionException e) { |
| 448 | 443 | // Ignore, maybeAddPool has already handled the error |
| 449 | 444 | } |
deleted driver-core/src/main/java/com/datastax/driver/core/SetKeyspaceException.java +0 −23
| @@ -1,23 +0,0 @@ | ||
| 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 | -@SuppressWarnings("serial") | |
| 19 | -class SetKeyspaceException extends Exception { | |
| 20 | - SetKeyspaceException(Exception cause) { | |
| 21 | - super(cause); | |
| 22 | - } | |
| 23 | -} |
modified driver-core/src/test/java/com/datastax/driver/core/AsyncQueryTest.java +42 −19
| @@ -16,15 +16,13 @@ | ||
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | 18 | import java.util.Collection; |
| 19 | -import java.util.concurrent.ExecutionException; | |
| 20 | -import java.util.concurrent.TimeUnit; | |
| 19 | +import java.util.List; | |
| 20 | +import java.util.concurrent.*; | |
| 21 | 21 | |
| 22 | 22 | import com.google.common.base.Function; |
| 23 | 23 | import com.google.common.collect.Lists; |
| 24 | -import com.google.common.util.concurrent.AsyncFunction; | |
| 25 | -import com.google.common.util.concurrent.Futures; | |
| 26 | -import com.google.common.util.concurrent.ListenableFuture; | |
| 27 | -import com.google.common.util.concurrent.Uninterruptibles; | |
| 24 | +import com.google.common.util.concurrent.*; | |
| 25 | +import org.testng.annotations.DataProvider; | |
| 28 | 26 | import org.testng.annotations.Test; |
| 29 | 27 | |
| 30 | 28 | import static org.assertj.core.api.Assertions.assertThat; |
| @@ -35,12 +33,24 @@ | ||
| 35 | 33 | |
| 36 | 34 | public class AsyncQueryTest extends CCMBridge.PerClassSingleNodeCluster { |
| 37 | 35 | |
| 36 | + @DataProvider(name="keyspace") | |
| 37 | + public static Object[][] keyspace() { | |
| 38 | + return new Object[][]{ { "asyncquerytest" }, { "\"AsyncQueryTest\"" } }; | |
| 39 | + } | |
| 40 | + | |
| 38 | 41 | @Override |
| 39 | 42 | protected Collection<String> getTableDefinitions() { |
| 40 | - return Lists.newArrayList( | |
| 41 | - "create table foo(k int primary key, v int)", | |
| 42 | - "insert into foo (k, v) values (1, 1)" | |
| 43 | - ); | |
| 43 | + List<String> definitions = Lists.newArrayList(); | |
| 44 | + | |
| 45 | + for (Object[] objects : keyspace()) { | |
| 46 | + String keyspace = (String)objects[0]; | |
| 47 | + | |
| 48 | + definitions.add(String.format("create keyspace %s WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}", keyspace)); | |
| 49 | + definitions.add(String.format("create table %s.foo(k int primary key, v int)", keyspace)); | |
| 50 | + definitions.add(String.format("insert into %s.foo (k, v) values (1, 1)", keyspace)); | |
| 51 | + } | |
| 52 | + | |
| 53 | + return definitions; | |
| 44 | 54 | } |
| 45 | 55 | |
| 46 | 56 | /** |
| @@ -76,27 +86,40 @@ | ||
| 76 | 86 | // Neither cluster2 nor session2 are initialized at this point |
| 77 | 87 | assertThat(cluster2.manager.metadata).isNull(); |
| 78 | 88 | |
| 79 | - ResultSetFuture future = session2.executeAsync(String.format("select v from %s.foo where k = 1", keyspace)); | |
| 89 | + ResultSetFuture future = session2.executeAsync("select release_version from system.local"); | |
| 80 | 90 | Row row = Uninterruptibles.getUninterruptibly(future).one(); |
| 81 | 91 | |
| 82 | - assertThat(row.getInt(0)).isEqualTo(1); | |
| 92 | + assertThat(row.getString(0)).isNotEmpty(); | |
| 83 | 93 | } finally { |
| 84 | 94 | if (cluster2 != null) |
| 85 | 95 | cluster2.close(); |
| 86 | 96 | } |
| 87 | 97 | } |
| 88 | 98 | |
| 89 | - @Test(groups = "short") | |
| 90 | - public void should_chain_query_on_async_session_init() throws Exception { | |
| 91 | - ListenableFuture<Integer> resultFuture = connectAndQuery(this.keyspace); | |
| 99 | + @Test(groups = "short", dataProvider = "keyspace", enabled = false, | |
| 100 | + description = "disabled because the blocking USE call in the current pool implementation makes it deadlock") | |
| 101 | + public void should_chain_query_on_async_session_init_with_same_executor(String keyspace) throws Exception { | |
| 102 | + ListenableFuture<Integer> resultFuture = connectAndQuery(keyspace, MoreExecutors.sameThreadExecutor()); | |
| 92 | 103 | |
| 93 | 104 | Integer result = Uninterruptibles.getUninterruptibly(resultFuture); |
| 94 | 105 | assertThat(result).isEqualTo(1); |
| 95 | 106 | } |
| 96 | 107 | |
| 108 | + @Test(groups = "short", dataProvider = "keyspace") | |
| 109 | + public void should_chain_query_on_async_session_init_with_different_executor(String keyspace) throws Exception { | |
| 110 | + ExecutorService executor = Executors.newFixedThreadPool(1); | |
| 111 | + | |
| 112 | + ListenableFuture<Integer> resultFuture = connectAndQuery(keyspace, executor); | |
| 113 | + | |
| 114 | + Integer result = Uninterruptibles.getUninterruptibly(resultFuture); | |
| 115 | + assertThat(result).isEqualTo(1); | |
| 116 | + | |
| 117 | + executor.shutdownNow(); | |
| 118 | + } | |
| 119 | + | |
| 97 | 120 | @Test(groups = "short") |
| 98 | 121 | public void should_propagate_error_to_chained_query_if_session_init_fails() throws Exception { |
| 99 | - ListenableFuture<Integer> resultFuture = connectAndQuery("wrong_keyspace"); | |
| 122 | + ListenableFuture<Integer> resultFuture = connectAndQuery("wrong_keyspace", MoreExecutors.sameThreadExecutor()); | |
| 100 | 123 | |
| 101 | 124 | try { |
| 102 | 125 | Uninterruptibles.getUninterruptibly(resultFuture); |
| @@ -107,20 +130,20 @@ | ||
| 107 | 130 | } |
| 108 | 131 | } |
| 109 | 132 | |
| 110 | - private ListenableFuture<Integer> connectAndQuery(String keyspace) { | |
| 133 | + private ListenableFuture<Integer> connectAndQuery(String keyspace, Executor executor) { | |
| 111 | 134 | ListenableFuture<Session> sessionFuture = cluster.connectAsync(keyspace); |
| 112 | 135 | ListenableFuture<ResultSet> queryFuture = Futures.transform(sessionFuture, new AsyncFunction<Session, ResultSet>() { |
| 113 | 136 | @Override |
| 114 | 137 | public ListenableFuture<ResultSet> apply(Session session) throws Exception { |
| 115 | 138 | return session.executeAsync("select v from foo where k = 1"); |
| 116 | 139 | } |
| 117 | - }); | |
| 140 | + }, executor); | |
| 118 | 141 | return Futures.transform(queryFuture, new Function<ResultSet, Integer>() { |
| 119 | 142 | @Override |
| 120 | 143 | public Integer apply(ResultSet rs) { |
| 121 | 144 | return rs.one().getInt(0); |
| 122 | 145 | } |
| 123 | - }); | |
| 146 | + }, executor); | |
| 124 | 147 | } |
| 125 | 148 | |
| 126 | 149 | private static HostConnectionPool getPool(Session session) { |