use of org.neo4j.causalclustering.core.consensus.LeaderLocator in project neo4j by neo4j.
the class GetServersProcedureV1Test method shouldReturnTheCoreLeaderForWriteAndReadReplicasAndCoresForReads.
@Test
public void shouldReturnTheCoreLeaderForWriteAndReadReplicasAndCoresForReads() throws Exception {
// given
final CoreTopologyService topologyService = mock(CoreTopologyService.class);
Map<MemberId, CoreServerInfo> coreMembers = new HashMap<>();
MemberId theLeader = member(0);
coreMembers.put(theLeader, adressesForCore(0));
when(topologyService.coreServers()).thenReturn(new CoreTopology(clusterId, false, coreMembers));
when(topologyService.readReplicas()).thenReturn(new ReadReplicaTopology(readReplicaInfoMap(1)));
LeaderLocator leaderLocator = mock(LeaderLocator.class);
when(leaderLocator.getLeader()).thenReturn(theLeader);
LegacyGetServersProcedure procedure = new LegacyGetServersProcedure(topologyService, leaderLocator, config, getInstance());
// when
ClusterView clusterView = run(procedure);
// then
ClusterView.Builder builder = new ClusterView.Builder();
builder.writeAddress(adressesForCore(0).connectors().boltAddress());
if (expectFollowersAsReadEndPoints) {
builder.readAddress(adressesForCore(0).connectors().boltAddress());
}
builder.readAddress(addressesForReadReplica(1).connectors().boltAddress());
builder.routeAddress(adressesForCore(0).connectors().boltAddress());
assertEquals(builder.build(), clusterView);
}
use of org.neo4j.causalclustering.core.consensus.LeaderLocator in project neo4j by neo4j.
the class GetServersProcedureV1Test method shouldReturnCoreMemberAsReadServerIfNoReadReplicasAvailable.
@Test
public void shouldReturnCoreMemberAsReadServerIfNoReadReplicasAvailable() throws Exception {
// given
final CoreTopologyService topologyService = mock(CoreTopologyService.class);
Map<MemberId, CoreServerInfo> coreMembers = new HashMap<>();
MemberId theLeader = member(0);
coreMembers.put(theLeader, adressesForCore(0));
when(topologyService.coreServers()).thenReturn(new CoreTopology(clusterId, false, coreMembers));
when(topologyService.readReplicas()).thenReturn(new ReadReplicaTopology(emptyMap()));
LeaderLocator leaderLocator = mock(LeaderLocator.class);
when(leaderLocator.getLeader()).thenReturn(theLeader);
LegacyGetServersProcedure procedure = new LegacyGetServersProcedure(topologyService, leaderLocator, config, getInstance());
// when
ClusterView clusterView = run(procedure);
// then
ClusterView.Builder builder = new ClusterView.Builder();
builder.writeAddress(adressesForCore(0).connectors().boltAddress());
builder.readAddress(adressesForCore(0).connectors().boltAddress());
builder.routeAddress(adressesForCore(0).connectors().boltAddress());
assertEquals(builder.build(), clusterView);
}
Aggregations