Skip to content

Commit

Permalink
Tests for CE/driver interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Needham committed Sep 30, 2016
1 parent 3f0a71e commit f5a2385
Show file tree
Hide file tree
Showing 8 changed files with 345 additions and 4 deletions.
Expand Up @@ -483,7 +483,7 @@ enum Cluster implements Status
NoLeaderAvailable( TransientError,
"No leader available at the moment. Retrying your request at a later time may succeed." ),

NotALeader( TransientError,
NotALeader( ClientError,
"The request cannot be processed by this server. Write requests can only be processed by the leader." ),
;

Expand Down
Expand Up @@ -147,6 +147,11 @@ private void initTimers()
} );
}

public void triggerElection() throws IOException
{
handle( new RaftMessages.Timeout.Election( myself ) );
}

public void stopTimers()
{
heartbeatTimer.cancel();
Expand Down
Expand Up @@ -542,4 +542,25 @@ public void startCoreMembers() throws ExecutionException, InterruptedException
executor.shutdown();
}
}

public ClusterMember getMemberByBoltAddress( AdvertisedSocketAddress advertisedSocketAddress )
{
for ( CoreClusterMember member : coreMembers.values() )
{
if ( member.boltAdvertisedAddress().equals( advertisedSocketAddress.toString() ) )
{
return member;
}
}

for ( EdgeClusterMember member : edgeMembers.values() )
{
if ( member.boltAdvertisedAddress().equals( advertisedSocketAddress.toString() ) )
{
return member;
}
}

throw new RuntimeException( "Could not find a member for bolt address " + advertisedSocketAddress );
}
}
Expand Up @@ -50,6 +50,7 @@ public class CoreClusterMember implements ClusterMember
private final File storeDir;
private final Map<String, String> config = stringMap();
private final int serverId;
private final String boltAdvertisedAddress;
private CoreGraphDatabase database;

public CoreClusterMember( int serverId, int clusterSize,
Expand Down Expand Up @@ -80,7 +81,9 @@ public CoreClusterMember( int serverId, int clusterSize,
config.put( new GraphDatabaseSettings.BoltConnector( "bolt" ).type.name(), "BOLT" );
config.put( new GraphDatabaseSettings.BoltConnector( "bolt" ).enabled.name(), "true" );
config.put( new GraphDatabaseSettings.BoltConnector( "bolt" ).address.name(), "0.0.0.0:" + boltPort );
config.put( new GraphDatabaseSettings.BoltConnector( "bolt" ).advertised_address.name(), "127.0.0.1:" + boltPort );
config.put( new GraphDatabaseSettings.BoltConnector( "bolt" ).listen_address.name(), "127.0.0.1:" + boltPort );
boltAdvertisedAddress = "127.0.0.1:" + boltPort;
config.put( new GraphDatabaseSettings.BoltConnector( "bolt" ).advertised_address.name(), boltAdvertisedAddress );
config.put( GraphDatabaseSettings.pagecache_memory.name(), "8m" );
config.put( GraphDatabaseSettings.auth_store.name(), new File( parentDir, "auth" ).getAbsolutePath() );
config.putAll( extraParams );
Expand All @@ -98,6 +101,16 @@ public CoreClusterMember( int serverId, int clusterSize,
storeDir.mkdirs();
}

public String boltAdvertisedAddress()
{
return boltAdvertisedAddress;
}

public String routingAddress()
{
return String.format( "bolt+routing://%s", boltAdvertisedAddress );
}

@Override
public void start()
{
Expand Down Expand Up @@ -131,6 +144,11 @@ public CoreState coreState()
return database.getDependencyResolver().resolveDependency( CoreState.class );
}

public RaftMachine raft()
{
return database.getDependencyResolver().resolveDependency( RaftMachine.class );
}

public MemberId id()
{
return database.getDependencyResolver().resolveDependency( RaftMachine.class ).identity();
Expand Down
Expand Up @@ -41,6 +41,7 @@ public class EdgeClusterMember implements ClusterMember
private final DiscoveryServiceFactory discoveryServiceFactory;
private final File storeDir;
private final int memberId;
private final String boltAdvertisedAddress;
private EdgeGraphDatabase database;

public EdgeClusterMember( File parentDir, int memberId, DiscoveryServiceFactory discoveryServiceFactory,
Expand All @@ -67,7 +68,8 @@ public EdgeClusterMember( File parentDir, int memberId, DiscoveryServiceFactory
config.put( new GraphDatabaseSettings.BoltConnector( "bolt" ).type.name(), "BOLT" );
config.put( new GraphDatabaseSettings.BoltConnector( "bolt" ).enabled.name(), "true" );
config.put( new GraphDatabaseSettings.BoltConnector( "bolt" ).address.name(), "0.0.0.0:" + (9000 + memberId) );
config.put( new GraphDatabaseSettings.BoltConnector( "bolt" ).advertised_address.name(), "127.0.0.1:" + (9000 + memberId) );
boltAdvertisedAddress = "127.0.0.1:" + (9000 + memberId);
config.put( new GraphDatabaseSettings.BoltConnector( "bolt" ).advertised_address.name(), boltAdvertisedAddress );

File neo4jHome = new File( parentDir, "server-edge-" + memberId );
config.put( GraphDatabaseSettings.logs_directory.name(), new File( neo4jHome, "logs" ).getAbsolutePath() );
Expand All @@ -77,7 +79,18 @@ public EdgeClusterMember( File parentDir, int memberId, DiscoveryServiceFactory
storeDir.mkdirs();
}

public String boltAdvertisedAddress()
{
return boltAdvertisedAddress;
}

public String routingAddress()
{
return String.format( "bolt+routing://%s", boltAdvertisedAddress );
}

@Override

public void start()
{
database = new EdgeGraphDatabase( storeDir, config,
Expand Down
7 changes: 7 additions & 0 deletions integrationtests/pom.xml
Expand Up @@ -129,6 +129,13 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-core-edge</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ha</artifactId>
Expand Down

0 comments on commit f5a2385

Please sign in to comment.