Search in sources :

Example 96 with MemberId

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

the class SimpleStorageTest method shouldWriteAndReadState.

@Test
public void shouldWriteAndReadState() throws Exception {
    // given
    SimpleStorage<MemberId> storage = new SimpleFileStorage<>(fsa.get(), new File("state-dir"), "member-id-a", new MemberId.Marshal(), NullLogProvider.getInstance());
    // when
    MemberId idA = new MemberId(UUID.randomUUID());
    storage.writeState(idA);
    MemberId idB = storage.readState();
    // then
    assertEquals(idA.getUuid(), idB.getUuid());
    assertEquals(idA, idB);
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) File(java.io.File) Test(org.junit.Test)

Example 97 with MemberId

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

the class SharedDiscoveryServiceIT method shouldDiscoverCompleteTargetSetWithoutDeadlocks.

@Test(timeout = TIMEOUT_MS)
public void shouldDiscoverCompleteTargetSetWithoutDeadlocks() throws Exception {
    // given
    ExecutorService es = Executors.newCachedThreadPool();
    long endTimeMillis = System.currentTimeMillis() + RUN_TIME_MS;
    while (endTimeMillis > System.currentTimeMillis()) {
        Set<MemberId> members = new HashSet<>();
        for (int i = 0; i < 3; i++) {
            members.add(new MemberId(UUID.randomUUID()));
        }
        SharedDiscoveryService sharedService = new SharedDiscoveryService();
        List<Callable<Void>> discoveryJobs = new ArrayList<>();
        for (MemberId member : members) {
            discoveryJobs.add(createDiscoveryJob(member, sharedService, members));
        }
        List<Future<Void>> results = es.invokeAll(discoveryJobs);
        for (Future<Void> result : results) {
            result.get(TIMEOUT_MS, MILLISECONDS);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Callable(java.util.concurrent.Callable) MemberId(org.neo4j.causalclustering.identity.MemberId) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 98 with MemberId

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

the class ClusterOverviewProcedureTest method shouldProvideOverviewOfCoreServersAndReadReplicas.

@Test
public void shouldProvideOverviewOfCoreServersAndReadReplicas() throws Exception {
    // given
    final CoreTopologyService topologyService = mock(CoreTopologyService.class);
    Map<MemberId, CoreServerInfo> coreMembers = new HashMap<>();
    MemberId theLeader = new MemberId(UUID.randomUUID());
    MemberId follower1 = new MemberId(UUID.randomUUID());
    MemberId follower2 = new MemberId(UUID.randomUUID());
    coreMembers.put(theLeader, adressesForCore(0));
    coreMembers.put(follower1, adressesForCore(1));
    coreMembers.put(follower2, adressesForCore(2));
    Map<MemberId, ReadReplicaInfo> replicaMembers = new HashMap<>();
    MemberId replica4 = new MemberId(UUID.randomUUID());
    MemberId replica5 = new MemberId(UUID.randomUUID());
    replicaMembers.put(replica4, addressesForReadReplica(4));
    replicaMembers.put(replica5, addressesForReadReplica(5));
    when(topologyService.coreServers()).thenReturn(new CoreTopology(null, false, coreMembers));
    when(topologyService.readReplicas()).thenReturn(new ReadReplicaTopology(replicaMembers));
    LeaderLocator leaderLocator = mock(LeaderLocator.class);
    when(leaderLocator.getLeader()).thenReturn(theLeader);
    ClusterOverviewProcedure procedure = new ClusterOverviewProcedure(topologyService, leaderLocator, NullLogProvider.getInstance());
    // when
    final RawIterator<Object[], ProcedureException> members = procedure.apply(null, new Object[0]);
    assertThat(members.next(), new IsRecord(theLeader.getUuid(), 5000, Role.LEADER, asSet("core", "core0")));
    assertThat(members.next(), new IsRecord(follower1.getUuid(), 5001, Role.FOLLOWER, asSet("core", "core1")));
    assertThat(members.next(), new IsRecord(follower2.getUuid(), 5002, Role.FOLLOWER, asSet("core", "core2")));
    assertThat(members.next(), new IsRecord(replica4.getUuid(), 6004, Role.READ_REPLICA, asSet("replica", "replica4")));
    assertThat(members.next(), new IsRecord(replica5.getUuid(), 6005, Role.READ_REPLICA, asSet("replica", "replica5")));
    assertFalse(members.hasNext());
}
Also used : ReadReplicaInfo(org.neo4j.causalclustering.discovery.ReadReplicaInfo) HashMap(java.util.HashMap) CoreTopology(org.neo4j.causalclustering.discovery.CoreTopology) MemberId(org.neo4j.causalclustering.identity.MemberId) LeaderLocator(org.neo4j.causalclustering.core.consensus.LeaderLocator) CoreTopologyService(org.neo4j.causalclustering.discovery.CoreTopologyService) CoreServerInfo(org.neo4j.causalclustering.discovery.CoreServerInfo) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) ReadReplicaTopology(org.neo4j.causalclustering.discovery.ReadReplicaTopology) Test(org.junit.Test)

Example 99 with MemberId

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

the class RaftMessageEncodingDecodingTest method shouldSerializeAppendResponse.

@Test
public void shouldSerializeAppendResponse() throws Exception {
    MemberId sender = new MemberId(UUID.randomUUID());
    RaftMessages.AppendEntries.Response request = new AppendEntriesResponseBuilder().from(sender).success().matchIndex(12).build();
    serializeReadBackAndVerifyMessage(request);
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) AppendEntriesResponseBuilder(org.neo4j.causalclustering.core.consensus.roles.AppendEntriesResponseBuilder) Test(org.junit.Test)

Example 100 with MemberId

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

the class RaftMessageEncodingDecodingTest method shouldSerializeAppendRequestWithNoEntries.

@Test
public void shouldSerializeAppendRequestWithNoEntries() throws Exception {
    MemberId sender = new MemberId(UUID.randomUUID());
    RaftMessages.AppendEntries.Request request = new AppendEntriesRequestBuilder().from(sender).leaderCommit(2).leaderTerm(4).build();
    serializeReadBackAndVerifyMessage(request);
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) AppendEntriesRequestBuilder(org.neo4j.causalclustering.core.consensus.roles.AppendEntriesRequestBuilder) Test(org.junit.Test)

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