Search in sources :

Example 1 with DirectReplicator

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
    }
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) TransactionCommitProcess(org.neo4j.kernel.impl.api.TransactionCommitProcess) DirectReplicator(org.neo4j.causalclustering.core.replication.DirectReplicator) Test(org.junit.Test)

Example 2 with DirectReplicator

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
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) InMemoryStateStorage(org.neo4j.causalclustering.core.state.storage.InMemoryStateStorage) LeaderLocator(org.neo4j.causalclustering.core.consensus.LeaderLocator) DirectReplicator(org.neo4j.causalclustering.core.replication.DirectReplicator) Locks(org.neo4j.kernel.impl.locking.Locks) Test(org.junit.Test)

Example 3 with DirectReplicator

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
    }
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) InMemoryStateStorage(org.neo4j.causalclustering.core.state.storage.InMemoryStateStorage) AcquireLockTimeoutException(org.neo4j.storageengine.api.lock.AcquireLockTimeoutException) LeaderLocator(org.neo4j.causalclustering.core.consensus.LeaderLocator) DirectReplicator(org.neo4j.causalclustering.core.replication.DirectReplicator) Locks(org.neo4j.kernel.impl.locking.Locks) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 DirectReplicator (org.neo4j.causalclustering.core.replication.DirectReplicator)3 LeaderLocator (org.neo4j.causalclustering.core.consensus.LeaderLocator)2 InMemoryStateStorage (org.neo4j.causalclustering.core.state.storage.InMemoryStateStorage)2 MemberId (org.neo4j.causalclustering.identity.MemberId)2 Locks (org.neo4j.kernel.impl.locking.Locks)2 TransactionFailureException (org.neo4j.kernel.api.exceptions.TransactionFailureException)1 TransactionCommitProcess (org.neo4j.kernel.impl.api.TransactionCommitProcess)1 TransactionToApply (org.neo4j.kernel.impl.api.TransactionToApply)1 AcquireLockTimeoutException (org.neo4j.storageengine.api.lock.AcquireLockTimeoutException)1