Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 6a42707
Author: Michael Bouschen <[email protected]>
Date:   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

commit 293e4fb
Author: Michael Bouschen <[email protected]>
Date:   Mon Mar 4 21:09:01 2024 +0100

    JDO-836: Add cancel.conf and log Statments to QueryCancel
  • Loading branch information
mboapache committed Jul 14, 2024
1 parent 29a9809 commit fd36d0c
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 18 deletions.
19 changes: 19 additions & 0 deletions exectck/src/main/java/org/apache/jdo/exectck/RunTCK.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -541,6 +545,7 @@ private int executeTestClass(
command.add("-cp");
command.add(cpString);
command.addAll(cfgPropsString);
command.add(getDatastoreSupportsQueryCancelOption());
command.add(dbproperties);
command.add(jvmproperties);
if (debugTCK) {
Expand Down Expand Up @@ -706,4 +711,18 @@ private void finalizeTCKRun(String logDir, String cpString, String cfgDirName, i
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;
}
}
40 changes: 22 additions & 18 deletions tck/src/main/java/org/apache/jdo/tck/query/api/QueryCancel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -56,30 +55,35 @@
public class QueryCancel extends QueryTest {

/** Time for the main thread to sleep after starting a parallel thread. */
private static final int MAIN_SLEEP_MILLIS = 40;
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
*/
@SuppressWarnings("unchecked")
@Test
@Execution(ExecutionMode.CONCURRENT)
public void testCancel() throws InterruptedException {
public void testCancel() throws Exception {
PersistenceManager pm = getPMF().getPersistenceManager();
try {
// Test query
Expand All @@ -102,17 +106,17 @@ public void testCancel() throws InterruptedException {

// cancel query
query.cancel(t);
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 ");
}
}
Expand Down Expand Up @@ -158,17 +162,17 @@ public void testCancelAll() throws Exception {
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) {
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 ");
}
}
Expand Down Expand Up @@ -209,14 +213,14 @@ public void run() {
Object result = query.execute();
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, "
Expand Down
23 changes: 23 additions & 0 deletions tck/src/main/resources/conf/cancel.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 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.

jdo.tck.description = All query tests with standard mapping, no testdata.
jdo.tck.mapping.companyfactory =
jdo.tck.testdata =
jdo.tck.standarddata =
jdo.tck.mapping = 0
jdo.tck.requiredOptions =
jdo.tck.classes = \
org.apache.jdo.tck.query.api.QueryCancel

0 comments on commit fd36d0c

Please sign in to comment.