|
28 | 28 | import org.neo4j.driver.internal.cluster.RoutingSettings;
|
29 | 29 | import org.neo4j.driver.internal.util.ChannelTrackingDriverFactory;
|
30 | 30 | import org.neo4j.driver.internal.util.Clock;
|
| 31 | +import org.neo4j.driver.v1.AuthTokens; |
31 | 32 | import org.neo4j.driver.v1.Config;
|
32 | 33 | import org.neo4j.driver.v1.Driver;
|
| 34 | +import org.neo4j.driver.v1.GraphDatabase; |
33 | 35 | import org.neo4j.driver.v1.Record;
|
34 | 36 | import org.neo4j.driver.v1.Session;
|
35 | 37 | import org.neo4j.driver.v1.StatementResult;
|
36 | 38 | import org.neo4j.driver.v1.Transaction;
|
37 | 39 | import org.neo4j.driver.v1.Value;
|
38 | 40 | import org.neo4j.driver.v1.exceptions.ClientException;
|
39 | 41 | import org.neo4j.driver.v1.exceptions.ServiceUnavailableException;
|
| 42 | +import org.neo4j.driver.v1.exceptions.TransientException; |
| 43 | +import org.neo4j.driver.v1.util.StubServer; |
40 | 44 | import org.neo4j.driver.v1.util.TestNeo4jSession;
|
41 | 45 | import org.neo4j.driver.v1.util.TestUtil;
|
42 | 46 |
|
@@ -385,6 +389,18 @@ public void shouldThrowWhenConnectionKilledDuringTransactionMarkedForSuccess()
|
385 | 389 | testFailWhenConnectionKilledDuringTransaction( true );
|
386 | 390 | }
|
387 | 391 |
|
| 392 | + @Test |
| 393 | + public void shouldThrowCommitError() throws Exception |
| 394 | + { |
| 395 | + testTxCloseErrorPropagation( "commit_error.script", true, "Unable to commit" ); |
| 396 | + } |
| 397 | + |
| 398 | + @Test |
| 399 | + public void shouldThrowRollbackError() throws Exception |
| 400 | + { |
| 401 | + testTxCloseErrorPropagation( "rollback_error.script", false, "Unable to rollback" ); |
| 402 | + } |
| 403 | + |
388 | 404 | private void testFailWhenConnectionKilledDuringTransaction( boolean markForSuccess )
|
389 | 405 | {
|
390 | 406 | ChannelTrackingDriverFactory factory = new ChannelTrackingDriverFactory( 1, Clock.SYSTEM );
|
@@ -420,4 +436,45 @@ private void testFailWhenConnectionKilledDuringTransaction( boolean markForSucce
|
420 | 436 |
|
421 | 437 | assertEquals( 0, session.run( "MATCH (n:MyNode {id: 1}) RETURN count(n)" ).single().get( 0 ).asInt() );
|
422 | 438 | }
|
| 439 | + |
| 440 | + private static void testTxCloseErrorPropagation( String script, boolean commit, String expectedErrorMessage ) |
| 441 | + throws Exception |
| 442 | + { |
| 443 | + StubServer server = StubServer.start( script, 9001 ); |
| 444 | + try |
| 445 | + { |
| 446 | + Config config = Config.build().withLogging( DEV_NULL_LOGGING ).withoutEncryption().toConfig(); |
| 447 | + try ( Driver driver = GraphDatabase.driver( "bolt://localhost:9001", AuthTokens.none(), config ); |
| 448 | + Session session = driver.session() ) |
| 449 | + { |
| 450 | + Transaction tx = session.beginTransaction(); |
| 451 | + StatementResult result = tx.run( "CREATE (n {name:'Alice'}) RETURN n.name AS name" ); |
| 452 | + assertEquals( "Alice", result.single().get( "name" ).asString() ); |
| 453 | + |
| 454 | + if ( commit ) |
| 455 | + { |
| 456 | + tx.success(); |
| 457 | + } |
| 458 | + else |
| 459 | + { |
| 460 | + tx.failure(); |
| 461 | + } |
| 462 | + |
| 463 | + try |
| 464 | + { |
| 465 | + tx.close(); |
| 466 | + fail( "Exception expected" ); |
| 467 | + } |
| 468 | + catch ( TransientException e ) |
| 469 | + { |
| 470 | + assertEquals( "Neo.TransientError.General.DatabaseUnavailable", e.code() ); |
| 471 | + assertEquals( expectedErrorMessage, e.getMessage() ); |
| 472 | + } |
| 473 | + } |
| 474 | + } |
| 475 | + finally |
| 476 | + { |
| 477 | + assertEquals( 0, server.exitStatus() ); |
| 478 | + } |
| 479 | + } |
423 | 480 | }
|
0 commit comments