Skip to content

Commit c274976

Browse files
committed
Use stub server instead of an actual cluster
1 parent 9a8d9ec commit c274976

File tree

4 files changed

+39
-15
lines changed

4 files changed

+39
-15
lines changed

examples/src/main/java/org/neo4j/docs/driver/ConfigCustomResolverExample.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ public class ConfigCustomResolverExample implements AutoCloseable
3636
{
3737
private final Driver driver;
3838

39-
public ConfigCustomResolverExample( String virtualUri, String user, String password, ServerAddress[] addresses )
39+
public ConfigCustomResolverExample( String virtualUri, ServerAddress... addresses )
4040
{
41-
driver = createDriver( virtualUri, user, password, addresses );
41+
driver = GraphDatabase.driver( virtualUri, AuthTokens.none(),
42+
Config.build().withoutEncryption().withResolver( address -> new HashSet<>( Arrays.asList( addresses ) ) ).toConfig() );
43+
4244
}
4345

4446
// tag::config-custom-resolver[]
@@ -72,7 +74,7 @@ public void close() throws Exception
7274

7375
public boolean canConnect()
7476
{
75-
StatementResult result = driver.session().run( "RETURN 1" );
77+
StatementResult result = driver.session( AccessMode.READ ).run( "RETURN 1" );
7678
return result.single().get( 0 ).asInt() == 1;
7779
}
7880
}

examples/src/test/java/org/neo4j/docs/driver/ExamplesClusterIT.java renamed to examples/src/test/java/org/neo4j/docs/driver/ExamplesStubIT.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,31 @@
1919
package org.neo4j.docs.driver;
2020

2121
import org.junit.jupiter.api.Test;
22-
import org.junit.jupiter.api.extension.RegisterExtension;
2322

2423
import org.neo4j.driver.v1.net.ServerAddress;
25-
import org.neo4j.driver.v1.util.cc.Cluster;
26-
import org.neo4j.driver.v1.util.cc.ClusterExtension;
24+
import org.neo4j.driver.v1.util.StubServer;
2725

26+
import static org.junit.jupiter.api.Assertions.assertEquals;
2827
import static org.junit.jupiter.api.Assertions.assertTrue;
29-
import static org.neo4j.driver.v1.util.Neo4jRunner.PASSWORD;
30-
import static org.neo4j.driver.v1.util.Neo4jRunner.USER;
3128

32-
class ExamplesClusterIT
29+
public class ExamplesStubIT
3330
{
34-
@RegisterExtension
35-
static final ClusterExtension neo4j = new ClusterExtension();
36-
3731
@Test
3832
void testShouldRunConfigCustomResolverExample() throws Exception
3933
{
40-
Cluster cluster = neo4j.getCluster();
34+
StubServer server1 = StubServer.start( "get_routing_table_only.script", 9001 );
35+
StubServer server2 = StubServer.start( "return_1.script", 9002 );
4136

4237
// Given
43-
try ( ConfigCustomResolverExample example = new ConfigCustomResolverExample( "bolt+routing://x.acme.com", USER, PASSWORD,
44-
cluster.cores().stream().map( c -> c.getBoltAddress() ).toArray( i -> new ServerAddress[i] ) ) )
38+
try ( ConfigCustomResolverExample example = new ConfigCustomResolverExample( "bolt+routing://x.acme.com", ServerAddress.of( "localhost", 9001 ) ) )
4539
{
4640
// Then
4741
assertTrue( example.canConnect() );
4842
}
43+
finally
44+
{
45+
assertEquals( 0, server1.exitStatus() );
46+
assertEquals( 0, server2.exitStatus() );
47+
}
4948
}
5049
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
!: AUTO INIT
2+
!: AUTO RESET
3+
!: AUTO PULL_ALL
4+
5+
S: SUCCESS {"server": "Neo4j/3.2.2"}
6+
C: RUN "CALL dbms.cluster.routing.getRoutingTable({context})" {"context": {}}
7+
PULL_ALL
8+
S: SUCCESS {"fields": ["ttl", "servers"]}
9+
RECORD [9223372036854775807, [{"addresses": ["127.0.0.1:9001"],"role": "WRITE"}, {"addresses": ["127.0.0.1:9002"], "role": "READ"},{"addresses": ["127.0.0.1:9001"], "role": "ROUTE"}]]
10+
SUCCESS {}
11+
S: <EXIT>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
!: AUTO INIT
2+
!: AUTO RESET
3+
!: AUTO PULL_ALL
4+
!: AUTO RUN "COMMIT" {}
5+
!: AUTO RUN "ROLLBACK" {}
6+
!: AUTO RUN "BEGIN" {}
7+
8+
C: RUN "RETURN 1" {}
9+
PULL_ALL
10+
S: SUCCESS {"fields": ["1"]}
11+
RECORD [1]
12+
SUCCESS {}

0 commit comments

Comments
 (0)