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/[EMAIL
PROTECTED]&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 @@
<ProductGroup GroupId="6" GroupName="bread" Description=""/>
<ProductGroup GroupId="7" GroupName="Fruits" Description="Fr�chte etc."/>
<ProductGroup GroupId="8" GroupName="Dairy Products" Description="Kat
8"/>
+ <ProductGroup GroupId="4711" GroupName="Random Articles"
Description="Used for MetadataMultithreadedTest"/>
<Article ArticleId="1" ArticleName="Chai" SupplierId="1"
ProductGroupId="1" Unit="10 boxes x 20 bags" Price="18.53" Stock="39"
OrderedUnits="0" MinimumStock="10" InSelloutArticle="0"/>
<Article ArticleId="2" ArticleName="Chang" SupplierId="1"
ProductGroupId="1" Unit="24 - 12 oz bottles" Price="19.89" Stock="17"
OrderedUnits="40" MinimumStock="25" InSelloutArticle="0"/>
@@ -104,6 +105,9 @@
<Article ArticleId="75" ArticleName="Rh�nbr�u Klosterbier"
SupplierId="12" ProductGroupId="1" Unit="24 - 0.5 l bottles" Price="7.75"
Stock="125" OrderedUnits="0" MinimumStock="25" InSelloutArticle="0"/>
<Article ArticleId="76" ArticleName="Lakkalik��ri" SupplierId="23"
ProductGroupId="1" Unit="500 ml" Price="18.0" Stock="57" OrderedUnits="0"
MinimumStock="20" InSelloutArticle="0"/>
<Article ArticleId="77" ArticleName="Original Frankfurter gr�ne So�e"
SupplierId="12" ProductGroupId="2" Unit="12 boxes" Price="13.0" Stock="32"
OrderedUnits="0" MinimumStock="15" InSelloutArticle="0"/>
+ <Article ArticleId="4711" ArticleName="Proxied Article 1"
SupplierId="12" ProductGroupId="4711" Unit="1 Java class" Price="1.3" Stock="5"
OrderedUnits="0" MinimumStock="1" InSelloutArticle="0"/>
+ <Article ArticleId="4712" ArticleName="Proxied Article 2"
SupplierId="12" ProductGroupId="4711" Unit="1 Java class" Price="1.5" Stock="2"
OrderedUnits="0" MinimumStock="0" InSelloutArticle="0"/>
+ <Article ArticleId="4713" ArticleName="Proxied Article 3"
SupplierId="12" ProductGroupId="4711" Unit="1 Java class" Price="1.9" Stock="7"
OrderedUnits="0" MinimumStock="5" InSelloutArticle="0"/>
<Books ArtikelNr="100" Artikelname="Hamlet" LieferantenNr="12"
KategorieNr="5" Liefereinheit="12 boxes" Einzelpreis="34.0" Lagerbestand="32"
Bestellteeinheiten="0" Mindestbestand="15" Auslaufartikel="0" Isbn="1234567890"
Author="W. Shakespeare"/>
<Books ArtikelNr="101" Artikelname="Faust" LieferantenNr="12"
KategorieNr="5" Liefereinheit="12 boxes" Einzelpreis="56.0" Lagerbestand="32"
Bestellteeinheiten="0" Mindestbestand="15" Auslaufartikel="0" Isbn="1234567890"
Author="J.W. v. Goethe"/>
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]