modules/enterprise/server/jar/pom.xml
| 6
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/performance/test/AvailabilityInsertPurgeTest.java
| 3
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/test/AbstractEJB3PerformanceTest.java
| 20 +
modules/helpers/perftest-support/pom.xml
| 8
modules/helpers/perftest-support/src/main/java/org/rhq/helpers/perftest/support/reporting/ExcelExporter.java
| 153 ++++++++++
modules/helpers/perftest-support/src/main/java/org/rhq/helpers/perftest/support/reporting/PerformanceReportExporter.java
| 36 ++
modules/helpers/perftest-support/src/main/java/org/rhq/helpers/perftest/support/testng/PerformanceReporting.java
| 22 +
7 files changed, 241 insertions(+), 7 deletions(-)
New commits:
commit efcc6caf0f8bfb0c42bbafab7cec36fd76f58c9d
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Tue Oct 5 15:23:46 2010 +0200
Write performance reports to Excel files.
Needs some more work to support showing detail data.
diff --git a/modules/enterprise/server/jar/pom.xml
b/modules/enterprise/server/jar/pom.xml
index 5c94154..1f05256 100644
--- a/modules/enterprise/server/jar/pom.xml
+++ b/modules/enterprise/server/jar/pom.xml
@@ -408,12 +408,6 @@
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>net.sourceforge.jexcelapi</groupId>
- <artifactId>jxl</artifactId>
- <version>2.6.8</version>
- <scope>test</scope>
- </dependency>
<dependency>
<groupId>commons-jxpath</groupId>
diff --git
a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/performance/test/AvailabilityInsertPurgeTest.java
b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/performance/test/AvailabilityInsertPurgeTest.java
index f0d2a5d..a0d27f0 100644
---
a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/performance/test/AvailabilityInsertPurgeTest.java
+++
b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/performance/test/AvailabilityInsertPurgeTest.java
@@ -35,8 +35,10 @@ import org.rhq.enterprise.server.resource.ResourceManagerLocal;
import org.rhq.enterprise.server.system.SystemManagerLocal;
import org.rhq.enterprise.server.test.AbstractEJB3PerformanceTest;
import org.rhq.enterprise.server.util.LookupUtil;
+import org.rhq.helpers.perftest.support.reporting.ExcelExporter;
import org.rhq.helpers.perftest.support.testng.DatabaseSetupInterceptor;
import org.rhq.helpers.perftest.support.testng.DatabaseState;
+import org.rhq.helpers.perftest.support.testng.PerformanceReporting;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Listeners;
@@ -50,6 +52,7 @@ import org.testng.annotations.Test;
*/
@Test(groups = "PERF")
@Listeners({ DatabaseSetupInterceptor.class })
+(a)PerformanceReporting(exporter=ExcelExporter.class)
public class AvailabilityInsertPurgeTest extends AbstractEJB3PerformanceTest {
ResourceManagerLocal resourceManager;
diff --git
a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/test/AbstractEJB3PerformanceTest.java
b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/test/AbstractEJB3PerformanceTest.java
index 057b6c7..5a79853 100644
---
a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/test/AbstractEJB3PerformanceTest.java
+++
b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/test/AbstractEJB3PerformanceTest.java
@@ -20,6 +20,8 @@ package org.rhq.enterprise.server.test;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.rhq.helpers.perftest.support.reporting.PerformanceReportExporter;
+import org.rhq.helpers.perftest.support.testng.PerformanceReporting;
import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
@@ -96,9 +98,27 @@ public class AbstractEJB3PerformanceTest extends AbstractEJB3Test {
protected void reportTimings(ITestResult result, Method meth) {
printTimings(meth.getName());
+ Class clazz = meth.getDeclaringClass();
+ PerformanceReporting pr = (PerformanceReporting)
clazz.getAnnotation(PerformanceReporting.class);
+ if (pr != null) {
+ String file = pr.baseFilename();
+ Class<? extends PerformanceReportExporter> exporterClazz =
pr.exporter();
+ try {
+ PerformanceReportExporter exporter = exporterClazz.newInstance();
+ exporter.setBaseFile(file);
+ exporter.export(timings,result);
+ }
+ catch (Exception e) {
+ // TODO fix this
+ e.printStackTrace();
+ }
+
+ }
+
timings.clear();
startTime.clear();
+
}
@BeforeMethod
diff --git a/modules/helpers/perftest-support/pom.xml
b/modules/helpers/perftest-support/pom.xml
index b8b26af..35c1cd2 100644
--- a/modules/helpers/perftest-support/pom.xml
+++ b/modules/helpers/perftest-support/pom.xml
@@ -80,6 +80,12 @@
<type>jar</type>
<scope>compile</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.poi</groupId>
+ <artifactId>poi</artifactId>
+ <version>3.6</version>
+ </dependency>
+
</dependencies>
<build>
<plugins>
@@ -110,4 +116,4 @@
</plugins>
</build>
-</project>
\ No newline at end of file
+</project>
diff --git
a/modules/helpers/perftest-support/src/main/java/org/rhq/helpers/perftest/support/reporting/ExcelExporter.java
b/modules/helpers/perftest-support/src/main/java/org/rhq/helpers/perftest/support/reporting/ExcelExporter.java
new file mode 100644
index 0000000..aabeb23
--- /dev/null
+++
b/modules/helpers/perftest-support/src/main/java/org/rhq/helpers/perftest/support/reporting/ExcelExporter.java
@@ -0,0 +1,153 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2010 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * 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 version 2 of the License.
+ *
+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.rhq.helpers.perftest.support.reporting;
+
+import org.apache.poi.hssf.usermodel.HSSFCellStyle;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.*;
+import org.testng.ITestResult;
+
+import java.io.*;
+import java.util.Map;
+
+
+/**
+ * Export data to an excel sheet
+ *
+ * @author Heiko W. Rupp
+ */
+public class ExcelExporter implements PerformanceReportExporter {
+
+ private static final String DOT_XLS = ".xls";
+ String baseFileName ;
+
+ @Override
+ public void setBaseFile(String fileName) {
+ if (!fileName.endsWith(DOT_XLS))
+ baseFileName = fileName + DOT_XLS;
+ else
+ baseFileName = fileName;
+ }
+
+ @Override
+ public void export(Map<String, Long> timings, ITestResult result) {
+
+
+ Workbook wb;
+ InputStream inp = null;
+ CellStyle integerStyle;
+ // Check if Workbook is present - otherwise create it
+ try {
+ inp = new FileInputStream(baseFileName);
+ wb = new HSSFWorkbook(inp);
+ } catch (Exception e) {
+ wb = new HSSFWorkbook();
+ }
+ // Now write to it
+ try {
+ // Check if we have our sheet, otherwise create
+ if (wb.getNumberOfSheets()==0) {
+ wb.createSheet("Overview");
+
+ }
+ Sheet sheet = wb.getSheetAt(0);
+
+ DataFormat df = wb.createDataFormat();
+ integerStyle = wb.createCellStyle();
+ integerStyle.setDataFormat(df.getFormat("#######0"));
+
+
+ createHeaderIfNeeded(sheet);
+
+ // Test name
+ Row row = appendRow(sheet);
+ Cell cell = row.createCell(0);
+ cell.setCellType(Cell.CELL_TYPE_STRING);
+ cell.setCellValue(result.getName());
+
+ // success ?
+ cell = row.createCell(1);
+ cell.setCellType(Cell.CELL_TYPE_BOOLEAN);
+ cell.setCellValue(result.isSuccess());
+
+ // timing from TestNG
+ cell = row.createCell(2);
+ cell.setCellType(Cell.CELL_TYPE_NUMERIC);
+ cell.setCellStyle(integerStyle);
+ cell.setCellValue(result.getEndMillis()-result.getStartMillis());
+
+ // timing of our business logic
+ long time = getTotalTime(timings);
+ cell = row.createCell(3);
+ cell.setCellType(Cell.CELL_TYPE_NUMERIC);
+ cell.setCellStyle(integerStyle);
+ cell.setCellValue(time);
+
+
+ // Write the output to a file
+ FileOutputStream fileOut = new FileOutputStream(baseFileName);
+ wb.write(fileOut);
+ fileOut.close();
+ if (inp!=null)
+ inp.close();
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ private void createHeaderIfNeeded(Sheet sheet) {
+ Row row = sheet.getRow(0);
+ if (row==null)
+ row = sheet.createRow(0);
+ Cell cell = row.createCell(0);
+ cell.setCellValue("Name");
+ cell = row.createCell(1);
+ cell.setCellValue("Success");
+ cell = row.createCell(2);
+ cell.setCellValue("TestNG timing");
+ cell = row.createCell(3);
+ cell.setCellValue("Perf timing");
+
+ sheet.autoSizeColumn(0);
+ sheet.autoSizeColumn(2);
+ sheet.autoSizeColumn(3);
+
+ }
+
+ private long getTotalTime(Map<String, Long> timings) {
+ long summaryTime = 0L;
+ for (Map.Entry<String,Long> item : timings.entrySet()) {
+ System.out.println(":| " + item.getKey() + " => " +
item.getValue());
+ summaryTime += item.getValue();
+ }
+ return summaryTime;
+ }
+
+ /**
+ * Append a row to the sheet
+ * @param sheet Sheet to append a new empty row to
+ * @return the newly created row
+ */
+ private Row appendRow(Sheet sheet) {
+ int lastRow = sheet.getLastRowNum();
+ Row ret = sheet.createRow(lastRow+1);
+ return ret;
+ }
+}
diff --git
a/modules/helpers/perftest-support/src/main/java/org/rhq/helpers/perftest/support/reporting/PerformanceReportExporter.java
b/modules/helpers/perftest-support/src/main/java/org/rhq/helpers/perftest/support/reporting/PerformanceReportExporter.java
new file mode 100644
index 0000000..537da7e
--- /dev/null
+++
b/modules/helpers/perftest-support/src/main/java/org/rhq/helpers/perftest/support/reporting/PerformanceReportExporter.java
@@ -0,0 +1,36 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2010 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * 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 version 2 of the License.
+ *
+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.rhq.helpers.perftest.support.reporting;
+
+import org.testng.ITestResult;
+
+import java.util.Map;
+
+/**
+ * Define a reporter, that can be used to export
+ * performance test results with.
+ *
+ * @author Heiko W. Rupp
+ */
+public interface PerformanceReportExporter {
+
+ public void setBaseFile(String fileName);
+
+ public void export(Map<String,Long> timings, ITestResult result);
+}
diff --git
a/modules/helpers/perftest-support/src/main/java/org/rhq/helpers/perftest/support/testng/PerformanceReporting.java
b/modules/helpers/perftest-support/src/main/java/org/rhq/helpers/perftest/support/testng/PerformanceReporting.java
new file mode 100644
index 0000000..6673d5b
--- /dev/null
+++
b/modules/helpers/perftest-support/src/main/java/org/rhq/helpers/perftest/support/testng/PerformanceReporting.java
@@ -0,0 +1,22 @@
+package org.rhq.helpers.perftest.support.testng;
+
+import org.rhq.helpers.perftest.support.reporting.PerformanceReportExporter;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Define were to export performance test results to
+ *
+ * @author Heiko W. Rupp
+ */
+(a)Retention(RetentionPolicy.RUNTIME)
+(a)Target(ElementType.TYPE)
+public @interface PerformanceReporting {
+
+ String baseFilename() default "performance-report";
+
+ Class<? extends PerformanceReportExporter> exporter() ;
+}