From 31a84faba724accd71d447a0174f623ba53063f7 Mon Sep 17 00:00:00 2001 From: Deepika Valluru Date: Tue, 17 Nov 2026 15:50:48 +0530 Subject: [PATCH 1/2] GH-4408: Fix overall timeout for multiple update operations --- .../sparql/modify/UpdateEngineWorker.java | 2 +- .../modify/TestUpdateTimeoutMultiOp.java | 50 +++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 jena-arq/src/test/java/org/apache/jena/sparql/modify/TestUpdateTimeoutMultiOp.java diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/modify/UpdateEngineWorker.java b/jena-arq/src/main/java/org/apache/jena/sparql/modify/UpdateEngineWorker.java index b477919d6e6..1118d71e4fc 100644 --- a/jena-arq/src/main/java/org/apache/jena/sparql/modify/UpdateEngineWorker.java +++ b/jena-arq/src/main/java/org/apache/jena/sparql/modify/UpdateEngineWorker.java @@ -628,7 +628,7 @@ private void updateRemainingQueryTimeout(Context context) { } else { long currentTimeMillis = System.currentTimeMillis(); long elapsedMillis = currentTimeMillis - startTimeMillis; - remainingOverallTimeoutMillis -= elapsedMillis; + remainingOverallTimeoutMillis = timeout.overallTimeoutMillis() - elapsedMillis; if ( remainingOverallTimeoutMillis < 0 ) { remainingOverallTimeoutMillis = 0; } diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/modify/TestUpdateTimeoutMultiOp.java b/jena-arq/src/test/java/org/apache/jena/sparql/modify/TestUpdateTimeoutMultiOp.java new file mode 100644 index 00000000000..45f1ff62135 --- /dev/null +++ b/jena-arq/src/test/java/org/apache/jena/sparql/modify/TestUpdateTimeoutMultiOp.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.jena.sparql.modify; + +import java.util.concurrent.TimeUnit; + +import org.junit.jupiter.api.Test; + +import org.apache.jena.sparql.core.DatasetGraph; +import org.apache.jena.sparql.core.DatasetGraphFactory; +import org.apache.jena.sparql.exec.UpdateExec; +import org.apache.jena.sparql.sse.SSE; +import org.apache.jena.system.Txn; + +public class TestUpdateTimeoutMultiOp { + private static final String TWO_OPS = + "DELETE { ?s ?p ?o } WHERE { ?s ?p ?o } ;" + + "INSERT { ?s ?p ?o } WHERE { GRAPH { ?s ?p ?o } }"; + + @Test + public void update_timeout_two_operations() { + DatasetGraph dsg = DatasetGraphFactory.createTxnMem(); + + Txn.executeWrite(dsg, () -> + dsg.add(SSE.parseQuad("( :s :p :o)"))); + + Txn.executeWrite(dsg, () -> + UpdateExec.dataset(dsg) + .update(TWO_OPS) + .timeout(600, TimeUnit.SECONDS) + .execute()); + } +} From dd87e41e798499ef58901b010537045178e8be24 Mon Sep 17 00:00:00 2001 From: Deepika Valluru Date: Tue, 17 Nov 2026 17:39:39 +0530 Subject: [PATCH 2/2] GH-4408: Assert results of multiple update operations --- .../sparql/modify/TestUpdateTimeoutMultiOp.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/modify/TestUpdateTimeoutMultiOp.java b/jena-arq/src/test/java/org/apache/jena/sparql/modify/TestUpdateTimeoutMultiOp.java index 45f1ff62135..36f09eaeb95 100644 --- a/jena-arq/src/test/java/org/apache/jena/sparql/modify/TestUpdateTimeoutMultiOp.java +++ b/jena-arq/src/test/java/org/apache/jena/sparql/modify/TestUpdateTimeoutMultiOp.java @@ -29,6 +29,9 @@ import org.apache.jena.sparql.sse.SSE; import org.apache.jena.system.Txn; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + public class TestUpdateTimeoutMultiOp { private static final String TWO_OPS = "DELETE { ?s ?p ?o } WHERE { ?s ?p ?o } ;" @@ -38,13 +41,20 @@ public class TestUpdateTimeoutMultiOp { public void update_timeout_two_operations() { DatasetGraph dsg = DatasetGraphFactory.createTxnMem(); - Txn.executeWrite(dsg, () -> - dsg.add(SSE.parseQuad("( :s :p :o)"))); + Txn.executeWrite(dsg, () -> { + dsg.add(SSE.parseQuad("( :s :p :o)")); + dsg.getDefaultGraph().add(SSE.parseTriple("(:old :p :o)")); + }); Txn.executeWrite(dsg, () -> UpdateExec.dataset(dsg) .update(TWO_OPS) .timeout(600, TimeUnit.SECONDS) .execute()); + + Txn.executeRead(dsg, () -> { + assertTrue(dsg.getDefaultGraph().contains(SSE.parseTriple("(:s :p :o)"))); + assertFalse(dsg.getDefaultGraph().contains(SSE.parseTriple("(:old :p :o)"))); + }); } }