Search in sources :

Example 81 with MemberId

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

the class ReplicatedLockTokenStateMachineTest method shouldSetInitialPendingRequestToInitialState.

@Test
public void shouldSetInitialPendingRequestToInitialState() throws Exception {
    // Given
    @SuppressWarnings("unchecked") StateStorage<ReplicatedLockTokenState> storage = mock(StateStorage.class);
    MemberId initialHoldingCoreMember = member(0);
    ReplicatedLockTokenState initialState = new ReplicatedLockTokenState(123, new ReplicatedLockTokenRequest(initialHoldingCoreMember, 3));
    when(storage.getInitialState()).thenReturn(initialState);
    // When
    ReplicatedLockTokenStateMachine stateMachine = new ReplicatedLockTokenStateMachine(storage);
    // Then
    LockToken initialToken = stateMachine.currentToken();
    assertEquals(initialState.get().owner(), initialToken.owner());
    assertEquals(initialState.get().id(), initialToken.id());
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) Test(org.junit.Test)

Example 82 with MemberId

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

the class ReplicatedLockTokenStateMachineTest method shouldBeIdempotent.

@Test
public void shouldBeIdempotent() throws Exception {
    // given
    EphemeralFileSystemAbstraction fsa = fileSystemRule.get();
    fsa.mkdir(testDir.directory());
    StateMarshal<ReplicatedLockTokenState> marshal = new ReplicatedLockTokenState.Marshal(new MemberId.Marshal());
    DurableStateStorage<ReplicatedLockTokenState> storage = new DurableStateStorage<>(fsa, testDir.directory(), "state", marshal, 100, NullLogProvider.getInstance());
    try (Lifespan lifespan = new Lifespan(storage)) {
        ReplicatedLockTokenStateMachine stateMachine = new ReplicatedLockTokenStateMachine(storage);
        MemberId memberA = member(0);
        MemberId memberB = member(1);
        stateMachine.applyCommand(new ReplicatedLockTokenRequest(memberA, 0), 3, r -> {
        });
        // when
        stateMachine.applyCommand(new ReplicatedLockTokenRequest(memberB, 1), 2, r -> {
        });
        // then
        assertEquals(memberA, stateMachine.currentToken().owner());
    }
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) StateMarshal(org.neo4j.causalclustering.core.state.storage.StateMarshal) DurableStateStorage(org.neo4j.causalclustering.core.state.storage.DurableStateStorage) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) Test(org.junit.Test)

Example 83 with MemberId

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

the class CoreReplicatedContentMarshalTest method shouldMarshalMemberSet.

@Test
public void shouldMarshalMemberSet() throws Exception {
    ByteBuf buffer = Unpooled.buffer();
    ReplicatedContent message = new MemberIdSet(asSet(new MemberId(UUID.randomUUID()), new MemberId(UUID.randomUUID())));
    assertMarshalingEquality(buffer, message);
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) MemberIdSet(org.neo4j.causalclustering.core.consensus.membership.MemberIdSet) ByteBuf(io.netty.buffer.ByteBuf) NetworkFlushableByteBuf(org.neo4j.causalclustering.messaging.NetworkFlushableByteBuf) Test(org.junit.Test)

Example 84 with MemberId

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

the class VoteStateTest method shouldUpdateVote.

@Test
public void shouldUpdateVote() throws Exception {
    // given
    VoteState voteState = new VoteState();
    MemberId member1 = new MemberId(UUID.randomUUID());
    MemberId member2 = new MemberId(UUID.randomUUID());
    // when
    voteState.update(member1, 0);
    voteState.update(member2, 1);
    // then
    assertEquals(member2, voteState.votedFor());
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) Test(org.junit.Test)

Example 85 with MemberId

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

the class VoteStateTest method shouldStoreVote.

@Test
public void shouldStoreVote() throws Exception {
    // given
    VoteState voteState = new VoteState();
    MemberId member = new MemberId(UUID.randomUUID());
    // when
    voteState.update(member, 0);
    // then
    assertEquals(member, voteState.votedFor());
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) 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