Skip to content

Commit

Permalink
Remove sneaky netty catch
Browse files Browse the repository at this point in the history
Depending on bootstrap config the bind exception type may vary.
  • Loading branch information
RagnarW committed Sep 28, 2018
1 parent f28a269 commit d8401e0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import io.netty.channel.EventLoopGroup;
import io.netty.channel.socket.ServerSocketChannel;

import java.net.BindException;
import java.util.concurrent.TimeUnit;

import org.neo4j.causalclustering.helper.SuspendableLifeCycle;
Expand Down Expand Up @@ -115,17 +114,14 @@ protected void start0()
try
{
channel = bootstrap.bind().syncUninterruptibly().channel();
debugLog.info( "%s: bound to '%s' with transport '%s'", serverName, listenAddress, bootstrapConfiguration.channelClass() );
debugLog.info( "%s: bound to '%s' with transport '%s'", serverName, listenAddress, bootstrapConfiguration.channelClass().getSimpleName() );
}
catch ( Exception e )
{
//noinspection ConstantConditions netty sneaky throw
if ( e instanceof BindException )
{
String message = serverName + ": address is already bound: " + listenAddress;
userLog.error( message );
debugLog.error( message, e );
}
String message =
format( "%s: cannot bind to '%s' with transport '%s'.", serverName, listenAddress, bootstrapConfiguration.channelClass().getSimpleName() );
userLog.error( message + " Message: " + e.getMessage() );
debugLog.error( message, e );
throw e;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ public AdvertisedSocketAddress secondary()
catch ( StoreCopyFailedException e )
{
assertableLogProvider.assertContainsExactlyOneMessageMatching(
both( startsWith( "Connection refused:" ) ).and( containsString( "localhost/127.0.0.1:" + port ) ) );
both( containsString( "Connection refused:" ) ).and( containsString( "localhost/127.0.0.1:" + port ) ) );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ public void testAddressAlreadyBoundMessage() throws Throwable
{
//expected.
}
logProvider.assertContainsMessageContaining( "server-name: address is already bound: " );
userLogProvider.assertContainsMessageContaining( "server-name: address is already bound: " );
String expectedPartOfMessage = String.format( "server-name: cannot bind to '%s' with transport ", listenSocketAddress );
logProvider.assertContainsMessageContaining( expectedPartOfMessage );
userLogProvider.assertContainsMessageContaining( expectedPartOfMessage );
}

@SuppressWarnings( "SameParameterValue" )
Expand Down

0 comments on commit d8401e0

Please sign in to comment.