mkalen 2005/03/11 10:18:19
Modified: src/test/org/apache/ojb/broker/metadata
MetadataMultithreadedTest.java
Log:
Merge with OJB_1_0_RELEASE branch: testcase for asserting that
CollectionProxy loading is able to reset profile even if "wrong"
metadataprofile is active at load time. (Already passes in OJB1.1 because of
broker refactoring.)
Revision Changes Path
1.12 +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.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- MetadataMultithreadedTest.java 11 Mar 2005 18:01:05 -0000 1.11
+++ MetadataMultithreadedTest.java 11 Mar 2005 18:18:19 -0000 1.12
@@ -137,6 +137,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
+ {
+ final MetadataManager mm = ojb.getMetadataManager();
+
+ // 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 = ojb.lookupBroker();
+ 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
{
int loops = 7;
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]