Skip to content

Commit

Permalink
Merge pull request #7975 from tinwelint/3.0-show-lock-result
Browse files Browse the repository at this point in the history
Includes reason for master replying NOT_LOCKED
  • Loading branch information
davidegrohmann committed Sep 28, 2016
2 parents cb95f12 + 4371961 commit a3f2808
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ private void receiveLockResponse( Response<LockResult> response )
case DEAD_LOCKED:
throw new DeadlockDetectedException( result.getMessage() );
case NOT_LOCKED:
throw new UnsupportedOperationException();
throw new UnsupportedOperationException( result.toString() );
case OK_LOCKED:
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.neo4j.com.RequestContext;
import org.neo4j.com.ResourceReleaser;
import org.neo4j.com.Response;
import org.neo4j.com.TransactionObligationResponse;
import org.neo4j.com.TransactionStream;
import org.neo4j.com.TransactionStreamResponse;
import org.neo4j.graphdb.TransientFailureException;
Expand All @@ -50,10 +51,12 @@

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
Expand All @@ -63,7 +66,10 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;

import static org.neo4j.com.ResourceReleaser.NO_OP;
import static org.neo4j.kernel.impl.locking.ResourceTypes.NODE;
import static org.neo4j.kernel.impl.store.StoreId.DEFAULT;
import static org.neo4j.logging.AssertableLogProvider.inLog;

public class SlaveLocksClientTest
Expand Down Expand Up @@ -543,6 +549,32 @@ public void stopDoesNothingWhenLocksAreNotTxTerminationAware()
verify( master, never() ).endLockSession( any( RequestContext.class ), anyBoolean() );
}

@Test
public void shouldIncludeReasonForNotLocked() throws Exception
{
// GIVEN
SlaveLocksClient client = newSlaveLocksClient( lockManager, false );
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( resourceType, nodeId );
fail( "Should have failed" );
}
catch ( UnsupportedOperationException e )
{
// THEN
assertThat( e.getMessage(), containsString( lockResult.getMessage() ) );
assertThat( e.getMessage(), containsString( lockResult.getStatus().name() ) );
}
}

private SlaveLocksClient newSlaveLocksClient( Locks lockManager, boolean txTerminationAwareLocks )
{
return new SlaveLocksClient( master, local, lockManager, mock( RequestContextFactory.class ),
Expand Down

0 comments on commit a3f2808

Please sign in to comment.