use of org.neo4j.kernel.ha.com.master.MasterImpl.SPI 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())));
}
use of org.neo4j.kernel.ha.com.master.MasterImpl.SPI in project neo4j by neo4j.
the class MasterImplTest method lockResultMustHaveMessageWhenAcquiringExclusiveLockWithoutConversation.
@Test
public void lockResultMustHaveMessageWhenAcquiringExclusiveLockWithoutConversation() throws Exception {
MasterImpl.SPI spi = mockedSpi();
ConversationManager conversationManager = mock(ConversationManager.class);
Config config = config();
MasterImpl master = new MasterImpl(spi, conversationManager, null, config);
RequestContext context = createRequestContext(master);
when(conversationManager.acquire(context)).thenThrow(new NoSuchEntryException(""));
master.acquireExclusiveLock(context, ResourceTypes.NODE, 1);
ArgumentCaptor<LockResult> captor = ArgumentCaptor.forClass(LockResult.class);
verify(spi).packTransactionObligationResponse(argThat(is(context)), captor.capture());
assertThat(captor.getValue().getMessage(), is(not(nullValue())));
}
use of org.neo4j.kernel.ha.com.master.MasterImpl.SPI in project neo4j by neo4j.
the class MasterImplTest method givenStartedAndInaccessibleWhenNewLockSessionThrowException.
@Test
public void givenStartedAndInaccessibleWhenNewLockSessionThrowException() throws Throwable {
// Given
MasterImpl.SPI spi = mock(MasterImpl.SPI.class);
Config config = config();
when(spi.isAccessible()).thenReturn(false);
MasterImpl instance = new MasterImpl(spi, mock(ConversationManager.class), mock(MasterImpl.Monitor.class), config);
instance.start();
// When
try {
instance.newLockSession(new RequestContext(0, 1, 2, 0, 0));
fail();
} catch (org.neo4j.kernel.api.exceptions.TransactionFailureException e) {
// Ok
}
}
use of org.neo4j.kernel.ha.com.master.MasterImpl.SPI in project neo4j by neo4j.
the class MasterImplTest method lockResultMustHaveMessageWhenAcquiringSharedLockWithoutConversation.
@Test
public void lockResultMustHaveMessageWhenAcquiringSharedLockWithoutConversation() throws Exception {
MasterImpl.SPI spi = mockedSpi();
ConversationManager conversationManager = mock(ConversationManager.class);
Config config = config();
MasterImpl master = new MasterImpl(spi, conversationManager, null, config);
RequestContext context = createRequestContext(master);
when(conversationManager.acquire(context)).thenThrow(new NoSuchEntryException(""));
master.acquireSharedLock(context, ResourceTypes.NODE, 1);
ArgumentCaptor<LockResult> captor = ArgumentCaptor.forClass(LockResult.class);
verify(spi).packTransactionObligationResponse(argThat(is(context)), captor.capture());
assertThat(captor.getValue().getMessage(), is(not(nullValue())));
}
use of org.neo4j.kernel.ha.com.master.MasterImpl.SPI 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;
}
Aggregations