db-jdo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m..@apache.org
Subject svn commit: r898066 - in /db/jdo/trunk/tck2/src: conf/ java/org/apache/jdo/tck/ java/org/apache/jdo/tck/api/persistencemanager/ java/org/apache/jdo/tck/query/api/
Date Mon, 11 Jan 2010 21:14:22 GMT
Author: mbo
Date: Mon Jan 11 21:14:20 2010
New Revision: 898066

URL: http://svn.apache.org/viewvc?rev=898066&view=rev
Log:
JDO-623: added DatastoreTimeout TCK testcase

Added:
    db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/api/persistencemanager/DatastoreTimeout.java
Removed:
    db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/query/api/QueryTimeout.java
Modified:
    db/jdo/trunk/tck2/src/conf/jdo-2_3-signatures.txt
    db/jdo/trunk/tck2/src/conf/jdori-pmf.properties
    db/jdo/trunk/tck2/src/conf/pm.conf
    db/jdo/trunk/tck2/src/conf/query.conf
    db/jdo/trunk/tck2/src/conf/security.policy
    db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/JDO_Test.java

Modified: db/jdo/trunk/tck2/src/conf/jdo-2_3-signatures.txt
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/conf/jdo-2_3-signatures.txt?rev=898066&r1=898065&r2=898066&view=diff
==============================================================================
--- db/jdo/trunk/tck2/src/conf/jdo-2_3-signatures.txt (original)
+++ db/jdo/trunk/tck2/src/conf/jdo-2_3-signatures.txt Mon Jan 11 21:14:20 2010
@@ -126,6 +126,8 @@
         = "javax.jdo.option.GetDataStoreConnection";
     static String OPTION_GET_JDBC_CONNECTION
         = "javax.jdo.option.GetJDBCConnection";
+    static String OPTION_DATASTORE_TIMEOUT
+        = "javax.jdo.option.DatastoreTimeout";
     static String OPTION_QUERY_SQL
         = "javax.jdo.query.SQL";
     static String OPTION_UNCONSTRAINED_QUERY_VARIABLES
@@ -781,8 +783,10 @@
     public varargs java.util.Set getManagedObjects(Class[] classes);
     public varargs java.util.Set getManagedObjects(java.util.EnumSet states, Class[] classes);
     javax.jdo.FetchGroup getFetchGroup(Class cls, String name);
-    public void setQueryTimeoutMillis(Integer interval);
-    public Integer getQueryTimeoutMillis();
+    public void setDatastoreReadTimeoutMillis(Integer interval);
+    public Integer getDatastoreReadTimeoutMillis();
+    public void setDatastoreWriteTimeoutMillis(Integer interval);
+    public Integer getDatastoreWriteTimeoutMillis();
 }
 
 public interface javax.jdo.PersistenceManagerFactory extends java.io.Serializable {
@@ -851,8 +855,10 @@
     public void registerMetadata(javax.jdo.metadata.JDOMetadata metadata);
     public javax.jdo.metadata.JDOMetadata newMetadata();
     public javax.jdo.metadata.TypeMetadata getMetadata(String className);
-    public void setQueryTimeoutMillis(Integer interval);
-    public Integer getQueryTimeoutMillis();
+    public void setDatastoreReadTimeoutMillis(Integer interval);
+    public Integer getDatastoreReadTimeoutMillis();
+    public void setDatastoreWriteTimeoutMillis(Integer interval);
+    public Integer getDatastoreWriteTimeoutMillis();
 }
 
 public interface javax.jdo.Query extends java.io.Serializable {
@@ -896,12 +902,14 @@
     public long deletePersistentAll();
     public void setUnmodifiable();
     public boolean isUnmodifiable();
-    public void setTimeoutMillis(Integer interval);
-    public Integer getTimeoutMillis();
     public void cancelAll();
     public void cancel(Thread);
     public Boolean getSerializeRead();
     public void setSerializeRead(Boolean);
+    public void setDatastoreReadTimeoutMillis(Integer interval);
+    public Integer getDatastoreReadTimeoutMillis();
+    public void setDatastoreWriteTimeoutMillis(Integer interval);
+    public Integer getDatastoreWriteTimeoutMillis();
 }
 
 public interface javax.jdo.spi.Detachable {

Modified: db/jdo/trunk/tck2/src/conf/jdori-pmf.properties
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/conf/jdori-pmf.properties?rev=898066&r1=898065&r2=898066&view=diff
==============================================================================
--- db/jdo/trunk/tck2/src/conf/jdori-pmf.properties (original)
+++ db/jdo/trunk/tck2/src/conf/jdori-pmf.properties Mon Jan 11 21:14:20 2010
@@ -43,3 +43,4 @@
 datanucleus.connectionPoolingType=C3P0
 datanucleus.implementationCreatorName=asm
 datanucleus.rdbms.omitDatabaseMetaDataGetColumns=true
+#datanucleus.query.JDOQL.implementation=JDOQL2

Modified: db/jdo/trunk/tck2/src/conf/pm.conf
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/conf/pm.conf?rev=898066&r1=898065&r2=898066&view=diff
==============================================================================
--- db/jdo/trunk/tck2/src/conf/pm.conf (original)
+++ db/jdo/trunk/tck2/src/conf/pm.conf Mon Jan 11 21:14:20 2010
@@ -27,6 +27,7 @@
 org.apache.jdo.tck.api.persistencemanager.DataStoreCacheTest \
 org.apache.jdo.tck.api.persistencemanager.DataStoreConnection \
 org.apache.jdo.tck.api.persistencemanager.DataStoreConnectionThrows \
+org.apache.jdo.tck.api.persistencemanager.DatastoreTimeout \
 org.apache.jdo.tck.api.persistencemanager.DeletePersistent \
 org.apache.jdo.tck.api.persistencemanager.DeletePersistentAllFails \
 org.apache.jdo.tck.api.persistencemanager.DeletePersistentFailsIfInstanceIsTransient \

Modified: db/jdo/trunk/tck2/src/conf/query.conf
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/conf/query.conf?rev=898066&r1=898065&r2=898066&view=diff
==============================================================================
--- db/jdo/trunk/tck2/src/conf/query.conf (original)
+++ db/jdo/trunk/tck2/src/conf/query.conf Mon Jan 11 21:14:20 2010
@@ -51,7 +51,6 @@
 org.apache.jdo.tck.query.api.NewQuerySingleString \
 org.apache.jdo.tck.query.api.QueryCancel \
 org.apache.jdo.tck.query.api.QueryExtentions \
-org.apache.jdo.tck.query.api.QueryTimeout \
 org.apache.jdo.tck.query.api.SetCandidateCollection \
 org.apache.jdo.tck.query.api.SetCandidateExtent \
 org.apache.jdo.tck.query.api.SetFilter \

Modified: db/jdo/trunk/tck2/src/conf/security.policy
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/conf/security.policy?rev=898066&r1=898065&r2=898066&view=diff
==============================================================================
--- db/jdo/trunk/tck2/src/conf/security.policy (original)
+++ db/jdo/trunk/tck2/src/conf/security.policy Mon Jan 11 21:14:20 2010
@@ -1,22 +1,22 @@
 // JUnit code base
-grant codeBase "file://${jdo.tck.junit.jarfile}" {
+grant codeBase "file:/D:/users\\michael\\.maven/repository/junit/jars/junit-3.8.1.jar" {
     permission java.io.FilePermission "${user.home}${/}junit.properties", "read";
 };
 
 // Springbeans code base
-grant codeBase "file://${jdo.tck.springbeans.jarfile}" {
+grant codeBase "file:/D:/users\\michael\\.maven/repository/org.springframework/jars/spring-beans-2.0.jar"
{
     permission java.lang.RuntimePermission "accessDeclaredMembers";
     permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
     permission java.lang.RuntimePermission "getClassLoader";
 };
 
 // Springcore code base
-grant codeBase "file://${jdo.tck.springcore.jarfile}" {
+grant codeBase "file:/D:/users\\michael\\.maven/repository/org.springframework/jars/spring-core-2.0.jar"
{
     permission java.lang.RuntimePermission "accessDeclaredMembers";
 };
 
 // TCK test classes
-grant codeBase "file://${jdo.tck.testclasses.dir}/-" {
+grant codeBase "file:/D:/projects/jdo/workspace/jdo/trunk/tck2/target/classes/-" {
     permission javax.jdo.spi.JDOPermission "closePersistenceManagerFactory";
     permission javax.jdo.spi.JDOPermission "setStateManager";
 // needed for Springbeans
@@ -26,18 +26,18 @@
 };
 
 // TCK PC enhanced classes
-grant codebase "file://${jdo.tck.enhanced.jarfile}" {
+grant codebase "file:/D:/projects/jdo/workspace/jdo/trunk/tck2/target/enhanced/-" {
     permission javax.jdo.spi.JDOPermission "setStateManager";
 };
 
 // JDO API code base
-grant codeBase "file://${jdo.api.jarfile}" {
+grant codeBase "file:/D:/users\\michael\\.maven/repository/javax.jdo/jars/jdo2-api-2.2-SNAPSHOT.jar"
{
     permission javax.jdo.spi.JDOPermission "getMetadata";
     permission javax.jdo.spi.JDOPermission "setStateManager";
 };
 
 // JDO RI code base
-grant codeBase "file://${jdo.tck.jdori.jarfile}" {
+grant codeBase "file:/D:/users\\michael\\.maven/repository/org.datanucleus/jars/datanucleus-core-1.0-SNAPSHOT.jar"
{
     permission javax.jdo.spi.JDOPermission "closePersistenceManagerFactory";
     permission javax.jdo.spi.JDOPermission "getMetadata";
     permission javax.jdo.spi.JDOPermission "setStateManager";
@@ -48,13 +48,13 @@
 };
 
 // JDO RI enhancer base
-grant codeBase "file://${jdo.tck.jdori.enhancer.jarfile}" {
+grant codeBase "file:/D:/users\\michael\\.maven/repository/org.datanucleus/jars/datanucleus-enhancer-1.0-SNAPSHOT.jar"
{
     permission java.lang.RuntimePermission "accessDeclaredMembers";
     permission java.lang.RuntimePermission "accessClassInPackage.sun.reflect";
 };
 
 // JDO RI store.rdbms code base
-grant codeBase "file://${jdo.tck.jdori.rdbms.jarfile}" {
+grant codeBase "file:/D:/users\\michael\\.maven/repository/org.datanucleus/jars/datanucleus-rdbms-1.0-SNAPSHOT.jar"
{
     permission java.lang.RuntimePermission "accessDeclaredMembers";
     permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
     permission java.lang.RuntimePermission "getClassLoader";

Modified: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/JDO_Test.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/JDO_Test.java?rev=898066&r1=898065&r2=898066&view=diff
==============================================================================
--- db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/JDO_Test.java (original)
+++ db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/JDO_Test.java Mon Jan 11 21:14:20 2010
@@ -878,6 +878,12 @@
             "javax.jdo.option.QueryCancel");
     }
 
+    /** Reports whether setting a Datastore timout is supported. */
+    public boolean isDatastoreTimeoutSupported() {
+        return supportedOptions.contains(
+            "javax.jdo.option.DatastoreTimeout");
+    }
+
     /** Reports whether a feature is supported */
     public boolean isSupported(String option) {
         return supportedOptions.contains(option);

Added: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/api/persistencemanager/DatastoreTimeout.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/api/persistencemanager/DatastoreTimeout.java?rev=898066&view=auto
==============================================================================
--- db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/api/persistencemanager/DatastoreTimeout.java
(added)
+++ db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/api/persistencemanager/DatastoreTimeout.java
Mon Jan 11 21:14:20 2010
@@ -0,0 +1,422 @@
+/*
+ * 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.jdo.tck.api.persistencemanager;
+
+import java.util.List;
+
+import junit.framework.AssertionFailedError;
+
+import javax.jdo.JDOFatalException;
+import javax.jdo.JDODataStoreException;
+import javax.jdo.JDOUnsupportedOptionException;
+import javax.jdo.PersistenceManager;
+import javax.jdo.Query;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.JDO_Test;
+import org.apache.jdo.tck.pc.mylib.PCPoint;
+import org.apache.jdo.tck.pc.mylib.PCRect;
+import org.apache.jdo.tck.util.BatchTestRunner;
+import org.apache.jdo.tck.util.ThreadExceptionHandler;
+
+/**
+ *<B>Title:</B> DatastoreTimeout
+ *<BR>
+ *<B>Keywords:</B> datastore timeout 
+ *<BR>
+ *<B>Assertion ID:</B> A??
+ *<BR>
+ *<B>Assertion Description: </B>
+ */
+
+public class DatastoreTimeout extends JDO_Test {
+
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A?? (DatastoreTimeout) failed: ";
+
+    /** Timeout value for datastore read */
+    private static Integer READ_TIMEOUT = new Integer(10);
+
+    /** Timeout value for datastore write */
+    private static Integer WRITE_TIMEOUT = new Integer(10);
+
+    /** Time for the main thread to sleep after starting a parallel thread. */
+    private static int MAIN_SLEEP_MILLIS = 1000;
+
+    /** Time for the parallel threads to sleep before commit. */
+    private static int THREAD_SLEEP_MILLIS = 7500;
+
+    /** Oid of the PCRect instance created by localSetUp */
+    private Object rectOid;
+
+    /** Oid of the first PCPOint instance created by localSetUp */
+    private Object point1Oid;
+
+    /** Oid of the second PCPoint instance created by localSetUp */
+    private Object point2Oid;
+
+    /**
+     * The <code>main</code> is called when the class
+     * is directly executed from the command line.
+     * @param args The arguments passed to the program.
+     */
+    public static void main(String[] args) {
+        BatchTestRunner.run(DatastoreTimeout.class);
+    }
+
+    /** Method testing DatastoreReadTimeout. */
+    public void testDatastoreReadTimeout() throws Exception {
+
+        // Thread executing the query
+        ThreadExceptionHandler group = new ThreadExceptionHandler();
+        ParallelWriter runnable = new ParallelWriter();
+        Thread t = new Thread(group, runnable, "Parallel Writer");
+        t.start();
+
+        // Wait for a second such that the other thread can lock the instancs
+        Thread.currentThread().sleep(MAIN_SLEEP_MILLIS);
+        
+        try {
+            runQueryReadingPCPointInstances();
+            runGetObjectByIdReadingPCPointInstance();
+            runNavigationalReadPCPointInstance();
+        }
+        finally {
+            t.join();
+            Throwable problem = group.getUncaughtException(t);
+            if (problem != null) {
+                if (problem instanceof AssertionFailedError)
+                    throw (AssertionFailedError)problem;
+                else
+                    throw new JDOFatalException( "Thread " + t.getName()+ 
+                                                 " results in exception ", problem);
+            }
+        }
+    }
+
+    /** Method testing DatastoreWriteTimeout. */
+    public void testDatastoreWriteTimeout() throws Exception {
+
+        // Thread executing the query
+        ThreadExceptionHandler group = new ThreadExceptionHandler();
+        ParallelReader runnable = new ParallelReader();
+        Thread t = new Thread(group, runnable, "Parallel Reader");
+        t.start();
+
+        // Wait for a second such that the other thread can lock the instancs
+        Thread.currentThread().sleep(MAIN_SLEEP_MILLIS);
+
+        try {
+            runUpdatePCointInstance();
+            runDeletePCPointInstance();
+            runDeletePCPointInstancesByQuery();
+        } 
+        finally {
+            t.join();
+            Throwable problem = group.getUncaughtException(t);
+            if (problem != null) {
+                if (problem instanceof AssertionFailedError)
+                    throw (AssertionFailedError)problem;
+                else
+                    throw new JDOFatalException( "Thread " + t.getName()+ 
+                                                 " results in exception ", problem);
+            }
+        }
+    }
+
+    /**
+     * @see JDO_Test#localSetUp()
+     */
+    protected void localSetUp() {
+        addTearDownClass(PCRect.class);
+        addTearDownClass(PCPoint.class);
+
+        getPM();
+        try {
+            Transaction tx = pm.currentTransaction();
+            tx.begin();
+            PCPoint p1 = new PCPoint(110, 120);
+            PCPoint p2 = new PCPoint(130, 140);
+            PCRect rect = new PCRect (0, p1, p2);
+            pm.makePersistent (rect);
+            tx.commit();
+            rectOid = pm.getObjectId(rect);
+            point1Oid = pm.getObjectId(p1);
+            point2Oid = pm.getObjectId(p2);
+        } 
+        finally {
+            cleanupPM();
+        }
+    }
+
+    // ----------------- Helper methods ---------------------------
+
+    /** DatastoreReadTimeout helper method: query reading PCPoint instance. */
+    private void runQueryReadingPCPointInstances() {
+        getPM();
+        try {
+            pm.currentTransaction().begin();
+            Query q = pm.newQuery(PCPoint.class);
+            q.setDatastoreReadTimeoutMillis(READ_TIMEOUT);
+            List result = (List)q.execute();
+            pm.currentTransaction().commit();
+            if (!isDatastoreTimeoutSupported()) {
+                fail(ASSERTION_FAILED, "Query.setDatastoreReadTimeoutMillis should throw
a " +
+                     "JDOUnsupportedOptionException, if datastore timeout is not supported
");
+            }
+        }
+        catch (JDOUnsupportedOptionException ex) {
+            if (isDatastoreTimeoutSupported()) {
+                fail(ASSERTION_FAILED, "Query.setDatastoreReadTimeoutMillis should not result
" + 
+                     "in a JDOUnsupportedOptionException, if datastore timeout is supported
");
+            }
+        }
+        catch (JDODataStoreException ex) {
+            if (!isDatastoreTimeoutSupported()) {
+                fail(ASSERTION_FAILED, "Query.execute should not result in a " +
+                     "JDODataStoreException, if datastore timeout is not supported.");
+            }
+        }
+        finally {
+            cleanupPM();
+        }
+    }
+
+    /** DatastoreReadTimeout helper method: getObjectById reading PCPoint instance. */
+    private void runGetObjectByIdReadingPCPointInstance() {
+        getPM();
+        try {
+            pm.currentTransaction().begin();
+            pm.setDatastoreReadTimeoutMillis(READ_TIMEOUT);
+            PCPoint point1 = (PCPoint)pm.getObjectById(point1Oid, true);
+            pm.currentTransaction().commit();
+            if (!isDatastoreTimeoutSupported()) {
+                fail(ASSERTION_FAILED, "PM.setDatastoreReadTimeoutMillis should throw a "
+
+                     "JDOUnsupportedOptionException, if datastore timeout is not supported
");
+            }
+        }
+        catch (JDOUnsupportedOptionException ex) {
+            if (isDatastoreTimeoutSupported()) {
+                fail(ASSERTION_FAILED, "PM.setDatastoreReadTimeoutMillis should not result
" + 
+                     "in a JDOUnsupportedOptionException, if datastore timeout is supported
");
+            }
+        }
+        catch (JDODataStoreException ex) {
+            if (!isDatastoreTimeoutSupported()) {
+                fail(ASSERTION_FAILED, "PM.getObjectById should not result in a " + 
+                     "JDODataStoreException, if datastore timeout is not supported.");
+            }
+        }
+        finally {
+            cleanupPM();
+        }
+    }
+
+    /** DatastoreReadTimeout helper method: navigation reading PCPoint instance. */
+    private void runNavigationalReadPCPointInstance() {
+        getPM();
+        try {
+            pm.currentTransaction().begin();
+            pm.setDatastoreReadTimeoutMillis(READ_TIMEOUT);
+            PCRect rect = (PCRect)pm.getObjectById(rectOid, true);
+            PCPoint p1 = rect.getUpperLeft();
+            p1.name();
+            pm.currentTransaction().commit();
+            if (!isDatastoreTimeoutSupported()) {
+                fail(ASSERTION_FAILED, "PM.setDatastoreReadTimeoutMillis should throw a "
+
+                     "JDOUnsupportedOptionException, if datastore timeout is not supported
");
+            }
+        }
+        catch (JDOUnsupportedOptionException ex) {
+            if (isDatastoreTimeoutSupported()) {
+                fail(ASSERTION_FAILED, "PM.setDatastoreReadTimeoutMillis should not result
" + 
+                     "in a JDOUnsupportedOptionException, if datastore timeout is supported
");
+            }
+        }
+        catch (JDODataStoreException ex) {
+            if (!isDatastoreTimeoutSupported()) {
+                fail(ASSERTION_FAILED, "Navigational access should not result in a " + 
+                     "JDODataStoreException, if datastore timeout is not supported.");
+            }
+        }
+        finally {
+            cleanupPM();
+        }
+    }
+
+    /** DatastoreWriteTimeout helper method: update PCPoint instance. */
+    private void runUpdatePCointInstance() {
+        getPM();
+        try {
+            pm.currentTransaction().begin();
+            pm.setDatastoreWriteTimeoutMillis(WRITE_TIMEOUT);
+            PCPoint point1 = (PCPoint)pm.getObjectById(point1Oid, true);
+            point1.setX(500);
+            pm.currentTransaction().commit();
+            if (!isDatastoreTimeoutSupported()) {
+                fail(ASSERTION_FAILED, "PM.setDatastoreWriteTimeoutMillis should throw a
" +
+                     "JDOUnsupportedOptionException, if datastore timeout is not supported
");
+            }
+        }
+        catch (JDOUnsupportedOptionException ex) {
+            if (isDatastoreTimeoutSupported()) {
+                fail(ASSERTION_FAILED, "PM.setDatastoreWriteTimeoutMillis should not result
" + 
+                     "in a JDOUnsupportedOptionException, if datastore timeout is supported
");
+            }
+        }
+        catch (JDODataStoreException ex) {
+            if (!isDatastoreTimeoutSupported()) {
+                fail(ASSERTION_FAILED, "PM.getObjectById should not result in a " + 
+                     "JDODataStoreException, if datastore timeout is not supported.");
+            }
+        }
+        finally {
+            cleanupPM();
+        }
+    }
+
+    /** DatastoreWriteTimeout helper method: delete PCPoint instance. */
+    private void runDeletePCPointInstance() {
+        getPM();
+        try {
+            pm.currentTransaction().begin();
+            pm.setDatastoreWriteTimeoutMillis(WRITE_TIMEOUT);
+            PCPoint point1 = (PCPoint)pm.getObjectById(point1Oid, true);
+            pm.deletePersistent(point1);
+            pm.currentTransaction().commit();
+            if (!isDatastoreTimeoutSupported()) {
+                fail(ASSERTION_FAILED, "PM.setDatastoreWriteTimeoutMillis should throw a
" +
+                     "JDOUnsupportedOptionException, if datastore timeout is not supported
");
+            }
+        }
+        catch (JDOUnsupportedOptionException ex) {
+            if (isDatastoreTimeoutSupported()) {
+                fail(ASSERTION_FAILED, "PM.setDatastoreWriteTimeoutMillis should not result
" + 
+                     "in a JDOUnsupportedOptionException, if datastore timeout is supported
");
+            }
+        }
+        catch (JDODataStoreException ex) {
+            if (!isDatastoreTimeoutSupported()) {
+                fail(ASSERTION_FAILED, "PM.getObjectById should not result in a " + 
+                     "JDODataStoreException, if datastore timeout is not supported.");
+            }
+        }
+        finally {
+            cleanupPM();
+        }
+    }    
+
+    /** DatastoreWriteTimeout helper method: delete by query. */
+    private void runDeletePCPointInstancesByQuery() {
+        getPM();
+        try {
+            pm.currentTransaction().begin();
+            Query q = pm.newQuery(PCPoint.class);
+            q.setDatastoreWriteTimeoutMillis(WRITE_TIMEOUT);
+            q.deletePersistentAll();
+            pm.currentTransaction().commit();
+            if (!isDatastoreTimeoutSupported()) {
+                fail(ASSERTION_FAILED, "Query.setDatastoreWriteTimeoutMillis should throw
a " +
+                     "JDOUnsupportedOptionException, if datastore timeout is not supported
");
+            }
+        }
+        catch (JDOUnsupportedOptionException ex) {
+            if (isDatastoreTimeoutSupported()) {
+                fail(ASSERTION_FAILED, "Query.setDatastoreWriteTimeoutMillis should not result
" + 
+                     "in a JDOUnsupportedOptionException, if datastore timeout is supported
");
+            }
+        }
+        catch (JDODataStoreException ex) {
+            if (!isDatastoreTimeoutSupported()) {
+                fail(ASSERTION_FAILED, "Query.deletePersistentAll should not result in a
" +
+                     "JDODataStoreException, if datastore timeout is not supported.");
+            }
+        }
+        finally {
+            cleanupPM();
+        }
+    }
+
+    // ------------- Helper classes -------------------------------
+
+    /** Runnable class updating instances and causing them to be read locked. */
+    class ParallelReader implements Runnable {
+
+        ParallelReader() { }
+
+        public void run() {
+            PersistenceManager parallelPM = getPMF().getPersistenceManager();
+            Transaction tx = parallelPM.currentTransaction();
+            // Run datastore transaction
+            tx.setOptimistic(false);
+            try {
+                tx.begin();
+                // read PCPoint instances
+                PCPoint p1 = (PCPoint)parallelPM.getObjectById(point1Oid, true);
+                p1.name();
+                PCPoint p2 = (PCPoint)parallelPM.getObjectById(point2Oid, true);
+                p2.name();
+                // Give the main thread a chance to try to write the instances
+                Thread.currentThread().sleep(THREAD_SLEEP_MILLIS);
+                tx.commit();
+            }
+            catch (InterruptedException ex) {
+                throw new RuntimeException(ex);
+            }
+            finally {
+                cleanupPM(parallelPM);
+            }
+        }
+    }
+
+    /** Runnable class updating instances and causing them to be write locked. */
+    class ParallelWriter implements Runnable {
+
+        ParallelWriter() { }
+
+        public void run() {
+            PersistenceManager parallelPM = getPMF().getPersistenceManager();
+            Transaction tx = parallelPM.currentTransaction();
+            // Run datastore transaction
+            tx.setOptimistic(false);
+            try {
+                tx.begin();
+                PCPoint p1 = (PCPoint)parallelPM.getObjectById(point1Oid);
+                p1.setX(210);
+                p1.setY(220);
+                PCPoint p2 = (PCPoint)parallelPM.getObjectById(point2Oid);
+                p2.setX(230);
+                p2.setY(240);
+                // Flush will set a write lock on the instances
+                parallelPM.flush();
+                // Give the main thread a chance to try to read the instances
+                Thread.currentThread().sleep(THREAD_SLEEP_MILLIS);
+                tx.commit();
+            } 
+            catch (InterruptedException ex) {
+                throw new RuntimeException(ex);
+            } 
+            finally {
+                cleanupPM(parallelPM);
+            }
+        }
+    }
+
+}
+



Mime
View raw message