Added:
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/EvictingCollectionOfInstancesSideEffects.java
URL:
http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/EvictingCollectionOfInstancesSideEffects.java?view=auto&rev=160090
==============================================================================
---
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/EvictingCollectionOfInstancesSideEffects.java
(added)
+++
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/EvictingCollectionOfInstancesSideEffects.java
Mon Apr 4 12:41:23 2005
@@ -0,0 +1,202 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.cache;
+
+import java.util.Collection;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.api.persistencemanager.PersistenceManagerTest;
+import org.apache.jdo.tck.pc.mylib.PCPoint2;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> EvictingCollectionOfInstancesSideEffects
+ *<BR>
+ *<B>Keywords:</B> cache
+ *<BR>
+ *<B>Assertion IDs:</B> A12.5.1-4
+ *<BR>
+ *<B>Assertion Description: </B>
+ If PersistenceManager.evict is called with no parameter, then all referenced
instances are evicted. For each instance evicted, it:
+ *<UL>
+ *<LI> calls the jdoPreClearmethod on each instance, if the class of the
instance implements InstanceCallbacks </LI>
+ *<LI> clears persistent fields on each instance after the call to
jdoPreClear()</LI>
+ *<LI> changes the state of instances to hollow or persistent-nontransactional
(cannot distinguish between these two states) this is not directly testable.
</LI>
+ *</UL>
+
+ */
+
+public class EvictingCollectionOfInstancesSideEffects extends
PersistenceManagerTest {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A12.5.1-4 (EvictingCollectionOfInstancesSideEffects)
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(EvictingCollectionOfInstancesSideEffects.class);
+ }
+
+ private PCPoint2 pnt1 = null;
+ private PCPoint2 pnt2 = null;
+ private PCPoint2 p1 = null;
+ private PCPoint2 p2 = null;
+
+ /** */
+ public void testEvictingCollectionOfInstancesSideEffects() {
+ pm = getPM();
+ createObjects(pm);
+ runTestEvictAllCollection(pm);
+ runTestEvictAllArray(pm);
+ pm.close();
+ pm = null;
+ }
+
+ /** */
+ private void createObjects(PersistenceManager pm) {
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.begin();
+ pnt1 = new PCPoint2(1,2);
+ pnt2 = new PCPoint2(2,3);
+ p1 = new PCPoint2 (3,1);
+ p2 = new PCPoint2 (4,2);
+ pm.makePersistent(pnt1);
+ pm.makePersistent(pnt2);
+ pm.makePersistent(p1);
+ pm.makePersistent(p2);
+ tx.commit();
+
+ // P-nontransactional instance
+ // Check whether pmf supported optimitic tx
+ tx.setOptimistic(isOptimisticSupported());
+ tx.begin();
+ pnt1.getX();
+ pnt2.getX();
+ tx.commit();
+
+ /* P-clean instance */
+ tx.setOptimistic(false);
+ tx.begin();
+ p1.getX();
+ p2.getX();
+ tx.commit();
+ }
+ finally {
+ if (tx.isActive())
+ tx.rollback();
+ }
+ }
+
+ /** */
+ private void runTestEvictAllCollection(PersistenceManager pm) {
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.begin();
+
+ Collection col1 = new java.util.HashSet();
+ col1.add(pnt1);
+ col1.add(p1);
+
+ pm.evictAll(col1);
+
+ if ( !p1.wasClearCalled()) {
+ fail(ASSERTION_FAILED,
+ "missing call of p1.jdoPreClear during
pm.evictAll(Collection)");
+ }
+ if ( !pnt1.wasClearCalled()) {
+ fail(ASSERTION_FAILED,
+ "missing call of pnt1.jdoPreClear during
pm.evictAll(Collection)");
+ }
+
+ if ( testState(p1, HOLLOW, "hollow") ||
+ testState(p1, PERSISTENT_NONTRANSACTIONAL,
"persistent_nontransactional")) {
+ ; // expected result
+ }
+ else {
+ fail(ASSERTION_FAILED,
+ "p1 should be HOLLOW or P-NONTX after
pm.evictAll(Collection).");
+ }
+
+ if ( testState(pnt1, HOLLOW, "hollow") ||
+ testState(pnt1, PERSISTENT_NONTRANSACTIONAL,
"persistent_nontransactional")) {
+ ; // expected result
+ } else {
+ fail(ASSERTION_FAILED,
+ "pnt1 should be HOLLOW or P-NONTX after
pm.evictAll(Collection).");
+ }
+
+ tx.commit();
+ }
+ finally {
+ if (tx.isActive())
+ tx.rollback();
+ }
+ }
+
+ /** */
+ private void runTestEvictAllArray(PersistenceManager pm) {
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.begin();
+
+ Collection col1 = new java.util.HashSet();
+ col1.add(pnt2);
+ col1.add(p2);
+
+ pm.evictAll(col1.toArray());
+
+ if ( !p2.wasClearCalled()) {
+ fail(ASSERTION_FAILED,
+ "missing call of p2.jdoPreClear during
pm.evictAll(Object[])");
+ }
+ if ( !pnt2.wasClearCalled()) {
+ fail(ASSERTION_FAILED,
+ "missing call of pnt2.jdoPreClear during
pm.evictAll(Object[])");
+ }
+
+ if ( testState(p2, HOLLOW, "hollow") ||
+ testState(p2, PERSISTENT_NONTRANSACTIONAL,
"persistent_nontransactional")) {
+ ; // expected result
+ } else {
+ fail(ASSERTION_FAILED,
+ "p2 should be HOLLOW or P-NONTX after
pm.evictAll(Object[]).");
+ }
+
+ if ( testState(pnt2, HOLLOW, "hollow") ||
+ testState(pnt2, PERSISTENT_NONTRANSACTIONAL,
"persistent_nontransactional")) {
+ ; // expected result
+ } else {
+ fail(ASSERTION_FAILED,
+ "pnt2 should be HOLLOW or P-NONTX after
pm.evictAll(Object[]).");
+ }
+
+ tx.commit();
+ }
+ finally {
+ if (tx.isActive())
+ tx.rollback();
+ }
+ }
+}
Propchange:
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/EvictingCollectionOfInstancesSideEffects.java
------------------------------------------------------------------------------
svn:executable = *
Added:
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/EvictingWithRestoreValuesFalse.java
URL:
http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/EvictingWithRestoreValuesFalse.java?view=auto&rev=160090
==============================================================================
---
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/EvictingWithRestoreValuesFalse.java
(added)
+++
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/EvictingWithRestoreValuesFalse.java
Mon Apr 4 12:41:23 2005
@@ -0,0 +1,129 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.cache;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.api.persistencemanager.PersistenceManagerTest;
+import org.apache.jdo.tck.JDO_Test;
+import org.apache.jdo.tck.pc.mylib.PCPoint2;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Evicting With RestoreValues False
+ *<BR>
+ *<B>Keywords:</B> cache
+ *<BR>
+ *<B>Assertion ID:</B> A12.6.1-1.
+ *<BR>
+ *<B>Assertion Description: </B>
+If users wish to automatically <code>evict</code> transactional instances at
transaction
+<code>rollback</code> time, then they should set <code>RestoreValues</code> to
<code>false</code>.
+For each persistent-clean instance that the
+JDO <code>PersistenceManager</code> evicts, it:
+<UL>
+<LI>calls the <code>jdoPreClear</code> method on each instance,
+if the class of the instance implements <code>InstanceCallbacks</code></LI>
+<LI>clears persistent fields on each instance (sets the value of the field to
its Java default value)</LI>
+<LI>changes the state of instances to hollow</LI>
+</UL>
+
+ */
+
+public class EvictingWithRestoreValuesFalse extends JDO_Test {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A12.6.1-1 (EvictingWithRestoreValuesFalse) 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(EvictingWithRestoreValuesFalse.class);
+ }
+
+ /** */
+ public void test() {
+ pm = getPM();
+ PCPoint2 pt = getHollowInstance();
+
+ Transaction tx = pm.currentTransaction();
+ tx.setRestoreValues(false); //This should cause eviction of
transactional instances when transaction is later rolled back.
+
+ //Test
+ tx.begin();
+ makePersistentClean(pt);
+ tx.rollback(); // This should evict pt
+ verify(pt);
+ }
+
+ /** */
+ private PCPoint2 getHollowInstance() {
+ Transaction tx = pm.currentTransaction();
+ tx.begin();
+ PCPoint2 pt = new PCPoint2(1,2);
+ pm.makePersistent(pt);
+ tx.commit();
+
+ int curr = currentState(pt);
+ if (curr != HOLLOW){
+ fail(ASSERTION_FAILED,
+ "Unable to create HOLLOW instance, state is " +
states[curr]);
+ }
+ return pt;
+ }
+
+ /** */
+ private void makePersistentClean(PCPoint2 pt) {
+ pm.makeTransactional(pt);
+ int curr = currentState(pt);
+ if (curr != PERSISTENT_CLEAN){
+ fail(ASSERTION_FAILED,
+ "Unable to create PERSISTENT_CLEAN instance, state is " +
states[curr]);
+ }
+ }
+
+ /** */
+ private void verify(PCPoint2 pt) {
+ // When PersistenceManager evicts instances, it: calls the
jdoPreClear method on each instance
+ if ( !pt.wasClearCalled()) {
+ fail(ASSERTION_FAILED,
+ "missing call of jdoPreClear");
+ }
+
+ // When PersistenceManager evicts instances, it: changes the
state of the instances to hollow
+ int curr = currentState(pt);
+ if ( (curr != HOLLOW) && (curr != PERSISTENT_NONTRANSACTIONAL) ) {
+ fail(ASSERTION_FAILED,
+ "Instance should be HOLLOW after tx.rollback(), state is " +
states[curr]);
+ }
+
+ pm.makeTransient(pt);
+ // When PersistenceManager evicts instances, it: clears persistent
fields on each instance (sets the value of the field to its Java default value)
+ int x=pt.getX();
+ Integer y=pt.getY();
+ if ((x != 0) || (y != null)) {
+ fail(ASSERTION_FAILED,
+ "persistent fields not cleared, pt.getX()=="+x+" and
pt.getY()=="+y);
+ }
+ }
+}
Propchange:
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/EvictingWithRestoreValuesFalse.java
------------------------------------------------------------------------------
svn:executable = *
Added:
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/EvictingWithRetainValuesFalse.java
URL:
http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/EvictingWithRetainValuesFalse.java?view=auto&rev=160090
==============================================================================
---
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/EvictingWithRetainValuesFalse.java
(added)
+++
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/EvictingWithRetainValuesFalse.java
Mon Apr 4 12:41:23 2005
@@ -0,0 +1,135 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.cache;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.JDO_Test;
+import org.apache.jdo.tck.pc.mylib.PCPoint2;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Evicting With RetainValues False
+ *<BR>
+ *<B>Keywords:</B> cache
+ *<BR>
+ *<B>Assertion ID:</B> A12.5.1-3.
+ *<BR>
+ *<B>Assertion Description: </B>
+If users wish to automatically <code>evict</code> transactional instances at
transaction
+<code>commit</code> time, then they should set <code>RetainValues</code> to
<code>false</code>.
+For each persistent-clean instance that the
+JDO <code>PersistenceManager</code> evicts, it:
+<UL>
+<LI>calls the <code>jdoPreClear</code> method on each instance,
+if the class of the instance implements <code>InstanceCallbacks</code></LI>
+<LI>clears persistent fields on each instance (sets the value of the field to
its Java default value)</LI>
+<LI>changes the state of instances to hollow</LI>
+</UL>
+
+ */
+
+public class EvictingWithRetainValuesFalse extends JDO_Test {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A12.5.1-3 (EvictingWithRetainValuesFalse) 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(EvictingWithRetainValuesFalse.class);
+ }
+
+ /** */
+ public void test() {
+
+ if (!isRetainValuesSupported()) {
+
printUnsupportedOptionalFeatureNotTested("EvictingWithRetainValuesFalse",
"javax.jdo.option.RetainValues");
+ }
+ else
+ {
+ pm = getPM();
+ PCPoint2 pt = getHollowInstance();
+
+ Transaction tx = pm.currentTransaction();
+ tx.setRetainValues(false); //This should cause eviction
of transactional instances when transaction is later commited.
+
+ //Test
+ tx.begin();
+ makePersistentClean(pt);
+ tx.commit(); // This should evict pt
+ verify(pt);
+ }
+ }
+
+ /** */
+ private PCPoint2 getHollowInstance() {
+ Transaction tx = pm.currentTransaction();
+ tx.begin();
+ PCPoint2 pt = new PCPoint2(1,2);
+ pm.makePersistent(pt);
+ tx.commit();
+
+ int curr = currentState(pt);
+ if (curr != HOLLOW){
+ fail(ASSERTION_FAILED,
+ "Unable to create HOLLOW instance, state is " +
states[curr]);
+ }
+ return pt;
+ }
+
+ /** */
+ private void makePersistentClean(PCPoint2 pt) {
+ pm.makeTransactional(pt);
+ int curr = currentState(pt);
+ if (curr != PERSISTENT_CLEAN){
+ fail(ASSERTION_FAILED,
+ "Unable to create PERSISTENT_CLEAN instance, state is " +
states[curr]);
+ }
+ }
+
+ /** */
+ private void verify(PCPoint2 pt) {
+ // When PersistenceManager evicts instances, it: calls the
jdoPreClear method on each instance
+ if ( !pt.wasClearCalled()) {
+ fail(ASSERTION_FAILED,
+ "missing call of jdoPreClear");
+ }
+
+ // When PersistenceManager evicts instances, it: changes the
state of the instances to hollow
+ int curr = currentState(pt);
+ if ( (curr != HOLLOW) && (curr != PERSISTENT_NONTRANSACTIONAL) ) {
+ fail(ASSERTION_FAILED,
+ "Instance should be HOLLOW after tx.commit(), state is " +
states[curr]);
+ }
+
+ pm.makeTransient(pt);
+ // When PersistenceManager evicts instances, it: clears persistent
fields on each instance (sets the value of the field to its Java default value)
+ int x=pt.getX();
+ Integer y=pt.getY();
+ if ((x != 0) || (y != null)) {
+ fail(ASSERTION_FAILED,
+ "persistent fields not cleared, pt.getX()=="+x+" and
pt.getY()=="+y);
+ }
+ }
+}
Propchange:
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/EvictingWithRetainValuesFalse.java
------------------------------------------------------------------------------
svn:executable = *
Added:
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/PassingNullToEvictAllThrowsException.java
URL:
http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/PassingNullToEvictAllThrowsException.java?view=auto&rev=160090
==============================================================================
---
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/PassingNullToEvictAllThrowsException.java
(added)
+++
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/PassingNullToEvictAllThrowsException.java
Mon Apr 4 12:41:23 2005
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.cache;
+
+import java.util.Collection;
+
+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> PassingNullToEvictAllThrowsException
+ *<BR>
+ *<B>Keywords:</B>
+ *<BR>
+ *<B>Assertion IDs:</B> A12.5-9
+ *<BR>
+ *<B>Assertion Description: </B>
+Passing a null valued argument to evictAll will throw a NullPointerException.
+
+ */
+
+public class PassingNullToEvictAllThrowsException extends
PersistenceManagerTest {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A12.5-9 (PassingNullToEvictAllThrowsException) 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(PassingNullToEvictAllThrowsException.class);
+ }
+
+ /** */
+ public void testPassingNullToEvictAllThrowsException() {
+ pm = getPM();
+
+ runTestEvictAll1(pm);
+ runTestEvictAll2(pm);
+
+ pm.close();
+ pm = null;
+ }
+
+ /* test evictAll (Collection pcs) */
+ private void runTestEvictAll1(PersistenceManager pm) {
+ Transaction tx = pm.currentTransaction();
+ if (debug) logger.debug ("** in runTestEvictAll1() ");
+ try {
+ tx.begin();
+ Collection col1 = null;
+ try {
+ pm.evictAll(col1);
+ fail(ASSERTION_FAILED,
+ "pm.evictAll should throw NullPointerException when
called with argument null");
+ }
+ catch (NullPointerException ex) {
+ // expected exception
+ }
+ tx .rollback();
+ tx = null;
+ }
+ finally {
+ if ((tx != null) && tx.isActive())
+ tx.rollback();
+ }
+ }
+
+ /* test evictAll (Object[] objArray) */
+ private void runTestEvictAll2(PersistenceManager pm) {
+ Transaction tx = pm.currentTransaction();
+ if (debug) logger.debug ("** in runTestEvictAll1() ");
+ try {
+ tx.begin();
+ Object[] arr = null;
+ try {
+ pm.evictAll(arr);
+ fail(ASSERTION_FAILED,
+ "pm.evictAll should throw NullPointerException when
called with argument null");
+ }
+ catch (NullPointerException ex) {
+ // expected exception
+ }
+ tx .rollback();
+ tx = null;
+ }
+ finally {
+ if ((tx != null) && tx.isActive())
+ tx.rollback();
+ }
+ }
+}
Propchange:
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/PassingNullToEvictAllThrowsException.java
------------------------------------------------------------------------------
svn:executable = *
Added:
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/PassingNullToEvictHasNoEffect.java
URL:
http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/PassingNullToEvictHasNoEffect.java?view=auto&rev=160090
==============================================================================
---
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/PassingNullToEvictHasNoEffect.java
(added)
+++
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/PassingNullToEvictHasNoEffect.java
Mon Apr 4 12:41:23 2005
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.cache;
+
+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> PassingNullToEvictHasNoEffect
+ *<BR>
+ *<B>Keywords:</B>
+ *<BR>
+ *<B>Assertion IDs:</B> A12.5-7
+ *<BR>
+ *<B>Assertion Description: </B>
+Passing a null value to PersistenceManager.evict will have no effect. A
+NullPointerException should NOT be thrown.
+
+ */
+
+public class PassingNullToEvictHasNoEffect extends PersistenceManagerTest {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A12.5-7 (PassingNullToEvictHasNoEffect) 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(PassingNullToEvictHasNoEffect.class);
+ }
+
+ /** */
+ public void test() {
+ pm = getPM();
+
+ runTestPassingNullToEvictHasNoEffect(pm);
+
+ pm.close();
+ pm = null;
+ }
+
+ /* test evict (object pc) */
+ public void runTestPassingNullToEvictHasNoEffect(PersistenceManager pm) {
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.begin();
+ pm.evict(null);
+ if (debug)
+ logger.debug (" \nPASSED in
testPassingNullToEvictHasNoEffect()");
+ tx.rollback();
+ tx = null;
+ }
+ finally {
+ if ((tx != null) && tx.isActive())
+ tx.rollback();
+ }
+ }
+}
Propchange:
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/PassingNullToEvictHasNoEffect.java
------------------------------------------------------------------------------
svn:executable = *
Added:
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/PassingNullToRefreshAllThrowsException.java
URL:
http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/PassingNullToRefreshAllThrowsException.java?view=auto&rev=160090
==============================================================================
---
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/PassingNullToRefreshAllThrowsException.java
(added)
+++
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/PassingNullToRefreshAllThrowsException.java
Mon Apr 4 12:41:23 2005
@@ -0,0 +1,116 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.cache;
+
+import java.util.Collection;
+
+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> Passing Null to RefreshAll Throws Exception
+ *<BR>
+ *<B>Keywords:</B> cache
+ *<BR>
+ *<B>Assertion IDs:</B> A12.5-10.
+ *<BR>
+ *<B>Assertion Description: </B>
+Passing a null valued argument to refreshAll will throw a
+NullPointerException.
+
+ */
+
+public class PassingNullToRefreshAllThrowsException
+ extends PersistenceManagerTest {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A12.5-10 (PassingNullToRefreshAllThrowsException) 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(PassingNullToRefreshAllThrowsException.class);
+ }
+
+ /** */
+ public void testPassingNullToRefreshAllThrowsException() {
+ pm = getPM();
+
+ runTestRefreshAll1(pm);
+ runTestRefreshAll2(pm);
+
+ pm.close();
+ pm = null;
+ }
+
+ /* test refreshAll (Collection pcs) */
+ public void runTestRefreshAll1(PersistenceManager pm) {
+ Transaction tx = pm.currentTransaction();
+ if (debug) logger.debug("** in runTestRefreshAll1() ");
+ try {
+ tx.begin();
+ Collection col1 = null;
+ try {
+ pm.refreshAll(col1);
+ fail(ASSERTION_FAILED,
+ "pm.refreshAll should throw NullPointerException when
called with argument null");
+ }
+ catch (NullPointerException ex) {
+ // expected exception
+ }
+ tx .rollback();
+ tx = null;
+ }
+ finally {
+ if ((tx != null) && tx.isActive())
+ tx.rollback();
+ }
+ }
+
+ /* test refreshAll (Object[] objArray) */
+ public void runTestRefreshAll2(PersistenceManager pm) {
+ Transaction tx = pm.currentTransaction();
+ if (debug) logger.debug ("** in runTestRefreshAll1() ");
+ try {
+ tx = pm.currentTransaction();
+ tx.begin();
+ Object[] arr = null;
+ try {
+ pm.refreshAll(arr);
+ fail(ASSERTION_FAILED,
+ "pm.refreshAll should throw NullPointerException when
called with argument null");
+ }
+ catch (NullPointerException ex) {
+ // expected exception
+ }
+ tx .rollback();
+ tx = null;
+ }
+ finally {
+ if ((tx != null) && tx.isActive())
+ tx.rollback();
+ }
+ }
+}
Propchange:
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/PassingNullToRefreshAllThrowsException.java
------------------------------------------------------------------------------
svn:executable = *
Added:
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/PassingNullToRefreshHasNoEffect.java
URL:
http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/PassingNullToRefreshHasNoEffect.java?view=auto&rev=160090
==============================================================================
---
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/PassingNullToRefreshHasNoEffect.java
(added)
+++
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/PassingNullToRefreshHasNoEffect.java
Mon Apr 4 12:41:23 2005
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.cache;
+
+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> Passing Null to Refresh has no Effect
+ *<BR>
+ *<B>Keywords:</B>
+ *<BR>
+ *<B>Assertion IDs:</B> A12.5-8
+ *<BR>
+ *<B>Assertion Description: </B>
+Passing a null value to PersistenceManager.refresh will have no effect. A
NullPointerException should NOT be thrown.
+
+ */
+
+public class PassingNullToRefreshHasNoEffect extends PersistenceManagerTest {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A12.5-8 (PassingNullToRefreshHasNoEffect) 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(PassingNullToRefreshHasNoEffect.class);
+ }
+
+ /** */
+ public void test() {
+ pm = getPM();
+
+ runTestPassingNullToRefreshHasNoEffect(pm);
+
+ pm.close();
+ pm = null;
+ }
+
+ /* test evict (object pc) */
+ private void runTestPassingNullToRefreshHasNoEffect(PersistenceManager pm)
{
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.begin();
+ PCPoint p1 = null;
+ pm.refresh(p1);
+ if (debug)
+ logger.debug (" \nPASSED in
testPassingNullToRefreshHasNoEffect()");
+ tx.rollback();
+ tx = null;
+ }
+ finally {
+ if ((tx != null) && tx.isActive())
+ tx.rollback();
+ }
+ }
+}
Propchange:
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/PassingNullToRefreshHasNoEffect.java
------------------------------------------------------------------------------
svn:executable = *
Added:
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/RefreshAllNoParameterSideEffects.java
URL:
http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/RefreshAllNoParameterSideEffects.java?view=auto&rev=160090
==============================================================================
---
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/RefreshAllNoParameterSideEffects.java
(added)
+++
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/RefreshAllNoParameterSideEffects.java
Mon Apr 4 12:41:23 2005
@@ -0,0 +1,262 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.cache;
+
+import java.util.Collection;
+import java.util.HashSet;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.PersistenceManagerFactory;
+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;
+import org.apache.jdo.tck.util.ThreadExceptionHandler;
+
+/**
+ *<B>Title:</B> Refresh All No Parameters Side Effects
+ *<BR>
+ *<B>Keywords:</B> cache
+ *<BR>
+ *<B>Assertion ID:</B> A12.5.1-5B
+ *<BR>
+ *<B>Assertion Description: </B>
+The refreshAll() updates the values in the parameter
+instance[s] from the data in the data store. ((The intended use is for
optimistic transactions where the state of
+the JDO Instance is not guaranteed to reflect the state in the data store.
This method can be used to minimize
+the occurrence of commit failures due to mismatch between the state of cached
instances and the state of
+data in the data store.)) This can be tested by using 2 PersistenceManagers,
independently change an object,
+then refresh.
+ */
+
+/** */
+public class RefreshAllNoParameterSideEffects extends PersistenceManagerTest {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A12.5.1-5B (RefreshAllNoParameterSideEffects) failed: ";
+
+ /** */
+ static final int DELAY = 100;
+
+ /**
+ * 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(RefreshAllNoParameterSideEffects.class);
+ }
+
+ /** */
+ public void test () throws Exception {
+ PersistenceManagerFactory pmf = getPMF();
+ PersistenceManager pm1 = pmf.getPersistenceManager();
+ PersistenceManager pm2 = pmf.getPersistenceManager();
+
+ try {
+ runTestRefreshAllNoParameterSideEffects(pm1, pm2);
+ }
+ finally {
+ cleanupPM(pm2);
+ pm2 = null;
+ cleanupPM(pm1);
+ pm1 = null;
+ }
+ }
+
+ /** */
+ private void runTestRefreshAllNoParameterSideEffects(PersistenceManager
pm1,
+ PersistenceManager
pm2) throws Exception {
+ if (!isOptimisticSupported()) {
+ if (debug)
+ logger.debug("Optimistic not supported => skip
RefreshAllNoParameterSideEffects");
+ return;
+ }
+
+ if (debug) logger.debug ("\nSTART RefreshAllNoParameterSideEffects");
+
+ ThreadExceptionHandler group = new ThreadExceptionHandler();
+ ThreadT1 thread1 = new ThreadT1(pm1);
+ Thread T1 = new Thread(group, thread1);
+ ThreadT2 thread2 = new ThreadT2(pm2);
+ Thread T2 = new Thread(group, thread2);
+ thread1.setOther(thread2);
+ thread2.setOther(thread1);
+
+ T1.start();
+ T2.start();
+
+ T1.join();
+ T2.join();
+
+ Throwable t1Problem = group.getUncaughtException(T1);
+ if (t1Problem != null) {
+ if (debug) {
+ logger.debug("RefreshAllNoParameterSideEffects ThreadT1
results in uncaught exception");
+ t1Problem.printStackTrace();
+ }
+ fail(ASSERTION_FAILED,
+ "ThreadT1 results in exception " + t1Problem);
+ }
+ Throwable t2Problem = group.getUncaughtException(T2);
+ if (t2Problem != null) {
+ if (debug) {
+ logger.debug("RefreshAllNoParameterSideEffects ThreadT2
results in uncaught exception");
+ t2Problem.printStackTrace();
+ }
+ fail(ASSERTION_FAILED,
+ "ThreadT2 results in exception " + t2Problem);
+ }
+
+ if (debug) logger.debug ("END RefreshAllNoParameterSideEffects");
+ }
+
+ /** */
+ class ThreadT1 implements Runnable {
+
+ PersistenceManager pm;
+ ThreadT2 other;
+ boolean commitDone;
+
+ /** */
+ public ThreadT1(PersistenceManager pm) {
+ this.pm = pm;
+ this.other = null;
+ this.commitDone = false;
+ }
+
+ /** */
+ void setOther(ThreadT2 other) {
+ this.other = other;
+ }
+
+ /** */
+ boolean isCommitDone() {
+ return commitDone;
+ }
+
+ /** */
+ synchronized public void run() {
+ PCPoint n1 = new PCPoint (5,1);
+ PCPoint n2 = new PCPoint (5,2);
+ Transaction tx = pm.currentTransaction();
+ tx.setOptimistic(true);
+ try {
+ tx.begin();
+ n1.setX(500);
+ n2.setX(501);
+
+ Collection col1 = new HashSet();
+ col1.add(n1);
+ col1.add(n2);
+
+ pm.makePersistentAll(col1);
+ pm.refreshAll();
+
+ RefreshAllNoParameterSideEffects.this.logger.debug(
+ " ThreadT1: waiting for ThreadT2.done");
+ while (!other.isDone()) {
+ try {
+ Thread.sleep(DELAY);
+ }
+ catch (InterruptedException ex) {
+ // ignore
+ }
+ }
+
+ tx.commit();
+ tx = null;
+ commitDone = true;
+ RefreshAllNoParameterSideEffects.this.logger.debug(
+ " ThreadT1: commit finished.");
+ }
+ finally {
+ if ((tx != null) && tx.isActive())
+ tx.rollback();
+ }
+ }
+ }
+
+ /** */
+ class ThreadT2 implements Runnable {
+
+ PersistenceManager pm = null;
+ ThreadT1 other = null;
+ boolean done = false;
+
+ /** */
+ public ThreadT2(PersistenceManager pm) {
+ this.pm = pm;
+ this.other = null;
+ this.done = false;
+ }
+
+ /** */
+ boolean isDone() {
+ return done;
+ }
+
+
+ /** */
+ void setOther(ThreadT1 other) {
+ this.other = other;
+ }
+
+ /** */
+ synchronized public void run() {
+ PCPoint p1 = new PCPoint (5,1);
+ PCPoint p2 = new PCPoint (5,2);
+ Transaction tx = pm.currentTransaction();
+ tx.setOptimistic(true);
+ try {
+ tx.begin();
+ p1.setX(200);
+ p2.setX(201);
+
+ Collection col1 = new HashSet();
+ col1.add(p1);
+ col1.add(p2);
+ pm.makePersistentAll(col1);
+ pm.refreshAll();
+ done = true;
+
+ RefreshAllNoParameterSideEffects.this.logger.debug(
+ " ThreadT2: waiting for commit of ThreadT1");
+ while (! other.isCommitDone()) {
+ try {
+ Thread.sleep(DELAY);
+ }
+ catch (InterruptedException ex) {
+ // ignore
+ }
+ }
+
+ tx.commit();
+ tx = null;
+ RefreshAllNoParameterSideEffects.this.logger.debug(
+ " ThreadT2: commit finished.");
+ }
+ finally {
+ if ((tx != null) && tx.isActive())
+ tx.rollback();
+ }
+ }
+ }
+}
+
Propchange:
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/RefreshAllNoParameterSideEffects.java
------------------------------------------------------------------------------
svn:executable = *
Added:
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/RefreshAllWithArraySideEffects.java
URL:
http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/RefreshAllWithArraySideEffects.java?view=auto&rev=160090
==============================================================================
---
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/RefreshAllWithArraySideEffects.java
(added)
+++
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/RefreshAllWithArraySideEffects.java
Mon Apr 4 12:41:23 2005
@@ -0,0 +1,255 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.cache;
+
+import java.util.Collection;
+import java.util.HashSet;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.PersistenceManagerFactory;
+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;
+import org.apache.jdo.tck.util.ThreadExceptionHandler;
+
+/**
+ *<B>Title:</B> Refresh All With Array Side Effects
+ *<BR>
+ *<B>Keywords:</B> cache
+ *<BR>
+ *<B>Assertion ID:</B> A12.5.1-5D
+ *<BR>
+ *<B>Assertion Description: </B>
+The refreshAll(Object[] pcs) updates the values in the parameter
+instance[s] from the data in the data store. ((The intended use is for
optimistic transactions where the state of
+the JDO Instance is not guaranteed to reflect the state in the data store.
This method can be used to minimize
+the occurrence of commit failures due to mismatch between the state of cached
instances and the state of
+data in the data store.)) This can be tested by using 2 PersistenceManagers,
independently change an object,
+then refresh.
+ */
+
+
+/** */
+public class RefreshAllWithArraySideEffects extends PersistenceManagerTest {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A12.5.1-5D (RefreshAllWithArraySideEffects) failed: ";
+
+ /** */
+ static final int DELAY = 100;
+
+ /**
+ * 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(RefreshAllWithArraySideEffects.class);
+ }
+
+ /** */
+ public void test () throws Exception {
+ PersistenceManagerFactory pmf = getPMF();
+ PersistenceManager pm1 = pmf.getPersistenceManager();
+ PersistenceManager pm2 = pmf.getPersistenceManager();
+
+ try {
+ runTestRefreshAllWithArraySideEffects(pm1, pm2);
+ }
+ finally {
+ cleanupPM(pm2);
+ pm2 = null;
+ cleanupPM(pm1);
+ pm1 = null;
+ }
+ }
+
+ /** */
+ private void runTestRefreshAllWithArraySideEffects(
+ PersistenceManager pm1, PersistenceManager pm2) throws Exception {
+ if (debug) logger.debug("\nSTART RefreshAllWithArraySideEffects");
+
+ ThreadExceptionHandler group = new ThreadExceptionHandler();
+ RefreshArrThreadT1 thread1 = new RefreshArrThreadT1(pm1);
+ Thread T1 = new Thread(group, thread1);
+ RefreshArrThreadT2 thread2 = new RefreshArrThreadT2(pm2);
+ Thread T2 = new Thread(group, thread2);
+ thread1.setOther(thread2);
+ thread2.setOther(thread1);
+
+ T1.start();
+ T2.start();
+
+ T1.join();
+ T2.join();
+
+ Throwable t1Problem = group.getUncaughtException(T1);
+ if (t1Problem != null) {
+ if (debug) {
+ logger.debug("RefreshAllWithArraySideEffects ThreadT1 results
in uncaught exception");
+ t1Problem.printStackTrace();
+ }
+ fail(ASSERTION_FAILED,
+ "ThreadT1 results in exception " + t1Problem);
+ }
+ Throwable t2Problem = group.getUncaughtException(T2);
+ if (t2Problem != null) {
+ if (debug) {
+ logger.debug("RefreshAllWithArraySideEffects ThreadT2 results
in uncaught exception");
+ t2Problem.printStackTrace();
+ }
+ fail(ASSERTION_FAILED,
+ "ThreadT2 results in exception " + t2Problem);
+ }
+
+ if (debug) logger.debug ("END RefreshAllWithArraySideEffects");
+ }
+
+ /** */
+ class RefreshArrThreadT1 implements Runnable {
+
+ PersistenceManager pm;
+ RefreshArrThreadT2 other;
+ boolean commitDone;
+
+ /** */
+ RefreshArrThreadT1(PersistenceManager pm) {
+ this.pm = pm;
+ this.other = null;
+ this.commitDone = false;
+ }
+
+ /** */
+ void setOther(RefreshArrThreadT2 other) {
+ this.other = other;
+ }
+
+ /** */
+ boolean isCommitDone() {
+ return commitDone;
+ }
+
+ /** */
+ synchronized public void run() {
+ PCPoint n1 = new PCPoint (5,1);
+ PCPoint n2 = new PCPoint (5,2);
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.begin();
+ n1.setX(500);
+ n2.setX(501);
+
+ Collection col1 = new HashSet();
+ col1.add(n1);
+ col1.add(n2);
+
+ pm.makePersistentAll(col1);
+ pm.refreshAll(col1.toArray());
+ RefreshAllWithArraySideEffects.this.logger.debug(
+ " ThreadT1: waiting for ThreadT2.done");
+
+ while (!other.isDone()) {
+ try {
+ Thread.sleep(DELAY);
+ }
+ catch (InterruptedException ex) {
+ // ignore
+ }
+ }
+
+ tx.commit();
+ tx = null;
+ commitDone = true;
+ RefreshAllWithArraySideEffects.this.logger.debug(
+ " ThreadT1: commit finished.");
+ }
+ finally {
+ if ((tx != null) && tx.isActive())
+ tx.rollback();
+ }
+ }
+ }
+
+ /** */
+ class RefreshArrThreadT2 implements Runnable{
+
+
+ PersistenceManager pm;
+ RefreshArrThreadT1 other;
+ boolean done;
+
+ /** */
+ public RefreshArrThreadT2(PersistenceManager pm) {
+ this.pm = pm;
+ this.other = null;
+ this.done = false;
+ }
+
+ /** */
+ boolean isDone() {
+ return done;
+ }
+
+
+ /** */
+ void setOther(RefreshArrThreadT1 other) {
+ this.other = other;
+ }
+
+ /** */
+ synchronized public void run() {
+ PCPoint p1 = new PCPoint (5,1);
+ PCPoint p2 = new PCPoint (5,2);
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.begin();
+ p1.setX(200);
+ p2.setX(201);
+
+ Collection col1 = new HashSet();
+ col1.add(p1);
+ col1.add(p2);
+ pm.makePersistentAll(col1);
+ pm.refreshAll(col1.toArray());
+ done = true;
+
+ RefreshAllWithArraySideEffects.this.logger.debug(
+ " ThreadT2: waiting for commit of ThreadT1");
+ while (!other.isCommitDone()) {
+ try {
+ Thread.sleep(DELAY);
+ }
+ catch (InterruptedException ex) {
+ // ignore
+ }
+ }
+ tx.commit();
+ tx = null;
+ RefreshAllWithArraySideEffects.this.logger.debug(
+ " ThreadT2: commit finished.");
+ }
+ finally {
+ if ((tx != null) && tx.isActive())
+ tx.rollback();
+ }
+
+ }
+ }
+}
Propchange:
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/RefreshAllWithArraySideEffects.java
------------------------------------------------------------------------------
svn:executable = *
Added:
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/RefreshAllWithCollectionSideEffects.java
URL:
http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/RefreshAllWithCollectionSideEffects.java?view=auto&rev=160090
==============================================================================
---
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/RefreshAllWithCollectionSideEffects.java
(added)
+++
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/RefreshAllWithCollectionSideEffects.java
Mon Apr 4 12:41:23 2005
@@ -0,0 +1,253 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.cache;
+
+import java.util.Collection;
+import java.util.HashSet;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.PersistenceManagerFactory;
+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;
+import org.apache.jdo.tck.util.ThreadExceptionHandler;
+
+/**
+ *<B>Title:</B> Refresh All With Collection Side Effects
+ *<BR>
+ *<B>Keywords:</B> cache
+ *<BR>
+ *<B>Assertion ID:</B> A12.5.1-5C
+ *<BR>
+ *<B>Assertion Description: </B>
+The refreshAll(Collection pcs) updates the values in the parameter
+instance[s] from the data in the data store. ((The intended use is for
optimistic transactions where the state of
+the JDO Instance is not guaranteed to reflect the state in the data store.
This method can be used to minimize
+the occurrence of commit failures due to mismatch between the state of cached
instances and the state of
+data in the data store.)) This can be tested by using 2 PersistenceManagers,
independently change an object,
+then refresh.
+ */
+
+
+/** */
+public class RefreshAllWithCollectionSideEffects extends
PersistenceManagerTest {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A12.5.1-5C (RefreshAllWithCollectionSideEffects) failed: ";
+
+ /** */
+ static final int DELAY = 100;
+
+ /**
+ * 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(RefreshAllWithCollectionSideEffects.class);
+ }
+
+ /** */
+ public void test () throws Exception {
+ PersistenceManagerFactory pmf = getPMF();
+ PersistenceManager pm1 = pmf.getPersistenceManager();
+ PersistenceManager pm2 = pmf.getPersistenceManager();
+
+ try {
+ runTestRefreshAllWithCollectionSideEffects(pm1, pm2);
+ }
+ finally {
+ cleanupPM(pm2);
+ pm2 = null;
+ cleanupPM(pm1);
+ pm1 = null;
+ }
+ }
+
+ /** */
+ public void runTestRefreshAllWithCollectionSideEffects(PersistenceManager
pm1,
+ PersistenceManager
pm2) throws Exception {
+ if (debug) logger.debug("\nSTART RefreshAllWithCollectionSideEffects");
+
+ ThreadExceptionHandler group = new ThreadExceptionHandler();
+ RefreshColThreadT1 thread1 = new RefreshColThreadT1(pm1);
+ Thread T1 = new Thread(group, thread1);
+ RefreshColThreadT2 thread2 = new RefreshColThreadT2(pm2);
+ Thread T2 = new Thread(group, thread2);
+ thread1.setOther(thread2);
+ thread2.setOther(thread1);
+
+ T1.start();
+ T2.start();
+
+ T1.join();
+ T2.join();
+
+ Throwable t1Problem = group.getUncaughtException(T1);
+ if (t1Problem != null) {
+ if (debug) {
+ logger.debug("RefreshAllWithCollectionSideEffects ThreadT1
results in uncaught exception");
+ t1Problem.printStackTrace();
+ }
+ fail(ASSERTION_FAILED,
+ "ThreadT1 results in exception " + t1Problem);
+ }
+ Throwable t2Problem = group.getUncaughtException(T2);
+ if (t2Problem != null) {
+ if (debug) {
+ logger.debug("RefreshAllWithCollectionSideEffects ThreadT2
results in uncaught exception");
+ t2Problem.printStackTrace();
+ }
+ fail(ASSERTION_FAILED,
+ "ThreadT2 results in exception " + t2Problem);
+ }
+
+ if (debug) logger.debug("END RefreshAllWithCollectionSideEffects");
+ }
+
+ /** */
+ class RefreshColThreadT1 implements Runnable{
+
+ PersistenceManager pm;
+ RefreshColThreadT2 other;
+ boolean commitDone;
+
+ /** */
+ RefreshColThreadT1(PersistenceManager pm) {
+ this.pm = pm;
+ this.other = null;
+ this.commitDone = false;
+ }
+
+ /** */
+ void setOther(RefreshColThreadT2 other) {
+ this.other = other;
+ }
+
+ /** */
+ boolean isCommitDone() {
+ return commitDone;
+ }
+
+ /** */
+ synchronized public void run() {
+ PCPoint n1 = new PCPoint (5,1);
+ PCPoint n2 = new PCPoint (5,2);
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.begin();
+ n1.setX(500);
+ n2.setX(501);
+
+ Collection col1 = new HashSet();
+ col1.add(n1);
+ col1.add(n2);
+
+ pm.makePersistentAll(col1);
+ pm.refreshAll(col1);
+ RefreshAllWithCollectionSideEffects.this.logger.debug(
+ " ThreadT1: waiting for ThreadT2.done");
+
+ while (!other.isDone()) {
+ try {
+ Thread.sleep(DELAY);
+ }
+ catch (InterruptedException ex) {
+ // ignore
+ }
+ }
+
+ tx.commit();
+ tx = null;
+ commitDone = true;
+ RefreshAllWithCollectionSideEffects.this.logger.debug(
+ " ThreadT1: commit finished.");
+ }
+ finally {
+ if ((tx != null) && tx.isActive())
+ tx.rollback();
+ }
+ }
+ }
+
+ /** */
+ class RefreshColThreadT2 implements Runnable{
+
+ PersistenceManager pm = null;
+ RefreshColThreadT1 other = null;
+ boolean done = false;
+
+ /** */
+ RefreshColThreadT2(PersistenceManager pm) {
+ this.pm = pm;
+ this.other = null;
+ this.done = false;
+ }
+
+ /** */
+ boolean isDone() {
+ return done;
+ }
+
+
+ /** */
+ void setOther(RefreshColThreadT1 other) {
+ this.other = other;
+ }
+
+ /** */
+ synchronized public void run() {
+ PCPoint p1 = new PCPoint (5,1);
+ PCPoint p2 = new PCPoint (5,2);
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.begin();
+ p1.setX(200);
+ p2.setX(201);
+
+ Collection col1 = new HashSet();
+ col1.add(p1);
+ col1.add(p2);
+ pm.makePersistentAll(col1);
+ pm.refreshAll(col1);
+ done = true;
+
+ RefreshAllWithCollectionSideEffects.this.logger.debug(
+ " ThreadT2: waiting for commit of ThreadT1");
+ while (!other.isCommitDone()) {
+ try {
+ Thread.sleep(DELAY);
+ }
+ catch (InterruptedException ex) {
+ // ignore
+ }
+ }
+ tx.commit();
+ tx = null;
+ RefreshAllWithCollectionSideEffects.this.logger.debug(
+ " ThreadT2: commit finished.");
+ }
+ finally {
+ if ((tx != null) && tx.isActive())
+ tx.rollback();
+ }
+ }
+ }
+}
Propchange:
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/RefreshAllWithCollectionSideEffects.java
------------------------------------------------------------------------------
svn:executable = *
Added:
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/RefreshAllWithNoParameters.java
URL:
http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/RefreshAllWithNoParameters.java?view=auto&rev=160090
==============================================================================
---
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/RefreshAllWithNoParameters.java
(added)
+++
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/RefreshAllWithNoParameters.java
Mon Apr 4 12:41:23 2005
@@ -0,0 +1,102 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.cache;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.JDO_Test;
+import org.apache.jdo.tck.pc.mylib.PCPoint;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Refresh All With No Parameters
+ *<BR>
+ *<B>Keywords:</B> cache
+ *<BR>
+ *<B>Assertion ID:</B> A12.5.1-6.
+ *<BR>
+ *<B>Assertion Description: </B>
+ The <code>PersistenceManager.refreshAll</code> method with no parameters
+ causes all transactional instances to be refreshed. Note that this method
+ will cause loss of changes made to affected instances by the application
+ due to refreshing the contents from the data store.
+ The JDO <code>PersistenceManager</code>:
+ <UL>
+ <LI>loads persistent values from the data store;</LI>
+ <LI>loads persistent fields into the instance;</LI>
+ <LI>calls the <code>jdoPostLoad</code> method on each persistent instance,
+ if the class of the instance implements <code>InstanceCallbacks</code>;
and</LI>
+ <LI>changes the state of persistent-dirty instances to persistent-clean.</LI>
+ </UL>
+
+ */
+
+public class RefreshAllWithNoParameters extends JDO_Test {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A12.5.1-6 (RefreshAllWithNoParameters) 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(RefreshAllWithNoParameters.class);
+ }
+
+ /** */
+ public void test() {
+ pm = getPM();
+
+ runTestRefreshAll(pm);
+
+ pm.close();
+ pm = null;
+ }
+
+ /** */
+ private void runTestRefreshAll(PersistenceManager pm) {
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.begin();
+ PCPoint p = new PCPoint (100, 200);
+ pm.makePersistent(p);
+ tx.commit();
+
+ tx.begin();
+ p.setX(500);
+ p.setY(new Integer(800));
+ pm.refreshAll();
+ int currentX = p.getX();
+ Integer currentY = p.getY();
+ if ((currentX != 100) || !currentY.equals(new Integer(200))) {
+ fail(ASSERTION_FAILED,
+ "RefreshAll expected 100, 200; got " + currentX + ", " +
currentY);
+ }
+ tx.commit();
+ tx = null;
+ }
+ finally {
+ if ((tx != null) && tx.isActive())
+ tx.rollback();
+ }
+ }
+}
Propchange:
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/RefreshAllWithNoParameters.java
------------------------------------------------------------------------------
svn:executable = *
Added:
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/RefreshSideEffects.java
URL:
http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/RefreshSideEffects.java?view=auto&rev=160090
==============================================================================
---
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/RefreshSideEffects.java
(added)
+++
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/RefreshSideEffects.java
Mon Apr 4 12:41:23 2005
@@ -0,0 +1,238 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.cache;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.PersistenceManagerFactory;
+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;
+import org.apache.jdo.tck.util.ThreadExceptionHandler;
+
+/**
+ *<B>Title:</B> Refresh Side Effects
+ *<BR>
+ *<B>Keywords:</B> cache
+ *<BR>
+ *<B>Assertion ID:</B> A12.5.1-5A
+ *<BR>
+ *<B>Assertion Description: </B>
+ The refresh method updates the values in the parameter
+ instance[s] from the data in the data store. ((The intended use is for
optimistic transactions where the state of
+ the JDO Instance is not guaranteed to reflect the state in the data store.
This method can be used to minimize
+ the occurrence of commit failures due to mismatch between the state of cached
instances and the state of
+ data in the data store.)) This can be tested by using 2 PersistenceManagers,
independently change an object,
+ then refresh.
+ */
+
+/** */
+public class RefreshSideEffects extends PersistenceManagerTest {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A12.5.1-5A (RefreshSideEffects) failed: ";
+
+ /** */
+ static final int DELAY = 100;
+
+ /**
+ * 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(RefreshSideEffects.class);
+ }
+
+ /** */
+ public void test () throws Exception {
+ PersistenceManagerFactory pmf = getPMF();
+ PersistenceManager pm1 = pmf.getPersistenceManager();
+ PersistenceManager pm2 = pmf.getPersistenceManager();
+
+ try {
+ runTestRefreshSideEffects(pm1, pm2);
+ }
+ finally {
+ cleanupPM(pm2);
+ pm2 = null;
+ cleanupPM(pm1);
+ pm1 = null;
+ }
+ }
+
+ /** */
+ private void runTestRefreshSideEffects(PersistenceManager pm1,
+ PersistenceManager pm2) throws
Exception {
+ if (debug) logger.debug ("\nSTART RefreshSideEffects");
+
+ ThreadExceptionHandler group = new ThreadExceptionHandler();
+ RefreshThreadT1 thread1 = new RefreshThreadT1(pm1);
+ Thread T1 = new Thread(group, thread1);
+ RefreshThreadT2 thread2 = new RefreshThreadT2(pm2);
+ Thread T2 = new Thread(group, thread2);
+ thread1.setOther(thread2);
+ thread2.setOther(thread1);
+
+ T1.start();
+ T2.start();
+
+ T1.join();
+ T2.join();
+
+ Throwable t1Problem = group.getUncaughtException(T1);
+ if (t1Problem != null) {
+ if (debug) {
+ logger.debug("RefreshAllNoParameterSideEffects ThreadT1
results in uncaught exception");
+ t1Problem.printStackTrace();
+ }
+ fail(ASSERTION_FAILED,
+ "ThreadT1 results in exception " + t1Problem);
+ }
+ Throwable t2Problem = group.getUncaughtException(T2);
+ if (t2Problem != null) {
+ if (debug) {
+ logger.debug("RefreshAllNoParameterSideEffects ThreadT2
results in uncaught exception");
+ t2Problem.printStackTrace();
+ }
+ fail(ASSERTION_FAILED,
+ "ThreadT2 results in exception " + t2Problem);
+ }
+
+ if (debug) logger.debug ("END RefreshSideEffects");
+ }
+
+ /** */
+ class RefreshThreadT1 implements Runnable {
+
+ PersistenceManager pm;
+ RefreshThreadT2 other;
+ boolean commitDone;
+
+ /** */
+ RefreshThreadT1(PersistenceManager pm) {
+ this.pm = pm;
+ this.other = null;
+ this.commitDone = false;
+ }
+
+ /** */
+ void setOther(RefreshThreadT2 other) {
+ this.other = other;
+ }
+
+ /** */
+ boolean isCommitDone() {
+ return commitDone;
+ }
+
+ /** */
+ synchronized public void run() {
+ PCPoint n1 = new PCPoint (5,1);
+ Transaction tx = pm.currentTransaction();
+ try {
+ RefreshSideEffects.this.logger.debug(" ThreadT1: START");
+ tx.begin();
+ n1.setX(500);
+ pm.makePersistent(n1);
+ pm.refresh(n1);
+
+ RefreshSideEffects.this.logger.debug(
+ " ThreadT1: waiting for ThreadT2.done");
+ while (!other.isDone()) {
+ try {
+ Thread.sleep(DELAY);
+ }
+ catch (InterruptedException ex) {
+ // ignore
+ }
+ }
+
+ tx.commit();
+ tx = null;
+ commitDone = true;
+ RefreshSideEffects.this.logger.debug(
+ " ThreadT1: commit finished.");
+ }
+ finally {
+ if ((tx != null) && tx.isActive())
+ tx.rollback();
+ }
+ }
+ }
+
+ /** */
+ class RefreshThreadT2 implements Runnable {
+
+ PersistenceManager pm;
+ RefreshThreadT1 other;
+ boolean done;
+
+ /** */
+ RefreshThreadT2(PersistenceManager pm) {
+ this.pm = pm;
+ this.other = null;
+ this.done = false;
+ }
+
+ /** */
+ boolean isDone() {
+ return done;
+ }
+
+
+ /** */
+ void setOther(RefreshThreadT1 other) {
+ this.other = other;
+ }
+
+ /* test refresh() */
+ synchronized public void run() {
+ PCPoint p1 = new PCPoint (5,1);
+ Transaction tx = pm.currentTransaction();
+ try {
+ RefreshSideEffects.this.logger.debug(" ThreadT2: START");
+ tx.begin();
+ p1.setX(201);
+ pm.makePersistent(p1);
+ pm.refresh(p1);
+ done = true;
+
+ RefreshSideEffects.this.logger.debug(
+ " ThreadT2: waiting for commit of ThreadT1");
+ while (!other.isCommitDone()) {
+ try {
+ Thread.sleep(DELAY);
+ }
+ catch (InterruptedException ex) {
+ // ignore
+ }
+ }
+ tx.commit();
+ tx = null;
+ RefreshSideEffects.this.logger.debug(
+ " ThreadT2: commit finished.");
+ }
+ finally {
+ if ((tx != null) && tx.isActive())
+ tx.rollback();
+ }
+ }
+ }
+}
Propchange:
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/RefreshSideEffects.java
------------------------------------------------------------------------------
svn:executable = *
Added:
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/Retrieve.java
URL:
http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/Retrieve.java?view=auto&rev=160090
==============================================================================
---
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/Retrieve.java
(added)
+++
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/Retrieve.java
Mon Apr 4 12:41:23 2005
@@ -0,0 +1,336 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.cache;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.jdo.PersistenceManager;
+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.PCPoint2;
+import org.apache.jdo.tck.pc.mylib.PCRect;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Retrieve
+ *<BR>
+ *<B>Keywords:</B> cache
+ *<BR>
+ *<B>Assertion IDs:</B> A12.6.1-2, A12.6.1-5
+ *<BR>
+ *<B>Assertion Description: </B>
+These methods request the PersistenceManager to load all persistent fields
into
+the parameter instances. Subsequent to this call, the application might
+call makeTransient on the parameter instances, and the fields can no
+longer be touched by the PersistenceManager. The PersistenceManager
+might also retrieve related instances according to a pre-read policy
+(not specified by JDO).
+The JDO PersistenceManager loads persistent values from the datastore into the
instance
+and if the class of the instance implements InstanceCallbacks calls
jdoPostLoad.
+ */
+
+public class Retrieve extends JDO_Test {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertions A12.6.1-2, A12.6.1-5 (Retrieve) 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(Retrieve.class);
+ }
+
+ private PCPoint p1 = null;
+ private String p1print = null;
+ private PCPoint p2 = null;
+ private PCPoint2 p3 = null;
+ private PCRect rect = null;
+
+ private static final Integer one = new Integer(1);
+ private static final Integer three = new Integer(3);
+
+ /** */
+ public void test () {
+ pm = getPM();
+
+ runTestRetrieve(pm);
+ runTestRetrieveAllWithCollection(pm);
+ runTestRetrieveAllWithArray(pm);
+ runTestRetrieveAllWithCollectionDFGtrue(pm);
+ runTestRetrieveAllWithArrayDFGtrue(pm);
+ runTestRetrieveAllWithCollectionDFGfalse(pm);
+ runTestRetrieveAllWithArrayDFGfalse(pm);
+
+ pm.close();
+ pm = null;
+ }
+
+ /** */
+ private void runTestRetrieve(PersistenceManager pm) {
+ createObjects(pm);
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.begin();
+ pm.retrieve(p1);
+ pm.retrieve(p3);
+ pm.retrieve(rect);
+ pm.makeTransient(p1);
+ pm.makeTransient(rect);
+ tx.commit();
+ tx = null;
+ checkP1();
+ checkP3();
+ checkRectP1();
+ checkRectId();
+ }
+ finally {
+ if ((tx != null) && tx.isActive())
+ tx.rollback();
+ }
+ }
+
+ /** */
+ private void runTestRetrieveAllWithCollection(PersistenceManager pm) {
+ createObjects(pm);
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.begin();
+ Collection coll = new ArrayList();
+ coll.add(p1);
+ coll.add(p3);
+ coll.add(rect);
+ pm.retrieveAll(coll);
+ pm.makeTransientAll(coll);
+ tx.commit();
+ tx = null;
+ checkP1();
+ checkP3();
+ checkRectP1();
+ checkRectId();
+ }
+ finally {
+ if ((tx != null) && tx.isActive())
+ tx.rollback();
+ }
+ }
+
+ /** */
+ private void runTestRetrieveAllWithCollectionDFGtrue(PersistenceManager
pm) {
+ createObjects(pm);
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.begin();
+ Collection coll = new ArrayList();
+ coll.add(p1);
+ coll.add(p3);
+ coll.add(rect);
+ pm.retrieveAll(coll, true);
+ pm.makeTransientAll(coll);
+ tx.commit();
+ tx = null;
+ checkP1();
+ checkP3();
+ // checkRectP1(); p1 is not in the default fetch group by default
+ checkRectId();
+ }
+ finally {
+ if ((tx != null) && tx.isActive())
+ tx.rollback();
+ }
+ }
+
+ /** */
+ private void runTestRetrieveAllWithCollectionDFGfalse(PersistenceManager
pm) {
+ createObjects(pm);
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.begin();
+ Collection coll = new ArrayList();
+ coll.add(p1);
+ coll.add(p3);
+ coll.add(rect);
+ pm.retrieveAll(coll, true);
+ pm.makeTransientAll(coll);
+ tx.commit();
+ tx = null;
+ checkP1();
+ checkP3();
+ checkRectP1();
+ checkRectId();
+ }
+ finally {
+ if ((tx != null) && tx.isActive())
+ tx.rollback();
+ }
+ }
+
+ /** */
+ private void runTestRetrieveAllWithArray(PersistenceManager pm) {
+ createObjects(pm);
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.begin();
+ Object[] objs = new Object[3];
+ objs[0] = p1;
+ objs[1] = p3;
+ objs[2] = rect;
+ pm.retrieveAll(objs);
+ pm.makeTransientAll(objs);
+ tx.commit();
+ tx = null;
+ checkP1();
+ checkP3();
+ checkRectP1();
+ checkRectId();
+ }
+ finally {
+ if ((tx != null) && tx.isActive())
+ tx.rollback();
+ }
+ }
+
+ /** */
+ private void runTestRetrieveAllWithArrayDFGtrue(PersistenceManager pm) {
+ createObjects(pm);
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.begin();
+ Object[] objs = new Object[3];
+ objs[0] = p1;
+ objs[1] = p3;
+ objs[2] = rect;
+ pm.retrieveAll(objs, true);
+ pm.makeTransientAll(objs);
+ tx.commit();
+ tx = null;
+ checkP1();
+ checkP3();
+ // checkRectP1(); p1 is not in the default fetch group by default
+ checkRectId();
+ }
+ finally {
+ if ((tx != null) && tx.isActive())
+ tx.rollback();
+ }
+ }
+
+ /** */
+ private void runTestRetrieveAllWithArrayDFGfalse(PersistenceManager pm) {
+ createObjects(pm);
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.begin();
+ Object[] objs = new Object[3];
+ objs[0] = p1;
+ objs[1] = p3;
+ objs[2] = rect;
+ pm.retrieveAll(objs, true);
+ pm.makeTransientAll(objs);
+ tx.commit();
+ tx = null;
+ checkP1();
+ checkP3();
+ checkRectP1();
+ checkRectId();
+ }
+ finally {
+ if ((tx != null) && tx.isActive())
+ tx.rollback();
+ }
+ }
+
+ /** */
+ private void createObjects(PersistenceManager pm) {
+ Transaction tx = pm.currentTransaction();
+ try {
+ tx.setRetainValues(false);
+ tx.begin();
+ p1 = new PCPoint(1,1);
+ p1print = p1.toString();
+ p2 = new PCPoint(2,2);
+ p3 = new PCPoint2(3,3);
+ rect = new PCRect(100, p1, p2);
+ pm.makePersistent(p1);
+ pm.makePersistent(p2);
+ pm.makePersistent(p3);
+ pm.makePersistent(rect);
+ if (debug) {
+ logger.debug("p1: " + p1.name());
+ logger.debug("p2: " + p2.name());
+ logger.debug("p3: " + p3.name());
+ logger.debug("rect id: " + rect.getId() +
+ ", upperLeft: " + rect.getUpperLeft().name() +
+ ", lowerRight: " + rect.getLowerRight().name());
+ }
+ tx.commit();
+ tx = null;
+ }
+ finally {
+ if ((tx != null) && tx.isActive())
+ tx.rollback();
+ }
+ }
+
+ /** */
+ private void checkP1() {
+ if (((p1.getX() != 1) || (!one.equals(p1.getY())))) {
+ fail(ASSERTION_FAILED,
+ "Error in p1 fields. Expected x:1, y:1; got x:" + p1.getX() +
+ ", y:" + p1.getY());
+ }
+ }
+
+ /** */
+ private void checkP3() {
+ if ((p3.getX() != 3) || (!three.equals(p3.getY()))) {
+ fail(ASSERTION_FAILED,
+ "Error in p3 fields. Expected x:3, y:3; got x:" + p3.getX() +
+ ", y:" + p3.getY());
+ }
+
+ if (!p3.wasPostLoadCalled()) {
+ fail(ASSERTION_FAILED,
+ "missing call of jdoPostLoad for p3");
+ }
+ }
+
+ /** */
+ private void checkRectId() {
+ if (rect.getId() == 0) {
+ fail(ASSERTION_FAILED,
+ "Error in rect field id. Expected id!= 0; got id:0");
+ }
+ }
+
+ /** */
+ private void checkRectP1() {
+ if (rect.getUpperLeft()!= p1) {
+ fail(ASSERTION_FAILED,
+ "Error in rect field upperLeft. Expected:" + p1print +
+ ", got:" + rect.getUpperLeft());
+ }
+ }
+}
Propchange:
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/Retrieve.java
------------------------------------------------------------------------------
svn:executable = *
Added:
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/close/AfterCloseAllMethodsThrowException.java
URL:
http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/close/AfterCloseAllMethodsThrowException.java?view=auto&rev=160090
==============================================================================
---
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/close/AfterCloseAllMethodsThrowException.java
(added)
+++
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/close/AfterCloseAllMethodsThrowException.java
Mon Apr 4 12:41:23 2005
@@ -0,0 +1,101 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.JDOFatalUserException;
+import javax.jdo.PersistenceManager;
+import javax.jdo.PersistenceManagerFactory;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.api.persistencemanager.PersistenceManagerTest;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> AfterCloseAllMethodsThrowException
+ *<BR>
+ *<B>Keywords:</B> exception
+ *<BR>
+ *<B>Assertion IDs:</B> A12.5-6
+ *<BR>
+ *<B>Assertion Description: </B>
+After the PersistenceManager.close method completes,
+all methods on PersistenceManager except isClosed throw a
+JDOFatalUserException.
+
+ */
+
+public class AfterCloseAllMethodsThrowException extends PersistenceManagerTest
{
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A12.5-6 (AfterCloseAllMethodsThrowException) 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(AfterCloseAllMethodsThrowException.class);
+ }
+
+ private PersistenceManagerFactory pmf;
+ private PersistenceManager pm;
+ private Transaction tx;
+
+ /** */
+ public void testAfterCloseAllMethodsThrowException() {
+ pm = getPM();
+ pm.close();
+ runTestEvict();
+ runTestRefresh();
+ runTestIsClosed();
+ pm = null;
+ }
+
+ /** */
+ private void runTestEvict() {
+ try {
+ pm.evictAll();
+ fail(ASSERTION_FAILED,
+ "pm.evictAll does not throw exception if pm is closed.");
+ }
+ catch (JDOFatalUserException ex) {
+ // caught expected exception
+ }
+ }
+
+ /** */
+ private void runTestRefresh() {
+ try {
+ pm.refreshAll();
+ fail(ASSERTION_FAILED,
+ "pm.refreshAll does not throw exception if pm is closed.");
+ }
+ catch (JDOFatalUserException ex) {
+ // caught expected exception
+ }
+ }
+
+ /** */
+ private void runTestIsClosed() {
+ if (!pm.isClosed())
+ fail(ASSERTION_FAILED,
+ "pm.isClosed returns false for closed pm.");
+ }
+}
+