|
18 | 18 | */
|
19 | 19 | package org.neo4j.driver.v1.integration;
|
20 | 20 |
|
| 21 | +import io.netty.channel.Channel; |
21 | 22 | import org.junit.jupiter.api.Test;
|
22 | 23 | import org.junit.jupiter.api.extension.RegisterExtension;
|
23 | 24 |
|
24 | 25 | import java.time.LocalDate;
|
| 26 | +import java.util.ArrayList; |
25 | 27 | import java.util.HashMap;
|
| 28 | +import java.util.List; |
26 | 29 | import java.util.Map;
|
27 | 30 | import java.util.concurrent.CompletionStage;
|
28 | 31 |
|
29 |
| -import org.neo4j.driver.internal.logging.DevNullLogging; |
| 32 | +import org.neo4j.driver.internal.cluster.RoutingSettings; |
| 33 | +import org.neo4j.driver.internal.messaging.Message; |
| 34 | +import org.neo4j.driver.internal.messaging.request.GoodbyeMessage; |
| 35 | +import org.neo4j.driver.internal.messaging.request.HelloMessage; |
| 36 | +import org.neo4j.driver.internal.retry.RetrySettings; |
30 | 37 | import org.neo4j.driver.internal.util.EnabledOnNeo4jWith;
|
31 |
| -import org.neo4j.driver.v1.AuthTokens; |
32 |
| -import org.neo4j.driver.v1.Config; |
| 38 | +import org.neo4j.driver.internal.util.MessageRecordingDriverFactory; |
33 | 39 | import org.neo4j.driver.v1.Driver;
|
34 |
| -import org.neo4j.driver.v1.GraphDatabase; |
35 | 40 | import org.neo4j.driver.v1.Session;
|
36 | 41 | import org.neo4j.driver.v1.StatementResult;
|
37 | 42 | import org.neo4j.driver.v1.StatementResultCursor;
|
|
40 | 45 | import org.neo4j.driver.v1.exceptions.TransientException;
|
41 | 46 | import org.neo4j.driver.v1.summary.ResultSummary;
|
42 | 47 | import org.neo4j.driver.v1.util.SessionExtension;
|
43 |
| -import org.neo4j.driver.v1.util.StubServer; |
44 | 48 |
|
45 | 49 | import static java.time.Duration.ofMillis;
|
46 | 50 | import static java.util.Arrays.asList;
|
47 |
| -import static java.util.Collections.singletonMap; |
48 | 51 | import static org.hamcrest.MatcherAssert.assertThat;
|
49 | 52 | import static org.hamcrest.Matchers.containsString;
|
| 53 | +import static org.hamcrest.Matchers.greaterThan; |
| 54 | +import static org.hamcrest.Matchers.instanceOf; |
50 | 55 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
51 | 56 | import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
52 | 57 | import static org.junit.jupiter.api.Assertions.assertNotNull;
|
53 | 58 | import static org.junit.jupiter.api.Assertions.assertThrows;
|
54 | 59 | import static org.neo4j.driver.internal.util.Neo4jFeature.BOLT_V3;
|
| 60 | +import static org.neo4j.driver.v1.Config.defaultConfig; |
55 | 61 | import static org.neo4j.driver.v1.util.TestUtil.await;
|
56 | 62 |
|
57 | 63 | @EnabledOnNeo4jWith( BOLT_V3 )
|
@@ -257,22 +263,43 @@ void shouldUseBookmarksForAutoCommitTransactionsAndTransactionFunctions()
|
257 | 263 | }
|
258 | 264 |
|
259 | 265 | @Test
|
260 |
| - void shouldSendGoodbyeWhenClosingDriver() throws Throwable |
| 266 | + void shouldSendGoodbyeWhenClosingDriver() |
261 | 267 | {
|
262 |
| - StubServer server = StubServer.start( "goodbye_message.script", 9001 ); |
263 |
| - try |
| 268 | + int txCount = 13; |
| 269 | + MessageRecordingDriverFactory driverFactory = new MessageRecordingDriverFactory(); |
| 270 | + |
| 271 | + try ( Driver driver = driverFactory.newInstance( session.uri(), session.authToken(), RoutingSettings.DEFAULT, RetrySettings.DEFAULT, defaultConfig() ) ) |
264 | 272 | {
|
265 |
| - Config config = Config.build().withLogging( DevNullLogging.DEV_NULL_LOGGING ).withoutEncryption().toConfig(); |
266 |
| - try ( Driver driver = GraphDatabase.driver( "bolt://localhost:9001", AuthTokens.none(), config ); Session session = driver.session() ) |
| 273 | + List<Session> sessions = new ArrayList<>(); |
| 274 | + List<Transaction> txs = new ArrayList<>(); |
| 275 | + for ( int i = 0; i < txCount; i++ ) |
267 | 276 | {
|
268 |
| - StatementResult result = |
269 |
| - session.run( "RETURN $x", singletonMap( "x", 1 ), TransactionConfig.builder().withMetadata( singletonMap( "mode", "r" ) ).build() ); |
270 |
| - assertEquals( 1, result.single().get( "x" ).asInt() ); |
| 277 | + Session session = driver.session(); |
| 278 | + sessions.add( session ); |
| 279 | + Transaction tx = session.beginTransaction(); |
| 280 | + txs.add( tx ); |
| 281 | + } |
| 282 | + |
| 283 | + for ( int i = 0; i < txCount; i++ ) |
| 284 | + { |
| 285 | + Session session = sessions.get( i ); |
| 286 | + Transaction tx = txs.get( i ); |
| 287 | + |
| 288 | + tx.run( "CREATE ()" ); |
| 289 | + tx.success(); |
| 290 | + tx.close(); |
| 291 | + session.close(); |
271 | 292 | }
|
272 | 293 | }
|
273 |
| - finally |
| 294 | + |
| 295 | + Map<Channel,List<Message>> messagesByChannel = driverFactory.getMessagesByChannel(); |
| 296 | + assertEquals( txCount, messagesByChannel.size() ); |
| 297 | + |
| 298 | + for ( List<Message> messages : messagesByChannel.values() ) |
274 | 299 | {
|
275 |
| - assertEquals( 0, server.exitStatus() ); |
| 300 | + assertThat( messages.size(), greaterThan( 2 ) ); |
| 301 | + assertThat( messages.get( 0 ), instanceOf( HelloMessage.class ) ); // first message is HELLO |
| 302 | + assertThat( messages.get( messages.size() - 1 ), instanceOf( GoodbyeMessage.class ) ); // last message is GOODBYE |
276 | 303 | }
|
277 | 304 | }
|
278 | 305 |
|
|
0 commit comments