Skip to content

Commit 5dc1780

Browse files
authored
[Internal] Allow interrupt for already interrupted transaction (#1397)
1 parent a3912a5 commit 5dc1780

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

driver/src/main/java/org/neo4j/driver/internal/async/UnmanagedTransaction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public boolean isOpen() {
179179
public void markTerminated(Throwable cause) {
180180
executeWithLock(lock, () -> {
181181
if (state == State.TERMINATED) {
182-
if (causeOfTermination != null) {
182+
if (causeOfTermination != null && cause != null) {
183183
addSuppressedWhenNotCaptured(causeOfTermination, cause);
184184
}
185185
} else {

driver/src/test/java/org/neo4j/driver/internal/async/UnmanagedTransactionTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import static org.neo4j.driver.testutil.TestUtil.await;
4444
import static org.neo4j.driver.testutil.TestUtil.beginMessage;
4545
import static org.neo4j.driver.testutil.TestUtil.connectionMock;
46+
import static org.neo4j.driver.testutil.TestUtil.setupFailingRun;
4647
import static org.neo4j.driver.testutil.TestUtil.setupSuccessfulRunAndPull;
4748
import static org.neo4j.driver.testutil.TestUtil.setupSuccessfulRunRx;
4849
import static org.neo4j.driver.testutil.TestUtil.verifyBeginTx;
@@ -69,6 +70,7 @@
6970
import org.neo4j.driver.exceptions.AuthorizationExpiredException;
7071
import org.neo4j.driver.exceptions.ClientException;
7172
import org.neo4j.driver.exceptions.ConnectionReadTimeoutException;
73+
import org.neo4j.driver.exceptions.Neo4jException;
7274
import org.neo4j.driver.internal.FailableCursor;
7375
import org.neo4j.driver.internal.InternalBookmark;
7476
import org.neo4j.driver.internal.messaging.BoltProtocol;
@@ -456,6 +458,27 @@ void shouldServeTheSameStageOnInterruptAsync() {
456458
assertEquals(stage0, stage1);
457459
}
458460

461+
@Test
462+
void shouldHandleInterruptionWhenAlreadyInterrupted() throws ExecutionException, InterruptedException {
463+
// Given
464+
var connection = connectionMock(BoltProtocolV4.INSTANCE);
465+
var exception = new Neo4jException("message");
466+
setupFailingRun(connection, exception);
467+
var tx = beginTx(connection);
468+
Throwable actualException = null;
469+
470+
// When
471+
try {
472+
tx.runAsync(new Query("RETURN 1")).toCompletableFuture().get();
473+
} catch (ExecutionException e) {
474+
actualException = e.getCause();
475+
}
476+
tx.interruptAsync().toCompletableFuture().get();
477+
478+
// Then
479+
assertEquals(exception, actualException);
480+
}
481+
459482
private static UnmanagedTransaction beginTx(Connection connection) {
460483
return beginTx(connection, Collections.emptySet());
461484
}

0 commit comments

Comments
 (0)