Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Internal] Allow interrupt for already interrupted transaction #1397

Merged
merged 1 commit into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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