Return-Path: Delivered-To: apmail-db-ojb-dev-archive@www.apache.org Received: (qmail 20880 invoked from network); 11 Mar 2005 17:31:13 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 11 Mar 2005 17:31:13 -0000 Received: (qmail 96885 invoked by uid 500); 11 Mar 2005 17:31:12 -0000 Delivered-To: apmail-db-ojb-dev-archive@db.apache.org Received: (qmail 96853 invoked by uid 500); 11 Mar 2005 17:31:12 -0000 Mailing-List: contact ojb-dev-help@db.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "OJB Developers List" Reply-To: "OJB Developers List" Delivered-To: mailing list ojb-dev@db.apache.org Received: (qmail 96838 invoked by uid 500); 11 Mar 2005 17:31:12 -0000 Received: (qmail 96835 invoked by uid 99); 11 Mar 2005 17:31:11 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Fri, 11 Mar 2005 09:31:11 -0800 Received: (qmail 20852 invoked by uid 1890); 11 Mar 2005 17:31:10 -0000 Date: 11 Mar 2005 17:31:10 -0000 Message-ID: <20050311173110.20851.qmail@minotaur.apache.org> From: mkalen@apache.org To: db-ojb-cvs@apache.org Subject: cvs commit: db-ojb/src/test/org/apache/ojb/broker/metadata MetadataMultithreadedTest.java X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N mkalen 2005/03/11 09:31:10 Modified: src/schema ojbtest-data.xml src/test/org/apache/ojb/broker/metadata MetadataMultithreadedTest.java Log: Merge with OJB_1_0_RELEASE branch: Add new test method to provoke bug when materialising dynamic proxy created with pre-thread metadata changes activated. See thread at dev-list http://mail-archives.apache.org/eyebrowse/ReadMsg?listName=ojb-dev@db.apache.org&msgNo=9143 Revision Changes Path 1.19 +4 -0 db-ojb/src/schema/ojbtest-data.xml Index: ojbtest-data.xml =================================================================== RCS file: /home/cvs/db-ojb/src/schema/ojbtest-data.xml,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- ojbtest-data.xml 18 Dec 2004 14:01:16 -0000 1.18 +++ ojbtest-data.xml 11 Mar 2005 17:31:10 -0000 1.19 @@ -26,6 +26,7 @@ +
@@ -104,6 +105,9 @@
+
+
+
1.10 +107 -4 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.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- MetadataMultithreadedTest.java 5 Dec 2004 19:55:11 -0000 1.9 +++ MetadataMultithreadedTest.java 11 Mar 2005 17:31:10 -0000 1.10 @@ -2,6 +2,8 @@ import java.util.ArrayList; import java.util.List; +import java.util.Collection; +import java.util.Iterator; import org.apache.commons.lang.ClassUtils; import org.apache.ojb.broker.OJBRuntimeException; @@ -10,8 +12,12 @@ import org.apache.ojb.broker.Person; import org.apache.ojb.broker.Project; import org.apache.ojb.broker.Role; +import org.apache.ojb.broker.Article; +import org.apache.ojb.broker.ProductGroupWithCollectionProxy; +import org.apache.ojb.broker.accesslayer.OJBIterator; import org.apache.ojb.broker.query.Query; import org.apache.ojb.broker.query.QueryByCriteria; +import org.apache.ojb.broker.query.QueryFactory; import org.apache.ojb.broker.sequence.Repository; import org.apache.ojb.broker.util.ClassHelper; import org.apache.ojb.junit.JUnitExtensions; @@ -52,6 +58,10 @@ protected void setUp() throws Exception { super.setUp(); + MetadataManager mm = ojb.getMetadataManager(); + // enable the per thread changes of metadata + mm.setEnablePerThreadChanges(true); + defaultRepository = mm.copyOfGlobalRepository(); } protected void tearDown() throws Exception @@ -65,6 +75,70 @@ return oldTestObjectString; } + public void testProxiedLoading() throws Exception + { + PersistenceBroker broker = null; + try + { + MetadataManager mm = ojb.getMetadataManager(); + // Store the current repository mappings under a profile key + DescriptorRepository repository = mm.getRepository(); + String profileKey = "TestMappings"; + mm.addProfile(profileKey, repository); + + // "Destroy" this thread's mappings + mm.setDescriptor(defaultRepository); + + ProductGroupWithCollectionProxy pgTemplate = new ProductGroupWithCollectionProxy(); + pgTemplate.setGroupId(new Integer(6)); + Query query = QueryFactory.newQueryByExample(pgTemplate); + + broker = ojb.lookupBroker(); + Collection groups; + OJBIterator groupIter; + ProductGroupWithCollectionProxy pg; + + assertNotNull(groupIter = broker.getIteratorByQuery(query)); + assertTrue(groupIter.hasNext()); + + // We have not named any OJB profiles, so using dynamic proxies at this stage is not + // supported + Throwable expectedThrowable = null; + try { + System.err.println("------ The following exception is part of the tests..."); + groupIter.next(); + } catch (Throwable t) { + expectedThrowable = t; + System.err.println("------"); + } + assertNotNull("Should get metadata exception from proxy", expectedThrowable); + groupIter.releaseDbResources(); + + // Load the repository profile and re-try loading. + Iterator proxyIter; + broker.clearCache(); + mm.loadProfile(profileKey); + assertNotNull(groups = broker.getCollectionByQuery(query)); + assertEquals(1, groups.size()); + assertNotNull(proxyIter = groups.iterator()); + assertTrue(proxyIter.hasNext()); + assertNotNull(pg = (ProductGroupWithCollectionProxy) proxyIter.next()); + assertFalse(proxyIter.hasNext()); + assertEquals(pgTemplate.getGroupId(), pg.getGroupId()); + Collection articles; + assertNotNull(articles = pg.getAllArticlesInGroup()); + assertEquals(6, articles.size()); + + TestCaseRunnable tct [] = new TestCaseRunnable[]{new LazyLoading(articles)}; + runTestCaseRunnables(tct); + } + finally + { + if (broker != null) broker.close(); + } + + } + public void testRuntimeMetadataChanges() throws Exception { int loops = 7; @@ -77,9 +151,6 @@ try { MetadataManager mm = ojb.getMetadataManager(); - // enable the per thread changes of metadata - mm.setEnablePerThreadChanges(true); - defaultRepository = mm.copyOfGlobalRepository(); mm.setDescriptor(defaultRepository); ClassDescriptor cld; @@ -378,4 +449,36 @@ } } } + + /** + * Inner test class for lazy materialization of CollectionProxy in different thread. + */ + protected class LazyLoading extends JUnitExtensions.MultiThreadedTestCase.TestCaseRunnable + { + private Collection articles; + + public LazyLoading(Collection articles) + { + assertNotNull(this.articles = articles); + } + + public void runTestCase() throws Throwable + { + // Explicitly clear descriptor repository in this thread (similar to loading + // profile with unrelated class-mappings). + DescriptorRepository dr = new DescriptorRepository(); + MetadataManager.getInstance().setDescriptor(dr); + Article article; + int numArticles = 0; + for (Iterator iterator = articles.iterator(); iterator.hasNext();) + { + assertNotNull(article = (Article) iterator.next()); + assertNotNull(article.getArticleId()); + assertFalse(new Integer(0).equals(article.getArticleId())); + numArticles++; + } + assertEquals(6, numArticles); + } + } + } --------------------------------------------------------------------- To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org For additional commands, e-mail: ojb-dev-help@db.apache.org