Search in sources :

Example 1 with Monitor

use of org.neo4j.kernel.ha.com.master.MasterImpl.Monitor 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)

Aggregations

Collection (java.util.Collection)1 Test (org.junit.Test)1 RequestContext (org.neo4j.com.RequestContext)1 Config (org.neo4j.kernel.configuration.Config)1 DefaultConversationSPI (org.neo4j.kernel.ha.cluster.DefaultConversationSPI)1 Monitor (org.neo4j.kernel.ha.com.master.MasterImpl.Monitor)1 SPI (org.neo4j.kernel.ha.com.master.MasterImpl.SPI)1 Client (org.neo4j.kernel.impl.locking.Locks.Client)1