Author: arminw
Date: Sat Jan 7 16:27:44 2006
New Revision: 366953
URL: http://svn.apache.org/viewcvs?rev=366953&view=rev
Log:
fix thread handling problem, fix incorrect result, change order of tests on
each loop
Modified:
db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/performance/PerfMain.java
db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/performance/PerfRunner.java
db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/performance/PerfTest.java
Modified:
db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/performance/PerfMain.java
URL:
http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/performance/PerfMain.java?rev=366953&r1=366952&r2=366953&view=diff
==============================================================================
---
db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/performance/PerfMain.java
(original)
+++
db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/performance/PerfMain.java
Sat Jan 7 16:27:44 2006
@@ -225,57 +225,53 @@
}
if(logAll) printer().println("
" +
- EOL + "Start OJB performance-test framework - running " +
testLoops + " loops" +
- EOL +
"-------------------------------------------------------");
+ EOL + "Start OJB Performance Test - running " + testLoops + "
test loops" +
+ EOL + "---------------------------------------------------");
PerfRunner test;
+ ThreadGroup threadGroup = new ThreadGroup("PerfTest_Group_id=" +
Math.random());
for (int i = 0; i < testLoops; i++)
{
Runtime rt = Runtime.getRuntime();
long freeMem;
if(logAll) printer().println(" Loop " + (i + 1));
- if(i%2 == 0)
+ for(int j = 0; j < testList.size(); j++)
{
- for(int j = 0; j < testList.size(); j++)
- {
- String perfTest = (String) testList.get(j);
- Class testHandle = Class.forName(perfTest);
- test = new PerfRunner(testHandle);
- test.registerPerfMain(this);
-
- rt.gc();
- Thread.sleep(300);
- rt.freeMemory();
- rt.gc();
- Thread.sleep(100);
- freeMem = rt.freeMemory();
- test.performTest();
- freeMem = (freeMem - rt.freeMemory()) / 1024;
- if(logAll) printer().println(" allocated memory=" +
freeMem + "kb");
- // rt.gc();
- }
+ String perfTest = (String) testList.get(j);
+ Class testHandle = Class.forName(perfTest);
+ test = new PerfRunner(threadGroup, testHandle);
+ test.registerPerfMain(this);
+
+ rt.gc();
+ Thread.sleep(300);
+ rt.freeMemory();
+ rt.gc();
+ Thread.sleep(100);
+ freeMem = rt.freeMemory();
+ test.performTest();
+ freeMem = (freeMem - rt.freeMemory()) / 1024;
+ if(logAll) printer().println(" allocated memory=" + freeMem +
"kb");
+ // rt.gc();
+ }
+ ArrayList tmpList = new ArrayList(testList);
+ int size = tmpList.size();
+ Object last = tmpList.remove(size - 1);
+ tmpList.add(0, last);
+ testList = tmpList;
+ }
+
+ // should always be skipped, because we use 'thread.join'
+ while(threadGroup.activeCount() > 0)
+ {
+ PerfMain.printer().println("## active threads: " +
threadGroup.activeCount());
+ try
+ {
+ Thread.sleep(200);
}
- else
+ catch(InterruptedException ignore)
{
- for(int j = (testList.size() - 1); j >= 0; j--)
- {
- String perfTest = (String) testList.get(j);
- Class testHandle = Class.forName(perfTest);
- test = new PerfRunner(testHandle);
- test.registerPerfMain(this);
-
- rt.gc();
- Thread.sleep(300);
- rt.freeMemory();
- rt.gc();
- Thread.sleep(100);
- freeMem = rt.freeMemory();
- test.performTest();
- freeMem = (freeMem - rt.freeMemory()) / 1024;
- if(logAll) printer().println(" allocated memory: " +
freeMem + " kb");
- // rt.gc();
- }
+ // ignore
}
}
}
@@ -283,25 +279,6 @@
public void printResult()
{
printer().println();
- if (!getExceptionMap().isEmpty())
- {
- StringBuffer buf = new StringBuffer();
- buf.append(EOL).append("Failures occured, test not
valid:").append(EOL);
- Iterator it = getExceptionMap().entrySet().iterator();
- while (it.hasNext())
- {
- Map.Entry entry = (Map.Entry) it.next();
- buf.append("Failure cause by ").append(entry.getKey());
- if(entry.getValue() != null)
- {
- Throwable ex = ExceptionUtils.getRootCause((Exception)
entry.getValue());
- if(ex == null) ex = (Exception) entry.getValue();
- buf.append(EOL).append("Exception was:
").append(EOL).append(ExceptionUtils.getStackTrace(ex));
- }
- buf.append(EOL);
- }
- printer().println(buf.toString());
- }
printer().println(buildTestSummary(prepareTestResults()));
}
@@ -516,19 +493,30 @@
counter++;
}
buf.append(EOL);
+
+ if (!getExceptionMap().isEmpty())
+ {
+ buf.append(EOL).append("!! Failures occured, test not
valid:").append(EOL);
+ Iterator it = getExceptionMap().entrySet().iterator();
+ while (it.hasNext())
+ {
+ Map.Entry entry = (Map.Entry) it.next();
+ buf.append("Failure cause by ").append(entry.getKey());
+ if(entry.getValue() != null)
+ {
+ Throwable ex = ExceptionUtils.getRootCause((Exception)
entry.getValue());
+ if(ex == null) ex = (Exception) entry.getValue();
+ buf.append(EOL).append("Exception was:
").append(EOL).append(ExceptionUtils.getStackTrace(ex));
+ }
+ buf.append(EOL);
+ }
+ printer().println(buf.toString());
+ }
+
for (int i = 0; i < columnNumbers; i++)
{
buf.append(alignToLength(columnLength, "="));
}
-// if(failures.size() > 0)
-// {
-// buf.append(EOL + "Failures detected:" + EOL);
-// for(int i = 0; i < failures.size(); i++)
-// {
-// PerfResult perfResult = (PerfResult) failures.get(i);
-// buf.append("name=" + perfResult.getTestName() + ", isValid="
+perfResult.isValid() + EOL);
-// }
-// }
return buf.toString();
}
@@ -569,7 +557,7 @@
* testTimes[5] updating times
* testTimes[6] deleting times
*/
- public synchronized void addPeriodResult(String testName, long[] resultArr)
+ public synchronized void addPeriodResult(String testName, long[]
resultArr, boolean isValid)
{
PerfResult result = (PerfResult) resultMap.get(testName);
if (result == null)
@@ -583,6 +571,7 @@
resultMap.put(testName, result);
}
+ result.setValid(isValid);
result.addTestPeriod(resultArr[TIME_TOTAL]);
result.addInsertPeriod(resultArr[TIME_INSERT]);
result.addFetchPeriod(resultArr[TIME_FETCH]);
@@ -595,13 +584,13 @@
{
StringBuffer buf = new StringBuffer();
buf.append(" Test '").append(result.getTestName()).append("' [ms]")
- .append(":
testPeriod=").append(resultArr[0]/getConcurrentThreads())
- .append(" insert=").append(resultArr[1]/getConcurrentThreads())
- .append(" read=").append(resultArr[2]/getConcurrentThreads())
- .append(" read2=").append(resultArr[3]/getConcurrentThreads())
- .append("
byIdentity=").append(resultArr[4]/getConcurrentThreads())
- .append(" update=").append(resultArr[5]/getConcurrentThreads())
- .append("
delete=").append(resultArr[6]/getConcurrentThreads());
+ .append(":
testPeriod=").append(resultArr[TIME_TOTAL]/getConcurrentThreads())
+ .append("
insert=").append(resultArr[TIME_INSERT]/getConcurrentThreads())
+ .append("
read=").append(resultArr[TIME_FETCH]/getConcurrentThreads())
+ .append("
read2=").append(resultArr[TIME_FETCH_2]/getConcurrentThreads())
+ .append("
byIdentity=").append(resultArr[TIME_BY_IDENTITY]/getConcurrentThreads())
+ .append("
update=").append(resultArr[TIME_UPDATE]/getConcurrentThreads())
+ .append("
delete=").append(resultArr[TIME_DELETE]/getConcurrentThreads());
printer().print(buf.toString());
}
else
@@ -816,7 +805,7 @@
public long getTotalTime()
{
- long result = ((insertPeriod + fetchPeriod + updatePeriod +
deletePeriod) / getTestLoops()) / getNumberOfThreads();
+ long result = ((insertPeriod + fetchPeriod + fetchSecondPeriod +
byIdentityPeriod + updatePeriod + deletePeriod) / getTestLoops()) /
getNumberOfThreads();
return result > 0 ? result : 1;
}
Modified:
db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/performance/PerfRunner.java
URL:
http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/performance/PerfRunner.java?rev=366953&r1=366952&r2=366953&view=diff
==============================================================================
---
db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/performance/PerfRunner.java
(original)
+++
db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/performance/PerfRunner.java
Sat Jan 7 16:27:44 2006
@@ -39,6 +39,8 @@
private PerfMain perfMain;
private long perfTestId;
private boolean checked;
+ private boolean isValid;
+
/**
* The threads that are executing.
*/
@@ -47,14 +49,15 @@
private PerfTest test;
- public PerfRunner(Class perfTestClass)
+ public PerfRunner(ThreadGroup group, Class perfTestClass)
{
this.perfTestId = System.currentTimeMillis();
this.checked = false;
this.testClass = perfTestClass;
// create a tmp test instance
this.test = createTest();
- this.threadGroup = new ThreadGroup(testName() + "_Group");
+ this.threadGroup = group;
+ this.isValid = true;
}
private PerfTest createTest()
@@ -137,14 +140,6 @@
{
PerfMain.printer().println(PREFIX_LOG + "Thread join
interrupted.");
}
-
- // should always be skipped, because we use 'thread.join'
- while(threadGroup.activeCount() > 0)
- {
- PerfMain.printer().println("## active threads: " +
threadGroup.activeCount());
- }
-
- threads = null;
}
public void performTest()
@@ -177,7 +172,7 @@
// end of test threads
objectCountAfter = test.articleCount();
- perfMain.addPeriodResult(testName(), testTimes);
+ perfMain.addPeriodResult(testName(), testTimes, isValid);
perfMain.addConsistentResult(testName(), objectCount,
objectCountAfter);
// tear down tmp used test
@@ -192,6 +187,7 @@
public void registerException(String causer, Exception e)
{
+ this.isValid = false;
perfMain.registerException(causer, e);
}
Modified:
db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/performance/PerfTest.java
URL:
http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/performance/PerfTest.java?rev=366953&r1=366952&r2=366953&view=diff
==============================================================================
---
db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/performance/PerfTest.java
(original)
+++
db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/performance/PerfTest.java
Sat Jan 7 16:27:44 2006
@@ -207,7 +207,6 @@
// read objects
period = System.currentTimeMillis();
Collection col = readArticlesByCursor(objectName);
- period = System.currentTimeMillis() - period;
try
{
checkQueryResult(col, m_arr);
@@ -217,6 +216,7 @@
test.registerException(PREFIX_LOG
+ "(Something wrong with query result or with object
insert operation) ", e);
}
+ period = System.currentTimeMillis() - period;
test.addTime(PerfMain.TIME_FETCH, period);
totalTime+=period;
// System.out.println("R=" + period);
@@ -225,7 +225,6 @@
// read objects 2
period = System.currentTimeMillis();
col = readArticlesByCursor(objectName);
- period = System.currentTimeMillis() - period;
try
{
checkQueryResult(col, m_arr);
@@ -235,6 +234,7 @@
test.registerException(PREFIX_LOG
+ "(Something wrong with query result or with object
insert operation) ", e);
}
+ period = System.currentTimeMillis() - period;
test.addTime(PerfMain.TIME_FETCH_2, period);
totalTime+=period;
// System.out.println("R2=" + period);
@@ -328,11 +328,26 @@
if(col.size() > 0)
{
Iterator it = col.iterator();
- Object obj = it.next();
- if(!(obj instanceof PerfArticle))
+ while(it.hasNext())
{
- throw new Exception("Wrong object type found. Expected
instance of"+
- PerfArticle.class.getName() + ", found " +
obj.getClass().getName());
+ Object obj = it.next();
+ if(!(obj instanceof PerfArticle))
+ {
+ throw new Exception("Wrong object type found. Expected
instance of"+
+ PerfArticle.class.getName() + ", found " +
obj.getClass().getName());
+ }
+ else
+ {
+ PerfArticle article = (PerfArticle) obj;
+ article.getArticleId();
+ article.getArticleName();
+ article.getMinimumStock();
+ article.getPrice();
+ article.getProductGroupId();
+ article.getStock();
+ article.getSupplierId();
+ article.getUnit();
+ }
}
}
if (col.size() != m_arr.length)
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]