Skip to content

Commit afbd706

Browse files
committed
Remove unused methods from Neo4jRunner
Add guard against running when another Neo4j instance is running. The Neo4jRunner contained a lot of functionality that was not used, with four separate code paths for starting Neo4j, which made it somewhat complex to reason about how to prevent starting Neo4j over an existing instance. This removes those unused code paths and consolidates API usage to one main start path.
1 parent d1b4737 commit afbd706

File tree

9 files changed

+111
-237
lines changed

9 files changed

+111
-237
lines changed

driver/src/main/java/org/neo4j/driver/internal/pool/InternalConnectionPool.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,22 @@ public class InternalConnectionPool implements ConnectionPool
6565
*/
6666
private final ValidationStrategy<PooledConnection> connectionValidation;
6767

68+
/**
69+
* Timeout in milliseconds if there are no available sessions.
70+
*/
71+
private final long acquireSessionTimeout;
72+
6873
private final Clock clock;
6974
private final Config config;
7075

7176
public InternalConnectionPool( Config config )
7277
{
73-
this( loadConnectors(), Clock.SYSTEM, config );
78+
this( loadConnectors(), Clock.SYSTEM, config, Long.getLong( "neo4j.driver.acquireSessionTimeout", 30_000 ) );
7479
}
7580

76-
public InternalConnectionPool( Collection<Connector> conns, Clock clock, Config config )
81+
public InternalConnectionPool( Collection<Connector> conns, Clock clock, Config config, long acquireTimeout )
7782
{
83+
this.acquireSessionTimeout = acquireTimeout;
7884
this.config = config;
7985
this.clock = clock;
8086
this.connectionValidation = new PooledConnectionValidator( config.idleTimeBeforeConnectionTest() );
@@ -92,7 +98,7 @@ public Connection acquire( URI sessionURI )
9298
{
9399
try
94100
{
95-
Connection conn = pool( sessionURI ).acquire( 30, TimeUnit.SECONDS );
101+
Connection conn = pool( sessionURI ).acquire( acquireSessionTimeout, TimeUnit.MILLISECONDS );
96102
if( conn == null )
97103
{
98104
throw new ClientException(

driver/src/test/java/org/neo4j/driver/internal/pool/InternalConnectionPoolTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void shouldThrowExceptionWhenConnectionPoolIsFull() throws Throwable
5353
Connector connector = connector( "bolt" );
5454
Config config = Config.build().withConnectionPoolSize( 1 ).toConfig();
5555
InternalConnectionPool pool = new InternalConnectionPool( singletonList( connector ),
56-
Clock.SYSTEM, config );
56+
Clock.SYSTEM, config, 100 );
5757

5858
// When & Then
5959
pool.acquire( uri );
@@ -74,7 +74,7 @@ public void shouldAcquireAndRelease() throws Throwable
7474
Connector connector = connector( "bolt" );
7575
Config config = Config.defaultConfig();
7676
InternalConnectionPool pool = new InternalConnectionPool( singletonList( connector ),
77-
Clock.SYSTEM, config );
77+
Clock.SYSTEM, config, 100 );
7878

7979
Connection conn = pool.acquire( uri );
8080
conn.close();

driver/src/test/java/org/neo4j/driver/v1/integration/ConnectionPoolIT.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
*/
1919
package org.neo4j.driver.v1.integration;
2020

21-
import java.util.LinkedList;
22-
import java.util.concurrent.CountDownLatch;
23-
import java.util.concurrent.TimeUnit;
24-
2521
import org.junit.After;
2622
import org.junit.Rule;
2723
import org.junit.Test;
2824

25+
import java.util.LinkedList;
26+
import java.util.concurrent.CountDownLatch;
27+
import java.util.concurrent.TimeUnit;
28+
2929
import org.neo4j.driver.v1.Driver;
3030
import org.neo4j.driver.v1.GraphDatabase;
3131
import org.neo4j.driver.v1.Session;
@@ -53,7 +53,7 @@ public void shouldRecoverFromDownedServer() throws Throwable
5353
sessionGrabber.start();
5454

5555
// When
56-
neo4j.restartServerOnEmptyDatabase();
56+
neo4j.restart();
5757

5858
// Then we accept a hump with failing sessions, but demand that failures stop as soon as the server is back up.
5959
sessionGrabber.assertSessionsAvailableWithin( 60 );

driver/src/test/java/org/neo4j/driver/v1/integration/SSLSocketChannelIT.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import org.neo4j.driver.v1.ResultCursor;
4545
import org.neo4j.driver.v1.util.CertificateToolTest;
4646
import org.neo4j.driver.v1.util.Neo4jRunner;
47-
import org.neo4j.driver.v1.util.Neo4jSettings;
4847
import org.neo4j.driver.v1.util.TestNeo4j;
4948

5049
import static org.junit.Assert.assertEquals;
@@ -59,7 +58,7 @@
5958
public class SSLSocketChannelIT
6059
{
6160
@Rule
62-
public TestNeo4j neo4j = new TestNeo4j( Neo4jSettings.DEFAULT.usingTLS( true ) );
61+
public TestNeo4j neo4j = new TestNeo4j();
6362

6463
@Test
6564
public void shouldPerformTLSHandshakeWithEmptyKnownCertsFile() throws Throwable

driver/src/test/java/org/neo4j/driver/v1/integration/ServerKilledIT.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@
2121
import org.junit.Rule;
2222
import org.junit.Test;
2323

24-
import org.neo4j.driver.v1.GraphDatabase;
2524
import org.neo4j.driver.v1.Driver;
25+
import org.neo4j.driver.v1.GraphDatabase;
2626
import org.neo4j.driver.v1.Session;
2727
import org.neo4j.driver.v1.exceptions.ClientException;
2828
import org.neo4j.driver.v1.util.Neo4jRunner;
2929
import org.neo4j.driver.v1.util.TestNeo4j;
3030

3131
import static org.junit.Assert.fail;
32-
import static org.junit.Assume.assumeTrue;
3332

3433
/**
3534
* Mainly concerned about the connection pool - we want to make sure that bad connections are evacuated from the
@@ -44,9 +43,6 @@ public class ServerKilledIT
4443
public void shouldRecoverFromServerRestart() throws Throwable
4544
{
4645
// Given
47-
assumeTrue( neo4j.canControlServer() );
48-
49-
// And given we've spun up a few running sessions
5046
try ( Driver driver = GraphDatabase.driver( Neo4jRunner.DEFAULT_URL ) )
5147
{
5248
Session s1 = driver.session();
@@ -61,7 +57,7 @@ public void shouldRecoverFromServerRestart() throws Throwable
6157
s4.close();
6258

6359
// When
64-
neo4j.restartServerOnEmptyDatabase();
60+
neo4j.restart();
6561

6662
// Then we should be able to start using sessions again, at most O(numSessions) session calls later
6763
// TODO: These should value evicted immediately, not show up as application-loggingLevel errors first

driver/src/test/java/org/neo4j/driver/v1/stress/DriverStresser.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.neo4j.driver.v1.Session;
3434
import org.neo4j.driver.v1.Value;
3535
import org.neo4j.driver.v1.util.Neo4jRunner;
36+
import org.neo4j.driver.v1.util.Neo4jSettings;
3637

3738
import static org.neo4j.driver.v1.Values.parameters;
3839

@@ -57,7 +58,7 @@ public static void main( String... args ) throws Throwable
5758
public static void setup() throws Exception
5859
{
5960
server = Neo4jRunner.getOrCreateGlobalRunner();
60-
server.startServerOnEmptyDatabase();
61+
server.ensureRunning( Neo4jSettings.DEFAULT );
6162
driver = GraphDatabase.driver( "bolt://localhost" );
6263
}
6364

@@ -88,7 +89,7 @@ public int operation()
8889
public static void tearDown() throws Exception
8990
{
9091
driver.close();
91-
server.stopServerIfRunning();
92+
server.stop();
9293
}
9394

9495

0 commit comments

Comments
 (0)