Skip to content

Commit 4e92394

Browse files
authored
Migrate IT test to Testkit (#1094)
The following integration test has been converted to stub test: `CausalClusteringIT.shouldRediscoverWhenConnectionsToAllCoresBreak` -> `Routing.test_should_rediscover_when_all_connections_fail_using_s_and_tx_run`
1 parent 7a426ae commit 4e92394

File tree

3 files changed

+0
-225
lines changed

3 files changed

+0
-225
lines changed

driver/src/test/java/org/neo4j/driver/stress/CausalClusteringIT.java

Lines changed: 0 additions & 210 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
import java.util.ArrayList;
2828
import java.util.Arrays;
2929
import java.util.List;
30-
import java.util.Map;
31-
import java.util.Set;
3230
import java.util.concurrent.Callable;
3331
import java.util.concurrent.CompletionStage;
3432
import java.util.concurrent.CountDownLatch;
@@ -55,26 +53,20 @@
5553
import org.neo4j.driver.async.AsyncSession;
5654
import org.neo4j.driver.async.ResultCursor;
5755
import org.neo4j.driver.exceptions.ClientException;
58-
import org.neo4j.driver.exceptions.Neo4jException;
5956
import org.neo4j.driver.exceptions.ServiceUnavailableException;
6057
import org.neo4j.driver.exceptions.SessionExpiredException;
6158
import org.neo4j.driver.integration.NestedQueries;
62-
import org.neo4j.driver.internal.BoltServerAddress;
6359
import org.neo4j.driver.internal.cluster.RoutingSettings;
6460
import org.neo4j.driver.internal.retry.RetrySettings;
6561
import org.neo4j.driver.internal.security.SecurityPlanImpl;
6662
import org.neo4j.driver.internal.util.FailingConnectionDriverFactory;
6763
import org.neo4j.driver.internal.util.FakeClock;
68-
import org.neo4j.driver.internal.util.ServerVersion;
6964
import org.neo4j.driver.internal.util.ThrowingMessageEncoder;
7065
import org.neo4j.driver.internal.util.io.ChannelTrackingDriverFactory;
7166
import org.neo4j.driver.summary.ResultSummary;
7267
import org.neo4j.driver.util.cc.Cluster;
7368
import org.neo4j.driver.util.cc.ClusterExtension;
7469
import org.neo4j.driver.util.cc.ClusterMember;
75-
import org.neo4j.driver.util.cc.ClusterMemberRole;
76-
import org.neo4j.driver.util.cc.ClusterMemberRoleDiscoveryFactory;
77-
import org.neo4j.driver.util.cc.ClusterMemberRoleDiscoveryFactory.ClusterMemberRoleDiscovery;
7870

7971
import static java.util.concurrent.TimeUnit.MILLISECONDS;
8072
import static java.util.concurrent.TimeUnit.MINUTES;
@@ -96,7 +88,6 @@
9688
import static org.neo4j.driver.internal.InternalBookmark.parse;
9789
import static org.neo4j.driver.internal.logging.DevNullLogging.DEV_NULL_LOGGING;
9890
import static org.neo4j.driver.internal.util.Matchers.connectionAcquisitionTimeoutError;
99-
import static org.neo4j.driver.internal.util.Neo4jFeature.BOLT_V3;
10091
import static org.neo4j.driver.util.DaemonThreadFactory.daemon;
10192
import static org.neo4j.driver.util.TestUtil.await;
10293
import static org.neo4j.driver.util.TestUtil.awaitAllFutures;
@@ -481,61 +472,6 @@ RoutingSettings.DEFAULT, RetrySettings.DEFAULT, configWithoutLogging(), Security
481472
}
482473
}
483474

484-
@Test
485-
void shouldRediscoverWhenConnectionsToAllCoresBreak()
486-
{
487-
Cluster cluster = clusterRule.getCluster();
488-
489-
ChannelTrackingDriverFactory driverFactory = new ChannelTrackingDriverFactory();
490-
try ( Driver driver = driverFactory.newInstance( cluster.getRoutingUri(), clusterRule.getDefaultAuthToken(),
491-
RoutingSettings.DEFAULT, RetrySettings.DEFAULT, configWithoutLogging(), SecurityPlanImpl.insecure() ) )
492-
{
493-
String database = "neo4j";
494-
try ( Session session = driver.session( builder().withDatabase( database ).build() ) )
495-
{
496-
createNode( session, "Person", "name", "Vision" );
497-
498-
// force driver to connect to every cluster member
499-
for ( int i = 0; i < cluster.members().size(); i++ )
500-
{
501-
assertEquals( 1, countNodes( session, "Person", "name", "Vision" ) );
502-
}
503-
}
504-
505-
// now driver should have connections towards every cluster member
506-
// make all those connections throw and seem broken
507-
makeAllChannelsFailToRunQueries( driverFactory, ServerVersion.version( driver ) );
508-
509-
// observe that connection towards writer is broken
510-
try ( Session session = driver.session( builder().withDatabase( database ).withDefaultAccessMode( AccessMode.WRITE ).build() ) )
511-
{
512-
SessionExpiredException e = assertThrows( SessionExpiredException.class,
513-
() -> runCreateNode( session, "Person", "name", "Vision" ).consume() );
514-
assertEquals( "Disconnected", e.getCause().getMessage() );
515-
}
516-
517-
// probe connections to all readers
518-
int readersCount = cluster.followers().size() + cluster.readReplicas().size();
519-
for ( int i = 0; i < readersCount; i++ )
520-
{
521-
try ( Session session = driver.session( builder().withDatabase( database ).withDefaultAccessMode( AccessMode.READ ).build() ) )
522-
{
523-
runCountNodes( session, "Person", "name", "Vision" );
524-
}
525-
catch ( Throwable ignore )
526-
{
527-
}
528-
}
529-
530-
try ( Session session = driver.session( builder().withDatabase( database ).build() ) )
531-
{
532-
updateNode( session, "Person", "name", "Vision", "Thanos" );
533-
assertEquals( 0, countNodes( session, "Person", "name", "Vision" ) );
534-
assertEquals( 1, countNodes( session, "Person", "name", "Thanos" ) );
535-
}
536-
}
537-
}
538-
539475
@Test
540476
void shouldKeepOperatingWhenConnectionsBreak() throws Exception
541477
{
@@ -672,52 +608,6 @@ private <T> T inExpirableSession( Driver driver, Function<Driver,Session> acquir
672608
throw new TimeoutException( "Transaction did not succeed in time" );
673609
}
674610

675-
private void ensureNodeVisible( Cluster cluster, String name, Bookmark bookmark )
676-
{
677-
for ( ClusterMember member : cluster.members() )
678-
{
679-
int count = countNodesUsingDirectDriver( member, name, bookmark );
680-
assertEquals( 1, count );
681-
}
682-
}
683-
684-
private int countNodesUsingDirectDriver( ClusterMember member, final String name, Bookmark bookmark )
685-
{
686-
Driver driver = clusterRule.getCluster().getDirectDriver( member );
687-
try ( Session session = driver.session( builder().withBookmarks( bookmark ).build() ) )
688-
{
689-
return session.readTransaction( tx ->
690-
{
691-
Result result = tx.run( "MATCH (:Person {name: $name}) RETURN count(*)",
692-
parameters( "name", name ) );
693-
return result.single().get( 0 ).asInt();
694-
} );
695-
}
696-
}
697-
698-
private void awaitLeaderToStepDown( Set<ClusterMember> cores )
699-
{
700-
long deadline = System.currentTimeMillis() + DEFAULT_TIMEOUT_MS;
701-
ClusterOverview overview = null;
702-
do
703-
{
704-
for ( ClusterMember core : cores )
705-
{
706-
overview = fetchClusterOverview( core );
707-
if ( overview != null )
708-
{
709-
break;
710-
}
711-
}
712-
}
713-
while ( !isSingleFollowerWithReadReplicas( overview ) && System.currentTimeMillis() <= deadline );
714-
715-
if ( System.currentTimeMillis() > deadline )
716-
{
717-
throw new IllegalStateException( "Leader did not step down in " + DEFAULT_TIMEOUT_MS + "ms. Last seen cluster overview: " + overview );
718-
}
719-
}
720-
721611
private Driver createDriver( URI boltUri )
722612
{
723613
return createDriver( boltUri, configWithoutLogging() );
@@ -733,45 +623,6 @@ private Driver discoverDriver( List<URI> routingUris )
733623
return GraphDatabase.routingDriver( routingUris, clusterRule.getDefaultAuthToken(), configWithoutLogging() );
734624
}
735625

736-
private static ClusterOverview fetchClusterOverview( ClusterMember member )
737-
{
738-
int leaderCount = 0;
739-
int followerCount = 0;
740-
int readReplicaCount = 0;
741-
742-
Driver driver = clusterRule.getCluster().getDirectDriver( member );
743-
try
744-
{
745-
final ClusterMemberRoleDiscovery discovery = ClusterMemberRoleDiscoveryFactory.newInstance( ServerVersion.version( driver ) );
746-
final Map<BoltServerAddress,ClusterMemberRole> clusterOverview = discovery.findClusterOverview( driver );
747-
for ( BoltServerAddress address : clusterOverview.keySet() )
748-
{
749-
ClusterMemberRole role = clusterOverview.get( address );
750-
if ( role == ClusterMemberRole.LEADER )
751-
{
752-
leaderCount++;
753-
}
754-
else if ( role == ClusterMemberRole.FOLLOWER )
755-
{
756-
followerCount++;
757-
}
758-
else if ( role == ClusterMemberRole.READ_REPLICA )
759-
{
760-
readReplicaCount++;
761-
}
762-
else
763-
{
764-
throw new AssertionError( "Unknown role: " + role );
765-
}
766-
}
767-
return new ClusterOverview( leaderCount, followerCount, readReplicaCount );
768-
}
769-
catch ( Neo4jException ignore )
770-
{
771-
return null;
772-
}
773-
}
774-
775626
private static void createNodesInDifferentThreads( int count, final Driver driver ) throws Exception
776627
{
777628
final CountDownLatch beforeRunLatch = new CountDownLatch( count );
@@ -860,16 +711,6 @@ private static void createNode( Session session, String label, String property,
860711
} );
861712
}
862713

863-
private static void updateNode( Session session, String label, String property, String oldValue, String newValue )
864-
{
865-
session.writeTransaction( tx ->
866-
{
867-
tx.run( "MATCH (n: " + label + '{' + property + ": $oldValue}) SET n." + property + " = $newValue",
868-
parameters( "oldValue", oldValue, "newValue", newValue ) );
869-
return null;
870-
} );
871-
}
872-
873714
private static int countNodes( Session session, String label, String property, String value )
874715
{
875716
return session.readTransaction( tx -> runCountNodes( tx, label, property, value ) );
@@ -915,33 +756,6 @@ private static ExecutorService newExecutor()
915756
return Executors.newCachedThreadPool( daemon( CausalClusteringIT.class.getSimpleName() + "-thread-" ) );
916757
}
917758

918-
private static boolean isSingleFollowerWithReadReplicas( ClusterOverview overview )
919-
{
920-
if ( overview == null )
921-
{
922-
return false;
923-
}
924-
return overview.leaderCount == 0 &&
925-
overview.followerCount == 1 &&
926-
overview.readReplicaCount == ClusterExtension.READ_REPLICA_COUNT;
927-
}
928-
929-
private static void makeAllChannelsFailToRunQueries( ChannelTrackingDriverFactory driverFactory, ServerVersion dbVersion )
930-
{
931-
for ( Channel channel : driverFactory.channels() )
932-
{
933-
RuntimeException error = new ServiceUnavailableException( "Disconnected" );
934-
if ( BOLT_V3.availableIn( dbVersion ) )
935-
{
936-
channel.pipeline().addLast( ThrowingMessageEncoder.forRunWithMetadataMessage( error ) );
937-
}
938-
else
939-
{
940-
channel.pipeline().addLast( ThrowingMessageEncoder.forRunMessage( error ) );
941-
}
942-
}
943-
}
944-
945759
private static class RecordAndSummary
946760
{
947761
final Record record;
@@ -953,28 +767,4 @@ private static class RecordAndSummary
953767
this.summary = summary;
954768
}
955769
}
956-
957-
private static class ClusterOverview
958-
{
959-
final int leaderCount;
960-
final int followerCount;
961-
final int readReplicaCount;
962-
963-
ClusterOverview( int leaderCount, int followerCount, int readReplicaCount )
964-
{
965-
this.leaderCount = leaderCount;
966-
this.followerCount = followerCount;
967-
this.readReplicaCount = readReplicaCount;
968-
}
969-
970-
@Override
971-
public String toString()
972-
{
973-
return "ClusterOverview{" +
974-
"leaderCount=" + leaderCount +
975-
", followerCount=" + followerCount +
976-
", readReplicaCount=" + readReplicaCount +
977-
'}';
978-
}
979-
}
980770
}

driver/src/test/java/org/neo4j/driver/util/Neo4jSettings.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,6 @@ public Map<String, String> propertiesMap()
8686
return settings;
8787
}
8888

89-
public Neo4jSettings updateWith( Neo4jSettings other )
90-
{
91-
return updateWith( other.settings, other.excludes );
92-
}
93-
9489
public Neo4jSettings updateWith( String key, String value )
9590
{
9691
return updateWith( map(key, value), excludes );

driver/src/test/java/org/neo4j/driver/util/cc/ClusterControl.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,9 @@ static void stopCluster( Path path )
5252
executeCommand( "neoctrl-cluster", "stop", path.toString() );
5353
}
5454

55-
static void stopClusterMember( Path path )
56-
{
57-
executeCommand( "neoctrl-stop", path.toString() );
58-
}
59-
6055
static void killCluster( Path path )
6156
{
6257
executeCommand( "neoctrl-cluster", "stop", "--kill", path.toString() );
6358
}
6459

65-
static void killClusterMember( Path path )
66-
{
67-
executeCommand( "neoctrl-stop", "--kill", path.toString() );
68-
}
69-
7060
}

0 commit comments

Comments
 (0)