35
35
36
36
import org .neo4j .driver .internal .cluster .RoutingSettings ;
37
37
import org .neo4j .driver .internal .retry .RetrySettings ;
38
- import org .neo4j .driver .internal .util .Clock ;
39
- import org .neo4j .driver .internal .util .ConnectionTrackingDriverFactory ;
40
38
import org .neo4j .driver .internal .util .FakeClock ;
41
39
import org .neo4j .driver .internal .util .ThrowingConnection ;
42
40
import org .neo4j .driver .internal .util .ThrowingConnectionDriverFactory ;
70
68
import static org .hamcrest .Matchers .instanceOf ;
71
69
import static org .hamcrest .Matchers .startsWith ;
72
70
import static org .junit .Assert .assertEquals ;
71
+ import static org .junit .Assert .assertFalse ;
73
72
import static org .junit .Assert .assertNotNull ;
74
73
import static org .junit .Assert .assertNull ;
75
74
import static org .junit .Assert .assertThat ;
@@ -236,7 +235,7 @@ public Void apply( Session session )
236
235
}
237
236
238
237
@ Test
239
- public void shouldDropBrokenOldSessions () throws Exception
238
+ public void shouldDropBrokenOldConnections () throws Exception
240
239
{
241
240
Cluster cluster = clusterRule .getCluster ();
242
241
@@ -249,19 +248,24 @@ public void shouldDropBrokenOldSessions() throws Exception
249
248
.toConfig ();
250
249
251
250
FakeClock clock = new FakeClock ();
252
- ConnectionTrackingDriverFactory driverFactory = new ConnectionTrackingDriverFactory ( clock );
251
+ ThrowingConnectionDriverFactory driverFactory = new ThrowingConnectionDriverFactory ( clock );
253
252
254
253
URI routingUri = cluster .leader ().getRoutingUri ();
255
254
AuthToken auth = clusterRule .getDefaultAuthToken ();
256
255
RetrySettings retrySettings = RetrySettings .DEFAULT ;
257
256
258
257
try ( Driver driver = driverFactory .newInstance ( routingUri , auth , defaultRoutingSettings (), retrySettings , config ) )
259
258
{
260
- // create nodes in different threads using different sessions
259
+ // create nodes in different threads using different sessions and connections
261
260
createNodesInDifferentThreads ( concurrentSessionsCount , driver );
262
261
263
- // now pool contains many sessions, make them all invalid
264
- driverFactory .closeConnections ();
262
+ // now pool contains many connections, make them all invalid
263
+ List <ThrowingConnection > oldConnections = driverFactory .pollConnections ();
264
+ for ( ThrowingConnection oldConnection : oldConnections )
265
+ {
266
+ oldConnection .setNextResetError ( new ServiceUnavailableException ( "Unable to reset" ) );
267
+ }
268
+
265
269
// move clock forward more than configured liveness check timeout
266
270
clock .progress ( MINUTES .toMillis ( livenessCheckTimeoutMinutes + 1 ) );
267
271
@@ -273,6 +277,12 @@ public void shouldDropBrokenOldSessions() throws Exception
273
277
assertEquals ( 1 , records .size () );
274
278
assertEquals ( concurrentSessionsCount , records .get ( 0 ).get ( 0 ).asInt () );
275
279
}
280
+
281
+ // all old connections failed to reset and should be closed
282
+ for ( ThrowingConnection connection : oldConnections )
283
+ {
284
+ assertFalse ( connection .isOpen () );
285
+ }
276
286
}
277
287
}
278
288
@@ -573,7 +583,7 @@ public void shouldRediscoverWhenConnectionsToAllCoresBreak()
573
583
// make all those connections throw and seem broken
574
584
for ( ThrowingConnection connection : driverFactory .getConnections () )
575
585
{
576
- connection .setNextRunFailure ( new ServiceUnavailableException ( "Disconnected" ) );
586
+ connection .setNextRunError ( new ServiceUnavailableException ( "Disconnected" ) );
577
587
}
578
588
579
589
// observe that connection towards writer is broken
@@ -620,7 +630,7 @@ public void shouldKeepOperatingWhenConnectionsBreak() throws Exception
620
630
String value = "Tony Stark" ;
621
631
Cluster cluster = clusterRule .getCluster ();
622
632
623
- ConnectionTrackingDriverFactory driverFactory = new ConnectionTrackingDriverFactory ( Clock . SYSTEM );
633
+ ThrowingConnectionDriverFactory driverFactory = new ThrowingConnectionDriverFactory ( );
624
634
AtomicBoolean stop = new AtomicBoolean ();
625
635
executor = newExecutor ();
626
636
@@ -639,11 +649,15 @@ public void shouldKeepOperatingWhenConnectionsBreak() throws Exception
639
649
results .add ( executor .submit ( createNodesCallable ( driver , label , property , value , stop ) ) );
640
650
}
641
651
642
- // terminate connections while reads and writes are in progress
652
+ // make connections throw while reads and writes are in progress
643
653
long deadline = System .currentTimeMillis () + MINUTES .toMillis ( 1 );
644
654
while ( System .currentTimeMillis () < deadline && !stop .get () )
645
655
{
646
- driverFactory .closeConnections ();
656
+ List <ThrowingConnection > connections = driverFactory .pollConnections ();
657
+ for ( ThrowingConnection connection : connections )
658
+ {
659
+ connection .setNextRunError ( new ServiceUnavailableException ( "Unable to execute query" ) );
660
+ }
647
661
SECONDS .sleep ( 5 ); // sleep a bit to allow readers and writers to progress
648
662
}
649
663
stop .set ( true );
@@ -676,7 +690,7 @@ private static void setupLastConnectionToThrow( ThrowingConnectionDriverFactory
676
690
{
677
691
List <ThrowingConnection > connections = factory .getConnections ();
678
692
ThrowingConnection lastConnection = connections .get ( connections .size () - 1 );
679
- lastConnection .setNextRunFailure ( error );
693
+ lastConnection .setNextRunError ( error );
680
694
}
681
695
682
696
private int executeWriteAndReadThroughBolt ( ClusterMember member ) throws TimeoutException , InterruptedException
0 commit comments