Search in sources :

Example 6 with DefaultConversationSPI

use of org.neo4j.kernel.ha.cluster.DefaultConversationSPI in project neo4j by neo4j.

the class MasterImplTest method failingToStartTxShouldNotLeadToNPE.

@Test
public void failingToStartTxShouldNotLeadToNPE() throws Throwable {
    // Given
    MasterImpl.SPI spi = mockedSpi();
    DefaultConversationSPI conversationSpi = mockedConversationSpi();
    Config config = config();
    ConversationManager conversationManager = new ConversationManager(conversationSpi, config);
    when(spi.isAccessible()).thenReturn(true);
    when(conversationSpi.acquireClient()).thenThrow(new RuntimeException("Nope"));
    when(spi.getTransactionChecksum(anyLong())).thenReturn(1L);
    mockEmptyResponse(spi);
    MasterImpl instance = new MasterImpl(spi, conversationManager, mock(MasterImpl.Monitor.class), config);
    instance.start();
    Response<HandshakeResult> response = instance.handshake(1, newStoreIdForCurrentVersion());
    HandshakeResult handshake = response.response();
    // When
    try {
        instance.newLockSession(new RequestContext(handshake.epoch(), 1, 2, 0, 0));
        fail("Should have failed.");
    } catch (Exception e) {
        // Then
        assertThat(e, instanceOf(RuntimeException.class));
        assertThat(e.getMessage(), equalTo("Nope"));
    }
}
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) RequestContext(org.neo4j.com.RequestContext) DeadlockDetectedException(org.neo4j.kernel.DeadlockDetectedException) IllegalResourceException(org.neo4j.kernel.impl.transaction.IllegalResourceException) TransactionNotPresentOnMasterException(org.neo4j.com.TransactionNotPresentOnMasterException) NoSuchEntryException(org.neo4j.kernel.impl.util.collection.NoSuchEntryException) Test(org.junit.Test)

Example 7 with DefaultConversationSPI

use of org.neo4j.kernel.ha.cluster.DefaultConversationSPI in project neo4j by neo4j.

the class MasterImplConversationStopFuzzIT method shouldHandleRandomizedLoad.

@Test
public void shouldHandleRandomizedLoad() throws Throwable {
    // Given
    DefaultConversationSPI conversationSPI = new DefaultConversationSPI(locks, scheduler);
    final ExposedConversationManager conversationManager = new ExposedConversationManager(conversationSPI, config, 100, 0);
    ConversationTestMasterSPI conversationTestMasterSPI = new ConversationTestMasterSPI();
    MasterImpl master = new MasterImpl(conversationTestMasterSPI, conversationManager, new Monitors().newMonitor(MasterImpl.Monitor.class), config);
    life.add(conversationManager);
    life.start();
    ConversationKiller conversationKiller = new ConversationKiller(conversationManager);
    executor.submit(conversationKiller);
    List<Callable<Void>> slaveWorkers = workers(master, numberOfWorkers);
    List<Future<Void>> workers = executor.invokeAll(slaveWorkers);
    // Wait for all workers to complete
    for (Future<Void> future : workers) {
        future.get();
    }
    conversationKiller.stop();
    assertTrue(executionStatistic.isSuccessfulExecution());
}
Also used : DefaultConversationSPI(org.neo4j.kernel.ha.cluster.DefaultConversationSPI) Callable(java.util.concurrent.Callable) Monitors(org.neo4j.kernel.monitoring.Monitors) Future(java.util.concurrent.Future) Test(org.junit.Test)

Example 8 with DefaultConversationSPI

use of org.neo4j.kernel.ha.cluster.DefaultConversationSPI in project neo4j by neo4j.

the class MasterImplTest method shouldNotAllowCommitIfThereIsNoMatchingLockSession.

@Test
public void shouldNotAllowCommitIfThereIsNoMatchingLockSession() throws Throwable {
    // Given
    MasterImpl.SPI spi = mock(MasterImpl.SPI.class);
    DefaultConversationSPI conversationSpi = mockedConversationSpi();
    Config config = config();
    ConversationManager conversationManager = new ConversationManager(conversationSpi, config);
    when(spi.isAccessible()).thenReturn(true);
    when(spi.getTransactionChecksum(anyLong())).thenReturn(1L);
    mockEmptyResponse(spi);
    MasterImpl master = new MasterImpl(spi, conversationManager, mock(MasterImpl.Monitor.class), config);
    master.start();
    HandshakeResult handshake = master.handshake(1, newStoreIdForCurrentVersion()).response();
    RequestContext ctx = new RequestContext(handshake.epoch(), 1, 2, 0, 0);
    // When
    try {
        master.commit(ctx, mock(TransactionRepresentation.class));
        fail("Should have failed.");
    } catch (TransactionNotPresentOnMasterException e) {
        // Then
        assertThat(e.getMessage(), equalTo(new TransactionNotPresentOnMasterException(ctx).getMessage()));
    }
}
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) TransactionNotPresentOnMasterException(org.neo4j.com.TransactionNotPresentOnMasterException) RequestContext(org.neo4j.com.RequestContext) Test(org.junit.Test)

Example 9 with DefaultConversationSPI

use of org.neo4j.kernel.ha.cluster.DefaultConversationSPI in project neo4j by neo4j.

the class MasterImplTest method shouldAllowStartNewTransactionAfterClientSessionWasRemovedOnTimeout.

@Test
public void shouldAllowStartNewTransactionAfterClientSessionWasRemovedOnTimeout() throws Throwable {
    //Given
    MasterImpl.SPI spi = mockedSpi();
    DefaultConversationSPI conversationSpi = mockedConversationSpi();
    Monitor monitor = mock(Monitor.class);
    Config config = config();
    Client client = mock(Client.class);
    ConversationManager conversationManager = new ConversationManager(conversationSpi, config);
    int machineId = 1;
    MasterImpl master = new MasterImpl(spi, conversationManager, monitor, config);
    when(spi.isAccessible()).thenReturn(true);
    when(conversationSpi.acquireClient()).thenReturn(client);
    master.start();
    HandshakeResult handshake = master.handshake(1, newStoreIdForCurrentVersion()).response();
    RequestContext requestContext = new RequestContext(handshake.epoch(), machineId, 0, 0, 0);
    // When
    master.newLockSession(requestContext);
    master.acquireSharedLock(requestContext, ResourceTypes.NODE, 1L);
    conversationManager.stop(requestContext);
    master.newLockSession(requestContext);
    //Then
    Map<Integer, Collection<RequestContext>> transactions = master.getOngoingTransactions();
    assertEquals(1, transactions.size());
    assertThat(transactions.get(machineId), org.hamcrest.Matchers.hasItem(requestContext));
}
Also used : SPI(org.neo4j.kernel.ha.com.master.MasterImpl.SPI) DefaultConversationSPI(org.neo4j.kernel.ha.cluster.DefaultConversationSPI) Config(org.neo4j.kernel.configuration.Config) Monitor(org.neo4j.kernel.ha.com.master.MasterImpl.Monitor) Collection(java.util.Collection) RequestContext(org.neo4j.com.RequestContext) Client(org.neo4j.kernel.impl.locking.Locks.Client) Test(org.junit.Test)

Example 10 with DefaultConversationSPI

use of org.neo4j.kernel.ha.cluster.DefaultConversationSPI 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

DefaultConversationSPI (org.neo4j.kernel.ha.cluster.DefaultConversationSPI)10 Test (org.junit.Test)9 Config (org.neo4j.kernel.configuration.Config)9 SPI (org.neo4j.kernel.ha.com.master.MasterImpl.SPI)9 RequestContext (org.neo4j.com.RequestContext)8 Client (org.neo4j.kernel.impl.locking.Locks.Client)6 Monitor (org.neo4j.kernel.ha.com.master.MasterImpl.Monitor)5 LockResult (org.neo4j.kernel.ha.lock.LockResult)4 ResourceTypes (org.neo4j.kernel.impl.locking.ResourceTypes)4 DeadlockDetectedException (org.neo4j.kernel.DeadlockDetectedException)3 IllegalResourceException (org.neo4j.kernel.impl.transaction.IllegalResourceException)3 TransactionNotPresentOnMasterException (org.neo4j.com.TransactionNotPresentOnMasterException)2 TransactionRepresentation (org.neo4j.kernel.impl.transaction.TransactionRepresentation)2 Collection (java.util.Collection)1 Callable (java.util.concurrent.Callable)1 Future (java.util.concurrent.Future)1 NoSuchEntryException (org.neo4j.kernel.impl.util.collection.NoSuchEntryException)1 Monitors (org.neo4j.kernel.monitoring.Monitors)1