db-jdo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From an...@apache.org
Subject svn commit: r1697862 - in /db/jdo/trunk/tck/src: conf/pm.conf java/org/apache/jdo/tck/api/persistencemanager/close/AutoCloseable.java java/org/apache/jdo/tck/api/persistencemanager/close/CloseWithActiveTxRollsBack.java
Date Wed, 26 Aug 2015 09:19:17 GMT
Author: andyj
Date: Wed Aug 26 09:19:16 2015
New Revision: 1697862

URL: http://svn.apache.org/r1697862
Log:
JDO-735 Add 2 new tests for PM close, and disabled previous JDO <= 3.1 test for PM.close

Added:
    db/jdo/trunk/tck/src/java/org/apache/jdo/tck/api/persistencemanager/close/AutoCloseable.java
    db/jdo/trunk/tck/src/java/org/apache/jdo/tck/api/persistencemanager/close/CloseWithActiveTxRollsBack.java
Modified:
    db/jdo/trunk/tck/src/conf/pm.conf

Modified: db/jdo/trunk/tck/src/conf/pm.conf
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck/src/conf/pm.conf?rev=1697862&r1=1697861&r2=1697862&view=diff
==============================================================================
--- db/jdo/trunk/tck/src/conf/pm.conf (original)
+++ db/jdo/trunk/tck/src/conf/pm.conf Wed Aug 26 09:19:16 2015
@@ -63,10 +63,11 @@ org.apache.jdo.tck.api.persistencemanage
 org.apache.jdo.tck.api.persistencemanager.cache.RefreshSideEffects \
 org.apache.jdo.tck.api.persistencemanager.cache.Retrieve \
 org.apache.jdo.tck.api.persistencemanager.close.AfterCloseAllMethodsThrowException \
-org.apache.jdo.tck.api.persistencemanager.close.CloseThrowsExceptionWhenActiveTx \
 org.apache.jdo.tck.api.persistencemanager.close.IsClosedIsFalseUponConstruction \
 org.apache.jdo.tck.api.persistencemanager.close.IsClosedIsFalseUponRetrievalFromPool \
 org.apache.jdo.tck.api.persistencemanager.close.IsClosedIsTrueAfterClose \
+org.apache.jdo.tck.api.persistencemanager.close.CloseWithActiveTxRollsBack \
+org.apache.jdo.tck.api.persistencemanager.close.AutoCloseable \
 org.apache.jdo.tck.api.persistencemanager.extent.GetExtentWithInstancesMadePersistentViaReachability
\
 org.apache.jdo.tck.api.persistencemanager.extent.GetExtentWithNoSubclasses \
 org.apache.jdo.tck.api.persistencemanager.extent.GetExtentWithSubclasses \

Added: db/jdo/trunk/tck/src/java/org/apache/jdo/tck/api/persistencemanager/close/AutoCloseable.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck/src/java/org/apache/jdo/tck/api/persistencemanager/close/AutoCloseable.java?rev=1697862&view=auto
==============================================================================
--- db/jdo/trunk/tck/src/java/org/apache/jdo/tck/api/persistencemanager/close/AutoCloseable.java
(added)
+++ db/jdo/trunk/tck/src/java/org/apache/jdo/tck/api/persistencemanager/close/AutoCloseable.java
Wed Aug 26 09:19:16 2015
@@ -0,0 +1,64 @@
+/*
+ * 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.close;
+
+import javax.jdo.JDOUserException;
+import javax.jdo.PersistenceManager;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.api.persistencemanager.PersistenceManagerTest;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> AutoCloseable
+ *<BR>
+ *<B>Keywords:</B> exception
+ *<BR>
+ *<B>Assertion IDs:</B> A12.6 ?.
+ *<BR>
+ *<B>Assertion Description: </B>
+In a non-managed environment, if the PM is created with try-with-resources then it is automatically
closed at the end of that block.
+ */
+
+public class AutoCloseable extends PersistenceManagerTest {
+    
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A12.6-? (AutoCloseable) failed: ";
+    
+    /**
+     * 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(AutoCloseable.class);
+    }
+
+    /** */
+    public void test() {
+
+        try (PersistenceManager pm1 = getPM())
+        {
+            pm = pm1;
+            assertFalse(pm.isClosed());
+        }
+
+        assertTrue(pm.isClosed());
+    }
+}

Added: db/jdo/trunk/tck/src/java/org/apache/jdo/tck/api/persistencemanager/close/CloseWithActiveTxRollsBack.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck/src/java/org/apache/jdo/tck/api/persistencemanager/close/CloseWithActiveTxRollsBack.java?rev=1697862&view=auto
==============================================================================
--- db/jdo/trunk/tck/src/java/org/apache/jdo/tck/api/persistencemanager/close/CloseWithActiveTxRollsBack.java
(added)
+++ db/jdo/trunk/tck/src/java/org/apache/jdo/tck/api/persistencemanager/close/CloseWithActiveTxRollsBack.java
Wed Aug 26 09:19:16 2015
@@ -0,0 +1,95 @@
+/*
+ * 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.close;
+
+import javax.jdo.JDOObjectNotFoundException;
+import javax.jdo.JDOUserException;
+import javax.jdo.PersistenceManager;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.api.persistencemanager.PersistenceManagerTest;
+import org.apache.jdo.tck.pc.mylib.PCPoint;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Close Throws Exception
+ *<BR>
+ *<B>Keywords:</B> exception
+ *<BR>
+ *<B>Assertion IDs:</B> A12.6-2.
+ *<BR>
+ *<B>Assertion Description: </B>
+In a non-managed environment, if the current transaction is active, close will roll back
the transaction.
+ */
+
+public class CloseWithActiveTxRollsBack extends PersistenceManagerTest {
+    
+    /** */
+    private static final String ASSERTION_FAILED = 
+        "Assertion A12.6-2 (CloseWithActiveTxRollsBack) failed: ";
+    
+    /**
+     * 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(CloseWithActiveTxRollsBack.class);
+    }
+
+    /** */
+    public void test() {
+        pm = getPM();
+        Transaction tx = pm.currentTransaction();
+        tx.begin();
+
+        Object id = null;
+		try {
+			PCPoint pc = new PCPoint(101, 200);
+			pm.makePersistent(pc);
+			id = pm.getObjectId(pc);
+
+			// This should rollback the transaction
+			pm.close();
+
+			assertFalse(tx.isActive());
+			assertTrue(pm.isClosed());
+        }
+		finally {
+            pm = null;
+			PersistenceManager pm2 = getPM();
+            pm2.currentTransaction().begin();
+			try {
+				try {
+					pm2.getObjectById(id);
+					fail("Object was persisted despite closing the PM. Active transaction should have rolled
back");
+				}
+				catch (JDOObjectNotFoundException onfe) {
+					// Expected, since rolled back
+				}
+			}
+			finally {
+                if (pm2.currentTransaction().isActive()) {
+                    pm2.currentTransaction().rollback();
+                }
+				pm2.close();
+                pm = null;
+			}
+		}
+    }
+}



Mime
View raw message