Search in sources :

Example 16 with SPI

use of org.neo4j.kernel.ha.com.master.MasterImpl.SPI in project neo4j by neo4j.

the class MasterImplTest method shouldAllowCommitIfClientHoldsNoLocks.

@Test
public void shouldAllowCommitIfClientHoldsNoLocks() throws Throwable {
    // Given
    MasterImpl.SPI spi = mock(MasterImpl.SPI.class);
    Config config = config();
    DefaultConversationSPI conversationSpi = mockedConversationSpi();
    ConversationManager conversationManager = new ConversationManager(conversationSpi, config);
    Client locks = mock(Client.class);
    when(locks.trySharedLock(ResourceTypes.SCHEMA, ResourceTypes.schemaResource())).thenReturn(true);
    when(spi.isAccessible()).thenReturn(true);
    when(spi.getTransactionChecksum(anyLong())).thenReturn(1L);
    when(conversationSpi.acquireClient()).thenReturn(locks);
    mockEmptyResponse(spi);
    MasterImpl master = new MasterImpl(spi, conversationManager, mock(MasterImpl.Monitor.class), config);
    master.start();
    HandshakeResult handshake = master.handshake(1, newStoreIdForCurrentVersion()).response();
    int no_lock_session = -1;
    RequestContext ctx = new RequestContext(handshake.epoch(), 1, no_lock_session, 0, 0);
    TransactionRepresentation tx = mock(TransactionRepresentation.class);
    // When
    master.commit(ctx, tx);
    // Then
    verify(spi).applyPreparedTransaction(tx);
}
Also used : SPI(org.neo4j.kernel.ha.com.master.MasterImpl.SPI) DefaultConversationSPI(org.neo4j.kernel.ha.cluster.DefaultConversationSPI) Monitor(org.neo4j.kernel.ha.com.master.MasterImpl.Monitor) Config(org.neo4j.kernel.configuration.Config) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) RequestContext(org.neo4j.com.RequestContext) Client(org.neo4j.kernel.impl.locking.Locks.Client) Test(org.junit.Test)

Aggregations

SPI (org.neo4j.kernel.ha.com.master.MasterImpl.SPI)16 Test (org.junit.Test)14 Config (org.neo4j.kernel.configuration.Config)14 RequestContext (org.neo4j.com.RequestContext)12 DefaultConversationSPI (org.neo4j.kernel.ha.cluster.DefaultConversationSPI)9 Monitor (org.neo4j.kernel.ha.com.master.MasterImpl.Monitor)7 LockResult (org.neo4j.kernel.ha.lock.LockResult)6 Client (org.neo4j.kernel.impl.locking.Locks.Client)6 DeadlockDetectedException (org.neo4j.kernel.DeadlockDetectedException)4 ResourceTypes (org.neo4j.kernel.impl.locking.ResourceTypes)4 IllegalResourceException (org.neo4j.kernel.impl.transaction.IllegalResourceException)4 NoSuchEntryException (org.neo4j.kernel.impl.util.collection.NoSuchEntryException)4 TransactionNotPresentOnMasterException (org.neo4j.com.TransactionNotPresentOnMasterException)3 TransactionRepresentation (org.neo4j.kernel.impl.transaction.TransactionRepresentation)2 Collection (java.util.Collection)1 InOrder (org.mockito.InOrder)1 ConversationManager (org.neo4j.kernel.ha.com.master.ConversationManager)1 HandshakeResult (org.neo4j.kernel.ha.com.master.HandshakeResult)1 InvalidEpochException (org.neo4j.kernel.ha.com.master.InvalidEpochException)1 MasterImpl (org.neo4j.kernel.ha.com.master.MasterImpl)1