Search in sources :

Example 1 with DefaultConversationSPI

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

the class MasterImplTest method lockResultMustHaveMessageWhenAcquiringExclusiveLockDeadlocks.

@Test
public void lockResultMustHaveMessageWhenAcquiringExclusiveLockDeadlocks() throws Exception {
    MasterImpl.SPI spi = mockedSpi();
    DefaultConversationSPI conversationSpi = mockedConversationSpi();
    Config config = config();
    ConversationManager conversationManager = new ConversationManager(conversationSpi, config);
    conversationManager.start();
    Client locks = mock(Client.class);
    MasterImpl master = new MasterImpl(spi, conversationManager, null, config);
    RequestContext context = createRequestContext(master);
    when(conversationSpi.acquireClient()).thenReturn(locks);
    ResourceTypes type = ResourceTypes.NODE;
    doThrow(new DeadlockDetectedException("")).when(locks).acquireExclusive(LockTracer.NONE, type, 1);
    master.acquireExclusiveLock(context, type, 1);
    ArgumentCaptor<LockResult> captor = ArgumentCaptor.forClass(LockResult.class);
    verify(spi).packTransactionObligationResponse(argThat(is(context)), captor.capture());
    assertThat(captor.getValue().getMessage(), is(not(nullValue())));
}
Also used : SPI(org.neo4j.kernel.ha.com.master.MasterImpl.SPI) ResourceTypes(org.neo4j.kernel.impl.locking.ResourceTypes) DefaultConversationSPI(org.neo4j.kernel.ha.cluster.DefaultConversationSPI) LockResult(org.neo4j.kernel.ha.lock.LockResult) Config(org.neo4j.kernel.configuration.Config) DeadlockDetectedException(org.neo4j.kernel.DeadlockDetectedException) RequestContext(org.neo4j.com.RequestContext) Client(org.neo4j.kernel.impl.locking.Locks.Client) Test(org.junit.Test)

Example 2 with DefaultConversationSPI

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

the class MasterImplTest method newMasterWithLocksClient.

private MasterImpl newMasterWithLocksClient(Client client) throws Throwable {
    SPI spi = mockedSpi();
    DefaultConversationSPI conversationSpi = mockedConversationSpi();
    when(spi.isAccessible()).thenReturn(true);
    when(conversationSpi.acquireClient()).thenReturn(client);
    Config config = config();
    ConversationManager conversationManager = new ConversationManager(conversationSpi, config);
    MasterImpl master = new MasterImpl(spi, conversationManager, mock(Monitor.class), config);
    master.start();
    return master;
}
Also used : DefaultConversationSPI(org.neo4j.kernel.ha.cluster.DefaultConversationSPI) Monitor(org.neo4j.kernel.ha.com.master.MasterImpl.Monitor) Config(org.neo4j.kernel.configuration.Config) SPI(org.neo4j.kernel.ha.com.master.MasterImpl.SPI) DefaultConversationSPI(org.neo4j.kernel.ha.cluster.DefaultConversationSPI)

Example 3 with DefaultConversationSPI

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

the class MasterImplTest method lockResultMustHaveMessageWhenAcquiringSharedLockThrowsIllegalResource.

@Test
public void lockResultMustHaveMessageWhenAcquiringSharedLockThrowsIllegalResource() throws Exception {
    MasterImpl.SPI spi = mockedSpi();
    DefaultConversationSPI conversationSpi = mockedConversationSpi();
    Config config = config();
    ConversationManager conversationManager = new ConversationManager(conversationSpi, config);
    conversationManager.start();
    Client locks = mock(Client.class);
    MasterImpl master = new MasterImpl(spi, conversationManager, null, config);
    RequestContext context = createRequestContext(master);
    when(conversationSpi.acquireClient()).thenReturn(locks);
    ResourceTypes type = ResourceTypes.NODE;
    doThrow(new IllegalResourceException("")).when(locks).acquireExclusive(LockTracer.NONE, type, 1);
    master.acquireSharedLock(context, type, 1);
    ArgumentCaptor<LockResult> captor = ArgumentCaptor.forClass(LockResult.class);
    verify(spi).packTransactionObligationResponse(argThat(is(context)), captor.capture());
    assertThat(captor.getValue().getMessage(), is(not(nullValue())));
}
Also used : SPI(org.neo4j.kernel.ha.com.master.MasterImpl.SPI) ResourceTypes(org.neo4j.kernel.impl.locking.ResourceTypes) DefaultConversationSPI(org.neo4j.kernel.ha.cluster.DefaultConversationSPI) LockResult(org.neo4j.kernel.ha.lock.LockResult) Config(org.neo4j.kernel.configuration.Config) RequestContext(org.neo4j.com.RequestContext) Client(org.neo4j.kernel.impl.locking.Locks.Client) IllegalResourceException(org.neo4j.kernel.impl.transaction.IllegalResourceException) Test(org.junit.Test)

Example 4 with DefaultConversationSPI

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

the class MasterImplTest method lockResultMustHaveMessageWhenAcquiringExclusiveLockThrowsIllegalResource.

@Test
public void lockResultMustHaveMessageWhenAcquiringExclusiveLockThrowsIllegalResource() throws Exception {
    MasterImpl.SPI spi = mockedSpi();
    DefaultConversationSPI conversationSpi = mockedConversationSpi();
    Config config = config();
    ConversationManager conversationManager = new ConversationManager(conversationSpi, config);
    conversationManager.start();
    Client locks = mock(Client.class);
    MasterImpl master = new MasterImpl(spi, conversationManager, null, config);
    RequestContext context = createRequestContext(master);
    when(conversationSpi.acquireClient()).thenReturn(locks);
    ResourceTypes type = ResourceTypes.NODE;
    doThrow(new IllegalResourceException("")).when(locks).acquireExclusive(LockTracer.NONE, type, 1);
    master.acquireExclusiveLock(context, type, 1);
    ArgumentCaptor<LockResult> captor = ArgumentCaptor.forClass(LockResult.class);
    verify(spi).packTransactionObligationResponse(argThat(is(context)), captor.capture());
    assertThat(captor.getValue().getMessage(), is(not(nullValue())));
}
Also used : SPI(org.neo4j.kernel.ha.com.master.MasterImpl.SPI) ResourceTypes(org.neo4j.kernel.impl.locking.ResourceTypes) DefaultConversationSPI(org.neo4j.kernel.ha.cluster.DefaultConversationSPI) LockResult(org.neo4j.kernel.ha.lock.LockResult) Config(org.neo4j.kernel.configuration.Config) RequestContext(org.neo4j.com.RequestContext) Client(org.neo4j.kernel.impl.locking.Locks.Client) IllegalResourceException(org.neo4j.kernel.impl.transaction.IllegalResourceException) Test(org.junit.Test)

Example 5 with DefaultConversationSPI

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

the class MasterImplTest method lockResultMustHaveMessageWhenAcquiringSharedLockDeadlocks.

@Test
public void lockResultMustHaveMessageWhenAcquiringSharedLockDeadlocks() throws Exception {
    MasterImpl.SPI spi = mockedSpi();
    DefaultConversationSPI conversationSpi = mockedConversationSpi();
    Config config = config();
    ConversationManager conversationManager = new ConversationManager(conversationSpi, config);
    conversationManager.start();
    Client locks = mock(Client.class);
    MasterImpl master = new MasterImpl(spi, conversationManager, null, config);
    RequestContext context = createRequestContext(master);
    when(conversationSpi.acquireClient()).thenReturn(locks);
    ResourceTypes type = ResourceTypes.NODE;
    doThrow(new DeadlockDetectedException("")).when(locks).acquireExclusive(LockTracer.NONE, type, 1);
    master.acquireSharedLock(context, type, 1);
    ArgumentCaptor<LockResult> captor = ArgumentCaptor.forClass(LockResult.class);
    verify(spi).packTransactionObligationResponse(argThat(is(context)), captor.capture());
    assertThat(captor.getValue().getMessage(), is(not(nullValue())));
}
Also used : SPI(org.neo4j.kernel.ha.com.master.MasterImpl.SPI) ResourceTypes(org.neo4j.kernel.impl.locking.ResourceTypes) DefaultConversationSPI(org.neo4j.kernel.ha.cluster.DefaultConversationSPI) LockResult(org.neo4j.kernel.ha.lock.LockResult) Config(org.neo4j.kernel.configuration.Config) DeadlockDetectedException(org.neo4j.kernel.DeadlockDetectedException) 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