kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 239fdfe59e418008d81222f3bbe5cebedfcbd14b70bc3174f88f0cee8dd64995 |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2014-08-18 21:38 +02:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2014-08-18 21:38 +02:00 |
| Parents | 485fdbbd739f |
1 file changed
added driver-core/src/test/java/com/datastax/driver/core/AsyncQueryTest.java +41 −0
| @@ -0,0 +1,41 @@ | ||
| 1 | +package com.datastax.driver.core; | |
| 2 | + | |
| 3 | +import java.util.Collection; | |
| 4 | +import java.util.concurrent.TimeUnit; | |
| 5 | + | |
| 6 | +import com.google.common.collect.Lists; | |
| 7 | +import org.testng.annotations.Test; | |
| 8 | + | |
| 9 | +import static org.testng.Assert.assertEquals; | |
| 10 | +import static org.testng.Assert.assertTrue; | |
| 11 | + | |
| 12 | +public class AsyncQueryTest extends CCMBridge.PerClassSingleNodeCluster { | |
| 13 | + | |
| 14 | + @Override | |
| 15 | + protected Collection<String> getTableDefinitions() { | |
| 16 | + return Lists.newArrayList(); | |
| 17 | + } | |
| 18 | + | |
| 19 | + /** | |
| 20 | + * Checks that a cancelled query releases the connection (JAVA-407). | |
| 21 | + */ | |
| 22 | + @Test(groups = "short") | |
| 23 | + public void cancelQueryTest() throws InterruptedException { | |
| 24 | + ResultSetFuture future = session.executeAsync("select release_version from system.local"); | |
| 25 | + future.cancel(true); | |
| 26 | + assertTrue(future.isCancelled()); | |
| 27 | + | |
| 28 | + TimeUnit.MILLISECONDS.sleep(100); | |
| 29 | + | |
| 30 | + HostConnectionPool pool = getPool(session); | |
| 31 | + for (Connection connection : pool.connections) { | |
| 32 | + assertEquals(connection.inFlight.get(), 0); | |
| 33 | + } | |
| 34 | + } | |
| 35 | + | |
| 36 | + private static HostConnectionPool getPool(Session session) { | |
| 37 | + Collection<HostConnectionPool> pools = ((SessionManager) session).pools.values(); | |
| 38 | + assertEquals(pools.size(), 1); | |
| 39 | + return pools.iterator().next(); | |
| 40 | + } | |
| 41 | +} |