27
27
28
28
import java .io .IOException ;
29
29
import java .net .URI ;
30
- import java .util .Comparator ;
31
30
import java .util .List ;
32
31
import java .util .concurrent .TimeUnit ;
33
- import java .util .concurrent .atomic .AtomicInteger ;
34
32
35
- import org .neo4j .driver .AccessMode ;
36
- import org .neo4j .driver .AuthToken ;
37
- import org .neo4j .driver .AuthTokens ;
38
33
import org .neo4j .driver .Config ;
39
34
import org .neo4j .driver .Driver ;
40
35
import org .neo4j .driver .GraphDatabase ;
41
36
import org .neo4j .driver .Record ;
42
- import org .neo4j .driver .Session ;
43
- import org .neo4j .driver .TransactionWork ;
44
37
import org .neo4j .driver .async .AsyncSession ;
45
- import org .neo4j .driver .exceptions .SessionExpiredException ;
46
- import org .neo4j .driver .internal .DriverFactory ;
47
- import org .neo4j .driver .internal .cluster .RoutingSettings ;
48
- import org .neo4j .driver .internal .retry .RetrySettings ;
49
- import org .neo4j .driver .internal .security .SecurityPlanImpl ;
50
- import org .neo4j .driver .internal .util .DriverFactoryWithFixedRetryLogic ;
51
38
import org .neo4j .driver .internal .util .Futures ;
52
39
import org .neo4j .driver .net .ServerAddress ;
53
40
import org .neo4j .driver .net .ServerAddressResolver ;
66
53
import static org .mockito .Mockito .verify ;
67
54
import static org .mockito .Mockito .when ;
68
55
import static org .neo4j .driver .SessionConfig .builder ;
69
- import static org .neo4j .driver .util .StubServer .INSECURE_CONFIG ;
70
56
import static org .neo4j .driver .util .StubServer .insecureBuilder ;
71
57
72
58
/**
@@ -166,50 +152,6 @@ void shouldHandleLeaderSwitchAndRetryWhenWritingInTxFunctionRX() throws IOExcept
166
152
assertThat ( writeServer .exitStatus (), equalTo ( 0 ) );
167
153
}
168
154
169
- // fixed retries are not currently supported in testkit
170
- @ Test
171
- void shouldRetryReadTransactionUntilFailure () throws Exception
172
- {
173
- StubServer router = stubController .startStub ( "acquire_endpoints_v3.script" , 9001 );
174
- StubServer brokenReader1 = stubController .startStub ( "dead_read_server_tx.script" , 9005 );
175
- StubServer brokenReader2 = stubController .startStub ( "dead_read_server_tx.script" , 9006 );
176
-
177
- try ( Driver driver = newDriverWithFixedRetries ( "neo4j://127.0.0.1:9001" , 1 ); Session session = driver .session () )
178
- {
179
- AtomicInteger invocations = new AtomicInteger ();
180
- assertThrows ( SessionExpiredException .class , () -> session .readTransaction ( queryWork ( "MATCH (n) RETURN n.name" , invocations ) ) );
181
- assertEquals ( 2 , invocations .get () );
182
- }
183
- finally
184
- {
185
- assertEquals ( 0 , router .exitStatus () );
186
- assertEquals ( 0 , brokenReader1 .exitStatus () );
187
- assertEquals ( 0 , brokenReader2 .exitStatus () );
188
- }
189
- }
190
-
191
- // fixed retries are not currently supported in testkit
192
- @ Test
193
- void shouldRetryWriteTransactionUntilFailure () throws Exception
194
- {
195
- StubServer router = stubController .startStub ( "acquire_endpoints_v3.script" , 9001 );
196
- StubServer brokenWriter1 = stubController .startStub ( "dead_write_server.script" , 9007 );
197
- StubServer brokenWriter2 = stubController .startStub ( "dead_write_server.script" , 9008 );
198
-
199
- try ( Driver driver = newDriverWithFixedRetries ( "neo4j://127.0.0.1:9001" , 1 ); Session session = driver .session () )
200
- {
201
- AtomicInteger invocations = new AtomicInteger ();
202
- assertThrows ( SessionExpiredException .class , () -> session .writeTransaction ( queryWork ( "CREATE (n {name:'Bob'})" , invocations ) ) );
203
- assertEquals ( 2 , invocations .get () );
204
- }
205
- finally
206
- {
207
- assertEquals ( 0 , router .exitStatus () );
208
- assertEquals ( 0 , brokenWriter1 .exitStatus () );
209
- assertEquals ( 0 , brokenWriter2 .exitStatus () );
210
- }
211
- }
212
-
213
155
@ Test
214
156
void shouldFailInitialDiscoveryWhenConfiguredResolverThrows ()
215
157
{
@@ -223,65 +165,4 @@ void shouldFailInitialDiscoveryWhenConfiguredResolverThrows()
223
165
assertEquals ( "Resolution failure!" , error .getMessage () );
224
166
verify ( resolver ).resolve ( ServerAddress .of ( "my.server.com" , 9001 ) );
225
167
}
226
-
227
- // general error reporting and handling should be improved before this can be moved to testkit
228
- // also, backend closes socket on general errors and it negatively impacts testkit's teardown process
229
- @ Test
230
- void useSessionAfterDriverIsClosed () throws Exception
231
- {
232
- StubServer router = stubController .startStub ( "acquire_endpoints_v3.script" , 9001 );
233
- StubServer readServer = stubController .startStub ( "read_server_v3_read.script" , 9005 );
234
-
235
- try ( Driver driver = GraphDatabase .driver ( "neo4j://127.0.0.1:9001" , INSECURE_CONFIG ) )
236
- {
237
- try ( Session session = driver .session ( builder ().withDefaultAccessMode ( AccessMode .READ ).build () ) )
238
- {
239
- List <Record > records = session .run ( "MATCH (n) RETURN n.name" ).list ();
240
- assertEquals ( 3 , records .size () );
241
- }
242
-
243
- Session session = driver .session ( builder ().withDefaultAccessMode ( AccessMode .READ ).build () );
244
-
245
- driver .close ();
246
-
247
- assertThrows ( IllegalStateException .class , () -> session .run ( "MATCH (n) RETURN n.name" ) );
248
- }
249
- finally
250
- {
251
- assertEquals ( 0 , readServer .exitStatus () );
252
- assertEquals ( 0 , router .exitStatus () );
253
- }
254
- }
255
-
256
- private static Driver newDriverWithFixedRetries ( String uriString , int retries )
257
- {
258
- DriverFactory driverFactory = new DriverFactoryWithFixedRetryLogic ( retries );
259
- return newDriver ( uriString , driverFactory , INSECURE_CONFIG );
260
- }
261
-
262
- private static Driver newDriver ( String uriString , DriverFactory driverFactory , Config config )
263
- {
264
- URI uri = URI .create ( uriString );
265
- RoutingSettings routingConf = new RoutingSettings ( 1 , 1 , 0 , null );
266
- AuthToken auth = AuthTokens .none ();
267
- return driverFactory .newInstance ( uri , auth , routingConf , RetrySettings .DEFAULT , config , SecurityPlanImpl .insecure () );
268
- }
269
-
270
- private static TransactionWork <List <Record >> queryWork ( final String query , final AtomicInteger invocations )
271
- {
272
- return tx ->
273
- {
274
- invocations .incrementAndGet ();
275
- return tx .run ( query ).list ();
276
- };
277
- }
278
-
279
- static class PortBasedServerAddressComparator implements Comparator <ServerAddress >
280
- {
281
- @ Override
282
- public int compare ( ServerAddress a1 , ServerAddress a2 )
283
- {
284
- return Integer .compare ( a1 .port (), a2 .port () );
285
- }
286
- }
287
168
}
0 commit comments