use of org.neo4j.kernel.impl.locking.ResourceTypes 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.impl.locking.ResourceTypes 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())));
}
use of org.neo4j.kernel.impl.locking.ResourceTypes 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())));
}
use of org.neo4j.kernel.impl.locking.ResourceTypes 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())));
}
use of org.neo4j.kernel.impl.locking.ResourceTypes in project neo4j by neo4j.
the class SlaveLocksClientTest method shouldIncludeReasonForNotLocked.
@Test
public void shouldIncludeReasonForNotLocked() throws Exception {
// GIVEN
SlaveLocksClient client = newSlaveLocksClient(lockManager);
LockResult lockResult = new LockResult(LockStatus.NOT_LOCKED, "Simply not locked");
Response<LockResult> response = new TransactionObligationResponse<>(lockResult, DEFAULT, 2, NO_OP);
long nodeId = 0;
ResourceTypes resourceType = NODE;
when(master.acquireExclusiveLock(any(RequestContext.class), eq(resourceType), anyLong())).thenReturn(response);
// WHEN
try {
client.acquireExclusive(LockTracer.NONE, resourceType, nodeId);
fail("Should have failed");
} catch (UnsupportedOperationException e) {
// THEN
assertThat(e.getMessage(), containsString(lockResult.getMessage()));
assertThat(e.getMessage(), containsString(lockResult.getStatus().name()));
}
}
Aggregations