Return-Path: Delivered-To: apmail-db-ojb-dev-archive@www.apache.org Received: (qmail 82472 invoked from network); 28 Sep 2004 14:13:56 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 28 Sep 2004 14:13:56 -0000 Received: (qmail 61884 invoked by uid 500); 28 Sep 2004 14:13:54 -0000 Delivered-To: apmail-db-ojb-dev-archive@db.apache.org Received: (qmail 61831 invoked by uid 500); 28 Sep 2004 14:13:52 -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 61815 invoked by uid 500); 28 Sep 2004 14:13:52 -0000 Received: (qmail 61789 invoked by uid 99); 28 Sep 2004 14:13:52 -0000 X-ASF-Spam-Status: No, hits=-10.0 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Tue, 28 Sep 2004 07:13:51 -0700 Received: (qmail 82386 invoked by uid 1510); 28 Sep 2004 14:13:50 -0000 Date: 28 Sep 2004 14:13:50 -0000 Message-ID: <20040928141350.82385.qmail@minotaur.apache.org> From: arminw@apache.org To: db-ojb-cvs@apache.org Subject: cvs commit: db-ojb/src/test/org/apache/ojb repository_junit_reference.xml X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N arminw 2004/09/28 07:13:50 Modified: src/schema Tag: OJB_1_0_RELEASE ojbtest-schema.xml src/test/org/apache/ojb/broker Tag: OJB_1_0_RELEASE MultithreadedReadTest.java src/test/org/apache/ojb Tag: OJB_1_0_RELEASE repository_junit_reference.xml Log: modify test to show problem with object materialization in multthreaded environments under heavy load Revision Changes Path No revision No revision 1.80.2.2 +15 -1 db-ojb/src/schema/ojbtest-schema.xml Index: ojbtest-schema.xml =================================================================== RCS file: /home/cvs/db-ojb/src/schema/ojbtest-schema.xml,v retrieving revision 1.80.2.1 retrieving revision 1.80.2.2 diff -u -r1.80.2.1 -r1.80.2.2 --- ojbtest-schema.xml 27 Jul 2004 00:31:50 -0000 1.80.2.1 +++ ojbtest-schema.xml 28 Sep 2004 14:13:49 -0000 1.80.2.2 @@ -857,6 +857,20 @@ + + + + + +
+ + + + + + +
+ No revision No revision 1.3.2.1 +265 -51 db-ojb/src/test/org/apache/ojb/broker/MultithreadedReadTest.java Index: MultithreadedReadTest.java =================================================================== RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/MultithreadedReadTest.java,v retrieving revision 1.3 retrieving revision 1.3.2.1 diff -u -r1.3 -r1.3.2.1 --- MultithreadedReadTest.java 5 Apr 2004 17:11:48 -0000 1.3 +++ MultithreadedReadTest.java 28 Sep 2004 14:13:49 -0000 1.3.2.1 @@ -6,6 +6,8 @@ import java.util.Iterator; import java.util.List; +import org.apache.ojb.broker.metadata.ClassDescriptor; +import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor; import org.apache.ojb.broker.query.Criteria; import org.apache.ojb.broker.query.QueryByCriteria; import org.apache.ojb.junit.JUnitExtensions; @@ -19,7 +21,11 @@ */ public class MultithreadedReadTest extends JUnitExtensions.MultiThreadedTestCase { - int loops = 2; + static final int NONE = ObjectReferenceDescriptor.CASCADE_NONE; + static final int LINK = ObjectReferenceDescriptor.CASCADE_LINK; + static final int OBJECT = ObjectReferenceDescriptor.CASCADE_OBJECT; + + int loops = 1; int concurrentThreads = 19; int numberOfObjects = 30; @@ -41,19 +47,39 @@ protected void tearDown() throws Exception { + PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker(); + try + { + changeReferenceSetting(broker, AccountImpl.class, "buyer", true, NONE, NONE, false); + changeReferenceSetting(broker, BuyerImpl.class, "address", true, NONE, NONE, false); + changeReferenceSetting(broker, BuyerImpl.class, "invoices", true, NONE, NONE, false); + changeReferenceSetting(broker, BuyerImpl.class, "articles", true, NONE, NONE, false); + } + finally + { + if(broker != null) + { + broker.close(); + } + } super.tearDown(); } public void testClosedPB() throws Throwable { String name = "testClosedPB_"+System.currentTimeMillis(); - - Integer[] ids = prepareTestRead(name, 5); Account account = null; PersistenceBroker broker = null; try { broker = PersistenceBrokerFactory.defaultPersistenceBroker(); + changeReferenceSetting(broker, AccountImpl.class, "buyer", true, OBJECT, OBJECT, false); + changeReferenceSetting(broker, BuyerImpl.class, "address", true, OBJECT, OBJECT, false); + changeReferenceSetting(broker, BuyerImpl.class, "invoices", true, OBJECT, OBJECT, false); + changeReferenceSetting(broker, BuyerImpl.class, "articles", true, OBJECT, OBJECT, false); + Integer[] ids = prepareTestRead(broker, name, 5); + broker.clearCache(); + Criteria crit = new Criteria(); crit.addIn("id", Arrays.asList(ids)); QueryByCriteria query = new QueryByCriteria(Account.class, crit); @@ -89,13 +115,18 @@ for (int k = 0; k < loops; k++) { String searchCriteria = "testObjectMaterializationByDifferentThread_" + System.currentTimeMillis(); - prepareTestRead(searchCriteria, concurrentThreads); - - Collection accounts; PersistenceBroker broker = null; + Collection accounts; try { broker = PersistenceBrokerFactory.defaultPersistenceBroker(); + changeReferenceSetting(broker, AccountImpl.class, "buyer", true, OBJECT, OBJECT, false); + changeReferenceSetting(broker, BuyerImpl.class, "address", true, OBJECT, OBJECT, true); + changeReferenceSetting(broker, BuyerImpl.class, "invoices", true, OBJECT, OBJECT, true); + changeReferenceSetting(broker, BuyerImpl.class, "articles", true, OBJECT, OBJECT, false); + prepareTestRead(broker, searchCriteria, concurrentThreads); + broker.clearCache(); + Criteria crit = new Criteria(); crit.addEqualTo("name", searchCriteria); QueryByCriteria query = new QueryByCriteria(Account.class, crit); @@ -123,15 +154,32 @@ public void testMultithreadedRead() throws Exception { String searchCriteria = "testMultithreadedRead_" + System.currentTimeMillis(); - prepareTestRead(searchCriteria, numberOfObjects); + PersistenceBroker broker = null; + try + { + broker = PersistenceBrokerFactory.defaultPersistenceBroker(); + changeReferenceSetting(broker, AccountImpl.class, "buyer", true, OBJECT, OBJECT, false); + changeReferenceSetting(broker, BuyerImpl.class, "address", true, OBJECT, OBJECT, false); + changeReferenceSetting(broker, BuyerImpl.class, "invoices", true, OBJECT, OBJECT, false); + changeReferenceSetting(broker, BuyerImpl.class, "articles", true, OBJECT, OBJECT, false); + prepareTestRead(broker, searchCriteria, numberOfObjects); + broker.clearCache(); + } + finally + { + if(broker != null) broker.close(); + } + + System.out.println(); System.out.println("Multithreaded read of objects - start"); System.out.println("" + concurrentThreads + " concurrent threads read " + numberOfObjects + " objects per thread, loop " + loops + " times"); for (int k = 0; k < loops; k++) { - PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker(); + broker = PersistenceBrokerFactory.defaultPersistenceBroker(); broker.clearCache(); broker.close(); + TestCaseRunnable tct [] = new TestCaseRunnable[concurrentThreads]; for (int i = 0; i < concurrentThreads; i++) { @@ -140,7 +188,7 @@ // run test classes runTestCaseRunnables(tct); } - System.out.println(); + System.out.println("Multithreaded read of objects - end"); } @@ -150,15 +198,33 @@ public void testMultithreadedLazyRead() throws Exception { String name = "testMultithreadedLazyRead" + System.currentTimeMillis(); - List identityList = prepareTestLazyRead(name, concurrentThreads); + PersistenceBroker broker = null; + List identityList = null; + try + { + broker = PersistenceBrokerFactory.defaultPersistenceBroker(); + changeReferenceSetting(broker, AccountImpl.class, "buyer", true, OBJECT, OBJECT, false); + changeReferenceSetting(broker, BuyerImpl.class, "address", true, OBJECT, OBJECT, true); + changeReferenceSetting(broker, BuyerImpl.class, "invoices", true, OBJECT, OBJECT, true); + changeReferenceSetting(broker, BuyerImpl.class, "articles", true, OBJECT, OBJECT, true); + identityList = prepareTestLazyRead(broker, name, concurrentThreads); + broker.clearCache(); + } + finally + { + if(broker != null) broker.close(); + } + + System.out.println(); System.out.println("Multithreaded lazy read of objects - start"); System.out.println("" + concurrentThreads + " concurrent threads read different object with lazy" + " materialization reference, loop " + loops + " times"); for (int k = 0; k < loops; k++) { - PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker(); + broker = PersistenceBrokerFactory.defaultPersistenceBroker(); broker.clearCache(); broker.close(); + TestCaseRunnable tct [] = new TestCaseRunnable[concurrentThreads]; for (int i = 0; i < concurrentThreads; i++) { @@ -167,63 +233,85 @@ // run test classes runTestCaseRunnables(tct); } - System.out.println(); System.out.println("Multithreaded lazy read of objects - end"); } - private Integer[] prepareTestRead(String name, int numbers) throws Exception + private Integer[] prepareTestRead(PersistenceBroker broker, String name, int numbers) throws Exception { Integer[] ids = new Integer[numbers]; - PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker(); - try + for (int i = 0; i < numbers; i++) { - broker.beginTransaction(); - for (int i = 0; i < numbers; i++) - { - AddressType type = new AddressTypeImpl(name); - Address address = new AddressImpl(name, type); - Buyer buyer = new BuyerImpl(name, address); - Account account = new AccountImpl(name, buyer); - broker.store(account); - ids[i] = account.getId(); - } - broker.commitTransaction(); - broker.clearCache(); + AddressType type = new AddressTypeImpl(name); + Address address = new AddressImpl(name, type); + Buyer buyer = new BuyerImpl(name, address); + buyer.setArticles(buildArticles(name, numbers)); + buyer.setInvoices(buildInvoices(name, numbers)); + Account account = new AccountImpl(name, buyer); + broker.store(account); + ids[i] = account.getId(); } - finally + return ids; + } + + private List prepareTestLazyRead(PersistenceBroker broker, String searchCriteria, int numbers) throws Exception + { + List result = new ArrayList(); + for (int i = 0; i < numbers; i++) { - if (broker != null) broker.close(); + AddressType type = new AddressTypeImpl(searchCriteria); + Address address = new AddressImpl(searchCriteria, type); + Buyer buyer = new BuyerImpl(searchCriteria, address); + buyer.setArticles(buildArticles(searchCriteria, numbers)); + buyer.setInvoices(buildInvoices(searchCriteria, numbers)); + Account account = new AccountImpl(searchCriteria, buyer); + broker.store(account); + Identity oid = broker.serviceIdentity().buildIdentity(account); + result.add(oid); } - return ids; + return result; } - private List prepareTestLazyRead(String searchCriteria, int numbers) throws Exception + private List buildInvoices(String name, int numbers) { List result = new ArrayList(); - PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker(); - try + for(int i = 0; i < numbers; i++) { - broker.beginTransaction(); - for (int i = 0; i < numbers; i++) - { - AddressType type = new AddressTypeImpl(searchCriteria); - Address address = new AddressImpl(searchCriteria, type); - Buyer buyer = new BuyerImpl(searchCriteria, address); - Account account = new AccountImpl(searchCriteria, buyer); - broker.store(account); - Identity oid = new Identity(account, broker); - result.add(oid); - } - broker.commitTransaction(); - broker.clearCache(); + String invoiceNumber = "I_" + (long)(Math.random() * Long.MAX_VALUE); + Invoice invoice = new InvoiceImpl(name, invoiceNumber); + result.add(invoice); } - finally + return result; + } + + private List buildArticles(String name, int numbers) + { + List result = new ArrayList(); + for(int i = 0; i < numbers; i++) { - if (broker != null) broker.close(); + Article a = new ArticleImpl(name, "a article description"); + result.add(a); } return result; } + void changeReferenceSetting(PersistenceBroker broker, Class clazz, String fieldName, boolean autoRetrieve, int autoUpdate, int autoDelete, boolean proxy) + { + ClassDescriptor cld = broker.getClassDescriptor(clazz); + ObjectReferenceDescriptor descriptor = cld.getCollectionDescriptorByName(fieldName); + if(descriptor == null) + { + descriptor = cld.getObjectReferenceDescriptorByName(fieldName); + } + if(descriptor == null) + { + throw new RuntimeException("Field name " + fieldName + " does not represent a reference in class '" + clazz.getName() + "'"); + } + descriptor.setLazy(proxy); + descriptor.setCascadeRetrieve(autoRetrieve); + descriptor.setCascadingStore(autoUpdate); + descriptor.setCascadingDelete(autoDelete); + } + //*********************************************** // test handle of multithreaded test @@ -263,6 +351,8 @@ assertNotNull("All buyers have a reference to an Address", account.getBuyer().getAddress()); assertNotNull("All addresses have a reference to an AdressType", account.getBuyer().getAddress().getType()); assertNotNull("All AddressType have a name", account.getBuyer().getAddress().getType().getName()); + assertNotNull("All buyers have populated 1:n reference to Invoice", account.getBuyer().getInvoices()); + assertNotNull("All buyers have populated 1:n reference to Article", account.getBuyer().getArticles()); // System.out.println(""+Thread.currentThread().toString()+": passed"); } } @@ -291,6 +381,8 @@ assertNotNull("All buyers have a reference to an Address", account.getBuyer().getAddress()); assertNotNull("All addresses have a reference to an AdressType", account.getBuyer().getAddress().getType()); assertNotNull("All AddressType have a name", account.getBuyer().getAddress().getType().getName()); + assertNotNull("All buyers have populated 1:n reference to Invoice", account.getBuyer().getInvoices()); + assertNotNull("All buyers have populated 1:n reference to Article", account.getBuyer().getArticles()); // System.out.println(""+Thread.currentThread().toString()+": passed"); } } @@ -335,6 +427,8 @@ assertNotNull("All buyers have a reference to an Address", account.getBuyer().getAddress()); assertNotNull("All addresses have a reference to an AdressType", account.getBuyer().getAddress().getType()); assertNotNull("All AddressType have a name", account.getBuyer().getAddress().getType().getName()); + assertNotNull("All buyers have populated 1:n reference to Invoice", account.getBuyer().getInvoices()); + assertNotNull("All buyers have populated 1:n reference to Article", account.getBuyer().getArticles()); } } @@ -359,6 +453,8 @@ assertEquals(name, account.getBuyer().getAddress().getName()); assertNotNull("All addresses have a reference to an AdressType", account.getBuyer().getAddress().getType()); assertNotNull("All AddressType have a name", account.getBuyer().getAddress().getType().getName()); + assertNotNull("All buyers have populated 1:n reference to Invoice", account.getBuyer().getInvoices()); + assertNotNull("All buyers have populated 1:n reference to Article", account.getBuyer().getArticles()); } } @@ -407,13 +503,18 @@ public interface Buyer extends Base { Address getAddress(); - void setAddress(Address address); + public List getInvoices(); + public void setInvoices(List invoices); + public List getArticles(); + public void setArticles(List articles); } public static class BuyerImpl extends BaseImpl implements Buyer { - Address address; + private Address address; + private List invoices; + private List articles; public BuyerImpl(String name, Address address) { @@ -421,6 +522,14 @@ this.address = address; } + public BuyerImpl(String name, Address address, List invoices, List articles) + { + super(name); + this.address = address; + this.invoices = invoices; + this.articles = articles; + } + public BuyerImpl(Address address) { this.address = address; @@ -431,6 +540,26 @@ } + public List getInvoices() + { + return invoices; + } + + public void setInvoices(List invoices) + { + this.invoices = invoices; + } + + public List getArticles() + { + return articles; + } + + public void setArticles(List articles) + { + this.articles = articles; + } + public Address getAddress() { return address; @@ -539,6 +668,91 @@ public void setName(String name) { this.name = name; + } + } + + public static interface Invoice extends Base + { + public String getInvoiceNumber(); + public void setInvoiceNumber(String invoiceNumber); + } + + public static class InvoiceImpl extends BaseImpl implements Invoice + { + private String invoiceNumber; + private Integer buyerId; + + public InvoiceImpl() + { + } + + public InvoiceImpl(String name, String invoiceNumber) + { + super(name); + this.invoiceNumber = invoiceNumber; + } + + + public Integer getBuyerId() + { + return buyerId; + } + + public void setBuyerId(Integer buyerId) + { + this.buyerId = buyerId; + } + + public String getInvoiceNumber() + { + return invoiceNumber; + } + + public void setInvoiceNumber(String invoiceNumber) + { + this.invoiceNumber = invoiceNumber; + } + } + + public static interface Article extends Base + { + public String getDescription(); + public void setDescription(String description); + } + + public static class ArticleImpl extends BaseImpl implements Article + { + private String description; + private Integer buyerId; + + public ArticleImpl() + { + } + + public ArticleImpl(String name, String description) + { + super(name); + this.description = description; + } + + public Integer getBuyerId() + { + return buyerId; + } + + public void setBuyerId(Integer buyerId) + { + this.buyerId = buyerId; + } + + public String getDescription() + { + return description; + } + + public void setDescription(String description) + { + this.description = description; } } } No revision No revision 1.17.2.2 +95 -3 db-ojb/src/test/org/apache/ojb/repository_junit_reference.xml Index: repository_junit_reference.xml =================================================================== RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/repository_junit_reference.xml,v retrieving revision 1.17.2.1 retrieving revision 1.17.2.2 diff -u -r1.17.2.1 -r1.17.2.2 --- repository_junit_reference.xml 11 Sep 2004 17:42:08 -0000 1.17.2.1 +++ repository_junit_reference.xml 28 Sep 2004 14:13:50 -0000 1.17.2.2 @@ -1175,6 +1175,14 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +