Search in sources :

Example 1 with TopologyService

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);
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) ClusterId(org.neo4j.causalclustering.identity.ClusterId) CoreServerInfo(org.neo4j.causalclustering.discovery.CoreServerInfo) CoreTopology(org.neo4j.causalclustering.discovery.CoreTopology) TopologyService(org.neo4j.causalclustering.discovery.TopologyService) Test(org.junit.Test)

Example 2 with TopologyService

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();
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) ClusterId(org.neo4j.causalclustering.identity.ClusterId) CoreServerInfo(org.neo4j.causalclustering.discovery.CoreServerInfo) CoreTopology(org.neo4j.causalclustering.discovery.CoreTopology) TopologyService(org.neo4j.causalclustering.discovery.TopologyService) Test(org.junit.Test)

Example 3 with TopologyService

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());
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) Config(org.neo4j.kernel.configuration.Config) TopologyService(org.neo4j.causalclustering.discovery.TopologyService) Test(org.junit.Test)

Example 4 with TopologyService

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)));
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) TopologyService(org.neo4j.causalclustering.discovery.TopologyService) Test(org.junit.Test)

Example 5 with TopologyService

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));
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) ArrayList(java.util.ArrayList) TopologyService(org.neo4j.causalclustering.discovery.TopologyService) UserDefinedConfigurationStrategyTest.fakeTopologyService(org.neo4j.causalclustering.readreplica.UserDefinedConfigurationStrategyTest.fakeTopologyService) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 TopologyService (org.neo4j.causalclustering.discovery.TopologyService)5 MemberId (org.neo4j.causalclustering.identity.MemberId)5 CoreServerInfo (org.neo4j.causalclustering.discovery.CoreServerInfo)2 CoreTopology (org.neo4j.causalclustering.discovery.CoreTopology)2 ClusterId (org.neo4j.causalclustering.identity.ClusterId)2 ArrayList (java.util.ArrayList)1 UserDefinedConfigurationStrategyTest.fakeTopologyService (org.neo4j.causalclustering.readreplica.UserDefinedConfigurationStrategyTest.fakeTopologyService)1 Config (org.neo4j.kernel.configuration.Config)1