Skip to content

Commit

Permalink
Update tests to reflect breaking changes in 5.0 (neo4j#1163)
Browse files Browse the repository at this point in the history
  • Loading branch information
gjmwoods authored Feb 25, 2022
1 parent f4c3d6d commit 6cbfe71
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,17 @@ void shouldExplainConnectionError()
void shouldHandleFailureAtRunTime()
{
String label = UUID.randomUUID().toString(); // avoid clashes with other tests

String query = "CREATE CONSTRAINT ON (a:`" + label + "`) ASSERT a.name IS UNIQUE";
// given
Transaction tx = session.beginTransaction();
tx.run( "CREATE CONSTRAINT ON (a:`" + label + "`) ASSERT a.name IS UNIQUE" );
tx.run( query );
tx.commit();

// and
Transaction anotherTx = session.beginTransaction();

// then expect
ClientException e = assertThrows( ClientException.class, () -> anotherTx.run( "CREATE INDEX ON :`" + label + "`(name)" ) );
ClientException e = assertThrows( ClientException.class, () -> anotherTx.run( query ) );
anotherTx.rollback();
assertThat( e.getMessage(), containsString( label ) );
assertThat( e.getMessage(), containsString( "name" ) );
Expand Down
13 changes: 7 additions & 6 deletions driver/src/test/java/org/neo4j/driver/integration/SessionIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -770,9 +770,9 @@ void shouldThrowRunFailureImmediatelyAndCloseSuccessfully()
{
try ( Session session = neo4j.driver().session() )
{
ClientException e = assertThrows( ClientException.class, () -> session.run( "RETURN 10 / 0" ) );
ClientException e = assertThrows( ClientException.class, () -> session.run( "RETURN 1 * \"x\"" ) );

assertThat( e.getMessage(), containsString( "/ by zero" ) );
assertThat( e.getMessage(), containsString( "Type mismatch" ) );
}
}

Expand Down Expand Up @@ -804,9 +804,10 @@ void shouldThrowRunFailureImmediatelyAfterMultipleSuccessfulRunsAndCloseSuccessf
{
session.run( "CREATE ()" );
session.run( "CREATE ()" );
ClientException e = assertThrows( ClientException.class, () -> session.run( "RETURN 10 / 0" ) );

assertThat( e.getMessage(), containsString( "/ by zero" ) );
ClientException e = assertThrows( ClientException.class, () -> session.run( "RETURN 1 * \"x\"" ) );

assertThat( e.getMessage(), containsString( "Type mismatch" ) );
}
}

Expand All @@ -817,8 +818,8 @@ void shouldThrowRunFailureImmediatelyAndAcceptSubsequentRun()
{
session.run( "CREATE ()" );
session.run( "CREATE ()" );
ClientException e = assertThrows( ClientException.class, () -> session.run( "RETURN 10 / 0" ) );
assertThat( e.getMessage(), containsString( "/ by zero" ) );
ClientException e = assertThrows( ClientException.class, () -> session.run( "RETURN 1 * \"x\"" ) );
assertThat( e.getMessage(), containsString( "Type mismatch" ) );
session.run( "CREATE ()" );
}
}
Expand Down
12 changes: 6 additions & 6 deletions driver/src/test/java/org/neo4j/driver/integration/SummaryIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@
import java.util.List;
import java.util.concurrent.TimeUnit;

import org.neo4j.driver.Session;
import org.neo4j.driver.Result;
import org.neo4j.driver.Session;
import org.neo4j.driver.Value;
import org.neo4j.driver.Values;
import org.neo4j.driver.internal.util.EnabledOnNeo4jWith;
import org.neo4j.driver.internal.util.Neo4jFeature;
import org.neo4j.driver.summary.Notification;
import org.neo4j.driver.summary.Plan;
import org.neo4j.driver.summary.ProfiledPlan;
import org.neo4j.driver.summary.ResultSummary;
import org.neo4j.driver.summary.QueryType;
import org.neo4j.driver.summary.ResultSummary;
import org.neo4j.driver.util.DatabaseExtension;
import org.neo4j.driver.util.ParallelizableIT;

Expand Down Expand Up @@ -125,12 +125,12 @@ void shouldContainCorrectStatistics()
assertTrue( session.run( "CREATE (n {magic: 42})" ).consume().counters().containsUpdates() );
assertThat( session.run( "MATCH (n:ALabel) REMOVE n:ALabel " ).consume().counters().labelsRemoved(), equalTo( 1 ) );

assertThat( session.run( "CREATE INDEX ON :ALabel(prop)" ).consume().counters().indexesAdded(), equalTo( 1 ) );
assertThat( session.run( "DROP INDEX ON :ALabel(prop)" ).consume().counters().indexesRemoved(), equalTo( 1 ) );
assertThat( session.run( "CREATE INDEX superIndex FOR (n:ALabel) ON (n.prop)" ).consume().counters().indexesAdded(), equalTo( 1 ) );
assertThat( session.run( "DROP INDEX superIndex" ).consume().counters().indexesRemoved(), equalTo( 1 ) );

assertThat( session.run( "CREATE CONSTRAINT ON (book:Book) ASSERT book.isbn IS UNIQUE" )
assertThat( session.run( "CREATE CONSTRAINT restrictedConstraint ON (book:Book) ASSERT book.isbn IS UNIQUE" )
.consume().counters().constraintsAdded(), equalTo( 1 ) );
assertThat( session.run( "DROP CONSTRAINT ON (book:Book) ASSERT book.isbn IS UNIQUE" )
assertThat( session.run( "DROP CONSTRAINT restrictedConstraint" )
.consume().counters().constraintsRemoved(), equalTo( 1 ) );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -700,17 +700,17 @@ public CompletionStage<String> execute( AsyncTransaction tx )
@Test
void shouldNotPropagateRunFailureWhenClosed()
{
session.runAsync( "RETURN 10 / 0" );
session.runAsync( "RETURN 1 * \"x\"" );

await( session.closeAsync() );
}

@Test
void shouldPropagateRunFailureImmediately()
{
ClientException e = assertThrows( ClientException.class, () -> await( session.runAsync( "RETURN 10 / 0" ) ) );
ClientException e = assertThrows( ClientException.class, () -> await( session.runAsync( "RETURN 1 * \"x\"" ) ) );

assertThat( e.getMessage(), containsString( "/ by zero" ) );
assertThat( e.getMessage(), containsString( "Type mismatch" ) );
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ void shouldFailToCommitWhenQueriesFail()

tx.runAsync( "CREATE (:TestNode)" );
tx.runAsync( "CREATE (:TestNode)" );
tx.runAsync( "RETURN 10 / 0" );
tx.runAsync( "RETURN 1 * \"x\"" );
tx.runAsync( "CREATE (:TestNode)" );

ClientException e = assertThrows( ClientException.class, () -> await( tx.commitAsync() ) );
Expand All @@ -690,10 +690,10 @@ void shouldFailToCommitWhenBlockedRunFailed()
{
AsyncTransaction tx = await( session.beginTransactionAsync() );

ClientException runException = assertThrows( ClientException.class, () -> await( tx.runAsync( "RETURN 42 / 0" ) ) );
ClientException runException = assertThrows( ClientException.class, () -> await( tx.runAsync( "RETURN 1 * \"x\"" ) ) );

ClientException commitException = assertThrows( ClientException.class, () -> await( tx.commitAsync() ) );
assertThat( runException.getMessage(), containsString( "/ by zero" ) );
assertThat( runException.getMessage(), containsString( "Type mismatch" ) );
assertNoCircularReferences( commitException );
assertThat( commitException.getMessage(), containsString( "Transaction can't be committed" ) );
}
Expand All @@ -713,7 +713,7 @@ void shouldRollbackSuccessfullyWhenBlockedRunFailed()
{
AsyncTransaction tx = await( session.beginTransactionAsync() );

assertThrows( ClientException.class, () -> await( tx.runAsync( "RETURN 42 / 0" ) ) );
assertThrows( ClientException.class, () -> await( tx.runAsync( "RETURN 1 * \"x\"" ) ) );

await( tx.rollbackAsync() );
}
Expand Down

0 comments on commit 6cbfe71

Please sign in to comment.