use of org.neo4j.kernel.ha.lock.LockResult 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.ha.lock.LockResult in project neo4j by neo4j.
the class MasterImpl method acquireExclusiveLock.
@Override
public Response<LockResult> acquireExclusiveLock(RequestContext context, ResourceType type, long... resourceIds) {
assertCorrectEpoch(context);
Locks.Client session;
try {
session = conversationManager.acquire(context).getLocks();
} catch (NoSuchEntryException | ConcurrentAccessException e) {
return spi.packTransactionObligationResponse(context, new LockResult(LockStatus.NOT_LOCKED, "Unable to acquire exclusive lock: " + e.getMessage()));
}
try {
for (long resourceId : resourceIds) {
session.acquireExclusive(LockTracer.NONE, type, resourceId);
}
return spi.packTransactionObligationResponse(context, new LockResult(LockStatus.OK_LOCKED));
} catch (DeadlockDetectedException e) {
return spi.packTransactionObligationResponse(context, new LockResult(LockStatus.DEAD_LOCKED, "Can't acquire exclusive lock, because it would have caused a deadlock: " + e.getMessage()));
} catch (IllegalResourceException e) {
return spi.packTransactionObligationResponse(context, new LockResult(LockStatus.NOT_LOCKED, "Attempted to lock illegal resource: " + e.getMessage()));
} finally {
conversationManager.release(context);
}
}
use of org.neo4j.kernel.ha.lock.LockResult in project neo4j by neo4j.
the class MasterImpl method acquireSharedLock.
@Override
public Response<LockResult> acquireSharedLock(RequestContext context, ResourceType type, long... resourceIds) {
assertCorrectEpoch(context);
Locks.Client session;
try {
session = conversationManager.acquire(context).getLocks();
} catch (NoSuchEntryException | ConcurrentAccessException e) {
return spi.packTransactionObligationResponse(context, new LockResult(LockStatus.NOT_LOCKED, "Unable to acquire shared lock: " + e.getMessage()));
}
try {
for (long resourceId : resourceIds) {
session.acquireShared(LockTracer.NONE, type, resourceId);
}
return spi.packTransactionObligationResponse(context, new LockResult(LockStatus.OK_LOCKED));
} catch (DeadlockDetectedException e) {
return spi.packTransactionObligationResponse(context, new LockResult(LockStatus.DEAD_LOCKED, e.getMessage()));
} catch (IllegalResourceException e) {
return spi.packTransactionObligationResponse(context, new LockResult(LockStatus.NOT_LOCKED, "Attempted to lock illegal resource: " + e.getMessage()));
} finally {
conversationManager.release(context);
}
}
Aggregations