You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by ar...@apache.org on 2003/02/06 02:20:55 UTC
cvs commit: db-ojb/src/test/org/apache/ojb repository_junit.xml
arminw 2003/02/05 17:20:55
Modified: src/schema ojbtest-schema.xml
src/test/org/apache/ojb/broker
PerformanceJdbcReferenceTest.java
PerformanceTest.java
src/test/org/apache/ojb/odmg PerformanceTest.java
src/test/org/apache/ojb repository_junit.xml
Added: src/test/org/apache/ojb/performance PerfArticle.java
PerfArticleImpl.java PerfHandle.java PerfMain.java
PerfTest.java
Log:
add a simple framework to allow
comparison of OJB with other O/R tools,
update performance tests
Revision Changes Path
1.22 +21 -0 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.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- ojbtest-schema.xml 16 Jan 2003 22:24:25 -0000 1.21
+++ ojbtest-schema.xml 6 Feb 2003 01:20:54 -0000 1.22
@@ -541,4 +541,25 @@
<column name="PARENT_UID" type="DECIMAL"/>
</table>
+
+ <!--
+ private Long articleId;
+ private String articleName;
+ private int minimumStock;
+ private BigDecimal price;
+ private String unit;
+ private int stock;
+ private int supplierId;
+ private int productGroupId;
+ -->
+ <table name="PERF_ARTICLE">
+ <column name="ARTICLE_ID" required="true" primaryKey="true" type="DECIMAL"/>
+ <column name="ARTICLE_NAME" type="VARCHAR" size="150"/>
+ <column name="MINIMUM_STOCK" type="INTEGER"/>
+ <column name="PRICE" type="DECIMAL"/>
+ <column name="UNIT" type="VARCHAR" size="20"/>
+ <column name="STOCK" type="INTEGER"/>
+ <column name="SUPPLIER_ID" type="INTEGER"/>
+ <column name="PRODUCT_GROUP_ID" type="INTEGER"/>
+ </table>
</database>
1.11 +63 -68 db-ojb/src/test/org/apache/ojb/broker/PerformanceJdbcReferenceTest.java
Index: PerformanceJdbcReferenceTest.java
===================================================================
RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/PerformanceJdbcReferenceTest.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- PerformanceJdbcReferenceTest.java 5 Feb 2003 20:03:42 -0000 1.10
+++ PerformanceJdbcReferenceTest.java 6 Feb 2003 01:20:54 -0000 1.11
@@ -24,12 +24,23 @@
*/
public class PerformanceJdbcReferenceTest extends TestCase
{
- PersistenceBroker broker;
+ private Logger logger = LoggerFactory.getLogger("performance");;
- private static Class CLASS = PerformanceJdbcReferenceTest.class;
+ /**
+ * the number of PerformanceArticle objects to work with.
+ */
+ static int articleCount = 10000;
- private Logger logger;
+ /**
+ * the number of iterations to perform.
+ */
+ static int iterations = 2;
+ /**
+ * the offset value for PerformanceArticle primary keys
+ */
+ int offsetId = 10000;
+ PersistenceBroker broker;
private PerformanceArticle[] arr;
/**
@@ -40,27 +51,6 @@
{
super(name);
- logger = LoggerFactory.getLogger("performance");
- }
-
- /**
- * factory method that createa an PerformanceArticle with a given id.
- * @return the created PerformanceArticle object
- * @param id the primary key value for the new object
- */
- private PerformanceArticle createArticle(int id)
- {
- PerformanceArticle a = new PerformanceArticle();
- a.setArticleId(id);
- a.setArticleName("New Performance Article " + id);
- a.setMinimumStock(100);
- a.setOrderedUnits(17);
- a.setPrice(100.0);
- a.setProductGroupId(1);
- a.setStock(234);
- a.setSupplierId(4);
- a.setUnit("bottle");
- return a;
}
/**
@@ -80,7 +70,7 @@
iterations = Integer.parseInt(args[1]);
}
- String[] arr = {CLASS.getName()};
+ String[] arr = {PerformanceJdbcReferenceTest.class.getName()};
junit.textui.TestRunner.main(arr);
}
@@ -108,19 +98,24 @@
}
/**
- * the number of PerformanceArticle objects to work with.
- */
- static int articleCount = 10000;
-
- /**
- * the number of iterations to perform.
- */
- static int iterations = 2;
-
- /**
- * the offset value for PerformanceArticle primary keys
+ * factory method that createa an PerformanceArticle with a given id.
+ * @return the created PerformanceArticle object
+ * @param id the primary key value for the new object
*/
- int offsetId = 10000;
+ private PerformanceArticle createArticle(int id)
+ {
+ PerformanceArticle a = new PerformanceArticle();
+ a.setArticleId(id);
+ a.setArticleName("New Performance Article " + id);
+ a.setMinimumStock(100);
+ a.setOrderedUnits(17);
+ a.setPrice(100.0);
+ a.setProductGroupId(1);
+ a.setStock(234);
+ a.setSupplierId(4);
+ a.setUnit("bottle");
+ return a;
+ }
/**
* obtain a JDBC Connection. OJB API is used to make this code portable for
@@ -133,7 +128,7 @@
// the repository.xml file.
ClassDescriptor cld = broker.getClassDescriptor(PerformanceArticle.class);
JdbcConnectionDescriptor jcd = MetadataManager.getInstance().connectionRepository()
- .getDescriptor(TestHelper.DEF_KEY);
+ .getDescriptor(TestHelper.DEF_KEY);
ConnectionFactory cf = ConnectionFactoryFactory.getInstance().createConnectionFactory();
Connection conn = cf.lookupConnection(jcd);
return conn;
@@ -181,7 +176,7 @@
*/
protected void insertNewArticles() throws Exception
{
- clearTable();
+ clearTable();
Connection conn = getConnection();
@@ -226,16 +221,16 @@
}
- protected void clearTable() throws Exception
- {
- Connection conn = getConnection();
- ClassDescriptor cld = broker.getClassDescriptor(PerformanceArticle.class);
- String table = cld.getFullTableName();
- String column = cld.getFieldDescriptorByName("articleId").getColumnName();
- String sql = "DELETE FROM " + table + " WHERE " + column + " >= " + offsetId;
- PreparedStatement stmt = conn.prepareStatement(sql);
- stmt.execute();
- }
+ protected void clearTable() throws Exception
+ {
+ Connection conn = getConnection();
+ ClassDescriptor cld = broker.getClassDescriptor(PerformanceArticle.class);
+ String table = cld.getFullTableName();
+ String column = cld.getFieldDescriptorByName("articleId").getColumnName();
+ String sql = "DELETE FROM " + table + " WHERE " + column + " >= " + offsetId;
+ PreparedStatement stmt = conn.prepareStatement(sql);
+ stmt.execute();
+ }
/**
* read in all the PerformanceArticles from the RDBMS that have
@@ -252,15 +247,15 @@
String sql = broker.serviceSqlGenerator().getPreparedSelectByPkStatement(cld);
logger.debug("select stmt: " + sql);
- String colId = cld.getFieldDescriptorByName("articleId").getColumnName();
- String colName = cld.getFieldDescriptorByName("articleName").getColumnName();
- String colSupplier = cld.getFieldDescriptorByName("supplierId").getColumnName();
- String colGroup = cld.getFieldDescriptorByName("productGroupId").getColumnName();
- String colUnit = cld.getFieldDescriptorByName("unit").getColumnName();
- String colPrice = cld.getFieldDescriptorByName("price").getColumnName();
- String colStock = cld.getFieldDescriptorByName("stock").getColumnName();
- String colOrdered = cld.getFieldDescriptorByName("orderedUnits").getColumnName();
- String colMin = cld.getFieldDescriptorByName("minimumStock").getColumnName();
+ String colId = cld.getFieldDescriptorByName("articleId").getColumnName();
+ String colName = cld.getFieldDescriptorByName("articleName").getColumnName();
+ String colSupplier = cld.getFieldDescriptorByName("supplierId").getColumnName();
+ String colGroup = cld.getFieldDescriptorByName("productGroupId").getColumnName();
+ String colUnit = cld.getFieldDescriptorByName("unit").getColumnName();
+ String colPrice = cld.getFieldDescriptorByName("price").getColumnName();
+ String colStock = cld.getFieldDescriptorByName("stock").getColumnName();
+ String colOrdered = cld.getFieldDescriptorByName("orderedUnits").getColumnName();
+ String colMin = cld.getFieldDescriptorByName("minimumStock").getColumnName();
long start = System.currentTimeMillis();
try
@@ -319,16 +314,15 @@
logger.debug("select stmt: " + sql);
- String colId = cld.getFieldDescriptorByName("articleId").getColumnName();
- String colName = cld.getFieldDescriptorByName("articleName").getColumnName();
- String colSupplier = cld.getFieldDescriptorByName("supplierId").getColumnName();
- String colGroup = cld.getFieldDescriptorByName("productGroupId").getColumnName();
- String colUnit = cld.getFieldDescriptorByName("unit").getColumnName();
- String colPrice = cld.getFieldDescriptorByName("price").getColumnName();
- String colStock = cld.getFieldDescriptorByName("stock").getColumnName();
- String colOrdered = cld.getFieldDescriptorByName("orderedUnits").getColumnName();
- String colMin = cld.getFieldDescriptorByName("minimumStock").getColumnName();
-
+ String colId = cld.getFieldDescriptorByName("articleId").getColumnName();
+ String colName = cld.getFieldDescriptorByName("articleName").getColumnName();
+ String colSupplier = cld.getFieldDescriptorByName("supplierId").getColumnName();
+ String colGroup = cld.getFieldDescriptorByName("productGroupId").getColumnName();
+ String colUnit = cld.getFieldDescriptorByName("unit").getColumnName();
+ String colPrice = cld.getFieldDescriptorByName("price").getColumnName();
+ String colStock = cld.getFieldDescriptorByName("stock").getColumnName();
+ String colOrdered = cld.getFieldDescriptorByName("orderedUnits").getColumnName();
+ String colMin = cld.getFieldDescriptorByName("minimumStock").getColumnName();
int fetchCount = 0;
@@ -435,6 +429,7 @@
{
try
{
+ logger.info("Test for native JDBC");
for (int i = 0; i < iterations; i++)
{
logger.info("");
1.8 +40 -46 db-ojb/src/test/org/apache/ojb/broker/PerformanceTest.java
Index: PerformanceTest.java
===================================================================
RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/PerformanceTest.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- PerformanceTest.java 5 Feb 2003 20:03:41 -0000 1.7
+++ PerformanceTest.java 6 Feb 2003 01:20:54 -0000 1.8
@@ -1,7 +1,5 @@
package org.apache.ojb.broker;
-import java.util.Iterator;
-
import junit.framework.TestCase;
import org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldMaxPerformanceImpl;
import org.apache.ojb.broker.query.Criteria;
@@ -12,6 +10,8 @@
import org.apache.ojb.broker.util.logging.Logger;
import org.apache.ojb.broker.util.logging.LoggerFactory;
+import java.util.Iterator;
+
/**
* This TestCase contains the OJB performance benchmarks for the
* PersistenceBroker API.
@@ -19,39 +19,27 @@
*/
public class PerformanceTest extends TestCase
{
- PersistenceBroker broker;
-
- private static Class CLASS = PerformanceTest.class;
+ private Logger logger = LoggerFactory.getLogger("performance");
+ /**
+ * the number of PerformanceArticle objects to work with.
+ */
+ static int articleCount = 10000;
- private Logger logger;
+ /**
+ * the number of iterations to perform.
+ */
+ static int iterations = 2;
+ /**
+ * the offset value for PerformanceArticle primary keys
+ */
+ int offsetId = 123456;
+ PersistenceBroker broker;
private PerformanceArticle[] arr;
public PerformanceTest(String name)
-
{
super(name);
- logger = LoggerFactory.getLogger("performance");
- }
-
- /**
- * factory method that createa an PerformanceArticle with a given id.
- * @return the created PerformanceArticle object
- * @param id the primary key value for the new object
- */
- private PerformanceArticle createArticle(int id)
- {
- PerformanceArticle a = new PerformanceArticle();
- a.setArticleId(id);
- a.setArticleName("New Performance Article " + id);
- a.setMinimumStock(100);
- a.setOrderedUnits(17);
- a.setPrice(0.45);
- a.setProductGroupId(1);
- a.setStock(234);
- a.setSupplierId(4);
- a.setUnit("bottle");
- return a;
}
/**
@@ -71,7 +59,7 @@
iterations = Integer.parseInt(args[1]);
}
- String[] arr = { CLASS.getName()};
+ String[] arr = {PerformanceTest.class.getName()};
junit.textui.TestRunner.main(arr);
}
@@ -80,14 +68,14 @@
*/
public void setUp()
{
-
try
{
- // obtain broker instance
+ // obtain broker instance
broker = PersistenceBrokerFactory.defaultPersistenceBroker();
// manipulate configuration to use maximum performance field access
- OjbConfiguration conf = (OjbConfiguration) PersistenceBrokerFactory.getConfigurator().getConfigurationFor(null);
- conf.setPersistentFieldClass(PersistentFieldMaxPerformanceImpl.class);
+ OjbConfiguration conf = (OjbConfiguration) PersistenceBrokerFactory.
+ getConfigurator().getConfigurationFor(null);
+ conf.setPersistentFieldClass(PersistentFieldMaxPerformanceImpl.class);
}
catch (PBFactoryException e)
{
@@ -99,7 +87,6 @@
PerformanceArticle a = createArticle(offsetId + i);
arr[i] = a;
}
-
}
/**
@@ -111,19 +98,25 @@
}
/**
- * the number of PerformanceArticle objects to work with.
- */
- static int articleCount = 10000;
-
- /**
- * the number of iterations to perform.
+ * factory method that createa an PerformanceArticle with a given id.
+ * @return the created PerformanceArticle object
+ * @param id the primary key value for the new object
*/
- static int iterations = 2;
+ private PerformanceArticle createArticle(int id)
+ {
+ PerformanceArticle a = new PerformanceArticle();
+ a.setArticleId(id);
+ a.setArticleName("New Performance Article " + id);
+ a.setMinimumStock(100);
+ a.setOrderedUnits(17);
+ a.setPrice(0.45);
+ a.setProductGroupId(1);
+ a.setStock(234);
+ a.setSupplierId(4);
+ a.setUnit("bottle");
+ return a;
+ }
- /**
- * the offset value for PerformanceArticle primary keys
- */
- int offsetId = 123456;
/**
* deletes all PerformanceArticle created by <code>insertNewArticles</code>.
@@ -174,7 +167,7 @@
broker.beginTransaction();
for (int i = 0; i < articleCount; i++)
{
- Object[] pks = { new Integer(offsetId + i)};
+ Object[] pks = {new Integer(offsetId + i)};
Identity oid = new Identity(PerformanceArticle.class, pks);
PerformanceArticle a = (PerformanceArticle) broker.getObjectByIdentity(oid);
@@ -257,6 +250,7 @@
{
try
{
+ logger.info("Test for PB-api");
for (int i = 0; i < iterations; i++)
{
logger.info("");
1.9 +32 -28 db-ojb/src/test/org/apache/ojb/odmg/PerformanceTest.java
Index: PerformanceTest.java
===================================================================
RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/odmg/PerformanceTest.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- PerformanceTest.java 5 Feb 2003 20:04:40 -0000 1.8
+++ PerformanceTest.java 6 Feb 2003 01:20:54 -0000 1.9
@@ -23,11 +23,10 @@
*/
public class PerformanceTest extends TestCase
{
- private static Class CLASS = PerformanceTest.class;
- private Logger logger;
+ private Logger logger = LoggerFactory.getLogger("performance");
+
private PerformanceArticle[] arr;
private String databaseName;
- PersistenceBroker broker;
/**
* the number of PerformanceArticle objects to work with.
*/
@@ -44,27 +43,6 @@
public PerformanceTest(String name)
{
super(name);
- logger = LoggerFactory.getLogger("performance");
- }
-
- /**
- * factory method that createa an PerformanceArticle with a given id.
- * @return the created PerformanceArticle object
- * @param id the primary key value for the new object
- */
- private PerformanceArticle createArticle(int id)
- {
- PerformanceArticle a = new PerformanceArticle();
- a.setArticleId(id);
- a.setArticleName("New Performance Article " + id);
- a.setMinimumStock(100);
- a.setOrderedUnits(17);
- a.setPrice(0.45);
- a.setProductGroupId(1);
- a.setStock(234);
- a.setSupplierId(4);
- a.setUnit("bottle");
- return a;
}
/**
@@ -83,7 +61,7 @@
{
iterations = Integer.parseInt(args[1]);
}
- String[] arr = {CLASS.getName()};
+ String[] arr = {PerformanceTest.class.getName()};
junit.textui.TestRunner.main(arr);
}
@@ -94,7 +72,6 @@
public void setUp() throws PBFactoryException
{
databaseName = TestHelper.DEF_DATABASE_NAME;
- broker = PersistenceBrokerFactory.defaultPersistenceBroker();
arr = new PerformanceArticle[articleCount];
for (int i = 0; i < articleCount; i++)
{
@@ -110,7 +87,26 @@
public void tearDown()
{
databaseName = null;
- broker.close();
+ }
+
+ /**
+ * factory method that createa an PerformanceArticle with a given id.
+ * @return the created PerformanceArticle object
+ * @param id the primary key value for the new object
+ */
+ private PerformanceArticle createArticle(int id)
+ {
+ PerformanceArticle a = new PerformanceArticle();
+ a.setArticleId(id);
+ a.setArticleName("New Performance Article " + id);
+ a.setMinimumStock(100);
+ a.setOrderedUnits(17);
+ a.setPrice(0.45);
+ a.setProductGroupId(1);
+ a.setStock(234);
+ a.setSupplierId(4);
+ a.setUnit("bottle");
+ return a;
}
/**
@@ -194,10 +190,14 @@
*/
protected void readArticlesByCursor() throws Exception
{
+ // clear the cache
+ PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
broker.clearCache();
+ broker.close();
+
Implementation odmg = OJB.getInstance();
Database db = odmg.newDatabase();
- db.open(databaseName,Database.OPEN_READ_WRITE);
+ db.open(databaseName, Database.OPEN_READ_WRITE);
OQLQuery query = odmg.newOQLQuery();
String sql = "select allArticles from " + PerformanceArticle.class.getName() + " where articleId between " + new Integer(offsetId) + " and " + new Integer(offsetId + articleCount);
query.create(sql);
@@ -253,6 +253,7 @@
{
try
{
+ logger.info("Test for ODMG-api");
for (int i = 0; i < iterations; i++)
{
logger.info("");
@@ -261,7 +262,10 @@
// update all objects
updateExistingArticles();
// querying with empty cache
+ PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
broker.clearCache();
+ broker.close();
+
readArticles();
// querying with hot cache
readArticles();
1.1 db-ojb/src/test/org/apache/ojb/performance/PerfArticle.java
Index: PerfArticle.java
===================================================================
package org.apache.ojb.performance;
import java.math.BigDecimal;
/**
* Persistent object interface.
*
* @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
* @version $Id: PerfArticle.java,v 1.1 2003/02/06 01:20:54 arminw Exp $
*/
public interface PerfArticle
{
public Long getArticleId();
public void setArticleId(Long articleId);
public String getArticleName();
public void setArticleName(String articleName);
public int getMinimumStock();
public void setMinimumStock(int minimumStock);
public BigDecimal getPrice();
public void setPrice(BigDecimal price);
public String getUnit();
public void setUnit(String unit);
public int getStock();
public void setStock(int stock);
public int getSupplierId();
public void setSupplierId(int supplierId);
public int getProductGroupId();
public void setProductGroupId(int productGroupId);
}
1.1 db-ojb/src/test/org/apache/ojb/performance/PerfArticleImpl.java
Index: PerfArticleImpl.java
===================================================================
package org.apache.ojb.performance;
import java.math.BigDecimal;
/**
* Persistent object implementation.
*
* @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
* @version $Id: PerfArticleImpl.java,v 1.1 2003/02/06 01:20:54 arminw Exp $
*/
public class PerfArticleImpl implements PerfArticle
{
private Long articleId;
private String articleName;
private int minimumStock;
private BigDecimal price;
private String unit;
private int stock;
private int supplierId;
private int productGroupId;
public PerfArticleImpl()
{
}
public PerfArticleImpl(Long articleId, String articleName, int minimumStock, BigDecimal price, String unit, int stock, int supplierId, int productGroupId)
{
this.articleId = articleId;
this.articleName = articleName;
this.minimumStock = minimumStock;
this.price = price;
this.unit = unit;
this.stock = stock;
this.supplierId = supplierId;
this.productGroupId = productGroupId;
}
public Long getArticleId()
{
return articleId;
}
public void setArticleId(Long articleId)
{
this.articleId = articleId;
}
public String getArticleName()
{
return articleName;
}
public void setArticleName(String articleName)
{
this.articleName = articleName;
}
public int getMinimumStock()
{
return minimumStock;
}
public void setMinimumStock(int minimumStock)
{
this.minimumStock = minimumStock;
}
public BigDecimal getPrice()
{
return price;
}
public void setPrice(BigDecimal price)
{
this.price = price;
}
public String getUnit()
{
return unit;
}
public void setUnit(String unit)
{
this.unit = unit;
}
public int getStock()
{
return stock;
}
public void setStock(int stock)
{
this.stock = stock;
}
public int getSupplierId()
{
return supplierId;
}
public void setSupplierId(int supplierId)
{
this.supplierId = supplierId;
}
public int getProductGroupId()
{
return productGroupId;
}
public void setProductGroupId(int productGroupId)
{
this.productGroupId = productGroupId;
}
}
1.1 db-ojb/src/test/org/apache/ojb/performance/PerfHandle.java
Index: PerfHandle.java
===================================================================
package org.apache.ojb.performance;
import java.util.Collection;
import java.util.Iterator;
/**
* Derivate this class to implement a test client for the performance test.
*
* @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
* @version $Id: PerfHandle.java,v 1.1 2003/02/06 01:20:54 arminw Exp $
*/
public abstract class PerfHandle implements Runnable
{
private String PREFIX_LOG = "[" + this.getClass().getName() + "] ";
private PerfArticle[] arr;
private String threadName;
private PerfTest test;
private String objectName;
public PerfHandle(PerfTest test)
{
this.test = test;
}
/**
* Init the test. do setup stuff here
*/
public abstract void init() throws Exception;
/**
* Store the given articles to database. Do optimize
* performance.
*/
public abstract void insertNewArticles(PerfArticle[] arr) throws Exception;
/**
* Store the given articles to database. Implement a really
* resource stressing way.
*/
public abstract void insertNewArticlesStress(PerfArticle[] arr) throws Exception;
/**
* Read all stored articles from the database and return the
* result as collection of <code>PerfArticles</code>.
* Do optimize performance.
* @param articleName article name used for all {@link PerfArticle} created
* by this instance/thread. Use this name in your query to match all belonging articles
*/
public abstract Collection readArticlesByCursor(String articleName) throws Exception;
/**
* Delete all given article from the database.
* Do optimize performance.
*/
public abstract void deleteArticles(PerfArticle[] arr) throws Exception;
/**
* Delete all given article from the database in a really resource
* sressing way.
*/
public abstract void deleteArticlesStress(PerfArticle[] arr) throws Exception;
/**
* The returned name was used as 'articleName' for all
* created <code>PerfArticles</code> for this thread.
* This allows an easy build of the query statement
* to match the created {@link PerfArticles} for this
* instance/thread.
*/
public String getTestObjectName()
{
if (objectName == null)
objectName = test.testName() + "_" +
Thread.currentThread().toString() + "_" + test.getPerfTestId();
return objectName;
}
/**
* Return a new instance of a {@link PerfArticle} implementation.
*/
public abstract PerfArticle newPerfArticle(String articleName);
/**
* Do clean up.
*/
public abstract void tearDown() throws Exception;
/**
* Runnable implementation method.
*/
public void run()
{
arr = new PerfArticle[PerfMain.getIterationsPerThread()];
for (int i = 0; i < PerfMain.getIterationsPerThread(); i++)
{
PerfArticle a = newPerfArticle(getTestObjectName());
arr[i] = a;
}
try
{
long period = 0;
init();
if (!PerfMain.isUseStressMode())
{
period = System.currentTimeMillis();
insertNewArticles(arr);
period = System.currentTimeMillis() - period;
test.addTime(1, period);
}
else
{
period = System.currentTimeMillis();
insertNewArticlesStress(arr);
period = System.currentTimeMillis() - period;
test.addTime(1, period);
}
period = System.currentTimeMillis();
Collection col = readArticlesByCursor(objectName);
period = System.currentTimeMillis() - period;
test.addTime(2, period);
if (!PerfMain.isUseStressMode())
{
period = System.currentTimeMillis();
deleteArticles(arr);
period = System.currentTimeMillis() - period;
test.addTime(3, period);
}
else
{
period = System.currentTimeMillis();
deleteArticlesStress(arr);
period = System.currentTimeMillis() - period;
test.addTime(3, period);
}
tearDown();
}
catch (Exception e)
{
e.printStackTrace();
test.registerException(test.testName(), e);
}
finally
{
test.checkOut();
test.activeThreads(true);
}
}
private boolean checkQueryResult(Collection col)
{
Iterator iter = col.iterator();
int fetchCount = 0;
while (iter.hasNext())
{
fetchCount++;
PerfArticle a = (PerfArticle) iter.next();
}
if (fetchCount != arr.length)
{
System.out.println("## Read objects: Could not found number of created objects, expected " +
(arr.length) + " found " + fetchCount + " ##");
}
return true;
}
}
1.1 db-ojb/src/test/org/apache/ojb/performance/PerfMain.java
Index: PerfMain.java
===================================================================
package org.apache.ojb.performance;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
/**
* The OJB stress/performance test - a small performance test framework for
* testing multi-threaded environments.
*
*
*
*
*
*
*
* <p>
* <b>You have two possibilities to run this test:</b>
* <p>
* - use the build script and call
* <br/>
* <code>bin/build.sh performance2</code>
* or
* <br/>
* <code>bin\build.bat performance2</code>
* </p>
* <p>
* - or perform the test class by yourself
* <br/>
* <code>
* java -classpath .... MyPerfTest.class 10 2000 false 3 2 true
* </code>
* <br/>
* The programm parameter are in order of use:
* <ul>
* <li>number of concurrent threads</li>
* <li>number of handled objects per thread</li>
* <li><code>true</code> client side id generation </li>
* <li>chose the api: <i>1</i> PB-api test, <i>2</i> ODMG-api test, <i>3</i> both api tests</li>
* <li>number of test loops</li>
* <li><code>true</code> use a special stress mode (useful for development)</li>
* </ul>
* </p>
* </p>
* @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
* @version $Id: PerfMain.java,v 1.1 2003/02/06 01:20:54 arminw Exp $
*/
public class PerfMain
{
protected static final String EOL = System.getProperty("line.separator");
private static final String PREFIX_LOG = "[" + PerfMain.class.getName() + "] ";
/**
* iterations per thread
*/
private static int iterationsPerThread = 500;
/**
* number of concurrent threads
*/
private static int concurrentThreads = 10;
/**
* if false we use performance optimized delete/insert method
*/
private static boolean useStressMode = false;
/**
* number of test loops
*/
private static int testLoops = 1;
private Map resultMap;
private Map exceptionMap;
public static void main(String[] args)
{
PerfMain main = new PerfMain();
try
{
long peroid = System.currentTimeMillis();
// start the test
main.startPerfTest(args);
// print the test results
main.printResult(System.out);
peroid = System.currentTimeMillis() - peroid;
System.out.println();
System.out.println("PerfTest takes " + peroid / 1000 + " [sec]");
}
catch (Exception e)
{
e.printStackTrace();
}
System.exit(0);
}
public PerfMain()
{
this.resultMap = new HashMap();
this.exceptionMap = new Hashtable();
}
/**
* Call this to begin the performance test.
*/
public void startPerfTest(String[] args) throws Exception
{
ArrayList testList = null;
try
{
// comma separated list of the PerfTest implementation classes
if (args.length > 0)
{
StringTokenizer tok = new StringTokenizer(args[0], ",");
testList = new ArrayList();
while (tok.hasMoreTokens())
{
testList.add(tok.nextToken().trim());
}
}
else
{
throw new IllegalArgumentException("No test handles found!");
}
// number of test loops
if (args.length > 1)
{
testLoops = args.length > 1 ? Integer.parseInt(args[1]) : 1;
}
// number of threads
if (args.length > 2)
{
concurrentThreads = Integer.parseInt(args[2]);
}
// number of insert/fetch/delete loops per thread
if (args.length > 3)
{
iterationsPerThread = Integer.parseInt(args[3]);
}
// run in stress mode
if (args.length > 4)
{
useStressMode = Boolean.valueOf(args[4]).booleanValue();
}
}
catch (Exception e)
{
e.printStackTrace();
System.err.println();
System.err.println("Usage of PerfMain:" +
"java -classpath CLASSPATH org.apache.ojb.performance.PerfMain" +
" [comma separated list of PerfTest implementation classes]" +
" [number of test loops]" +
" [number of threads]" +
" [number of insert/fetch/delete loops per thread]" +
" [boolean - run in stress mode]");
System.err.println();
System.err.println("Example: java -classpath" +
" CLASSPATH org.apache.ojb.performance.PerfMain org.MyPerfTest 3 10 500 false");
}
System.out.println("####################################################" +
EOL + "# Start OJB performance-test framework - do " + testLoops + " loop #" +
EOL + "####################################################" + EOL);
Iterator it = testList.iterator();
while (it.hasNext())
{
String perfTest = (String) it.next();
PerfTest test = (PerfTest) Class.forName(perfTest).newInstance();
test.registerPerfMain(this);
Runtime rt = Runtime.getRuntime();
long freeMem = 0;
for (int i = 0; i < testLoops; i++)
{
System.out.println("perform test loop " + (i + 1));
freeMem = rt.freeMemory();
test.performTest();
freeMem = (freeMem - rt.freeMemory()) / 1024;
System.out.println("allocated memory after test: " + freeMem + " kb");
rt.gc();
}
}
}
public void printResult(OutputStream out)
{
PrintStream print = new PrintStream(out);
print.println();
if (!getExceptionMap().isEmpty())
{
StringBuffer buf = new StringBuffer();
buf.append(EOL + "Failures occured, test not valid:" + EOL);
Iterator it = getExceptionMap().keySet().iterator();
while (it.hasNext())
{
String causer = (String) it.next();
buf.append("Failure cause by " + causer + ", exception was " + exceptionMap.get(causer) + EOL);
}
print.println(buf.toString());
}
Iterator it = resultMap.values().iterator();
while (it.hasNext())
{
PerfResult result = (PerfResult) it.next();
print.println(buildTestSummary(result));
}
}
private String buildTestSummary(PerfResult result)
{
String sep = System.getProperty("line.separator");
StringBuffer buf = new StringBuffer();
buf.append(sep);
buf.append("----------------------------------------------------");
buf.append(sep);
buf.append("TEST SUMMARY - " + result.getTestName());
buf.append(sep);
buf.append("----------------------------------------------------");
buf.append(sep);
buf.append(PerfMain.getConcurrentThreads() + " concurrent threads, handle " + PerfMain.getIterationsPerThread() + " articles per thread");
buf.append(sep);
buf.append("Test period: " + (double) (((double) result.getTestPeriod()) / 1000) + " [sec]");
buf.append(sep);
buf.append("Inserting period: " + result.getInsertPeriod() + " [msec]");
buf.append(sep);
buf.append("Fetching period: " + result.getFetchPeriod() + " [msec]");
buf.append(sep);
buf.append("Deleting period: " + result.getDeletePeriod() + " [msec]");
buf.append(sep);
if (result.isValid())
{
buf.append(sep + "Test was successful" + sep);
}
else
{
buf.append(sep + buildObjectBeforeAfterList(result.consistentList) + sep);
}
buf.append("----------------------------------------------------");
return buf.toString();
}
private String buildObjectBeforeAfterList(List consistentList)
{
StringBuffer buf = new StringBuffer();
buf.append("Test failed, inconsistent object count:");
buf.append(EOL);
for (int i = 0; i < consistentList.size(); i++)
{
ConsistentEntry entry = (ConsistentEntry) consistentList.get(i);
buf.append("passed: " + entry.isPassed() + " - objects before test/ after test " +
entry.getObjectsBefore() + "/" + entry.getObjectsAfter() + EOL);
}
return buf.toString();
}
/**
* resultArr[0] startTime/test length
* resultArr[1] inserting times
* resultArr[2] fetching times
* resultArr[3] deleting times
*/
public void addPeriodResult(String testName, long[] resultArr)
{
PerfResult result = (PerfResult) resultMap.get(testName);
if (result == null)
{
result = new PerfResult();
result.setTestName(testName);
result.setIterationsPerThread(getIterationsPerThread());
result.setNumberOfThreads(getConcurrentThreads());
result.setTestLoops(getTestLoops());
resultMap.put(testName, result);
}
result.addTestPeriod(resultArr[0]);
result.addInsertPeriod(resultArr[1]);
result.addFetchPeriod(resultArr[2]);
result.addDeletePeriod(resultArr[3]);
}
public void addConsistentResult(String testName, int objectsBefore, int objectsAfter)
{
ConsistentEntry ce = new ConsistentEntry(objectsBefore, objectsAfter);
PerfResult result = (PerfResult) resultMap.get(testName);
result.addConsistentEntry(ce);
}
public synchronized void registerException(String causer, Exception e)
{
exceptionMap.put(causer, e);
}
public Map getExceptionMap()
{
return exceptionMap;
}
public Collection getResultList()
{
return resultMap.values();
}
public static int getIterationsPerThread()
{
return iterationsPerThread;
}
public static int getConcurrentThreads()
{
return concurrentThreads;
}
public static boolean isUseStressMode()
{
return useStressMode;
}
public static int getTestLoops()
{
return testLoops;
}
//================================================================
// inner class
//================================================================
public static class PerfResult
{
private String testName;
private long testPeriod;
private int testLoops;
private int numberOfThreads;
private int iterationsPerThread;
private long insertPeriod;
private long fetchPeriod;
private long deletePeriod;
private boolean valid;
private List consistentList;
public PerfResult()
{
setValid(true);
this.consistentList = new ArrayList();
}
public String toString()
{
String eol = System.getProperty("line.separator");
StringBuffer buf = new StringBuffer();
buf.append(eol + "[" + this.getClass().getName());
buf.append(eol + "testName=" + testName);
buf.append(eol + "testPeriod=" + testPeriod);
buf.append(eol + "testLoops=" + testLoops);
buf.append(eol + "numberOfThreads=" + numberOfThreads);
buf.append(eol + "iterationsPerThread=" + iterationsPerThread);
buf.append(eol + "isValid=" + isValid());
buf.append(eol + "insertPeriod=" + getInsertPeriod());
buf.append(eol + "fetchPeriod=" + getFetchPeriod());
buf.append(eol + "deletePeriod=" + getDeletePeriod());
buf.append(eol + "consistentList: " + consistentList);
buf.append("]");
return buf.toString();
}
public void addConsistentEntry(ConsistentEntry entry)
{
this.consistentList.add(entry);
valid = valid && entry.isPassed();
}
public boolean isValid()
{
return valid;
}
public void setValid(boolean valid)
{
this.valid = valid;
}
public String getTestName()
{
return testName;
}
public void setTestName(String testName)
{
this.testName = testName;
}
public long getTestPeriod()
{
return testPeriod / getTestLoops();
}
public void addTestPeriod(long testPeriod)
{
this.testPeriod += testPeriod;
}
public int getTestLoops()
{
return testLoops;
}
public void setTestLoops(int testLoops)
{
this.testLoops = testLoops;
}
public int getNumberOfThreads()
{
return numberOfThreads;
}
public void setNumberOfThreads(int numberOfThreads)
{
this.numberOfThreads = numberOfThreads;
}
public int getIterationsPerThread()
{
return iterationsPerThread;
}
public void setIterationsPerThread(int numberOfObjects)
{
this.iterationsPerThread = numberOfObjects;
}
public long getInsertPeriod()
{
return (insertPeriod / getTestLoops()) / getNumberOfThreads();
}
public void addInsertPeriod(long insertPeriod)
{
this.insertPeriod += insertPeriod;
}
public long getFetchPeriod()
{
return (fetchPeriod / getTestLoops()) / getNumberOfThreads();
}
public void addFetchPeriod(long fetchPeriod)
{
this.fetchPeriod += fetchPeriod;
}
public long getDeletePeriod()
{
return (deletePeriod / getTestLoops()) / getNumberOfThreads();
}
public void addDeletePeriod(long deletePeriod)
{
this.deletePeriod += deletePeriod;
}
}
//================================================================
// inner class
//================================================================
public static class ConsistentEntry
{
private int objectsBefore;
private int objectsAfter;
private boolean passed;
public ConsistentEntry(int objectsBefore, int objectsAfter)
{
this.objectsBefore = objectsBefore;
this.objectsAfter = objectsAfter;
}
public int getObjectsBefore()
{
return objectsBefore;
}
public int getObjectsAfter()
{
return objectsAfter;
}
public boolean isPassed()
{
return objectsBefore == objectsAfter;
}
public String toString()
{
StringBuffer buf = new StringBuffer();
buf.append("[" + this.getClass().getName()).
append(": objectsBefore=" + getObjectsBefore()).
append(" objectsAfter=" + objectsAfter).
append(" isPassed=" + isPassed());
return buf.toString();
}
}
}
1.1 db-ojb/src/test/org/apache/ojb/performance/PerfTest.java
Index: PerfTest.java
===================================================================
/*
* Date: 08.07.2002
* Time: 19:43:51
*/
package org.apache.ojb.performance;
/**
* Derivate this class to implement a test instance for the performance test.
*
* @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>.
* @version $Id: PerfTest.java,v 1.1 2003/02/06 01:20:54 arminw Exp $
*/
public abstract class PerfTest
{
private final String PREFIX_LOG = "[" + this.getClass().getName() + "] ";
/**
* testTimes[0] startTime/test length
* testTimes[1] inserting times
* testTimes[2] fetching times
* testTimes[3] deleting times
*/
private long[] testTimes;
private int threadCount;
private ThreadGroup threadGroup;
private PerfMain perfMain;
private long perfTestId;
private boolean checked;
public PerfTest()
{
threadGroup = new ThreadGroup(testName() + "_Group");
perfTestId = System.currentTimeMillis();
checked = false;
}
/**
* Returns the name of the test
*/
public abstract String testName();
/**
* Returns a new instance of a {@link PerfHandle} implementation.
*/
public abstract PerfHandle newPerfHandle(PerfTest test);
/**
* Returns the count of all found {@link PerformanceArticle}
* in database. Do not use the cache to get the count!
*/
public abstract int articleCount();
private void checkApi() throws Exception
{
PerfHandle handle = newPerfHandle(this);
PerfArticle article = handle.newPerfArticle(testName());
PerfArticle[] arr = new PerfArticle[]{article};
handle.init();
handle.insertNewArticles(arr);
handle.readArticlesByCursor(testName());
handle.deleteArticles(arr);
handle.tearDown();
checked = true;
}
public void performTest()
{
try
{
if (!checked)
{
checkApi();
System.out.println(PerfMain.EOL + "# Start PerfTest: " + testName() + " #");
}
int objectCount = 0;
int objectCountAfter = 0;
int activeThreadsStart = threadGroup.activeCount();
testTimes = new long[4];
threadCount = PerfMain.getConcurrentThreads();
objectCount = articleCount();
testMultithreaded();
while (threadGroup.activeCount() > activeThreadsStart)
{
System.out.println(PREFIX_LOG + "active threads/base threads: " + threadGroup.activeCount() + " / " + activeThreadsStart);
try
{
Thread.sleep(1500);
}
catch (InterruptedException e)
{
}
}
objectCountAfter = articleCount();
perfMain.addPeriodResult(testName(), testTimes);
perfMain.addConsistentResult(testName(), objectCount, objectCountAfter);
}
catch (Exception e)
{
perfMain.registerException(testName(), e);
e.printStackTrace();
}
}
public void registerException(String causer, Exception e)
{
perfMain.registerException(causer, e);
}
public void testMultithreaded()
{
String sep = System.getProperty("line.separator");
testTimes[0] = System.currentTimeMillis();
for (int i = 0; i < PerfMain.getConcurrentThreads(); i++)
{
PerfHandle ph = newPerfHandle(this);
new Thread(threadGroup, ph).start();
}
System.out.print("+");
while (activeThreads(false) > 0)
{
//loop till all threads ended
//method activeThreads "suspend" (call wait)
//this thread,
//cause we do not want to trace this loop
}
testTimes[0] = (long) (System.currentTimeMillis() - testTimes[0]);
}
public synchronized int activeThreads(boolean notify)
{
try
{
//freeze main thread, we only want to trace client threads
if (!notify)
wait();
else
notifyAll();
}
catch (InterruptedException e)
{
}
System.out.print(".");
return this.threadCount;
}
public synchronized void checkOut()
{
--threadCount;
}
public synchronized void addTime(int position, long time)
{
testTimes[position] = testTimes[position] + time;
}
public void registerPerfMain(PerfMain perfMain)
{
this.perfMain = perfMain;
}
public ThreadGroup getThreadGroup()
{
return threadGroup;
}
public long getPerfTestId()
{
return perfTestId;
}
}
1.39 +63 -0 db-ojb/src/test/org/apache/ojb/repository_junit.xml
Index: repository_junit.xml
===================================================================
RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/repository_junit.xml,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -r1.38 -r1.39
--- repository_junit.xml 2 Feb 2003 10:23:00 -0000 1.38
+++ repository_junit.xml 6 Feb 2003 01:20:54 -0000 1.39
@@ -3021,4 +3021,67 @@
</reference-descriptor>
</class-descriptor>
+<!-- ************************************************* -->
+<!-- Performance/Stress test descriptor -->
+<!-- ************************************************* -->
+<!--
+ private Long articleId;
+ private String articleName;
+ private int minimumStock;
+ private BigDecimal price;
+ private String unit;
+ private int stock;
+ private int supplierId;
+ private int productGroupId;
+-->
+<class-descriptor
+ class="org.apache.ojb.performance.PerfArticleImpl"
+ table="PERF_ARTICLE"
+ >
+ <documentation>The OJB PerfArticle implementation class descriptor</documentation>
+ <field-descriptor
+ name="articleId"
+ column="ARTICLE_ID"
+ jdbc-type="BIGINT"
+ primarykey="true"
+ autoincrement="true"
+ />
+ <field-descriptor
+ name="articleName"
+ column="ARTICLE_NAME"
+ jdbc-type="VARCHAR"
+ />
+ <field-descriptor
+ name="minimumStock"
+ column="MINIMUM_STOCK"
+ jdbc-type="INTEGER"
+ />
+ <field-descriptor
+ name="price"
+ column="PRICE"
+ jdbc-type="DECIMAL"
+ />
+ <field-descriptor
+ name="unit"
+ column="UNIT"
+ jdbc-type="VARCHAR"
+ />
+ <field-descriptor
+ name="stock"
+ column="STOCK"
+ jdbc-type="INTEGER"
+ />
+ <field-descriptor
+ name="supplierId"
+ column="SUPPLIER_ID"
+ jdbc-type="INTEGER"
+ />
+ <field-descriptor
+ name="productGroupId"
+ column="PRODUCT_GROUP_ID"
+ jdbc-type="INTEGER"
+ />
+ </class-descriptor>
+
+
<!-- Mapping of classes used in junit tests and tutorials ends here -->