Skip to content

Commit

Permalink
Add IPv6 support to test cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
martinfurmanski committed Jul 5, 2017
1 parent a678caa commit 272753e
Show file tree
Hide file tree
Showing 14 changed files with 352 additions and 142 deletions.
Expand Up @@ -25,4 +25,12 @@ public AdvertisedSocketAddress( String hostname, int port )
{
super( hostname, port );
}

/**
* Textual representation format for an advertised socket address.
*/
public static String advertisedAddress( String hostname, int port )
{
return new AdvertisedSocketAddress( hostname, port ).toString();
}
}
Expand Up @@ -25,4 +25,12 @@ public ListenSocketAddress( String hostname, int port )
{
super( hostname, port );
}

/**
* Textual representation format for a listen socket address.
*/
public static String listenAddress( String hostname, int port )
{
return new ListenSocketAddress( hostname, port ).toString();
}
}
Expand Up @@ -66,19 +66,15 @@ public boolean isWildcard()
return WILDCARDS.contains( hostname );
}

public boolean isIPv6()
{
return hostname.contains( ":" );
}

@Override
public String toString()
{
if ( hostname.contains( ":" ) )
{
// for ipv6 addresses we use brackets, as is common
return format( "[%s]:%s", hostname, port );
}
else
{
// hostnames and ipv4 addresses do not use brackets
return format( "%s:%s", hostname, port );
}
return format( isIPv6() ? "[%s]:%s" : "%s:%s", hostname, port );
}

@Override
Expand Down
Expand Up @@ -41,7 +41,6 @@
import org.neo4j.causalclustering.helper.RobustJobSchedulerWrapper;
import org.neo4j.causalclustering.identity.ClusterId;
import org.neo4j.causalclustering.identity.MemberId;
import org.neo4j.graphdb.config.Setting;
import org.neo4j.helpers.AdvertisedSocketAddress;
import org.neo4j.helpers.ListenSocketAddress;
import org.neo4j.kernel.configuration.Config;
Expand All @@ -55,6 +54,7 @@
import static com.hazelcast.spi.properties.GroupProperty.MERGE_FIRST_RUN_DELAY_SECONDS;
import static com.hazelcast.spi.properties.GroupProperty.MERGE_NEXT_RUN_DELAY_SECONDS;
import static com.hazelcast.spi.properties.GroupProperty.OPERATION_CALL_TIMEOUT_MILLIS;
import static com.hazelcast.spi.properties.GroupProperty.PREFER_IPv4_STACK;
import static com.hazelcast.spi.properties.GroupProperty.WAIT_SECONDS_BEFORE_JOIN;
import static org.neo4j.causalclustering.core.CausalClusteringSettings.discovery_listen_address;
import static org.neo4j.causalclustering.core.CausalClusteringSettings.initial_discovery_members;
Expand Down Expand Up @@ -172,6 +172,11 @@ private HazelcastInstance createHazelcastInstance()
String.valueOf( minimumClusterSizeThatCanTolerateOneFaultForExpectedClusterSize() ) );
c.setProperty( LOGGING_TYPE.getName(), "none" );

if ( hazelcastAddress.isIPv6() )
{
c.setProperty( PREFER_IPv4_STACK.getName(), "false" );
}

c.setNetworkConfig( networkConfig );

MemberAttributeConfig memberAttributeConfig = HazelcastClusterTopology.buildMemberAttributes( myself, config );
Expand Down
Expand Up @@ -31,13 +31,13 @@
import org.neo4j.causalclustering.discovery.SharedDiscoveryService;
import org.neo4j.causalclustering.readreplica.ReadReplicaGraphDatabase;
import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.kernel.monitoring.Monitors;
import org.neo4j.test.rule.TestDirectory;

import static java.util.Collections.emptyList;
import static java.util.Collections.emptyMap;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.neo4j.causalclustering.discovery.Cluster.buildAddresses;
import static org.neo4j.helpers.collection.Iterators.set;
import static org.neo4j.helpers.collection.MapUtil.stringMap;
import static org.neo4j.kernel.impl.pagecache.PageSwapperFactoryForTesting.TEST_PAGESWAPPER_NAME;
import static org.neo4j.kernel.impl.store.format.RecordFormatSelector.defaultFormat;
Expand Down Expand Up @@ -65,8 +65,9 @@ public void shouldFailToStartWithCustomIOConfigurationInCoreModeTest() throws Ex
{
Map<String,String> extraParams =
stringMap( GraphDatabaseSettings.pagecache_swapper.name(), TEST_PAGESWAPPER_NAME );
CoreClusterMember clusterMember = new CoreClusterMember( 0, 3, buildAddresses( set( 0, 1, 2 ) ), discovery,
defaultFormat().toString(), storeDir.directory(), extraParams, emptyMap() );
CoreClusterMember clusterMember = new CoreClusterMember( 0, 3, emptyList(), discovery,
defaultFormat().toString(), storeDir.directory(), extraParams, emptyMap(),
"127.0.0.1", "localhost" );
clusterMember.start();
fail( "Should not have created database with custom IO configuration in Core Mode." );
}
Expand All @@ -85,8 +86,9 @@ public void shouldFailToStartWithCustomIOConfigurationInReadReplicaModeTest() th
Map<String,String> extraParams =
stringMap( GraphDatabaseSettings.pagecache_swapper.name(), TEST_PAGESWAPPER_NAME );
ReadReplica clusterMember =
new ReadReplica( storeDir.directory(), 2, discovery, buildAddresses( set( 0, 1, 2 ) ),
extraParams, emptyMap(), defaultFormat().toString() );
new ReadReplica( storeDir.directory(), 2, discovery, emptyList(),
extraParams, emptyMap(), defaultFormat().toString(), new Monitors(),
"127.0.0.1", "localhost" );
clusterMember.start();
fail( "Should not have created database with custom IO configuration in Read Replica Mode." );
}
Expand Down

0 comments on commit 272753e

Please sign in to comment.