db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mka...@apache.org
Subject cvs commit: db-ojb/src/test/org/apache/ojb/broker/metadata MetadataMultithreadedTest.java
Date Thu, 03 Mar 2005 21:38:12 GMT
mkalen      2005/03/03 13:38:12

  Modified:    src/test/org/apache/ojb/broker/metadata Tag: OJB_1_0_RELEASE
                        MetadataMultithreadedTest.java
  Log:
  Testcase for reproducing ClassNotPersistenceCapableException under rare (evil!) circumstances
with per-thread metadata changes active, even after CollectionProxy-fix.
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.7.2.3   +51 -1     db-ojb/src/test/org/apache/ojb/broker/metadata/MetadataMultithreadedTest.java
  
  Index: MetadataMultithreadedTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/metadata/MetadataMultithreadedTest.java,v
  retrieving revision 1.7.2.2
  retrieving revision 1.7.2.3
  diff -u -r1.7.2.2 -r1.7.2.3
  --- MetadataMultithreadedTest.java	23 Feb 2005 21:51:34 -0000	1.7.2.2
  +++ MetadataMultithreadedTest.java	3 Mar 2005 21:38:12 -0000	1.7.2.3
  @@ -140,6 +140,56 @@
   
       }
   
  +    /**
  +     * Regression test for loading CollectionProxy data in a thread where the profile
  +     * is swapped, and the thread-local broker is closed, between CollectionProxy construction
  +     * and retrieveCollections-call.
  +     * @throws Exception on unexpected failure
  +     */
  +    public void testCollectionProxySwapProfiles() throws Exception
  +    {
  +        PersistenceBroker broker = null;
  +        try
  +        {
  +            MetadataManager mm = MetadataManager.getInstance();
  +
  +            // Store the current repository mappings under a profile key and load it
  +            DescriptorRepository repository = mm.getRepository();
  +            String profileKey = "TestMappings";
  +            mm.addProfile(profileKey, repository);
  +            mm.loadProfile(profileKey);
  +
  +            // Load object and proxy
  +            ProductGroupWithCollectionProxy pgTemplate = new ProductGroupWithCollectionProxy();
  +            pgTemplate.setGroupId(new Integer(6));
  +            Query query = QueryFactory.newQueryByExample(pgTemplate);
  +            broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  +            ProductGroupWithCollectionProxy productGroup;
  +            assertNotNull(productGroup =
  +                    (ProductGroupWithCollectionProxy) broker.getObjectByQuery(query));
  +
  +            // Close broker to make sure proxy needs a new internal one
  +            broker.close();
  +
  +            // Swap profile (to a completely empty one)
  +            final String emptyKey = "EMPTY";
  +            DescriptorRepository emptyDr = new DescriptorRepository();
  +            mm.addProfile(emptyKey, emptyDr);
  +            mm.loadProfile(emptyKey);
  +
  +            List collectionProxy = productGroup.getAllArticlesInGroup();
  +            assertNotNull(collectionProxy);
  +
  +            // Load proxy data, will throw ClassNotPersistenceCapableException
  +            // if not reactivating profile with new thread-local broker
  +            assertNotNull(collectionProxy.get(0));
  +        }
  +        finally
  +        {
  +            if (broker != null) broker.close();
  +        }
  +    }
  +
       public void testRuntimeMetadataChanges() throws Exception
       {
           PersistenceBroker broker = null;
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message