Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate IT tests to Testkit #1096

Merged
merged 1 commit into from
Dec 3, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
165 changes: 0 additions & 165 deletions driver/src/test/java/org/neo4j/driver/stress/CausalClusteringIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@
import org.neo4j.driver.Record;
import org.neo4j.driver.Result;
import org.neo4j.driver.Session;
import org.neo4j.driver.Transaction;
import org.neo4j.driver.Values;
import org.neo4j.driver.async.AsyncSession;
import org.neo4j.driver.async.ResultCursor;
import org.neo4j.driver.exceptions.ClientException;
Expand All @@ -70,7 +68,6 @@
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.MINUTES;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.junit.MatcherAssert.assertThat;
Expand All @@ -84,7 +81,6 @@
import static org.neo4j.driver.Logging.none;
import static org.neo4j.driver.SessionConfig.builder;
import static org.neo4j.driver.Values.parameters;
import static org.neo4j.driver.internal.InternalBookmark.parse;
import static org.neo4j.driver.internal.logging.DevNullLogging.DEV_NULL_LOGGING;
import static org.neo4j.driver.internal.util.Matchers.connectionAcquisitionTimeoutError;
import static org.neo4j.driver.util.DaemonThreadFactory.daemon;
Expand Down Expand Up @@ -158,97 +154,6 @@ void shouldExecuteReadAndWritesWhenDriverSuppliedWithAddressOfFollower() throws
assertEquals( 1, count );
}

@Test
void sessionCreationShouldFailIfCallingDiscoveryProcedureOnEdgeServer()
{
assertRoutingNotAvailableOnReadReplica();
Cluster cluster = clusterRule.getCluster();

ClusterMember readReplica = cluster.anyReadReplica();
final Driver driver = createDriver( readReplica.getRoutingUri() );
ServiceUnavailableException e = assertThrows( ServiceUnavailableException.class, driver::verifyConnectivity );
assertThat( e.getMessage(), containsString( "Unable to connect to database" ) );
}

// Ensure that Bookmarks work with single instances using a driver created using a bolt[not+routing] URI.
@Test
void bookmarksShouldWorkWithDriverPinnedToSingleServer() throws Exception
{
Cluster cluster = clusterRule.getCluster();
ClusterMember leader = cluster.leader();

try ( Driver driver = createDriver( leader.getBoltUri() ) )
{
Bookmark bookmark = inExpirableSession( driver, Driver::session, session ->
{
try ( Transaction tx = session.beginTransaction() )
{
tx.run( "CREATE (p:Person {name: $name })", Values.parameters( "name", "Alistair" ) );
tx.commit();
}

return session.lastBookmark();
} );

assertNotNull( bookmark );

try ( Session session = driver.session( builder().withBookmarks( bookmark ).build() );
Transaction tx = session.beginTransaction() )
{
Record record = tx.run( "MATCH (n:Person) RETURN COUNT(*) AS count" ).next();
assertEquals( 1, record.get( "count" ).asInt() );
tx.commit();
}
}
}

@Test
void shouldUseBookmarkFromAReadSessionInAWriteSession() throws Exception
{
Cluster cluster = clusterRule.getCluster();
ClusterMember leader = cluster.leader();

try ( Driver driver = createDriver( leader.getBoltUri() ) )
{
inExpirableSession( driver, createWritableSession( null ), session ->
{
session.run( "CREATE (p:Person {name: $name })", Values.parameters( "name", "Jim" ) );
return null;
} );

final Bookmark bookmark;
try ( Session session = driver.session( builder().withDefaultAccessMode( AccessMode.READ ).build() ) )
{
try ( Transaction tx = session.beginTransaction() )
{
tx.run( "MATCH (n:Person) RETURN COUNT(*) AS count" ).next();
tx.commit();
}

bookmark = session.lastBookmark();
}

assertNotNull( bookmark );

inExpirableSession( driver, createWritableSession( bookmark ), session ->
{
try ( Transaction tx = session.beginTransaction() )
{
tx.run( "CREATE (p:Person {name: $name })", Values.parameters( "name", "Alistair" ) );
tx.commit();
}

return null;
} );

try ( Session session = driver.session() )
{
Record record = session.run( "MATCH (n:Person) RETURN COUNT(*) AS count" ).next();
assertEquals( 2, record.get( "count" ).asInt() );
}
}
}

@Test
void shouldDropBrokenOldConnections() throws Exception
{
Expand Down Expand Up @@ -301,57 +206,6 @@ void shouldDropBrokenOldConnections() throws Exception
}
}

@Test
void beginTransactionThrowsForInvalidBookmark()
{
final String text = "hi, this is an invalid bookmark";
Bookmark invalidBookmark = parse( text );
ClusterMember leader = clusterRule.getCluster().leader();

try ( Driver driver = createDriver( leader.getBoltUri() );
Session session = driver.session( builder().withBookmarks( invalidBookmark ).build() ) )
{
ClientException e = assertThrows( ClientException.class, session::beginTransaction );
assertThat( e.getMessage(), containsString( text ) );
}
}

@Test
void shouldAcceptMultipleBookmarks() throws Exception
{
int threadCount = 5;
String label = "Person";
String property = "name";
String value = "Alice";

Cluster cluster = clusterRule.getCluster();
executor = newExecutor();

try ( Driver driver = createDriver( cluster.getRoutingUri() ) )
{
List<Future<Bookmark>> futures = new ArrayList<>();
for ( int i = 0; i < threadCount; i++ )
{
futures.add( executor.submit( createNodeAndGetBookmark( driver, label, property, value ) ) );
}

List<Bookmark> bookmarks = new ArrayList<>();
for ( Future<Bookmark> future : futures )
{
bookmarks.add( future.get( 10, SECONDS ) );
}

executor.shutdown();
assertTrue( executor.awaitTermination( 5, SECONDS ) );

try ( Session session = driver.session( builder().withDefaultAccessMode( AccessMode.READ ).withBookmarks( bookmarks ).build() ) )
{
int count = countNodes( session, label, property, value );
assertEquals( count, threadCount );
}
}
}

@Test
void shouldNotReuseReadConnectionForWriteTransaction()
{
Expand Down Expand Up @@ -667,25 +521,6 @@ private static int countNodes( Session session, String label, String property, S
return session.readTransaction( tx -> runCountNodes( tx, label, property, value ) );
}

private static Callable<Bookmark> createNodeAndGetBookmark( Driver driver, String label, String property,
String value )
{
return () -> createNodeAndGetBookmark( driver.session(), label, property, value );
}

private static Bookmark createNodeAndGetBookmark( Session session, String label, String property, String value )
{
try ( Session localSession = session )
{
localSession.writeTransaction( tx ->
{
runCreateNode( tx, label, property, value );
return null;
} );
return localSession.lastBookmark();
}
}

private static Result runCreateNode(QueryRunner queryRunner, String label, String property, String value )
{
return queryRunner.run( "CREATE (n:" + label + ") SET n." + property + " = $value", parameters( "value", value ) );
Expand Down