Improved Product creation performance test.

This commit is contained in:
trifonnt 2010-01-12 13:37:02 +00:00
parent 71a9fc9c3f
commit e114b8ce9b
3 changed files with 134 additions and 127 deletions

View File

@ -1,28 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.jdt.junit.launchconfig"> <launchConfiguration type="org.eclipse.jdt.junit.launchconfig">
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS"> <listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/extend/src/test/performance/SingleMProductTest.java"/> <listEntry value="/extend/src/test/performance/SingleMProductTest.java"/>
</listAttribute> </listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES"> <listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="1"/> <listEntry value="1"/>
</listAttribute> </listAttribute>
<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/> <booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/>
<booleanAttribute key="org.eclipse.hyades.trace.ui.ATTR_AUTO_MONITORING" value="true"/> <mapAttribute key="org.eclipse.debug.core.preferred_launchers">
<stringAttribute key="org.eclipse.hyades.trace.ui.ATTR_DATA_COLLECTOR" value="org.eclipse.tptp.trace.ui.jvmpiMechanism:org.eclipse.tptp.analysisType.memoryHeap,org.eclipse.tptp.analysisType.execution"/> <mapEntry key="[run]" value="org.eclipse.jdt.junit.launchconfig"/>
<stringAttribute key="org.eclipse.hyades.trace.ui.ATTR_DESTINATION_FILE" value=""/> </mapAttribute>
<stringAttribute key="org.eclipse.hyades.trace.ui.ATTR_DESTINATION_MONITOR" value="DefaultMonitor"/> <booleanAttribute key="org.eclipse.hyades.trace.ui.ATTR_AUTO_MONITORING" value="true"/>
<stringAttribute key="org.eclipse.hyades.trace.ui.ATTR_DESTINATION_PROJECT" value="ProfileProject"/> <stringAttribute key="org.eclipse.hyades.trace.ui.ATTR_DATA_COLLECTOR" value="org.eclipse.tptp.trace.ui.jvmpiMechanism:org.eclipse.tptp.analysisType.memoryHeap,org.eclipse.tptp.analysisType.execution"/>
<stringAttribute key="org.eclipse.hyades.trace.ui.ATTR_FILTER_SET" value="org.eclipse.hyades.trace.ui.filterSet.default"/> <stringAttribute key="org.eclipse.hyades.trace.ui.ATTR_DESTINATION_FILE" value=""/>
<booleanAttribute key="org.eclipse.hyades.trace.ui.ATTR_PROFILE_TO_FILE" value="false"/> <stringAttribute key="org.eclipse.hyades.trace.ui.ATTR_DESTINATION_MONITOR" value="DefaultMonitor"/>
<booleanAttribute key="org.eclipse.hyades.trace.ui.ATTR_PROFILING_LIMIT_INVOCATIONS" value="false"/> <stringAttribute key="org.eclipse.hyades.trace.ui.ATTR_DESTINATION_PROJECT" value="ProfileProject"/>
<intAttribute key="org.eclipse.hyades.trace.ui.ATTR_PROFILING_LIMIT_INVOCATIONS_NUM" value="10000"/> <stringAttribute key="org.eclipse.hyades.trace.ui.ATTR_FILTER_SET" value="org.eclipse.hyades.trace.ui.filterSet.default"/>
<booleanAttribute key="org.eclipse.hyades.trace.ui.ATTR_PROFILING_LIMIT_SECONDS" value="false"/> <booleanAttribute key="org.eclipse.hyades.trace.ui.ATTR_PROFILE_TO_FILE" value="false"/>
<intAttribute key="org.eclipse.hyades.trace.ui.ATTR_PROFILING_LIMIT_SECONDS_NUM" value="5"/> <booleanAttribute key="org.eclipse.hyades.trace.ui.ATTR_PROFILING_LIMIT_INVOCATIONS" value="false"/>
<stringAttribute key="org.eclipse.hyades.trace.ui.ATTR_PROFILING_SET" value="tptp-dummy-profiling-set-Profile-SingleMProductTest"/> <intAttribute key="org.eclipse.hyades.trace.ui.ATTR_PROFILING_LIMIT_INVOCATIONS_NUM" value="10000"/>
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/> <booleanAttribute key="org.eclipse.hyades.trace.ui.ATTR_PROFILING_LIMIT_SECONDS" value="false"/>
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/> <intAttribute key="org.eclipse.hyades.trace.ui.ATTR_PROFILING_LIMIT_SECONDS_NUM" value="5"/>
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/> <stringAttribute key="org.eclipse.hyades.trace.ui.ATTR_PROFILING_SET" value="tptp-dummy-profiling-set-Profile-SingleMProductTest"/>
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit3"/> <stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="test.performance.SingleMProductTest"/> <booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="extend"/> <stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
</launchConfiguration> <stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit3"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="test.performance.SingleMProductTest"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="extend"/>
</launchConfiguration>

View File

@ -1,137 +1,124 @@
package test.performance; package test.performance;
import java.io.FileInputStream; /**********************************************************************
import java.util.Properties; * This file is part of ADempiere Business Suite *
import java.util.logging.Level; * http://www.adempiere.org *
* *
import junit.framework.TestCase; * Copyright (C) Trifon Trifonov. *
* Copyright (C) Contributors *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, *
* MA 02110-1301, USA. *
* *
* Contributors: *
* - Trifon Trifonov (trifonnt@users.sourceforge.net) *
* *
* Sponsors: *
* - Catura AG (http://www.catura.de) *
***********************************************************************/
import java.text.DecimalFormat;
import java.text.NumberFormat;
import org.compiere.model.MProduct; import org.compiere.model.MProduct;
import org.compiere.util.CLogMgt; import test.AdempiereTestCase;
import org.compiere.util.DB;
import org.compiere.util.Ini;
public class MProductTest extends TestCase { /**
* @author Trifon Trifonov
*/
public class MProductTest extends AdempiereTestCase {
// Test: General
private Properties testProperties = null;
private Properties m_Ctx = null;
private String fileName_DefaultValue = "J:/Trifon-CD-0.3/workspace/adempiere-trunk/adempiere/Adempiere/Adempiere.properties";
private String fileName_Key = "AdempiereProperties";
private String fileName_Value = "";
private String isClient_DefaultValue = "Y";
private String isClient_Key = "isClient";
private boolean isClient_Value = true;
private String AD_User_ID_DefaultValue = "0";
private String AD_User_ID_Key = "AD_User_ID";
private int AD_User_ID_Value = 0;
// Test: Specific variables
private MProduct product = null; private MProduct product = null;
private int AD_Org_ID = 0;
private int M_Product_Category_ID = 0;
private int C_TaxCategory_ID = 0;
private int C_UOM_ID = 0;
private String ProductType = null;
@Override protected void setUp() throws Exception
protected void setUp() throws Exception { {
super.setUp(); super.setUp();
// How to setup language
//Env.setContext(getCtx(), Env.LANGUAGE, "en_US");
testProperties = new Properties(); // Organization
testProperties.load(new FileInputStream("test.properties")); AD_Org_ID = Integer.parseInt( testProperties.getProperty("AD_Org_ID", "0") ); // 0 in Any Tenant
fileName_Value = testProperties.getProperty(fileName_Key, fileName_DefaultValue); // M_Product_Category
isClient_Value = "Y".equals( testProperties.getProperty(isClient_Key, isClient_DefaultValue) ); M_Product_Category_ID = Integer.parseInt( testProperties.getProperty("M_Product_Category_ID", "105") ); // 105 in GardenWorld
AD_User_ID_Value = Integer.parseInt(testProperties.getProperty(AD_User_ID_Key, AD_User_ID_DefaultValue) ); // C_TaxCategory
C_TaxCategory_ID = Integer.parseInt( testProperties.getProperty("C_TaxCategory_ID", "107") ); // 107 in GardenWorld
// C_UOM
C_UOM_ID = Integer.parseInt( testProperties.getProperty("C_UOM_ID", "100") ); // 100 in GardenWorld
// C_UOM
ProductType = testProperties.getProperty("ProductType", "I"); // 'I' in GardenWorld
m_Ctx = new Properties(); // How to setup Log Level. Not necessary as AdempiereTestCase is taking care of it!
m_Ctx.setProperty("#AD_User_ID", Integer.valueOf(AD_User_ID_Value).toString()); // CLogMgt.setLevel(Level.OFF);
System.out.println("m_Ctx: " + m_Ctx);
if (fileName_Value.length() < 1) {
assertEquals("Please specify path to Adempiere.properties file!", true, false);
}
System.setProperty("PropertyFile", fileName_Value);
Ini.setClient (isClient_Value);
org.compiere.Adempiere.startup(isClient_Value);
// Force connection if there are enough parameters. Else we work with Adempiere.properties
// if (args.length >= 6) {
// CConnection cc = CConnection.get(Database.DB_ORACLE, args[1], Integer.valueOf(args[2]).intValue(), args[3], args[4], args[5]);
// System.out.println("DB UserID:"+cc.getDbUid());
// DB.setDBTarget(cc);
// }
//CLogMgt.setLevel(Level.ALL);
CLogMgt.setLevel(Level.OFF);
/* Available levels: /* Available levels:
Level.OFF, Level.SEVERE, Level.WARNING, Level.INFO, Level.OFF, Level.SEVERE, Level.WARNING, Level.INFO,
Level.CONFIG, Level.FINE, Level.FINER, Level.FINEST, Level.ALL Level.CONFIG, Level.FINE, Level.FINER, Level.FINEST, Level.ALL
*/ */
// assertEquals("Client is NOT GardenWorld", 11, Env.getAD_Client_ID(getCtx()));
} }
@Override
protected void tearDown() throws Exception {
super.tearDown();
testProperties = null;
m_Ctx = null;
}
public void testMProductCreation() { public void testMProductCreation() {
boolean singleCommit = true; boolean singleCommit = true;
String trxName = "test";
m_Ctx.setProperty("#AD_Client_ID", new Integer(11).toString());
// Start time - 20:16 // Start time - 20:16
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
System.out.println("Start Time(ms) = " + startTime); System.out.println("Start Time(ms) = " + startTime);
System.out.println("Start Time = " + new java.util.Date(startTime)); System.out.println("Start Time = " + new java.util.Date(startTime));
int startCount = 570000; int startCount = 43000;
int count = 10000; int count = 500;
// The 0 symbol shows a digit or 0 if no digit present
// The # symbol shows a digit or nothing if no digit present
NumberFormat formatter = new DecimalFormat("00000"); // -001235
for (int idx= startCount; idx < (startCount + count); idx++) { for (int idx= startCount; idx < (startCount + count); idx++) {
//product = MProduct.get(m_Ctx, int M_Product_ID) System.out.println("idx = " + idx);
product = new MProduct(m_Ctx, 0, trxName); product = new MProduct(getCtx(), 0, getTrxName());
//
product.setAD_Org_ID(0);
product.setValue("Test-Product-" + idx);
product.setName("Test-Product-" + idx);
// M_Product_Category String formattedIdx = formatter.format( idx );
int M_Product_Category_ID = 105; // TODO - Trifon product.setValue("test-product-" + formattedIdx);
product.setName("Test Product " + formattedIdx);
product.setAD_Org_ID(AD_Org_ID);
product.setM_Product_Category_ID(M_Product_Category_ID); product.setM_Product_Category_ID(M_Product_Category_ID);
// C_TaxCategory
int C_TaxCategory_ID = 107; // TODO - Trifon
product.setC_TaxCategory_ID(C_TaxCategory_ID); product.setC_TaxCategory_ID(C_TaxCategory_ID);
// C_UOM
int C_UOM_ID = 100; // TODO - Trifon
product.setC_UOM_ID(C_UOM_ID); product.setC_UOM_ID(C_UOM_ID);
// C_UOM
String ProductType = "I"; // TODO - Trifon
product.setProductType(ProductType); product.setProductType(ProductType);
boolean saveResult = product.save(); boolean saveResult = product.save();
if (!saveResult) { assertTrue("MProduct.save()", saveResult);
assertEquals("Product not updated!", true, saveResult); //System.out.println("product.getM_Product_ID: " + product.getM_Product_ID());
} else { if (singleCommit) {
//System.out.println("product.getM_Product_ID: " + product.getM_Product_ID()); try {
if (singleCommit) { commit();
try { } catch (Exception e) {
DB.commit(true, trxName); fail(e.getLocalizedMessage());
} catch (Exception e) { }
assertEquals("Product not updated!", true, false); }
} } // end 'for' loop
}
}
} // end loop
if (!singleCommit) { if (!singleCommit) {
try { try {
DB.commit(true, trxName); commit();
} catch (Exception e) { } catch (Exception e) {
assertEquals("Product not updated!", true, false); fail(e.getLocalizedMessage());
} }
} }
long endTime = System.currentTimeMillis(); long endTime = System.currentTimeMillis();
@ -152,4 +139,4 @@ public class MProductTest extends TestCase {
assertTrue(this.getClass().getName(), true); assertTrue(this.getClass().getName(), true);
} }
} }

View File

@ -1,4 +1,21 @@
AdempiereProperties=C:/Adempiere/Adempiere.properties AdempiereProperties=C:/Adempiere/Adempiere.properties
isClient=Y isClient=Y
AD_Client_ID=11 AD_Client_ID=11
AD_User_ID=0 #AD_Client_ID=1000006
AD_User_ID=0
# LogLevel: OFF, SEVERE, WARNING, INFO, CONFIG, FINE, FINER, FINEST, ALL
LogLevel=OFF
# MProductTest - Tenant: GardenWorld
AD_Org_ID=0
M_Product_Category_ID=105
C_TaxCategory_ID=107
C_UOM_ID=100
ProductType=I
# MProductTest - Tenant: Test6
#AD_Org_ID=0
#M_Product_Category_ID=1000006
#C_TaxCategory_ID=1000010
#C_UOM_ID=100
#ProductType=I