Skip to content

Commit

Permalink
Simplify exception handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
apcj committed Jul 4, 2016
1 parent ec17a01 commit 4dc1070
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
Expand Up @@ -56,7 +56,7 @@ public ClusterTopology currentTopology()
} }
catch ( Exception e ) catch ( Exception e )
{ {
log.warn( "Failed to read cluster topology from Hazelcast. Continuing with empty (disconnected) topology. " log.info( "Failed to read cluster topology from Hazelcast. Continuing with empty (disconnected) topology. "
+ "Connection will be reattempted on next polling attempt.", e ); + "Connection will be reattempted on next polling attempt.", e );
return new ClusterTopology( false, emptyMap(), emptySet() ); return new ClusterTopology( false, emptyMap(), emptySet() );
} }
Expand All @@ -80,22 +80,14 @@ public void registerEdgeServer( AdvertisedSocketAddress address )
private synchronized <T> T retry( Function<HazelcastInstance, T> hazelcastAccessor ) private synchronized <T> T retry( Function<HazelcastInstance, T> hazelcastAccessor )
{ {
boolean attemptedConnection = false; boolean attemptedConnection = false;
RuntimeException exception = null; HazelcastInstanceNotActiveException exception = null;


while ( !attemptedConnection ) while ( !attemptedConnection )
{ {
if ( hazelcastInstance == null ) if ( hazelcastInstance == null )
{ {
try attemptedConnection = true;
{ hazelcastInstance = connector.connectToHazelcast();
attemptedConnection = true;
hazelcastInstance = connector.connectToHazelcast();
}
catch ( IllegalStateException e )
{
log.info( "Unable to connect to core cluster" );
break;
}
} }


try try
Expand Down
Expand Up @@ -44,6 +44,7 @@
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any; import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.startsWith;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -138,7 +139,8 @@ public void shouldReturnEmptyTopologyIfUnableToConnectToHazelcast() throws Excep
ClusterTopology topology = client.currentTopology(); ClusterTopology topology = client.currentTopology();


assertEquals( 0, topology.coreMembers().size() ); assertEquals( 0, topology.coreMembers().size() );
verify( log ).info( "Unable to connect to core cluster" ); verify( log ).info( startsWith( "Failed to read cluster topology from Hazelcast." ),
any( IllegalStateException.class ) );
} }


@Test @Test
Expand Down

0 comments on commit 4dc1070

Please sign in to comment.