db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject cvs commit: db-ojb/src/test/org/apache/ojb/broker ObjectCacheTest.java
Date Fri, 14 Mar 2003 20:07:45 GMT
thma        2003/03/14 12:07:45

  Modified:    src/test/org/apache/ojb/broker ObjectCacheTest.java
  Log:
  add test for cache isolation
  
  Revision  Changes    Path
  1.2       +49 -9     db-ojb/src/test/org/apache/ojb/broker/ObjectCacheTest.java
  
  Index: ObjectCacheTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/ObjectCacheTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ObjectCacheTest.java	5 Mar 2003 23:52:08 -0000	1.1
  +++ ObjectCacheTest.java	14 Mar 2003 20:07:45 -0000	1.2
  @@ -1,27 +1,31 @@
   package org.apache.ojb.broker;
   
  +import java.io.Serializable;
  +
   import junit.framework.TestCase;
  +
  +import org.apache.ojb.broker.cache.CacheFilterClassImpl;
  +import org.apache.ojb.broker.cache.CacheFilterPackageImpl;
   import org.apache.ojb.broker.cache.MetaObjectCacheJCSImpl;
  +import org.apache.ojb.broker.cache.MetaObjectCachePerClassImpl;
   import org.apache.ojb.broker.cache.ObjectCache;
   import org.apache.ojb.broker.cache.ObjectCacheDefaultImpl;
   import org.apache.ojb.broker.cache.ObjectCacheEmptyImpl;
  +import org.apache.ojb.broker.cache.ObjectCacheFactory;
   import org.apache.ojb.broker.cache.ObjectCacheJCSImpl;
  -import org.apache.ojb.broker.cache.MetaObjectCachePerClassImpl;
   import org.apache.ojb.broker.cache.ObjectCachePerBrokerImpl;
  -import org.apache.ojb.broker.cache.ObjectCacheFactory;
  -import org.apache.ojb.broker.cache.CacheFilterPackageImpl;
  -import org.apache.ojb.broker.cache.CacheFilterClassImpl;
  -import org.apache.ojb.broker.util.configuration.impl.OjbConfiguration;
  -import org.apache.ojb.broker.util.configuration.impl.OjbConfigurator;
   import org.apache.ojb.broker.metadata.MetadataManager;
  +import org.apache.ojb.broker.query.QueryByIdentity;
   import org.apache.ojb.broker.sequence.SMKey;
  -
  -import java.io.Serializable;
  +import org.apache.ojb.broker.util.GUID;
  +import org.apache.ojb.broker.util.configuration.impl.OjbConfiguration;
  +import org.apache.ojb.broker.util.configuration.impl.OjbConfigurator;
   
   /**
    * Do some basic tests using ObjectCache implementations.
    *
    * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
  + * @author <a href="mailto:thma@apache.org">Thomas Mahler</a>
    * @version $Id$
    */
   public class ObjectCacheTest extends TestCase
  @@ -138,6 +142,42 @@
                   if (broker != null) broker.close();
               }
           }
  +    }
  +
  +	/**
  +	 * This test checks if the caches of two different brokers are properly isolated.
  +	 * changes made to an object in tx1 should not be visible in tx2 !
  +	 */
  +    public void testCacheIsolation() throws Exception
  +    {
  +        Object[] pk = new Object[] { new Long(42)};
  +        Identity oid = new Identity(Article.class, pk);
  +        
  +        GUID guid = new GUID();        
  +
  +        PersistenceBroker broker1 = PersistenceBrokerFactory.defaultPersistenceBroker();
  +        broker1.beginTransaction();
  +
  +        Article a1 = (Article) broker1.getObjectByQuery(new QueryByIdentity(oid));
  +        String originalName = a1.getArticleName();
  +        a1.setArticleName(guid.toString());
  +
  +        // start a second transaction
  +        PersistenceBroker broker2 = PersistenceBrokerFactory.defaultPersistenceBroker();
  +        broker2.beginTransaction();
  +
  +        Article a2 = (Article) broker2.getObjectByQuery(new QueryByIdentity(oid));
  +        
  +        assertEquals(guid.toString(), a1.getArticleName());
  +        assertEquals(originalName, a2.getArticleName());
  +        assertNotSame(a1, a2);
  +        
  +
  +        broker1.commitTransaction();
  +		broker1.close();
  +		
  +        broker2.commitTransaction();
  +		broker2.close();
       }
   
       private void checkBaseFunctions() throws Exception
  
  
  

Mime
View raw message