use of org.neo4j.causalclustering.discovery.TopologyService in project neo4j by neo4j.
the class UpstreamDatabaseStrategySelectorTest method shouldDefaultToRandomCoreServerIfNoOtherStrategySpecified.
@Test
public void shouldDefaultToRandomCoreServerIfNoOtherStrategySpecified() 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 defaultStrategy = new ConnectToRandomCoreServerStrategy();
defaultStrategy.setTopologyService(topologyService);
UpstreamDatabaseStrategySelector selector = new UpstreamDatabaseStrategySelector(defaultStrategy);
// when
MemberId instance = selector.bestUpstreamDatabase();
// then
assertEquals(memberId, instance);
}
use of org.neo4j.causalclustering.discovery.TopologyService 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.discovery.TopologyService 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());
}
use of org.neo4j.causalclustering.discovery.TopologyService in project neo4j by neo4j.
the class ConnectToRandomCoreServerStrategyTest method shouldConnectToRandomCoreServer.
@Test
public void shouldConnectToRandomCoreServer() throws Exception {
// given
MemberId memberId1 = new MemberId(UUID.randomUUID());
MemberId memberId2 = new MemberId(UUID.randomUUID());
MemberId memberId3 = new MemberId(UUID.randomUUID());
TopologyService topologyService = mock(TopologyService.class);
when(topologyService.coreServers()).thenReturn(fakeCoreTopology(memberId1, memberId2, memberId3));
ConnectToRandomCoreServerStrategy connectionStrategy = new ConnectToRandomCoreServerStrategy();
connectionStrategy.setTopologyService(topologyService);
// when
Optional<MemberId> memberId = connectionStrategy.upstreamDatabase();
// then
assertTrue(memberId.isPresent());
assertThat(memberId.get(), anyOf(equalTo(memberId1), equalTo(memberId2), equalTo(memberId3)));
}
use of org.neo4j.causalclustering.discovery.TopologyService in project neo4j by neo4j.
the class TypicallyConnectToRandomReadReplicaStrategyTest method shouldConnectToCoreOneInTenTimesByDefault.
@Test
public void shouldConnectToCoreOneInTenTimesByDefault() throws Exception {
// given
MemberId theCoreMemberId = new MemberId(UUID.randomUUID());
TopologyService topologyService = fakeTopologyService(fakeCoreTopology(theCoreMemberId), fakeReadReplicaTopology(memberIDs(100)));
TypicallyConnectToRandomReadReplicaStrategy connectionStrategy = new TypicallyConnectToRandomReadReplicaStrategy();
connectionStrategy.setTopologyService(topologyService);
List<MemberId> responses = new ArrayList<>();
// when
for (int i = 0; i < 10; i++) {
responses.add(connectionStrategy.upstreamDatabase().get());
}
// then
assertThat(responses, hasItem(theCoreMemberId));
}
Aggregations