Save This Page
Home » jdo2-tck-2.3-ea-src » org.apache.jdo.tck.api.persistencemanager.cache » [javadoc | source]
    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    * 
    9    *     http://www.apache.org/licenses/LICENSE-2.0
   10    * 
   11    * Unless required by applicable law or agreed to in writing, software 
   12    * distributed under the License is distributed on an "AS IS" BASIS, 
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
   14    * See the License for the specific language governing permissions and 
   15    * limitations under the License.
   16    */
   17   
   18   
   19   package org.apache.jdo.tck.api.persistencemanager.cache;
   20   
   21   import javax.jdo.PersistenceManager;
   22   import javax.jdo.Transaction;
   23   
   24   import org.apache.jdo.tck.api.persistencemanager.PersistenceManagerTest;
   25   import org.apache.jdo.tck.pc.mylib.PCPoint2;
   26   import org.apache.jdo.tck.util.BatchTestRunner;
   27   
   28   /**
   29    *<B>Title:</B> EvictAllWithNoParameters
   30    *<BR>
   31    *<B>Keywords:</B> cache
   32    *<BR>
   33    *<B>Assertion IDs:</B> A12.5.1-2
   34    *<BR>
   35    *<B>Assertion Description: </B>
   36    If PersistenceManager.evict is called with no parameter, then all referenced instances are evicted. For each instance evicted, it:
   37    *<UL>
   38    *<LI> calls the jdoPreClearmethod on each instance, if the class of the instance implements InstanceCallbacks </LI>
   39    *<LI> clears persistent fields on each instance after the call to jdoPreClear()</LI>
   40    *<LI> changes the state of instances to hollow or persistent-nontransactional (cannot distinguish between these two states) this is not directly testable. </LI>
   41    *</UL>
   42   
   43    */
   44   
   45   public class EvictAllWithNoParameters extends PersistenceManagerTest {
   46       
   47       /** */
   48       private static final String ASSERTION_FAILED = 
   49           "Assertion A12.5.1-2 (EvictAllWithNoParameters) failed: ";
   50       
   51       /**
   52        * The <code>main</code> is called when the class
   53        * is directly executed from the command line.
   54        * @param args The arguments passed to the program.
   55        */
   56       public static void main(String[] args) {
   57           BatchTestRunner.run(EvictAllWithNoParameters.class);
   58       }
   59       
   60       private PCPoint2 pnt1 = null;
   61       private PCPoint2 p1 = null;
   62   
   63       /** */
   64       public void testEvictAllWithNoParameters() {
   65           pm = getPM();
   66           createObjects(pm);
   67           runTestEvictAll(pm);
   68           pm.close();
   69           pm = null;
   70       }
   71       
   72       /** */
   73       private void createObjects(PersistenceManager pm) {
   74           Transaction tx = pm.currentTransaction();
   75           try {
   76               tx.begin();
   77               pnt1 = new PCPoint2(1,3);
   78               p1   = new PCPoint2 (3,5);
   79               pm.makePersistent(pnt1);
   80               pm.makePersistent(p1);
   81               tx.commit();
   82   
   83               // P-nontransactional instance
   84               // Check whether pmf supported optimitic tx
   85               tx.setOptimistic(isOptimisticSupported());
   86               tx.begin();
   87               pnt1.getX();
   88               tx.commit();
   89               
   90               // P-clean instance 
   91               tx.setOptimistic(false);
   92               tx.begin();
   93               p1.getX();
   94               tx.commit();
   95           }
   96           finally {
   97               if (tx.isActive())
   98                   tx.rollback();
   99           }
  100       }
  101   
  102       /** */
  103       private void runTestEvictAll(PersistenceManager pm) {
  104           Transaction tx = pm.currentTransaction();
  105           try {
  106               tx.begin();
  107               pm.evictAll();
  108   
  109               if ( !p1.wasClearCalled()) {
  110                   fail(ASSERTION_FAILED,
  111                        "missing call of p1.jdoPreClear during pm.evictAll");
  112               }
  113               if ( !pnt1.wasClearCalled()) {
  114                   fail(ASSERTION_FAILED,
  115                        "missing call of pnt1.jdoPreClear during pm.evictAll");
  116               }
  117   
  118               if ( testState(p1, HOLLOW, "hollow") ||
  119                    testState(p1, PERSISTENT_NONTRANSACTIONAL, "persistent_nontransaction")) {
  120                   ;  // expected result
  121               } 
  122               else {
  123                   fail(ASSERTION_FAILED,
  124                        "p1 should be HOLLOW or P-NONTX after pm.evictAll.");
  125               }
  126   
  127               if ( testState(pnt1, HOLLOW, "hollow") ||
  128                    testState(pnt1, PERSISTENT_NONTRANSACTIONAL, "persistent_nontransaction")) {
  129                   ;  // expected result
  130               } 
  131               else {
  132                   fail(ASSERTION_FAILED,
  133                        "pnt1 should be HOLLOW or P-NONTX after pm.evictAll.");
  134               }
  135               tx.commit();
  136               if (debug) logger.debug(" \nPASSED in testEvictAll()");
  137           }
  138           finally {
  139               if (tx.isActive())
  140                   tx.rollback();
  141           }
  142       }
  143   }

Save This Page
Home » jdo2-tck-2.3-ea-src » org.apache.jdo.tck.api.persistencemanager.cache » [javadoc | source]