|
18 | 18 | */
|
19 | 19 | package org.neo4j.driver.integration;
|
20 | 20 |
|
| 21 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
21 | 22 | import static org.junit.jupiter.api.Assertions.assertThrows;
|
22 | 23 | import static org.neo4j.driver.SessionConfig.builder;
|
23 | 24 |
|
| 25 | +import java.util.HashMap; |
| 26 | +import java.util.Map; |
| 27 | +import java.util.concurrent.CompletableFuture; |
24 | 28 | import org.junit.jupiter.api.Test;
|
25 | 29 | import org.junit.jupiter.api.extension.RegisterExtension;
|
26 | 30 | import org.neo4j.driver.AccessMode;
|
| 31 | +import org.neo4j.driver.Config; |
27 | 32 | import org.neo4j.driver.Driver;
|
28 | 33 | import org.neo4j.driver.GraphDatabase;
|
| 34 | +import org.neo4j.driver.Result; |
29 | 35 | import org.neo4j.driver.Session;
|
| 36 | +import org.neo4j.driver.internal.spi.ConnectionPool; |
30 | 37 | import org.neo4j.driver.util.DatabaseExtension;
|
31 | 38 | import org.neo4j.driver.util.ParallelizableIT;
|
32 | 39 |
|
@@ -84,6 +91,25 @@ void useSessionAfterDriverIsClosed() {
|
84 | 91 | assertThrows(IllegalStateException.class, () -> session.run("CREATE ()"));
|
85 | 92 | }
|
86 | 93 |
|
| 94 | + @Test |
| 95 | + void shouldInterruptStreamConsumptionAndEndRetriesOnDriverClosure() { |
| 96 | + int fetchSize = 5; |
| 97 | + Config config = Config.builder().withFetchSize(fetchSize).build(); |
| 98 | + Driver driver = GraphDatabase.driver(neo4j.uri(), neo4j.authToken(), config); |
| 99 | + Session session = driver.session(); |
| 100 | + |
| 101 | + IllegalStateException exception = assertThrows( |
| 102 | + IllegalStateException.class, |
| 103 | + () -> session.readTransaction(tx -> { |
| 104 | + Map<String, Object> parameters = new HashMap<>(); |
| 105 | + parameters.put("limit", fetchSize * 3); |
| 106 | + Result result = tx.run("UNWIND range(0, $limit) AS x RETURN x", parameters); |
| 107 | + CompletableFuture.runAsync(driver::close); |
| 108 | + return result.list(); |
| 109 | + })); |
| 110 | + assertEquals(ConnectionPool.CONNECTION_POOL_CLOSED_ERROR_MESSAGE, exception.getMessage()); |
| 111 | + } |
| 112 | + |
87 | 113 | private static Driver createDriver() {
|
88 | 114 | return GraphDatabase.driver(neo4j.uri(), neo4j.authToken());
|
89 | 115 | }
|
|
0 commit comments