Skip to content

Fix reset of transaction functions #340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public synchronized void onConnectionError( boolean recoverable )
}
}

private synchronized <T> T transaction( AccessMode mode, TransactionWork<T> work )
private <T> T transaction( AccessMode mode, TransactionWork<T> work )
{
RetryDecision decision = null;
List<Throwable> errors = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,25 @@ private static boolean canRetryOn( Throwable error )
{
return error instanceof SessionExpiredException ||
error instanceof ServiceUnavailableException ||
error instanceof TransientException;
isTransientError( error );
}

private static boolean isTransientError( Throwable error )
{
if ( error instanceof TransientException )
{
String code = ((TransientException) error).code();
// Retries should not happen when transaction was explicitly terminated by the user.
// Termination of transaction might result in two different error codes depending on where it was
// terminated. These are really client errors but classification on the server is not entirely correct and
// they are classified as transient.
if ( "Neo.TransientError.Transaction.Terminated".equals( code ) ||
"Neo.TransientError.Transaction.LockClientStopped".equals( code ) )
{
return false;
}
return true;
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,32 @@ public void sleepsOnTransientException() throws Exception
verify( clock ).sleep( 1 );
}

@Test
public void doesNothingWhenTransactionTerminatedError() throws Exception
{
Clock clock = mock( Clock.class );
ExponentialBackoff backoff = newBackoff( 1, 1, 1, 0, clock );

TransientException exception = new TransientException( "Neo.TransientError.Transaction.Terminated", "" );
ExponentialBackoffDecision decision = backoff.apply( exception, null );

assertFalse( decision.shouldRetry() );
verify( clock, never() ).sleep( anyLong() );
}

@Test
public void doesNothingWhenTransactionLockClientStoppedError() throws Exception
{
Clock clock = mock( Clock.class );
ExponentialBackoff backoff = newBackoff( 1, 1, 1, 0, clock );

TransientException exception = new TransientException( "Neo.TransientError.Transaction.LockClientStopped", "" );
ExponentialBackoffDecision decision = backoff.apply( exception, null );

assertFalse( decision.shouldRetry() );
verify( clock, never() ).sleep( anyLong() );
}

@Test
public void throwsWhenSleepInterrupted() throws Exception
{
Expand Down
Loading