Skip to content

Commit

Permalink
[Internal] Allow interrupt for already interrupted transaction (#1397)
Browse files Browse the repository at this point in the history
  • Loading branch information
injectives authored Mar 29, 2023
1 parent a3912a5 commit 5dc1780
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public boolean isOpen() {
public void markTerminated(Throwable cause) {
executeWithLock(lock, () -> {
if (state == State.TERMINATED) {
if (causeOfTermination != null) {
if (causeOfTermination != null && cause != null) {
addSuppressedWhenNotCaptured(causeOfTermination, cause);
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import static org.neo4j.driver.testutil.TestUtil.await;
import static org.neo4j.driver.testutil.TestUtil.beginMessage;
import static org.neo4j.driver.testutil.TestUtil.connectionMock;
import static org.neo4j.driver.testutil.TestUtil.setupFailingRun;
import static org.neo4j.driver.testutil.TestUtil.setupSuccessfulRunAndPull;
import static org.neo4j.driver.testutil.TestUtil.setupSuccessfulRunRx;
import static org.neo4j.driver.testutil.TestUtil.verifyBeginTx;
Expand All @@ -69,6 +70,7 @@
import org.neo4j.driver.exceptions.AuthorizationExpiredException;
import org.neo4j.driver.exceptions.ClientException;
import org.neo4j.driver.exceptions.ConnectionReadTimeoutException;
import org.neo4j.driver.exceptions.Neo4jException;
import org.neo4j.driver.internal.FailableCursor;
import org.neo4j.driver.internal.InternalBookmark;
import org.neo4j.driver.internal.messaging.BoltProtocol;
Expand Down Expand Up @@ -456,6 +458,27 @@ void shouldServeTheSameStageOnInterruptAsync() {
assertEquals(stage0, stage1);
}

@Test
void shouldHandleInterruptionWhenAlreadyInterrupted() throws ExecutionException, InterruptedException {
// Given
var connection = connectionMock(BoltProtocolV4.INSTANCE);
var exception = new Neo4jException("message");
setupFailingRun(connection, exception);
var tx = beginTx(connection);
Throwable actualException = null;

// When
try {
tx.runAsync(new Query("RETURN 1")).toCompletableFuture().get();
} catch (ExecutionException e) {
actualException = e.getCause();
}
tx.interruptAsync().toCompletableFuture().get();

// Then
assertEquals(exception, actualException);
}

private static UnmanagedTransaction beginTx(Connection connection) {
return beginTx(connection, Collections.emptySet());
}
Expand Down

0 comments on commit 5dc1780

Please sign in to comment.