@Test
void correctNumberOfRetiesAreLoggedOnFailure()
{

    Clock clock = mock( Clock.class );
    Logging logging = mock( Logging.class );
    Logger logger = mock( Logger.class );
    when( logging.getLog( anyString() ) ).thenReturn( logger );
    RetrySettings settings = RetrySettings.DEFAULT;
    RetryLogic logic = new ExponentialBackoffRetryLogic( settings, eventExecutor, clock, logging );
    ServiceUnavailableException error = assertThrows( ServiceUnavailableException.class, () ->
            logic.retry( new Supplier<Long>()
            {
                boolean invoked;
                @Override
                public Long get()
                {
                    // work that always fails and moves clock forward after the first failure
                    if ( invoked )
                    {
                        // move clock forward to stop retries
                        when( clock.millis() ).thenReturn( settings.maxRetryTimeMs() + 42 );
                    }
                    else
                    {
                        invoked = true;
                    }
                    throw new ServiceUnavailableException( "Error" );
                }
            } ) );
    assertEquals( "Error", error.getMessage() );
    verify( logger ).warn(
            startsWith( "Transaction failed and will be retried" ),
            any( ServiceUnavailableException.class )
    );
}