use of org.neo4j.causalclustering.identity.MemberId in project neo4j by neo4j.
the class RaftGroupMembershipTest method shouldRemoveLeaderAndAddItBackIn.
@Test
public void shouldRemoveLeaderAndAddItBackIn() throws Exception {
DirectNetworking net = new DirectNetworking();
// given
final MemberId leader1 = member(0);
final MemberId leader2 = member(1);
final MemberId stable1 = member(2);
final MemberId stable2 = member(3);
final MemberId[] allMembers = { leader1, leader2, stable1, stable2 };
final MemberId[] fewerMembers = { leader2, stable1, stable2 };
RaftTestFixture fixture = new RaftTestFixture(net, 3, allMembers);
fixture.bootstrap(allMembers);
// when
fixture.members().withId(leader1).timeoutService().invokeTimeout(ELECTION);
net.processMessages();
fixture.members().withId(leader1).raftInstance().setTargetMembershipSet(new RaftTestGroup(fewerMembers).getMembers());
net.processMessages();
fixture.members().withId(leader2).timeoutService().invokeTimeout(ELECTION);
net.processMessages();
fixture.members().withId(leader2).raftInstance().setTargetMembershipSet(new RaftTestGroup(allMembers).getMembers());
net.processMessages();
fixture.members().withId(leader2).timeoutService().invokeTimeout(HEARTBEAT);
net.processMessages();
// then
assertTrue(fixture.members().withId(leader2).raftInstance().isLeader());
assertThat(fixture.members().withIds(allMembers), hasCurrentMembers(new RaftTestGroup(allMembers)));
}
use of org.neo4j.causalclustering.identity.MemberId in project neo4j by neo4j.
the class RaftGroupMembershipTest method shouldRemoveFollowerAndAddItBackIn.
@Test
public void shouldRemoveFollowerAndAddItBackIn() throws Exception {
DirectNetworking net = new DirectNetworking();
// given
final MemberId leader = member(0);
final MemberId unstable = member(1);
final MemberId stable1 = member(2);
final MemberId stable2 = member(3);
final MemberId[] allMembers = { leader, unstable, stable1, stable2 };
final MemberId[] fewerMembers = { leader, stable1, stable2 };
RaftTestFixture fixture = new RaftTestFixture(net, 3, allMembers);
fixture.bootstrap(allMembers);
// when
fixture.members().withId(leader).timeoutService().invokeTimeout(ELECTION);
net.processMessages();
fixture.members().withId(leader).raftInstance().setTargetMembershipSet(new RaftTestGroup(fewerMembers).getMembers());
net.processMessages();
assertTrue(fixture.members().withId(leader).raftInstance().isLeader());
assertThat(fixture.members().withIds(fewerMembers), hasCurrentMembers(new RaftTestGroup(fewerMembers)));
fixture.members().withId(leader).raftInstance().setTargetMembershipSet(new RaftTestGroup(allMembers).getMembers());
net.processMessages();
fixture.members().withId(leader).timeoutService().invokeTimeout(HEARTBEAT);
net.processMessages();
// then
assertTrue(fixture.members().withId(leader).raftInstance().isLeader());
assertThat(fixture.members().withIds(allMembers), hasCurrentMembers(new RaftTestGroup(allMembers)));
}
use of org.neo4j.causalclustering.identity.MemberId in project neo4j by neo4j.
the class UpstreamDatabaseStrategySelectorTest method shouldUseSpecifiedStrategyInPreferenceToDefault.
@Test
public void shouldUseSpecifiedStrategyInPreferenceToDefault() throws Exception {
// given
TopologyService topologyService = mock(TopologyService.class);
MemberId memberId = new MemberId(UUID.randomUUID());
when(topologyService.coreServers()).thenReturn(new CoreTopology(new ClusterId(UUID.randomUUID()), false, mapOf(memberId, mock(CoreServerInfo.class))));
ConnectToRandomCoreServerStrategy shouldNotUse = new ConnectToRandomCoreServerStrategy();
UpstreamDatabaseSelectionStrategy mockStrategy = mock(UpstreamDatabaseSelectionStrategy.class);
when(mockStrategy.upstreamDatabase()).thenReturn(Optional.of(new MemberId(UUID.randomUUID())));
UpstreamDatabaseStrategySelector selector = new UpstreamDatabaseStrategySelector(shouldNotUse, iterable(mockStrategy), null, NullLogProvider.getInstance());
// when
selector.bestUpstreamDatabase();
// then
verify(mockStrategy, times(2)).upstreamDatabase();
}
use of org.neo4j.causalclustering.identity.MemberId in project neo4j by neo4j.
the class UserDefinedConfigurationStrategyTest method fakeReadReplicaTopology.
static ReadReplicaTopology fakeReadReplicaTopology(MemberId... readReplicaIds) {
assert readReplicaIds.length > 0;
Map<MemberId, ReadReplicaInfo> readReplicas = new HashMap<>();
int offset = 0;
for (MemberId memberId : readReplicaIds) {
readReplicas.put(memberId, new ReadReplicaInfo(new ClientConnectorAddresses(singletonList(new ClientConnectorAddresses.ConnectorUri(ClientConnectorAddresses.Scheme.bolt, new AdvertisedSocketAddress("localhost", 11000 + offset)))), new AdvertisedSocketAddress("localhost", 10000 + offset)));
offset++;
}
return new ReadReplicaTopology(readReplicas);
}
use of org.neo4j.causalclustering.identity.MemberId in project neo4j by neo4j.
the class UserDefinedConfigurationStrategyTest method shouldPickTheFirstMatchingServer.
@Test
public void shouldPickTheFirstMatchingServer() throws Exception {
// given
MemberId theCoreMemberId = new MemberId(UUID.randomUUID());
TopologyService topologyService = fakeTopologyService(fakeCoreTopology(theCoreMemberId), fakeReadReplicaTopology(memberIDs(100), new NoEastGroupGenerator()));
UserDefinedConfigurationStrategy strategy = new UserDefinedConfigurationStrategy();
Config config = Config.defaults().with(stringMap(CausalClusteringSettings.user_defined_upstream_selection_strategy.name(), "groups(east); groups(core); halt()"));
strategy.setConfig(config);
strategy.setTopologyService(topologyService);
//when
Optional<MemberId> memberId = strategy.upstreamDatabase();
// then
assertEquals(theCoreMemberId, memberId.get());
}
Aggregations