Search in sources :

Example 16 with MemberId

use of org.neo4j.causalclustering.identity.MemberId in project neo4j by neo4j.

the class ReadReplicaTopologyTest method shouldDetectRemovedMembers.

@Test
public void shouldDetectRemovedMembers() throws Exception {
    // given
    UUID one = UUID.randomUUID();
    UUID two = UUID.randomUUID();
    Map<MemberId, ReadReplicaInfo> initialMembers = new HashMap<>();
    initialMembers.put(new MemberId(one), mock(ReadReplicaInfo.class));
    initialMembers.put(new MemberId(two), mock(ReadReplicaInfo.class));
    Map<MemberId, ReadReplicaInfo> newMembers = new HashMap<>();
    newMembers.put(new MemberId(two), mock(ReadReplicaInfo.class));
    ReadReplicaTopology topology = new ReadReplicaTopology(initialMembers);
    // when
    TopologyDifference diff = topology.difference(new ReadReplicaTopology(newMembers));
    // then
    assertThat(diff.added().size(), Matchers.equalTo(0));
    assertThat(diff.removed().size(), Matchers.equalTo(1));
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) HashMap(java.util.HashMap) UUID(java.util.UUID) Test(org.junit.Test)

Example 17 with MemberId

use of org.neo4j.causalclustering.identity.MemberId in project neo4j by neo4j.

the class ReadReplicaTopologyTest method shouldDetectAddedAndRemovedMembers.

@Test
public void shouldDetectAddedAndRemovedMembers() throws Exception {
    // given
    Map<MemberId, ReadReplicaInfo> initialMembers = new HashMap<>();
    initialMembers.put(new MemberId(UUID.randomUUID()), mock(ReadReplicaInfo.class));
    initialMembers.put(new MemberId(UUID.randomUUID()), mock(ReadReplicaInfo.class));
    Map<MemberId, ReadReplicaInfo> newMembers = new HashMap<>();
    newMembers.put(new MemberId(UUID.randomUUID()), mock(ReadReplicaInfo.class));
    newMembers.put(new MemberId(UUID.randomUUID()), mock(ReadReplicaInfo.class));
    ReadReplicaTopology topology = new ReadReplicaTopology(initialMembers);
    // when
    TopologyDifference diff = topology.difference(new ReadReplicaTopology(newMembers));
    // then
    assertThat(diff.added().size(), Matchers.equalTo(2));
    assertThat(diff.removed().size(), Matchers.equalTo(2));
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 18 with MemberId

use of org.neo4j.causalclustering.identity.MemberId in project neo4j by neo4j.

the class ReadReplicaTopologyTest method shouldDetectAddedMembers.

@Test
public void shouldDetectAddedMembers() throws Exception {
    // given
    UUID one = UUID.randomUUID();
    UUID two = UUID.randomUUID();
    Map<MemberId, ReadReplicaInfo> initialMembers = new HashMap<>();
    initialMembers.put(new MemberId(one), mock(ReadReplicaInfo.class));
    initialMembers.put(new MemberId(two), mock(ReadReplicaInfo.class));
    Map<MemberId, ReadReplicaInfo> newMembers = new HashMap<>();
    newMembers.put(new MemberId(one), mock(ReadReplicaInfo.class));
    newMembers.put(new MemberId(two), mock(ReadReplicaInfo.class));
    newMembers.put(new MemberId(UUID.randomUUID()), mock(ReadReplicaInfo.class));
    ReadReplicaTopology topology = new ReadReplicaTopology(initialMembers);
    // when
    TopologyDifference diff = topology.difference(new ReadReplicaTopology(newMembers));
    // then
    assertThat(diff.added().size(), Matchers.equalTo(1));
    assertThat(diff.removed().size(), Matchers.equalTo(0));
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) HashMap(java.util.HashMap) UUID(java.util.UUID) Test(org.junit.Test)

Example 19 with MemberId

use of org.neo4j.causalclustering.identity.MemberId in project neo4j by neo4j.

the class ReadReplicaTopologyTest method identicalTopologiesShouldHaveNoDifference.

@Test
public void identicalTopologiesShouldHaveNoDifference() throws Exception {
    // given
    UUID one = UUID.randomUUID();
    UUID two = UUID.randomUUID();
    Map<MemberId, ReadReplicaInfo> readReplicaMembers = new HashMap<>();
    readReplicaMembers.put(new MemberId(one), mock(ReadReplicaInfo.class));
    readReplicaMembers.put(new MemberId(two), mock(ReadReplicaInfo.class));
    ReadReplicaTopology topology = new ReadReplicaTopology(readReplicaMembers);
    // when
    TopologyDifference diff = topology.difference(topology);
    // then
    assertThat(diff.added().size(), Matchers.equalTo(0));
    assertThat(diff.removed().size(), Matchers.equalTo(0));
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) HashMap(java.util.HashMap) UUID(java.util.UUID) Test(org.junit.Test)

Example 20 with MemberId

use of org.neo4j.causalclustering.identity.MemberId in project neo4j by neo4j.

the class CatchupPollingProcess method pullTransactions.

private void pullTransactions() {
    MemberId upstream;
    try {
        upstream = selectionStrategyPipeline.bestUpstreamDatabase();
    } catch (UpstreamDatabaseSelectionException e) {
        log.warn("Could not find upstream database from which to pull.", e);
        return;
    }
    StoreId localStoreId = localDatabase.storeId();
    boolean moreToPull = true;
    int batchCount = 1;
    while (moreToPull) {
        moreToPull = pullAndApplyBatchOfTransactions(upstream, localStoreId, batchCount);
        batchCount++;
    }
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) StoreId(org.neo4j.causalclustering.identity.StoreId) UpstreamDatabaseSelectionException(org.neo4j.causalclustering.readreplica.UpstreamDatabaseSelectionException)

Aggregations

MemberId (org.neo4j.causalclustering.identity.MemberId)114 Test (org.junit.Test)83 HashMap (java.util.HashMap)26 CoreTopology (org.neo4j.causalclustering.discovery.CoreTopology)16 CoreServerInfo (org.neo4j.causalclustering.discovery.CoreServerInfo)15 LeaderLocator (org.neo4j.causalclustering.core.consensus.LeaderLocator)13 ReadReplicaTopology (org.neo4j.causalclustering.discovery.ReadReplicaTopology)12 DirectNetworking (org.neo4j.causalclustering.core.consensus.DirectNetworking)10 RaftTestFixture (org.neo4j.causalclustering.core.consensus.RaftTestFixture)10 CoreTopologyService (org.neo4j.causalclustering.discovery.CoreTopologyService)10 Log (org.neo4j.logging.Log)10 ClusterId (org.neo4j.causalclustering.identity.ClusterId)9 ArrayList (java.util.ArrayList)8 UUID (java.util.UUID)8 RaftMessages (org.neo4j.causalclustering.core.consensus.RaftMessages)8 TopologyService (org.neo4j.causalclustering.discovery.TopologyService)7 ByteBuf (io.netty.buffer.ByteBuf)6 File (java.io.File)6 RaftLogEntry (org.neo4j.causalclustering.core.consensus.log.RaftLogEntry)6 HashSet (java.util.HashSet)5