use of org.neo4j.causalclustering.core.replication.DirectReplicator in project neo4j by neo4j.
the class CommitProcessStateMachineCollaborationTest method shouldFailTransactionIfLockSessionChanges.
@Test
public void shouldFailTransactionIfLockSessionChanges() throws Exception {
// given
int initialLockSessionId = 23;
TransactionToApply transactionToApply = new TransactionToApply(physicalTx(initialLockSessionId));
int finalLockSessionId = 24;
TransactionCommitProcess localCommitProcess = mock(TransactionCommitProcess.class);
ReplicatedTransactionStateMachine stateMachine = new ReplicatedTransactionStateMachine(lockState(finalLockSessionId), 16, NullLogProvider.getInstance());
stateMachine.installCommitProcess(localCommitProcess, -1L);
DirectReplicator<ReplicatedTransaction> replicator = new DirectReplicator<>(stateMachine);
ReplicatedTransactionCommitProcess commitProcess = new ReplicatedTransactionCommitProcess(replicator);
// when
try {
commitProcess.commit(transactionToApply, NULL, EXTERNAL);
fail("Should have thrown exception.");
} catch (TransactionFailureException e) {
// expected
}
}
use of org.neo4j.causalclustering.core.replication.DirectReplicator 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.replication.DirectReplicator 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