use of org.neo4j.causalclustering.core.state.storage.InMemoryStateStorage in project neo4j by neo4j.
the class RaftStateBuilder method build.
public RaftState build() throws IOException {
StateStorage<TermState> termStore = new InMemoryStateStorage<>(new TermState());
StateStorage<VoteState> voteStore = new InMemoryStateStorage<>(new VoteState());
StubMembership membership = new StubMembership(votingMembers, replicationMembers);
RaftState state = new RaftState(myself, termStore, membership, entryLog, voteStore, new InFlightMap<>(), NullLogProvider.getInstance());
Collection<RaftMessages.Directed> noMessages = Collections.emptyList();
List<RaftLogCommand> noLogCommands = Collections.emptyList();
state.update(new Outcome(null, term, leader, leaderCommit, votedFor, votesForMe, lastLogIndexBeforeWeBecameLeader, followerStates, false, noLogCommands, noMessages, emptySet(), commitIndex, emptySet()));
return state;
}
use of org.neo4j.causalclustering.core.state.storage.InMemoryStateStorage in project neo4j by neo4j.
the class LeaderOnlyLockManagerTest method shouldIssueLocksOnLeader.
@Test
public void shouldIssueLocksOnLeader() throws Exception {
// given
MemberId me = member(0);
ReplicatedLockTokenStateMachine replicatedLockStateMachine = new ReplicatedLockTokenStateMachine(new InMemoryStateStorage(new ReplicatedLockTokenState()));
DirectReplicator replicator = new DirectReplicator(replicatedLockStateMachine);
LeaderLocator leaderLocator = mock(LeaderLocator.class);
when(leaderLocator.getLeader()).thenReturn(me);
Locks locks = mock(Locks.class);
when(locks.newClient()).thenReturn(mock(Locks.Client.class));
LeaderOnlyLockManager lockManager = new LeaderOnlyLockManager(me, replicator, leaderLocator, locks, replicatedLockStateMachine);
// when
lockManager.newClient().acquireExclusive(LockTracer.NONE, ResourceTypes.NODE, 0L);
// then
}
use of org.neo4j.causalclustering.core.state.storage.InMemoryStateStorage in project neo4j by neo4j.
the class LeaderOnlyLockManagerTest method shouldNotIssueLocksOnNonLeader.
@Test
public void shouldNotIssueLocksOnNonLeader() throws Exception {
// given
MemberId me = member(0);
MemberId leader = member(1);
ReplicatedLockTokenStateMachine replicatedLockStateMachine = new ReplicatedLockTokenStateMachine(new InMemoryStateStorage(new ReplicatedLockTokenState()));
DirectReplicator replicator = new DirectReplicator(replicatedLockStateMachine);
LeaderLocator leaderLocator = mock(LeaderLocator.class);
when(leaderLocator.getLeader()).thenReturn(leader);
Locks locks = mock(Locks.class);
when(locks.newClient()).thenReturn(mock(Locks.Client.class));
LeaderOnlyLockManager lockManager = new LeaderOnlyLockManager(me, replicator, leaderLocator, locks, replicatedLockStateMachine);
// when
Locks.Client lockClient = lockManager.newClient();
try {
lockClient.acquireExclusive(LockTracer.NONE, ResourceTypes.NODE, 0L);
fail("Should have thrown exception");
} catch (AcquireLockTimeoutException e) {
// expected
}
}
Aggregations