2727
2828import  java .io .IOException ;
2929import  java .net .URI ;
30- import  java .util .Comparator ;
3130import  java .util .List ;
3231import  java .util .concurrent .TimeUnit ;
33- import  java .util .concurrent .atomic .AtomicInteger ;
3432
35- import  org .neo4j .driver .AccessMode ;
36- import  org .neo4j .driver .AuthToken ;
37- import  org .neo4j .driver .AuthTokens ;
3833import  org .neo4j .driver .Config ;
3934import  org .neo4j .driver .Driver ;
4035import  org .neo4j .driver .GraphDatabase ;
4136import  org .neo4j .driver .Record ;
42- import  org .neo4j .driver .Session ;
43- import  org .neo4j .driver .TransactionWork ;
4437import  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 ;
5138import  org .neo4j .driver .internal .util .Futures ;
5239import  org .neo4j .driver .net .ServerAddress ;
5340import  org .neo4j .driver .net .ServerAddressResolver ;
6653import  static  org .mockito .Mockito .verify ;
6754import  static  org .mockito .Mockito .when ;
6855import  static  org .neo4j .driver .SessionConfig .builder ;
69- import  static  org .neo4j .driver .util .StubServer .INSECURE_CONFIG ;
7056import  static  org .neo4j .driver .util .StubServer .insecureBuilder ;
7157
7258/** 
@@ -166,50 +152,6 @@ void shouldHandleLeaderSwitchAndRetryWhenWritingInTxFunctionRX() throws IOExcept
166152        assertThat ( writeServer .exitStatus (), equalTo ( 0  ) );
167153    }
168154
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- 
213155    @ Test 
214156    void  shouldFailInitialDiscoveryWhenConfiguredResolverThrows ()
215157    {
@@ -223,65 +165,4 @@ void shouldFailInitialDiscoveryWhenConfiguredResolverThrows()
223165        assertEquals ( "Resolution failure!" , error .getMessage () );
224166        verify ( resolver  ).resolve ( ServerAddress .of ( "my.server.com" , 9001  ) );
225167    }
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-     }
287168}
0 commit comments