Skip to content

Commit bc95327

Browse files
authored
Migrate IT tests to Testkit (#1096)
Tests: - `CausalClusteringIT.beginTransactionThrowsForInvalidBookmark` -> `TestBookmarks.test_fails_on_invalid_bookmark`, a similar case is also covered by `Routing.test_should_fail_with_routing_failure_on_invalid_bookmark_discovery_failure` - `CausalClusteringIT.shouldAcceptMultipleBookmarks` -> `TestBookmarks.test_can_handle_multiple_bookmarks` - `CausalClusteringIT.bookmarksShouldWorkWithDriverPinnedToSingleServer` -> `TestBookmarks.test_can_pass_write_bookmark_into_write_session` (Similar test, the original had dependency on constant leader. The suggested test seems to closely match expectation of bookmark behaviour on a single node.) - `CausalClusteringIT.shouldUseBookmarkFromAReadSessionInAWriteSession` -> `TestBookmarks.test_can_pass_read_bookmark_into_write_session` (Similar test, the original had dependency on constant leader. The suggested test seems to closely match expectation of bookmark behaviour on a single node.) - `CausalClusteringIT.sessionCreationShouldFailIfCallingDiscoveryProcedureOnEdgeServer` -> `Routing.test_should_fail_discovery_when_router_fails_with_procedure_not_found_code` (Similar test, the original was actually skipped because builds run with 4.x series.)
1 parent ea9ce62 commit bc95327

File tree

1 file changed

+0
-165
lines changed

1 file changed

+0
-165
lines changed

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

-165
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@
4848
import org.neo4j.driver.Record;
4949
import org.neo4j.driver.Result;
5050
import org.neo4j.driver.Session;
51-
import org.neo4j.driver.Transaction;
52-
import org.neo4j.driver.Values;
5351
import org.neo4j.driver.async.AsyncSession;
5452
import org.neo4j.driver.async.ResultCursor;
5553
import org.neo4j.driver.exceptions.ClientException;
@@ -70,7 +68,6 @@
7068
import static java.util.concurrent.TimeUnit.MILLISECONDS;
7169
import static java.util.concurrent.TimeUnit.MINUTES;
7270
import static java.util.concurrent.TimeUnit.SECONDS;
73-
import static org.hamcrest.Matchers.containsString;
7471
import static org.hamcrest.Matchers.greaterThan;
7572
import static org.hamcrest.Matchers.is;
7673
import static org.hamcrest.junit.MatcherAssert.assertThat;
@@ -84,7 +81,6 @@
8481
import static org.neo4j.driver.Logging.none;
8582
import static org.neo4j.driver.SessionConfig.builder;
8683
import static org.neo4j.driver.Values.parameters;
87-
import static org.neo4j.driver.internal.InternalBookmark.parse;
8884
import static org.neo4j.driver.internal.logging.DevNullLogging.DEV_NULL_LOGGING;
8985
import static org.neo4j.driver.internal.util.Matchers.connectionAcquisitionTimeoutError;
9086
import static org.neo4j.driver.util.DaemonThreadFactory.daemon;
@@ -158,97 +154,6 @@ void shouldExecuteReadAndWritesWhenDriverSuppliedWithAddressOfFollower() throws
158154
assertEquals( 1, count );
159155
}
160156

161-
@Test
162-
void sessionCreationShouldFailIfCallingDiscoveryProcedureOnEdgeServer()
163-
{
164-
assertRoutingNotAvailableOnReadReplica();
165-
Cluster cluster = clusterRule.getCluster();
166-
167-
ClusterMember readReplica = cluster.anyReadReplica();
168-
final Driver driver = createDriver( readReplica.getRoutingUri() );
169-
ServiceUnavailableException e = assertThrows( ServiceUnavailableException.class, driver::verifyConnectivity );
170-
assertThat( e.getMessage(), containsString( "Unable to connect to database" ) );
171-
}
172-
173-
// Ensure that Bookmarks work with single instances using a driver created using a bolt[not+routing] URI.
174-
@Test
175-
void bookmarksShouldWorkWithDriverPinnedToSingleServer() throws Exception
176-
{
177-
Cluster cluster = clusterRule.getCluster();
178-
ClusterMember leader = cluster.leader();
179-
180-
try ( Driver driver = createDriver( leader.getBoltUri() ) )
181-
{
182-
Bookmark bookmark = inExpirableSession( driver, Driver::session, session ->
183-
{
184-
try ( Transaction tx = session.beginTransaction() )
185-
{
186-
tx.run( "CREATE (p:Person {name: $name })", Values.parameters( "name", "Alistair" ) );
187-
tx.commit();
188-
}
189-
190-
return session.lastBookmark();
191-
} );
192-
193-
assertNotNull( bookmark );
194-
195-
try ( Session session = driver.session( builder().withBookmarks( bookmark ).build() );
196-
Transaction tx = session.beginTransaction() )
197-
{
198-
Record record = tx.run( "MATCH (n:Person) RETURN COUNT(*) AS count" ).next();
199-
assertEquals( 1, record.get( "count" ).asInt() );
200-
tx.commit();
201-
}
202-
}
203-
}
204-
205-
@Test
206-
void shouldUseBookmarkFromAReadSessionInAWriteSession() throws Exception
207-
{
208-
Cluster cluster = clusterRule.getCluster();
209-
ClusterMember leader = cluster.leader();
210-
211-
try ( Driver driver = createDriver( leader.getBoltUri() ) )
212-
{
213-
inExpirableSession( driver, createWritableSession( null ), session ->
214-
{
215-
session.run( "CREATE (p:Person {name: $name })", Values.parameters( "name", "Jim" ) );
216-
return null;
217-
} );
218-
219-
final Bookmark bookmark;
220-
try ( Session session = driver.session( builder().withDefaultAccessMode( AccessMode.READ ).build() ) )
221-
{
222-
try ( Transaction tx = session.beginTransaction() )
223-
{
224-
tx.run( "MATCH (n:Person) RETURN COUNT(*) AS count" ).next();
225-
tx.commit();
226-
}
227-
228-
bookmark = session.lastBookmark();
229-
}
230-
231-
assertNotNull( bookmark );
232-
233-
inExpirableSession( driver, createWritableSession( bookmark ), session ->
234-
{
235-
try ( Transaction tx = session.beginTransaction() )
236-
{
237-
tx.run( "CREATE (p:Person {name: $name })", Values.parameters( "name", "Alistair" ) );
238-
tx.commit();
239-
}
240-
241-
return null;
242-
} );
243-
244-
try ( Session session = driver.session() )
245-
{
246-
Record record = session.run( "MATCH (n:Person) RETURN COUNT(*) AS count" ).next();
247-
assertEquals( 2, record.get( "count" ).asInt() );
248-
}
249-
}
250-
}
251-
252157
@Test
253158
void shouldDropBrokenOldConnections() throws Exception
254159
{
@@ -301,57 +206,6 @@ void shouldDropBrokenOldConnections() throws Exception
301206
}
302207
}
303208

304-
@Test
305-
void beginTransactionThrowsForInvalidBookmark()
306-
{
307-
final String text = "hi, this is an invalid bookmark";
308-
Bookmark invalidBookmark = parse( text );
309-
ClusterMember leader = clusterRule.getCluster().leader();
310-
311-
try ( Driver driver = createDriver( leader.getBoltUri() );
312-
Session session = driver.session( builder().withBookmarks( invalidBookmark ).build() ) )
313-
{
314-
ClientException e = assertThrows( ClientException.class, session::beginTransaction );
315-
assertThat( e.getMessage(), containsString( text ) );
316-
}
317-
}
318-
319-
@Test
320-
void shouldAcceptMultipleBookmarks() throws Exception
321-
{
322-
int threadCount = 5;
323-
String label = "Person";
324-
String property = "name";
325-
String value = "Alice";
326-
327-
Cluster cluster = clusterRule.getCluster();
328-
executor = newExecutor();
329-
330-
try ( Driver driver = createDriver( cluster.getRoutingUri() ) )
331-
{
332-
List<Future<Bookmark>> futures = new ArrayList<>();
333-
for ( int i = 0; i < threadCount; i++ )
334-
{
335-
futures.add( executor.submit( createNodeAndGetBookmark( driver, label, property, value ) ) );
336-
}
337-
338-
List<Bookmark> bookmarks = new ArrayList<>();
339-
for ( Future<Bookmark> future : futures )
340-
{
341-
bookmarks.add( future.get( 10, SECONDS ) );
342-
}
343-
344-
executor.shutdown();
345-
assertTrue( executor.awaitTermination( 5, SECONDS ) );
346-
347-
try ( Session session = driver.session( builder().withDefaultAccessMode( AccessMode.READ ).withBookmarks( bookmarks ).build() ) )
348-
{
349-
int count = countNodes( session, label, property, value );
350-
assertEquals( count, threadCount );
351-
}
352-
}
353-
}
354-
355209
@Test
356210
void shouldNotReuseReadConnectionForWriteTransaction()
357211
{
@@ -667,25 +521,6 @@ private static int countNodes( Session session, String label, String property, S
667521
return session.readTransaction( tx -> runCountNodes( tx, label, property, value ) );
668522
}
669523

670-
private static Callable<Bookmark> createNodeAndGetBookmark( Driver driver, String label, String property,
671-
String value )
672-
{
673-
return () -> createNodeAndGetBookmark( driver.session(), label, property, value );
674-
}
675-
676-
private static Bookmark createNodeAndGetBookmark( Session session, String label, String property, String value )
677-
{
678-
try ( Session localSession = session )
679-
{
680-
localSession.writeTransaction( tx ->
681-
{
682-
runCreateNode( tx, label, property, value );
683-
return null;
684-
} );
685-
return localSession.lastBookmark();
686-
}
687-
}
688-
689524
private static Result runCreateNode(QueryRunner queryRunner, String label, String property, String value )
690525
{
691526
return queryRunner.run( "CREATE (n:" + label + ") SET n." + property + " = $value", parameters( "value", value ) );

0 commit comments

Comments
 (0)