Skip to content

Commit

Permalink
For tests, in Cluster.java remove intended cluster size param.
Browse files Browse the repository at this point in the history
It is irrelevant.
  • Loading branch information
Max Sumrall committed Aug 26, 2016
1 parent ed427f6 commit e7dfe74
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 47 deletions.
Expand Up @@ -67,6 +67,7 @@ public class Cluster
{ {
private static final int DEFAULT_TIMEOUT_MS = 15_000; private static final int DEFAULT_TIMEOUT_MS = 15_000;
private static final int DEFAULT_BACKOFF_MS = 100; private static final int DEFAULT_BACKOFF_MS = 100;
public final int defaultClusterSize = 3;


private final File parentDir; private final File parentDir;
private final DiscoveryServiceFactory discoveryServiceFactory; private final DiscoveryServiceFactory discoveryServiceFactory;
Expand Down Expand Up @@ -124,15 +125,15 @@ public EdgeClusterMember getEdgeMemberById( int memberId )
return edgeMembers.get( memberId ); return edgeMembers.get( memberId );
} }


public CoreClusterMember addCoreMemberWithId( int memberId, int intendedClusterSize ) public CoreClusterMember addCoreMemberWithId( int memberId )
{ {
return addCoreMemberWithId( memberId, intendedClusterSize, stringMap(), emptyMap(), StandardV3_0.NAME ); return addCoreMemberWithId( memberId, stringMap(), emptyMap(), StandardV3_0.NAME );
} }


public CoreClusterMember addCoreMemberWithIdAndInitialMembers( int memberId, int intendedClusterSize, List<AdvertisedSocketAddress> public CoreClusterMember addCoreMemberWithIdAndInitialMembers( int memberId,
initialMembers ) List<AdvertisedSocketAddress> initialMembers )
{ {
CoreClusterMember coreClusterMember = new CoreClusterMember( memberId, intendedClusterSize, initialMembers, CoreClusterMember coreClusterMember = new CoreClusterMember( memberId, defaultClusterSize, initialMembers,
discoveryServiceFactory, StandardV3_0.NAME, parentDir, discoveryServiceFactory, StandardV3_0.NAME, parentDir,
emptyMap(), emptyMap() ); emptyMap(), emptyMap() );
coreMembers.put( memberId, coreClusterMember ); coreMembers.put( memberId, coreClusterMember );
Expand Down Expand Up @@ -296,11 +297,10 @@ public CoreClusterMember coreTx( BiConsumer<CoreGraphDatabase, Transaction> op )
return leaderTx( op ); return leaderTx( op );
} }


private CoreClusterMember addCoreMemberWithId( int memberId, int intendedClusterSize, private CoreClusterMember addCoreMemberWithId( int memberId, Map<String,String> extraParams, Map<String,IntFunction<String>> instanceExtraParams, String recordFormat )
Map<String,String> extraParams, Map<String,IntFunction<String>> instanceExtraParams, String recordFormat )
{ {
List<AdvertisedSocketAddress> advertisedAddress = buildAddresses( coreMembers.keySet() ); List<AdvertisedSocketAddress> advertisedAddress = buildAddresses( coreMembers.keySet() );
CoreClusterMember coreClusterMember = new CoreClusterMember( memberId, intendedClusterSize, advertisedAddress, CoreClusterMember coreClusterMember = new CoreClusterMember( memberId, defaultClusterSize, advertisedAddress,
discoveryServiceFactory, recordFormat, parentDir, discoveryServiceFactory, recordFormat, parentDir,
extraParams, instanceExtraParams ); extraParams, instanceExtraParams );
coreMembers.put( memberId, coreClusterMember ); coreMembers.put( memberId, coreClusterMember );
Expand Down
Expand Up @@ -26,9 +26,9 @@
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;


import org.neo4j.coreedge.discovery.Cluster;
import org.neo4j.coreedge.core.consensus.roles.Role;
import org.neo4j.coreedge.core.CoreGraphDatabase; import org.neo4j.coreedge.core.CoreGraphDatabase;
import org.neo4j.coreedge.core.consensus.roles.Role;
import org.neo4j.coreedge.discovery.Cluster;
import org.neo4j.graphdb.Transaction; import org.neo4j.graphdb.Transaction;
import org.neo4j.test.coreedge.ClusterRule; import org.neo4j.test.coreedge.ClusterRule;


Expand Down Expand Up @@ -66,7 +66,7 @@ public void shouldBeAbleToAddAndRemoveCoreMembers() throws Exception
assertEquals( 2, cluster.numberOfCoreMembersReportedByTopology() ); assertEquals( 2, cluster.numberOfCoreMembersReportedByTopology() );


// when // when
cluster.addCoreMemberWithId( 4, 3 ).start(); cluster.addCoreMemberWithId( 4 ).start();


// then // then
assertEquals( 3, cluster.numberOfCoreMembersReportedByTopology() ); assertEquals( 3, cluster.numberOfCoreMembersReportedByTopology() );
Expand Down Expand Up @@ -100,7 +100,7 @@ public void shouldBeAbleToAddAndRemoveCoreMembersUnderModestLoad() throws Except
assertEquals( 2, cluster.numberOfCoreMembersReportedByTopology() ); assertEquals( 2, cluster.numberOfCoreMembersReportedByTopology() );


// when // when
cluster.addCoreMemberWithId( 4, 3 ).start(); cluster.addCoreMemberWithId( 4 ).start();


// then // then
assertEquals( 3, cluster.numberOfCoreMembersReportedByTopology() ); assertEquals( 3, cluster.numberOfCoreMembersReportedByTopology() );
Expand All @@ -124,7 +124,7 @@ public void shouldBeAbleToRestartTheCluster() throws Exception
// when // when
cluster.removeCoreMemberWithMemberId( 1 ); cluster.removeCoreMemberWithMemberId( 1 );


cluster.addCoreMemberWithId( 3, 3 ).start(); cluster.addCoreMemberWithId( 3 ).start();
cluster.shutdown(); cluster.shutdown();


cluster.start(); cluster.start();
Expand Down
Expand Up @@ -29,9 +29,9 @@
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;


import org.neo4j.coreedge.core.CoreEdgeClusterSettings;
import org.neo4j.coreedge.discovery.Cluster; import org.neo4j.coreedge.discovery.Cluster;
import org.neo4j.coreedge.discovery.CoreClusterMember; import org.neo4j.coreedge.discovery.CoreClusterMember;
import org.neo4j.coreedge.core.CoreEdgeClusterSettings;
import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Node;
import org.neo4j.io.fs.DefaultFileSystemAbstraction; import org.neo4j.io.fs.DefaultFileSystemAbstraction;
import org.neo4j.io.pagecache.PageCache; import org.neo4j.io.pagecache.PageCache;
Expand Down Expand Up @@ -139,7 +139,7 @@ public void shouldNotJoinClusterIfHasDataWithDifferentStoreId() throws Exception
// WHEN // WHEN
try try
{ {
cluster.addCoreMemberWithId( 0, 3 ).start(); cluster.addCoreMemberWithId( 0 ).start();
fail( "Should not have joined the cluster" ); fail( "Should not have joined the cluster" );
} }
catch ( RuntimeException e ) catch ( RuntimeException e )
Expand Down Expand Up @@ -169,7 +169,7 @@ public void laggingFollowerShouldDownloadSnapshot() throws Exception
} }


// WHEN // WHEN
cluster.addCoreMemberWithId( 0, 3 ).start(); cluster.addCoreMemberWithId( 0 ).start();


cluster.awaitLeader(); cluster.awaitLeader();


Expand Down Expand Up @@ -206,7 +206,7 @@ public void badFollowerShouldNotJoinCluster() throws Exception
// WHEN // WHEN
try try
{ {
cluster.addCoreMemberWithId( 0, 3 ).start(); cluster.addCoreMemberWithId( 0 ).start();
fail( "Should not have joined the cluster" ); fail( "Should not have joined the cluster" );
} }
catch ( RuntimeException e ) catch ( RuntimeException e )
Expand Down Expand Up @@ -234,7 +234,7 @@ public void aNewServerShouldJoinTheClusterByDownloadingASnapshot() throws Except
} }


// WHEN // WHEN
cluster.addCoreMemberWithId( 4, 4 ).start(); cluster.addCoreMemberWithId( 4 ).start();


cluster.awaitLeader(); cluster.awaitLeader();


Expand Down
Expand Up @@ -58,9 +58,9 @@ public void newMemberNotInInitialMembersConfig() throws Throwable
List<AdvertisedSocketAddress> onlyServerZero = singletonList( Cluster.socketAddressForServer( 0 ) ); List<AdvertisedSocketAddress> onlyServerZero = singletonList( Cluster.socketAddressForServer( 0 ) );


// then // then
cluster.addCoreMemberWithIdAndInitialMembers( 3, 3, onlyServerZero ).start(); cluster.addCoreMemberWithIdAndInitialMembers( 3, onlyServerZero ).start();
cluster.addCoreMemberWithIdAndInitialMembers( 4, 3, onlyServerZero ).start(); cluster.addCoreMemberWithIdAndInitialMembers( 4, onlyServerZero ).start();
cluster.addCoreMemberWithIdAndInitialMembers( 5, 3, onlyServerZero ).start(); cluster.addCoreMemberWithIdAndInitialMembers( 5, onlyServerZero ).start();


cluster.removeCoreMemberWithMemberId( 0 ); cluster.removeCoreMemberWithMemberId( 0 );
cluster.removeCoreMemberWithMemberId( 1 ); cluster.removeCoreMemberWithMemberId( 1 );
Expand Down
Expand Up @@ -19,19 +19,19 @@
*/ */
package org.neo4j.coreedge.scenarios; package org.neo4j.coreedge.scenarios;


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Objects;

import org.hamcrest.FeatureMatcher; import org.hamcrest.FeatureMatcher;
import org.hamcrest.Matcher; import org.hamcrest.Matcher;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.Parameterized; import org.junit.runners.Parameterized;


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Objects;

import org.neo4j.collection.RawIterator; import org.neo4j.collection.RawIterator;
import org.neo4j.coreedge.discovery.Cluster; import org.neo4j.coreedge.discovery.Cluster;
import org.neo4j.coreedge.discovery.HazelcastDiscoveryServiceFactory; import org.neo4j.coreedge.discovery.HazelcastDiscoveryServiceFactory;
Expand All @@ -48,10 +48,8 @@
import org.neo4j.test.coreedge.ClusterRule; import org.neo4j.test.coreedge.ClusterRule;


import static java.util.concurrent.TimeUnit.SECONDS; import static java.util.concurrent.TimeUnit.SECONDS;

import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;

import static org.neo4j.kernel.api.proc.ProcedureSignature.procedureName; import static org.neo4j.kernel.api.proc.ProcedureSignature.procedureName;
import static org.neo4j.kernel.api.security.AccessMode.Static.READ; import static org.neo4j.kernel.api.security.AccessMode.Static.READ;
import static org.neo4j.test.assertion.Assert.assertEventually; import static org.neo4j.test.assertion.Assert.assertEventually;
Expand Down Expand Up @@ -146,8 +144,8 @@ public void shouldDiscoverNewCoreMembers() throws Exception
Cluster cluster = clusterRule.startCluster(); Cluster cluster = clusterRule.startCluster();


// when // when
cluster.addCoreMemberWithId( 3, 4 ).start(); cluster.addCoreMemberWithId( 3 ).start();
cluster.addCoreMemberWithId( 4, 5 ).start(); cluster.addCoreMemberWithId( 4 ).start();


Matcher<List<MemberInfo>> expected = allOf( Matcher<List<MemberInfo>> expected = allOf(
containsAddress( "127.0.0.1:8000" ), containsAddress( "127.0.0.1:8001" ), containsAddress( "127.0.0.1:8002" ), containsAddress( "127.0.0.1:8000" ), containsAddress( "127.0.0.1:8001" ), containsAddress( "127.0.0.1:8002" ),
Expand Down
Expand Up @@ -23,9 +23,9 @@
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;


import org.neo4j.coreedge.core.CoreGraphDatabase;
import org.neo4j.coreedge.discovery.Cluster; import org.neo4j.coreedge.discovery.Cluster;
import org.neo4j.coreedge.discovery.CoreClusterMember; import org.neo4j.coreedge.discovery.CoreClusterMember;
import org.neo4j.coreedge.core.CoreGraphDatabase;
import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Transaction; import org.neo4j.graphdb.Transaction;
import org.neo4j.test.coreedge.ClusterRule; import org.neo4j.test.coreedge.ClusterRule;
Expand Down Expand Up @@ -73,7 +73,7 @@ public void shouldReplicateTransactionsToCoreMembers() throws Exception
public void shouldReplicateTransactionToCoreMemberAddedAfterInitialStartUp() throws Exception public void shouldReplicateTransactionToCoreMemberAddedAfterInitialStartUp() throws Exception
{ {
// given // given
cluster.addCoreMemberWithId( 3, 4 ).start(); cluster.addCoreMemberWithId( 3 ).start();


cluster.coreTx( ( db, tx ) -> { cluster.coreTx( ( db, tx ) -> {
Node node = db.createNode(); Node node = db.createNode();
Expand All @@ -82,7 +82,7 @@ public void shouldReplicateTransactionToCoreMemberAddedAfterInitialStartUp() thr
} ); } );


// when // when
cluster.addCoreMemberWithId( 4, 5 ).start(); cluster.addCoreMemberWithId( 4 ).start();
CoreClusterMember last = cluster.coreTx( ( db, tx ) -> { CoreClusterMember last = cluster.coreTx( ( db, tx ) -> {
Node node = db.createNode(); Node node = db.createNode();
node.setProperty( "foobar", "baz_bat" ); node.setProperty( "foobar", "baz_bat" );
Expand Down Expand Up @@ -131,8 +131,8 @@ public void shouldReplicateToCoreMembersAddedAfterInitialTransactions() throws E
} ); } );
} }


cluster.addCoreMemberWithId( 3, 4 ).start(); cluster.addCoreMemberWithId( 3 ).start();
cluster.addCoreMemberWithId( 4, 5 ).start(); cluster.addCoreMemberWithId( 4 ).start();


// then // then
assertEquals( 15, countNodes( last ) ); assertEquals( 15, countNodes( last ) );
Expand All @@ -150,7 +150,7 @@ public void shouldReplicateTransactionsToReplacementCoreMembers() throws Excepti
} ); } );


cluster.removeCoreMemberWithMemberId( 0 ); cluster.removeCoreMemberWithMemberId( 0 );
CoreClusterMember replacement = cluster.addCoreMemberWithId( 0, 3 ); CoreClusterMember replacement = cluster.addCoreMemberWithId( 0 );
replacement.start(); replacement.start();


CoreClusterMember leader = cluster.coreTx( ( db, tx ) -> { CoreClusterMember leader = cluster.coreTx( ( db, tx ) -> {
Expand Down
Expand Up @@ -105,7 +105,7 @@ public void shouldBeAbleToDownloadToNewInstanceAfterPruning() throws Exception
leader = cluster.awaitLeader(); leader = cluster.awaitLeader();


int newDbId = 3; int newDbId = 3;
cluster.addCoreMemberWithId( newDbId, 3 ).start(); cluster.addCoreMemberWithId( newDbId ).start();
CoreGraphDatabase newDb = cluster.getCoreMemberById( newDbId ).database(); CoreGraphDatabase newDb = cluster.getCoreMemberById( newDbId ).database();


// then // then
Expand Down
Expand Up @@ -80,7 +80,7 @@ public void singleServerWithinClusterShouldBeConsistentAfterRestart() throws Exc
{ {
cluster.removeCoreMemberWithMemberId( i ); cluster.removeCoreMemberWithMemberId( i );
fireSomeLoadAtTheCluster( cluster ); fireSomeLoadAtTheCluster( cluster );
cluster.addCoreMemberWithId( i, clusterSize ).start(); cluster.addCoreMemberWithId( i ).start();
} }


cluster.shutdown(); cluster.shutdown();
Expand Down
Expand Up @@ -19,13 +19,13 @@
*/ */
package org.neo4j.coreedge.scenarios; package org.neo4j.coreedge.scenarios;


import org.junit.Rule;
import org.junit.Test;

import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;


import org.junit.Rule;
import org.junit.Test;

import org.neo4j.consistency.ConsistencyCheckService; import org.neo4j.consistency.ConsistencyCheckService;
import org.neo4j.coreedge.discovery.Cluster; import org.neo4j.coreedge.discovery.Cluster;
import org.neo4j.coreedge.discovery.CoreClusterMember; import org.neo4j.coreedge.discovery.CoreClusterMember;
Expand All @@ -41,7 +41,6 @@
import org.neo4j.test.coreedge.ClusterRule; import org.neo4j.test.coreedge.ClusterRule;


import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;

import static org.neo4j.coreedge.discovery.Cluster.dataMatchesEventually; import static org.neo4j.coreedge.discovery.Cluster.dataMatchesEventually;
import static org.neo4j.graphdb.Label.label; import static org.neo4j.graphdb.Label.label;


Expand All @@ -60,7 +59,7 @@ public void restartFirstServer() throws Exception


// when // when
cluster.removeCoreMemberWithMemberId( 0 ); cluster.removeCoreMemberWithMemberId( 0 );
cluster.addCoreMemberWithId( 0, 3 ); cluster.addCoreMemberWithId( 0 );


// then // then
cluster.shutdown(); cluster.shutdown();
Expand All @@ -74,7 +73,7 @@ public void restartSecondServer() throws Exception


// when // when
cluster.removeCoreMemberWithMemberId( 1 ); cluster.removeCoreMemberWithMemberId( 1 );
cluster.addCoreMemberWithId( 1, 3 ); cluster.addCoreMemberWithId( 1 );


// then // then
cluster.shutdown(); cluster.shutdown();
Expand Down Expand Up @@ -110,7 +109,7 @@ public void restartWhileDoingTransactions() throws Exception
Thread.sleep( 500 ); Thread.sleep( 500 );


cluster.removeCoreMemberWithMemberId( 1 ); cluster.removeCoreMemberWithMemberId( 1 );
cluster.addCoreMemberWithId( 1, 3 ); cluster.addCoreMemberWithId( 1 );
Thread.sleep( 500 ); Thread.sleep( 500 );


// then // then
Expand Down Expand Up @@ -156,7 +155,7 @@ public void edgeTest() throws Exception
tx.success(); tx.success();
} }


cluster.addCoreMemberWithId( 2, 3 ).start(); cluster.addCoreMemberWithId( 2 ).start();
cluster.shutdown(); cluster.shutdown();


for ( CoreClusterMember core : cluster.coreMembers() ) for ( CoreClusterMember core : cluster.coreMembers() )
Expand Down

0 comments on commit e7dfe74

Please sign in to comment.