|
18 | 18 | */
|
19 | 19 | package org.neo4j.driver.integration;
|
20 | 20 |
|
21 |
| -import org.junit.jupiter.api.AfterEach; |
22 |
| -import org.junit.jupiter.api.BeforeAll; |
23 | 21 | import org.junit.jupiter.api.Test;
|
24 |
| -import reactor.core.publisher.Flux; |
25 |
| -import reactor.core.publisher.Mono; |
26 |
| -import reactor.test.StepVerifier; |
27 |
| - |
28 |
| -import java.io.IOException; |
29 |
| -import java.net.URI; |
30 |
| -import java.util.concurrent.TimeUnit; |
31 | 22 |
|
32 | 23 | import org.neo4j.driver.Config;
|
33 | 24 | import org.neo4j.driver.Driver;
|
34 | 25 | import org.neo4j.driver.GraphDatabase;
|
35 |
| -import org.neo4j.driver.Record; |
36 | 26 | import org.neo4j.driver.net.ServerAddress;
|
37 | 27 | import org.neo4j.driver.net.ServerAddressResolver;
|
38 |
| -import org.neo4j.driver.reactive.RxResult; |
39 |
| -import org.neo4j.driver.reactive.RxSession; |
40 |
| -import org.neo4j.driver.util.StubServer; |
41 |
| -import org.neo4j.driver.util.StubServerController; |
42 | 28 |
|
43 |
| -import static org.hamcrest.core.IsEqual.equalTo; |
44 |
| -import static org.hamcrest.junit.MatcherAssert.assertThat; |
45 | 29 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
46 | 30 | import static org.junit.jupiter.api.Assertions.assertThrows;
|
47 | 31 | import static org.mockito.ArgumentMatchers.any;
|
48 | 32 | import static org.mockito.Mockito.mock;
|
49 | 33 | import static org.mockito.Mockito.verify;
|
50 | 34 | import static org.mockito.Mockito.when;
|
51 |
| -import static org.neo4j.driver.SessionConfig.builder; |
52 |
| -import static org.neo4j.driver.util.StubServer.insecureBuilder; |
| 35 | +import static org.neo4j.driver.Logging.none; |
53 | 36 |
|
54 |
| -/** |
55 |
| - * New tests should be added to testkit (https://github.com/neo4j-drivers/testkit). |
56 |
| - * |
57 |
| - * This class exists only for the following: |
58 |
| - * - to keep the remaining tests that are due to be migrated |
59 |
| - * - to keep the tests that are currently not portable |
60 |
| - */ |
61 |
| -@Deprecated |
62 | 37 | class RoutingDriverBoltKitIT
|
63 | 38 | {
|
64 |
| - private static StubServerController stubController; |
65 |
| - |
66 |
| - @BeforeAll |
67 |
| - public static void setup() |
68 |
| - { |
69 |
| - stubController = new StubServerController(); |
70 |
| - } |
71 |
| - |
72 |
| - @AfterEach |
73 |
| - public void killServers() |
74 |
| - { |
75 |
| - stubController.reset(); |
76 |
| - } |
77 |
| - |
78 |
| - private static String extractNameField( Record record ) |
79 |
| - { |
80 |
| - return record.get( 0 ).asString(); |
81 |
| - } |
82 |
| - |
83 |
| - // RX is not currently supported in testkit. |
84 |
| - |
85 |
| - // This does not exactly reproduce the async and blocking versions above, as we don't have any means of ignoring |
86 |
| - // the flux of the RETURN 1 query (not pulling the result) like we do in above, so this is "just" a test for |
87 |
| - // a leader going away during the execution of a flux. |
88 |
| - @Test |
89 |
| - void shouldHandleLeaderSwitchAndRetryWhenWritingInTxFunctionRX() throws IOException, InterruptedException |
90 |
| - { |
91 |
| - // Given |
92 |
| - StubServer server = stubController.startStub( "acquire_endpoints_twice_v4.script", 9001 ); |
93 |
| - |
94 |
| - // START a write server that fails on the first write attempt but then succeeds on the second |
95 |
| - StubServer writeServer = stubController.startStub( "not_able_to_write_server_tx_func_retries_rx.script", 9007 ); |
96 |
| - URI uri = URI.create( "neo4j://127.0.0.1:9001" ); |
97 |
| - |
98 |
| - Driver driver = GraphDatabase.driver( uri, Config.builder().withMaxTransactionRetryTime( 1, TimeUnit.MILLISECONDS ).build() ); |
99 |
| - |
100 |
| - Flux<String> fluxOfNames = Flux.usingWhen( Mono.fromSupplier( () -> driver.rxSession( builder().withDatabase( "mydatabase" ).build() ) ), |
101 |
| - session -> session.writeTransaction( tx -> |
102 |
| - { |
103 |
| - RxResult result = tx.run( "RETURN 1" ); |
104 |
| - return Flux.from( result.records() ).limitRate( 100 ).thenMany( tx.run( "MATCH (n) RETURN n.name" ).records() ).limitRate( 100 ).map( |
105 |
| - RoutingDriverBoltKitIT::extractNameField ); |
106 |
| - } ), RxSession::close ); |
107 |
| - |
108 |
| - StepVerifier.create( fluxOfNames ).expectNext( "Foo", "Bar" ).verifyComplete(); |
109 |
| - |
110 |
| - // Finally |
111 |
| - driver.close(); |
112 |
| - assertThat( server.exitStatus(), equalTo( 0 ) ); |
113 |
| - assertThat( writeServer.exitStatus(), equalTo( 0 ) ); |
114 |
| - } |
115 |
| - |
116 | 39 | @Test
|
117 | 40 | void shouldFailInitialDiscoveryWhenConfiguredResolverThrows()
|
118 | 41 | {
|
119 | 42 | ServerAddressResolver resolver = mock( ServerAddressResolver.class );
|
120 | 43 | when( resolver.resolve( any( ServerAddress.class ) ) ).thenThrow( new RuntimeException( "Resolution failure!" ) );
|
121 | 44 |
|
122 |
| - Config config = insecureBuilder().withResolver( resolver ).build(); |
| 45 | + Config config = Config.builder() |
| 46 | + .withoutEncryption() |
| 47 | + .withLogging( none() ) |
| 48 | + .withResolver( resolver ) |
| 49 | + .build(); |
123 | 50 | final Driver driver = GraphDatabase.driver( "neo4j://my.server.com:9001", config );
|
124 | 51 |
|
125 | 52 | RuntimeException error = assertThrows( RuntimeException.class, driver::verifyConnectivity );
|
|
0 commit comments