You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jdo-commits@db.apache.org by mb...@apache.org on 2024/06/04 18:43:44 UTC
(db-jdo) branch JDO-836 updated: JDO-836: test case takes datastore query canceling into account
This is an automated email from the ASF dual-hosted git repository.
mbo pushed a commit to branch JDO-836
in repository https://gitbox.apache.org/repos/asf/db-jdo.git
The following commit(s) were added to refs/heads/JDO-836 by this push:
new 6a427078 JDO-836: test case takes datastore query canceling into account
6a427078 is described below
commit 6a427078f77945d1d9495c62a577dedbdeb0e95c
Author: Michael Bouschen <Mi...@akquinet.de>
AuthorDate: Tue Jun 4 20:41:52 2024 +0200
JDO-836: test case takes datastore query canceling into account
- added option jdo.tck.datastore.supportsQueryCancel to RunTCK
- Changed test query to include group by and having
- Changed expected JDO exceptions in test case
---
.../main/java/org/apache/jdo/exectck/RunTCK.java | 19 ++++++++
.../org/apache/jdo/tck/query/api/QueryCancel.java | 54 +++++++++-------------
2 files changed, 41 insertions(+), 32 deletions(-)
diff --git a/exectck/src/main/java/org/apache/jdo/exectck/RunTCK.java b/exectck/src/main/java/org/apache/jdo/exectck/RunTCK.java
index d5fafb56..b2528e13 100644
--- a/exectck/src/main/java/org/apache/jdo/exectck/RunTCK.java
+++ b/exectck/src/main/java/org/apache/jdo/exectck/RunTCK.java
@@ -154,6 +154,10 @@ public class RunTCK extends AbstractTCKMojo {
@Parameter(property = "jdo.tck.parallel.execution", defaultValue = "true", required = true)
private boolean testParallelExecution;
+ /** Whether the datastore support query canceling. */
+ @Parameter(property = "jdo.tck.datastore.supportsQueryCancel", required = false)
+ private String datastoreSupportsQueryCancel;
+
/**
* Helper method returning the trimmed value of the specified property.
*
@@ -541,6 +545,7 @@ public class RunTCK extends AbstractTCKMojo {
command.add("-cp");
command.add(cpString);
command.addAll(cfgPropsString);
+ command.add(getDatastoreSupportsQueryCancelOption());
command.add(dbproperties);
command.add(jvmproperties);
if (debugTCK) {
@@ -706,4 +711,18 @@ public class RunTCK extends AbstractTCKMojo {
private boolean disableColors() {
return !this.testRunnerColors.equalsIgnoreCase("enable");
}
+
+ private String getDatastoreSupportsQueryCancelOption() {
+ boolean support = true;
+ if (datastoreSupportsQueryCancel == null || datastoreSupportsQueryCancel.isEmpty()) {
+ // property not set -> check database
+ String db = System.getProperty("jdo.tck.database");
+ if (db != null && db.equals("derby")) {
+ support = false;
+ }
+ } else {
+ support = datastoreSupportsQueryCancel.equalsIgnoreCase("true");
+ }
+ return "-Djdo.tck.datastore.supportsQueryCancel=" + support;
+ }
}
diff --git a/tck/src/main/java/org/apache/jdo/tck/query/api/QueryCancel.java b/tck/src/main/java/org/apache/jdo/tck/query/api/QueryCancel.java
index f42c7644..5430faa8 100644
--- a/tck/src/main/java/org/apache/jdo/tck/query/api/QueryCancel.java
+++ b/tck/src/main/java/org/apache/jdo/tck/query/api/QueryCancel.java
@@ -17,7 +17,6 @@
package org.apache.jdo.tck.query.api;
-import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;
import javax.jdo.JDOFatalException;
import javax.jdo.JDOQueryInterruptedException;
@@ -25,14 +24,12 @@ import javax.jdo.JDOUnsupportedOptionException;
import javax.jdo.PersistenceManager;
import javax.jdo.Query;
import javax.jdo.Transaction;
-
import org.apache.jdo.tck.pc.mylib.PCPoint;
import org.apache.jdo.tck.pc.mylib.PCPoint2;
import org.apache.jdo.tck.query.QueryTest;
import org.apache.jdo.tck.util.ThreadExceptionHandler;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.parallel.Execution;
@@ -58,22 +55,27 @@ import org.opentest4j.AssertionFailedError;
public class QueryCancel extends QueryTest {
/** Time for the main thread to sleep after starting a parallel thread. */
- private static final int MAIN_SLEEP_MILLIS = 1000;
+ private static final int MAIN_SLEEP_MILLIS = 100;
/** Number of instances to be created. */
private static final int NO_OF_INSTANCES = 5000;
+ protected static final boolean DATASTORE_SUPPORTS_QUERY_CANCEL =
+ System.getProperty("jdo.tck.datastore.supportsQueryCancel", "true").equalsIgnoreCase("true");
+
/** */
private static final String ASSERTION_FAILED = "Assertion A14.6.1-8 (QueryCancel) failed: ";
/** Single String JDOQL Query to be canceled. */
private static final String SSJDOQL =
- "select avg (this.x + point2.y) "
+ "select max (this.x) "
+ "from PCPoint "
- + "where this.y >= 0 && point2.x >= 0 "
- + "variables PCPoint2 point2 "
+ + "where point2.x >= 0 "
+ + "variables PCPoint point2 "
+ "import org.apache.jdo.tck.pc.mylib.PCPoint; "
- + "import org.apache.jdo.tck.pc.mylib.PCPoint2; ";
+ + "import org.apache.jdo.tck.pc.mylib.PCPoint2; "
+ + "group by this.x % 10 "
+ + "having max (this.x) > 2 ";
/**
* @throws Exception exception
@@ -81,7 +83,7 @@ public class QueryCancel extends QueryTest {
@SuppressWarnings("unchecked")
@Test
@Execution(ExecutionMode.CONCURRENT)
- public void testCancel() throws InterruptedException {
+ public void testCancel() throws Exception {
PersistenceManager pm = getPMF().getPersistenceManager();
try {
// Test query
@@ -103,23 +105,18 @@ public class QueryCancel extends QueryTest {
Thread.sleep(MAIN_SLEEP_MILLIS);
// cancel query
- long start = System.currentTimeMillis();
- logger.info("Start query cancel " + start);
query.cancel(t);
- long end = System.currentTimeMillis();
- logger.info("End query cancel " + end);
- logger.info(" Query cancel took " + (end -start) + "ms");
- if (!isQueryCancelSupported()) {
+ if (!isQueryCancelSupported() || !DATASTORE_SUPPORTS_QUERY_CANCEL) {
fail(
ASSERTION_FAILED,
- "Query.cancel should throw a JDOQueryInterruptedException, "
+ "Query.cancel should throw a JDOUnsupportedOptionException, "
+ "if query canceling is not supported ");
}
- } catch (JDOUnsupportedOptionException | InterruptedException | BrokenBarrierException ex) {
- if (isQueryCancelSupported()) {
+ } catch (JDOUnsupportedOptionException ex) {
+ if (isQueryCancelSupported() && DATASTORE_SUPPORTS_QUERY_CANCEL) {
fail(
ASSERTION_FAILED,
- "Query.cancel should not result in a JDOQueryInterruptedException, "
+ "Query.cancel should not result in a JDOUnsupportedOptionException, "
+ "if query canceling is supported ");
}
}
@@ -140,7 +137,6 @@ public class QueryCancel extends QueryTest {
* @throws Exception exception
*/
@SuppressWarnings("unchecked")
- @Disabled
@Test
@Execution(ExecutionMode.CONCURRENT)
public void testCancelAll() throws Exception {
@@ -166,18 +162,17 @@ public class QueryCancel extends QueryTest {
Thread.sleep(MAIN_SLEEP_MILLIS);
query.cancelAll();
- if (!isQueryCancelSupported()) {
+ if (!isQueryCancelSupported() || !DATASTORE_SUPPORTS_QUERY_CANCEL) {
fail(
ASSERTION_FAILED,
- "Query.cancel should throw a JDOQueryInterruptedException, "
+ "Query.cancel should throw a JDOUnsupportedOptionException, "
+ "if query canceling is not supported ");
}
} catch (JDOUnsupportedOptionException ex) {
- logger.info("caught " + ex);
- if (isQueryCancelSupported()) {
+ if (isQueryCancelSupported() && DATASTORE_SUPPORTS_QUERY_CANCEL) {
fail(
ASSERTION_FAILED,
- "Query.cancel should not result in a JDOQueryInterruptedException, "
+ "Query.cancel should not result in a JDOUnsupportedOptionException, "
+ "if query canceling is supported ");
}
}
@@ -215,22 +210,17 @@ public class QueryCancel extends QueryTest {
// wait for the other thread
barrier.await();
- long start = System.currentTimeMillis();
- QueryCancel.this.logger.info("Start query execute " + start);
Object result = query.execute();
- long end = System.currentTimeMillis();
- QueryCancel.this.logger.info("End query execute " + end);
- QueryCancel.this.logger.info("query execute took " + (end - start) + "ms");
tx.commit();
tx = null;
- if (isQueryCancelSupported()) {
+ if (isQueryCancelSupported() && DATASTORE_SUPPORTS_QUERY_CANCEL) {
fail(
ASSERTION_FAILED,
"Query.execute should result in a JDOQueryInterruptedException, "
+ "if query canceling is supported.");
}
} catch (JDOQueryInterruptedException ex) {
- if (!isQueryCancelSupported()) {
+ if (!isQueryCancelSupported() || !DATASTORE_SUPPORTS_QUERY_CANCEL) {
fail(
ASSERTION_FAILED,
"Query.execute should not result in a JDOQueryInterruptedException, "