31
31
import java .util .concurrent .CountDownLatch ;
32
32
import java .util .concurrent .ExecutionException ;
33
33
import java .util .concurrent .ExecutorService ;
34
+ import java .util .concurrent .Executors ;
34
35
import java .util .concurrent .Future ;
35
36
import java .util .concurrent .TimeUnit ;
36
37
import java .util .concurrent .atomic .AtomicInteger ;
62
63
import org .neo4j .driver .v1 .util .TestNeo4j ;
63
64
64
65
import static java .lang .String .format ;
65
- import static java .util .concurrent .Executors .newSingleThreadExecutor ;
66
66
import static org .hamcrest .CoreMatchers .containsString ;
67
67
import static org .hamcrest .CoreMatchers .equalTo ;
68
68
import static org .hamcrest .CoreMatchers .instanceOf ;
@@ -98,6 +98,7 @@ public class SessionIT
98
98
public ExpectedException exception = ExpectedException .none ();
99
99
100
100
private Driver driver ;
101
+ private ExecutorService executor ;
101
102
102
103
@ After
103
104
public void tearDown ()
@@ -106,6 +107,10 @@ public void tearDown()
106
107
{
107
108
driver .close ();
108
109
}
110
+ if ( executor != null )
111
+ {
112
+ executor .shutdownNow ();
113
+ }
109
114
}
110
115
111
116
@ Test
@@ -1451,9 +1456,12 @@ private static void assertDeadlockDetectedError( ExecutionException e )
1451
1456
assertEquals ( "Neo.TransientError.Transaction.DeadlockDetected" , errorCode );
1452
1457
}
1453
1458
1454
- private static <T > Future <T > executeInDifferentThread ( Callable <T > callable )
1459
+ private <T > Future <T > executeInDifferentThread ( Callable <T > callable )
1455
1460
{
1456
- ExecutorService executor = newSingleThreadExecutor ( daemon ( "test-thread-" ) );
1461
+ if ( executor == null )
1462
+ {
1463
+ executor = Executors .newCachedThreadPool ( daemon ( getClass ().getSimpleName () + "-thread-" ) );
1464
+ }
1457
1465
return executor .submit ( callable );
1458
1466
}
1459
1467
@@ -1470,7 +1478,7 @@ private static void await( CountDownLatch latch )
1470
1478
}
1471
1479
}
1472
1480
1473
- private static abstract class NodeIdUpdater
1481
+ private abstract class NodeIdUpdater
1474
1482
{
1475
1483
final Future <Void > update ( final Driver driver , final int nodeId , final int newNodeId ,
1476
1484
final AtomicReference <Session > usedSessionRef , final CountDownLatch latchToWait )
0 commit comments