Skip to content

Commit 8dad6c4

Browse files
authored
Merge pull request #576 from PetrJanouch/2.0_shutdown_speedup
Speeding up the shutdown of the driver.
2 parents 1ad4543 + f3312f9 commit 8dad6c4

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

driver/src/main/java/org/neo4j/driver/internal/async/pool/ConnectionPoolImpl.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.concurrent.CompletionStage;
3131
import java.util.concurrent.ConcurrentHashMap;
3232
import java.util.concurrent.ConcurrentMap;
33+
import java.util.concurrent.TimeUnit;
3334
import java.util.concurrent.TimeoutException;
3435
import java.util.concurrent.atomic.AtomicBoolean;
3536

@@ -165,7 +166,10 @@ public CompletionStage<Void> close()
165166
}
166167
finally
167168
{
168-
eventLoopGroup().shutdownGracefully();
169+
// This is an attempt to speed up the shut down procedure of the driver
170+
// Feel free return this back to shutdownGracefully() method with default values
171+
// if this proves troublesome!!!
172+
eventLoopGroup().shutdownGracefully(200, 15_000, TimeUnit.MILLISECONDS);
169173
}
170174
}
171175
return Futures.asCompletionStage( eventLoopGroup().terminationFuture() )

examples/src/test/java/org/neo4j/docs/driver/ExamplesIT.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import static java.nio.charset.StandardCharsets.UTF_8;
4848
import static java.util.Arrays.asList;
4949
import static org.hamcrest.Matchers.containsString;
50+
import static org.hamcrest.Matchers.emptyString;
5051
import static org.hamcrest.Matchers.equalTo;
5152
import static org.hamcrest.Matchers.greaterThan;
5253
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
@@ -462,20 +463,29 @@ void testSlf4jLogging() throws Exception
462463
{
463464
// log file is defined in logback-test.xml configuration file
464465
Path logFile = Paths.get( "target", "test.log" );
465-
Files.deleteIfExists( logFile );
466+
if ( Files.exists( logFile ) )
467+
{
468+
// delete file made this test flaky
469+
// erase content instead
470+
Files.write( logFile, new byte[0] );
471+
}
472+
473+
// verify erased
474+
String logFileContent = new String( Files.readAllBytes( logFile ), UTF_8 );
475+
assertThat( logFileContent, is( emptyString() ) );
466476

477+
String randomString = UUID.randomUUID().toString();
467478
try ( Slf4jLoggingExample example = new Slf4jLoggingExample( uri, USER, PASSWORD ) )
468479
{
469-
String randomString = UUID.randomUUID().toString();
470480
Object result = example.runReturnQuery( randomString );
471481
assertEquals( randomString, result );
482+
}
483+
assertTrue( Files.exists( logFile ) );
472484

473-
assertTrue( Files.exists( logFile ) );
485+
logFileContent = new String( Files.readAllBytes( logFile ), UTF_8 );
486+
assertThat( logFileContent, containsString( "RETURN $x" ) );
487+
assertThat( logFileContent, containsString( randomString ) );
474488

475-
String logFileContent = new String( Files.readAllBytes( logFile ), UTF_8 );
476-
assertThat( logFileContent, containsString( "RETURN $x" ) );
477-
assertThat( logFileContent, containsString( randomString ) );
478-
}
479489
}
480490

481491
@Test

0 commit comments

Comments
 (0)