adjust the report and remove some bugs

This commit is contained in:
Tienan Chen 2013-11-19 14:50:24 +08:00
parent c75675145a
commit 0591a35e22
27 changed files with 473 additions and 127 deletions

View File

@ -162,12 +162,17 @@ public class TestPlanController extends BaseController {
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
return null;
}
ScriptBriefResultModel result = new ScriptBriefResultModel();
TestPlanContext context = this.getTestPlanContainer()
.getRunningTestPlans().get(testPlanId);
if (context == null) {
result.setFinished(true);
return result;
}
RunningScriptModel scriptModel = context.getRunningScriptMap().get(
new Integer(scriptId));
if (scriptModel == null || scriptModel.isFinish()) {
ScriptBriefResultModel result = new ScriptBriefResultModel();
result.setFinished(true);
return result;
}

View File

@ -6,6 +6,9 @@ import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import org.bench4q.master.communication.agent.scriptrecord.UsePluginModel;
import org.bench4q.master.communication.agent.scriptrecord.UserBehaviorModel;
@XmlRootElement(name = "runScenario")
public class RunScenarioModel {
private int poolSize;

View File

@ -0,0 +1,5 @@
package org.bench4q.master.communication.agent.scriptrecord;
public abstract class BehaviorBaseModel {
}

View File

@ -0,0 +1,56 @@
package org.bench4q.master.communication.agent.scriptrecord;
import java.io.ByteArrayOutputStream;
import java.util.List;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import org.bench4q.master.communication.agent.ParameterModel;
@XmlRootElement(name = "timerBehavior")
public class TimerBehaviorModel {
private String use;
private String name;
private List<ParameterModel> parameters;
@XmlElement
public String getUse() {
return use;
}
public void setUse(String use) {
this.use = use;
}
@XmlElement
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@XmlElementWrapper(name = "parameters")
@XmlElement(name = "parameter")
public List<ParameterModel> getParameters() {
return parameters;
}
public void setParameters(List<ParameterModel> parameters) {
this.parameters = parameters;
}
public String getModelString() throws JAXBException {
ByteArrayOutputStream os = new ByteArrayOutputStream();
Marshaller marshaller = JAXBContext.newInstance(this.getClass())
.createMarshaller();
marshaller.marshal(this, os);
return os.toString();
}
}

View File

@ -1,4 +1,4 @@
package org.bench4q.master.communication.agent;
package org.bench4q.master.communication.agent.scriptrecord;
import java.util.List;
@ -6,6 +6,8 @@ import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import org.bench4q.master.communication.agent.ParameterModel;
@XmlRootElement(name = "usePlugin")
public class UsePluginModel {
private String id;

View File

@ -1,4 +1,4 @@
package org.bench4q.master.communication.agent;
package org.bench4q.master.communication.agent.scriptrecord;
import java.io.ByteArrayOutputStream;
import java.util.List;
@ -10,8 +10,10 @@ import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import org.bench4q.master.communication.agent.ParameterModel;
@XmlRootElement(name = "userBehavior")
public class UserBehaviorModel {
public class UserBehaviorModel extends BehaviorBaseModel {
private String use;
private String name;
private List<ParameterModel> parameters;

View File

@ -0,0 +1,36 @@
package org.bench4q.master.entity.db;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "fortest")
public class ForTest {
private int id;
private String content;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false)
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Column(name = "content", columnDefinition = "LONGTEXT", nullable = false)
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}

View File

@ -51,7 +51,7 @@ public class MonitorResult {
this.type = type;
}
@Column(name = "content", columnDefinition = "TEXT", nullable = false)
@Column(name = "content", columnDefinition = "LONGTEXT", nullable = false)
public String getContent() {
return content;
}

View File

@ -68,7 +68,7 @@ public class Script {
this.user = user;
}
@Column(name = "scriptContent", columnDefinition = "TEXT", nullable = false)
@Column(name = "scriptContent", columnDefinition = "LONGTEXT", nullable = false)
@XmlElement
public String getScriptContent() {
return scriptContent;

View File

@ -79,7 +79,7 @@ public class TestPlan {
this.user = user;
}
@Column(name = "testPlanModelContent", columnDefinition = "Text", nullable = false)
@Column(name = "testPlanModelContent", columnDefinition = "LONGText", nullable = false)
public String getTestPlanModelContent() {
return testPlanModelContent;
}

View File

@ -16,10 +16,17 @@ import javax.persistence.Table;
public class TestPlanScriptResult {
private int id;
private TestPlanScript testPlanScript;
private long totalSuccessCount;
private long totalFailCount;
private long totalFinishedCount;
private long totalSuccessCountFromBegin;
private long totalFailCountFromBegin;
private long averageResponseTime;
private long maxResponseTime;
private long minResposneTime;
private long successThroughputThisTime;
private long failThroughputThisTime;
private long responseTimeDeviationThisTime;
private long failRateThisTime;
private long averageElapsedTime;
private Date createDatetime;
@ -44,31 +51,22 @@ public class TestPlanScriptResult {
this.testPlanScript = testPlanScript;
}
@Column(name = "totalSuccessCount", nullable = false)
public long getTotalSuccessCount() {
return totalSuccessCount;
@Column(name = "totalSuccessCountFromBegin", nullable = false)
public long getTotalSuccessCountFromBegin() {
return totalSuccessCountFromBegin;
}
public void setTotalSuccessCount(long totalSuccessCount) {
this.totalSuccessCount = totalSuccessCount;
public void setTotalSuccessCountFromBegin(long totalSuccessCountFromBegin) {
this.totalSuccessCountFromBegin = totalSuccessCountFromBegin;
}
@Column(name = "totalFailCount", nullable = false)
public long getTotalFailCount() {
return totalFailCount;
@Column(name = "totalFailCountFromBegin", nullable = false)
public long getTotalFailCountFromBegin() {
return totalFailCountFromBegin;
}
public void setTotalFailCount(long totalFailCount) {
this.totalFailCount = totalFailCount;
}
@Column(name = "totalFinishedCount", nullable = false)
public long getTotalFinishedCount() {
return totalFinishedCount;
}
public void setTotalFinishedCount(long totalFinishedCount) {
this.totalFinishedCount = totalFinishedCount;
public void setTotalFailCountFromBegin(long totalFailCountFromBegin) {
this.totalFailCountFromBegin = totalFailCountFromBegin;
}
@Column(name = "averageResponseTime", nullable = false)
@ -80,6 +78,61 @@ public class TestPlanScriptResult {
this.averageResponseTime = averageResponseTime;
}
@Column(name = "maxResponseTime", nullable = false)
public long getMaxResponseTime() {
return maxResponseTime;
}
public void setMaxResponseTime(long maxResponseTime) {
this.maxResponseTime = maxResponseTime;
}
@Column(name = "minResposneTime", nullable = false)
public long getMinResposneTime() {
return minResposneTime;
}
public void setMinResposneTime(long minResposneTime) {
this.minResposneTime = minResposneTime;
}
@Column(name = "successThroughputThisTime", nullable = false)
public long getSuccessThroughputThisTime() {
return successThroughputThisTime;
}
public void setSuccessThroughputThisTime(long successThroughputThisTime) {
this.successThroughputThisTime = successThroughputThisTime;
}
@Column(name = "failThroughputThisTime", nullable = false)
public long getFailThroughputThisTime() {
return failThroughputThisTime;
}
public void setFailThroughputThisTime(long failThroughputThisTime) {
this.failThroughputThisTime = failThroughputThisTime;
}
@Column(name = "responseTimeDeviationThisTime", nullable = false)
public long getResponseTimeDeviationThisTime() {
return responseTimeDeviationThisTime;
}
public void setResponseTimeDeviationThisTime(
long responseTimeDeviationThisTime) {
this.responseTimeDeviationThisTime = responseTimeDeviationThisTime;
}
@Column(name = "failRateThisTime", nullable = false)
public long getFailRateThisTime() {
return failRateThisTime;
}
public void setFailRateThisTime(long failRateThisTime) {
this.failRateThisTime = failRateThisTime;
}
@Column(name = "averageElapsedTime", nullable = false)
public long getAverageElapsedTime() {
return averageElapsedTime;

View File

@ -28,10 +28,10 @@ import com.lowagie.text.Document;
@Component
public class MonitorReportService {
public static String Processor = "ProcessorTimePercent";
public static String Memory = "Memory";
public static String logical_Disk = "logicalDisk";
public static String network_Interface = "networkInterface";
public static String Processor = "ProcessorTimePercent (unit: %)";
public static String Memory = "Memory Available Memory(unit: KiloByte)";
public static String logical_Disk = "logicalDisk IO (unit: Byte)";
public static String network_Interface = "networkInterface IO (unit: Byte/second)";
private TestPlanScriptService testPlanScriptService;
private TestPlanService testPlanService;
private MonitorResultService monitorResultService;
@ -166,14 +166,14 @@ public class MonitorReportService {
int seriesCount = list.get(0).getProcessorModel()
.getProcessorModelList().size();
TimeSeries[] timeSeriesArray = ReportService.buildSeries(seriesCount,
Processor);
List<TimeSeries> timeSeriesArray = ReportService.buildSeries(
seriesCount, Processor);
for (MonitorProcessorResponseModel model : list) {
for (int i = 0; i < timeSeriesArray.length; i++) {
timeSeriesArray[i].addOrUpdate(
new Second(model.getCreateDatetime()), model
.getProcessorModel().getProcessorModelList()
for (int i = 0; i < timeSeriesArray.size(); i++) {
timeSeriesArray.get(i).addOrUpdate(
new Second(model.getCreateDatetime()),
model.getProcessorModel().getProcessorModelList()
.get(i).getProcessorTimePercent());
}
}
@ -190,13 +190,13 @@ public class MonitorReportService {
return;
}
int seriesCount = 1;
TimeSeries[] timeSeriesArray = ReportService.buildSeries(seriesCount,
Memory);
List<TimeSeries> timeSeriesArray = ReportService.buildSeries(
seriesCount, Memory);
for (MonitorMemoryResponseModel model : list) {
for (int i = 0; i < timeSeriesArray.length; i++) {
timeSeriesArray[i].addOrUpdate(
new Second(model.getCreateDatetime()), model
.getMemoryModel().getPagesPerSecond());
for (int i = 0; i < timeSeriesArray.size(); i++) {
timeSeriesArray.get(i).addOrUpdate(
new Second(model.getCreateDatetime()),
model.getMemoryModel().getAvailableKiloBytes());
}
}
ReportService.writeImageIntoPdf(
@ -212,15 +212,15 @@ public class MonitorReportService {
}
int seriesCount = list.get(0).getLogicalDiskModel()
.getLogicalDiskList().size();
TimeSeries[] timeSeriesArray = ReportService.buildSeries(seriesCount,
logical_Disk);
List<TimeSeries> timeSeriesArray = ReportService.buildSeries(
seriesCount, logical_Disk);
for (MonitorLogicalDiskResponseModel model : list) {
for (int i = 0; i < timeSeriesArray.length; i++) {
timeSeriesArray[i].addOrUpdate(
new Second(model.getCreateDatetime()), model
.getLogicalDiskModel().getLogicalDiskList()
.get(i).getDiskTimePercent());
for (int i = 0; i < timeSeriesArray.size(); i++) {
timeSeriesArray.get(i).addOrUpdate(
new Second(model.getCreateDatetime()),
model.getLogicalDiskModel().getLogicalDiskList().get(i)
.getDiskBytesPerSecond());
}
}
@ -229,19 +229,27 @@ public class MonitorReportService {
timeSeriesArray, logical_Disk).toByteArray(), document);
}
/**
* refactor this kind of use
*
* @param list
* @param document
* @throws Exception
*/
private void createNetworkImage(List<MonitorNetWorkReponseModel> list,
Document document) throws Exception {
if (list == null || list.size() == 0) {
return;
}
int seriesCount = list.get(0).getModel().getNetworkList().size();
TimeSeries[] timeSeriesArray = ReportService.buildSeries(seriesCount,
network_Interface);
List<TimeSeries> timeSeriesArray = ReportService.buildSeries(
seriesCount, network_Interface);
for (MonitorNetWorkReponseModel model : list) {
for (int i = 0; i < timeSeriesArray.length; i++) {
timeSeriesArray[i].addOrUpdate(
new Second(model.getCreateDatetime()), model.getModel()
.getNetworkList().get(i)
for (int i = 0; i < timeSeriesArray.size(); i++) {
timeSeriesArray.get(i).addOrUpdate(
new Second(model.getCreateDatetime()),
model.getModel().getNetworkList().get(i)
.getBytesTotalPerSecond());
}
}

View File

@ -1,15 +1,22 @@
package org.bench4q.master.report;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.apache.commons.io.FileUtils;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.springframework.beans.factory.annotation.Autowired;
@ -25,10 +32,11 @@ import com.lowagie.text.pdf.PdfWriter;
@Component
public class ReportService {
public static String Time = "time";
// public static String Pdf_Path = "test.pdf";
public static String PDF_FOLDER = "report";
private ScriptReportService scriptReportService;
private MonitorReportService monitorReportService;
private static int PICTURE_WIDTH = 500;
private static int PICTURE_HIGHT = 600;
public ScriptReportService getScriptReportService() {
return scriptReportService;
@ -91,39 +99,62 @@ public class ReportService {
document.add(paragraph);
}
static ByteArrayOutputStream buildChartStream(Document document,
int seriesCount, TimeSeries[] timeSeriesArray, String value)
public static ByteArrayOutputStream buildChartStream(Document document,
int seriesCount, List<TimeSeries> timeSeriesArray, String value)
throws IOException {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
JFreeChart chart = ChartFactory.createTimeSeriesChart(value,
ReportService.Time, value, buildDataSet(timeSeriesArray), true,
true, true);
chart.setBackgroundPaint(java.awt.Color.white);
ChartUtilities.writeChartAsPNG(outputStream, chart, 400, 300);
adjustChartFont(value, chart);
ChartUtilities.writeChartAsPNG(outputStream, chart, PICTURE_WIDTH,
PICTURE_HIGHT);
return outputStream;
}
static TimeSeries[] buildSeries(int seriesCount, String mainTitle) {
TimeSeries[] timeSeriesArray = new TimeSeries[seriesCount];
private static void adjustChartFont(String value, JFreeChart chart) {
Font xfont = new Font("ËÎÌå", Font.CENTER_BASELINE, 14);// X
Font yfont = new Font("ËÎÌå", Font.CENTER_BASELINE, 14);// Y
Font kfont = new Font("ËÎÌå", Font.CENTER_BASELINE, 12);//
Font titleFont = new Font("΢ÈíÑźÚ", Font.CENTER_BASELINE, 16); // title
chart.setBorderStroke(new BasicStroke(1));
chart.setBorderVisible(true);
chart.setBorderPaint(Color.cyan);
chart.setTitle(new TextTitle(value, titleFont));
XYPlot plot = chart.getXYPlot();
plot.getRangeAxis().setLabelFont(yfont);
plot.getRangeAxis().setTickLabelFont(kfont);
plot.getDomainAxis().setLabelFont(xfont);
plot.getDomainAxis().setTickLabelFont(kfont);
chart.setBackgroundPaint(java.awt.Color.white);
}
public static List<TimeSeries> buildSeries(int seriesCount, String mainTitle) {
List<TimeSeries> timeSeriesArray = new ArrayList<TimeSeries>(
seriesCount);
for (int i = 0; i < seriesCount; i++) {
timeSeriesArray[i] = new TimeSeries(mainTitle + "-" + i);
timeSeriesArray.add(new TimeSeries(mainTitle + "-" + i));
}
return timeSeriesArray;
}
static TimeSeriesCollection buildDataSet(final TimeSeries[] timeSeriesArray) {
static TimeSeriesCollection buildDataSet(
final List<TimeSeries> timeSeriesArray) {
TimeSeriesCollection lineDataset = new TimeSeriesCollection();
if (timeSeriesArray == null) {
return null;
}
for (int i = 0; i < timeSeriesArray.length; i++) {
lineDataset.addSeries(timeSeriesArray[i]);
for (TimeSeries timeSeries : timeSeriesArray) {
lineDataset.addSeries(timeSeries);
}
return lineDataset;
}
static void writeImageIntoPdf(byte[] buffer, Document document)
public static void writeImageIntoPdf(byte[] buffer, Document document)
throws Exception {
Image image = Image.getInstance(buffer);
image.setAlignment(Element.ALIGN_CENTER);

View File

@ -1,34 +1,32 @@
package org.bench4q.master.report;
import java.io.ByteArrayOutputStream;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.apache.log4j.Logger;
import org.bench4q.master.entity.db.TestPlanScript;
import org.bench4q.master.entity.db.TestPlanScriptResult;
import org.bench4q.master.service.MonitorResultService;
import org.bench4q.master.service.TestPlanScriptService;
import org.bench4q.master.service.TestPlanService;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.time.Second;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.lowagie.text.Document;
import com.lowagie.text.Element;
import com.lowagie.text.Paragraph;
@Component
public class ScriptReportService {
public static String Average_Response_Time = "averageResponseTime";
public static String SCRIPT_TITLE = "Script result";
public static String Average_Response_Time = "averageResponseTime(unit: ms)";
public static String MAX_RESPONSE_TIME = "maxResponseTime(unit : time)";
private TestPlanScriptService testPlanScriptService;
private TestPlanService testPlanService;
private MonitorResultService monitorResultService;
private Logger logger = Logger.getLogger(ScriptReportService.class);
public TestPlanScriptService getTestPlanScriptService() {
return testPlanScriptService;
@ -84,41 +82,74 @@ public class ScriptReportService {
private void createAverageReponseTimeImage(
List<TestPlanScriptResult> results, Document document) {
TimeSeries timeSeries = new TimeSeries(Average_Response_Time);
TimeSeriesCollection lineSeriesCollection = new TimeSeriesCollection();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
String scriptName = "null";
// TimeSeriesCollection lineSeriesCollection = new
// TimeSeriesCollection();
List<TimeSeries> timeSeriesList = new ArrayList<TimeSeries>();
// ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
// String scriptName = "null";
if (results == null) {
return;
}
for (TestPlanScriptResult result : results) {
timeSeries.addOrUpdate(new Second(result.getCreateDatetime()),
result.getAverageResponseTime());
}
lineSeriesCollection.addSeries(timeSeries);
JFreeChart chart = ChartFactory.createTimeSeriesChart(
Average_Response_Time, ReportService.Time,
Average_Response_Time, lineSeriesCollection, true, true, true);
chart.setBackgroundPaint(java.awt.Color.white);
if (results.size() > 0) {
scriptName = results.get(0).getTestPlanScript().getScript()
.getName();
chart.addSubtitle(new TextTitle(scriptName));
}
addScriptSeries(results, timeSeriesList, "averageResponseTime");
addScriptSeries(results, timeSeriesList, "maxResponseTime");
try {
ChartUtilities.writeChartAsPNG(outputStream, chart, 400, 300);
Paragraph paragraph = new Paragraph(Average_Response_Time + " of "
+ scriptName);
paragraph.setAlignment(Element.ALIGN_CENTER);
document.add(paragraph);
ReportService.writeImageIntoPdf(outputStream.toByteArray(),
document);
ReportService.writeImageIntoPdf(
ReportService.buildChartStream(document,
timeSeriesList.size(), timeSeriesList,
Average_Response_Time + "&" + MAX_RESPONSE_TIME)
.toByteArray(), document);
} catch (Exception e) {
e.printStackTrace();
}
// JFreeChart chart = ChartFactory.createTimeSeriesChart(SCRIPT_TITLE,
// ReportService.Time, Average_Response_Time + "&"
// + MAX_RESPONSE_TIME, lineSeriesCollection, true, true,
// true);
// chart.setBackgroundPaint(java.awt.Color.white);
//
// if (results.size() > 0) {
// scriptName = results.get(0).getTestPlanScript().getScript()
// .getName();
// chart.addSubtitle(new TextTitle(scriptName));
// }
// ReportService.buildChartStream(document, lineSeriesCollection
// .getSeriesCount(), lineSeriesCollection.getSeries().toArray(a),
// Average_Response_Time + "&" + MAX_RESPONSE_TIME);
// ReportService.writeImageIntoPdf(ReportService.buildChartStream(),
// document);
// try {
// ChartUtilities.writeChartAsPNG(outputStream, chart, 400, 300);
// Paragraph paragraph = new Paragraph(Average_Response_Time + " of "
// + scriptName);
// paragraph.setAlignment(Element.ALIGN_CENTER);
// document.add(paragraph);
// ReportService.writeImageIntoPdf(outputStream.toByteArray(),
// document);
// } catch (Exception e) {
// e.printStackTrace();
// }
}
// TODO: refactor this to a kind of command mode
private void addScriptSeries(List<TestPlanScriptResult> results,
List<TimeSeries> timeSeriesList, String fieldName) {
try {
TimeSeries timeSeries = new TimeSeries(fieldName);
for (TestPlanScriptResult result : results) {
Field field = result.getClass().getDeclaredField(fieldName);
field.setAccessible(true);
timeSeries.addOrUpdate(new Second(result.getCreateDatetime()),
field.getLong(result));
}
timeSeriesList.add(timeSeries);
} catch (Exception e) {
logger.error(e.toString()
+ " in addScriptSeries where fieldName is : " + fieldName);
}
}
}

View File

@ -11,8 +11,8 @@ import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import org.bench4q.master.communication.agent.RunScenarioModel;
import org.bench4q.master.communication.agent.UsePluginModel;
import org.bench4q.master.communication.agent.UserBehaviorModel;
import org.bench4q.master.communication.agent.scriptrecord.UsePluginModel;
import org.bench4q.master.communication.agent.scriptrecord.UserBehaviorModel;
public class Bench4qTestScriptAdapter implements IScriptAdapter {
private RunScenarioModel runScenarioModel;

View File

@ -3,8 +3,8 @@ package org.bench4q.master.scriptrecord.httpcapture;
import java.util.List;
import org.bench4q.master.communication.agent.RunScenarioModel;
import org.bench4q.master.communication.agent.UsePluginModel;
import org.bench4q.master.communication.agent.UserBehaviorModel;
import org.bench4q.master.communication.agent.scriptrecord.UsePluginModel;
import org.bench4q.master.communication.agent.scriptrecord.UserBehaviorModel;
public interface IScriptAdapter {

View File

@ -20,7 +20,7 @@ import javax.xml.bind.Marshaller;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.bench4q.master.communication.agent.RunScenarioModel;
import org.bench4q.master.communication.agent.UserBehaviorModel;
import org.bench4q.master.communication.agent.scriptrecord.UserBehaviorModel;
import org.bench4q.master.scriptrecord.httpcapture.Action;
import org.bench4q.master.scriptrecord.httpcapture.Config;
import org.bench4q.master.scriptrecord.httpcapture.HeaderValue;

View File

@ -5,8 +5,8 @@ import java.util.List;
import org.apache.log4j.Logger;
import org.bench4q.master.communication.agent.ParameterModel;
import org.bench4q.master.communication.agent.UsePluginModel;
import org.bench4q.master.communication.agent.UserBehaviorModel;
import org.bench4q.master.communication.agent.scriptrecord.UsePluginModel;
import org.bench4q.master.communication.agent.scriptrecord.UserBehaviorModel;
import org.bench4q.master.scriptrecord.httpcapture.Config;
import org.bench4q.master.scriptrecord.httpcapture.HeaderValue;
import org.bench4q.master.scriptrecord.httpcapture.IScriptAdapter;

View File

@ -62,6 +62,7 @@ public class MonitorResultService {
return true;
} catch (Exception e) {
logger.error(e.toString() + " when saveMonitorResult");
e.printStackTrace();
transaction.rollback();
return false;
} finally {

View File

@ -2,6 +2,7 @@ package org.bench4q.master.service;
import java.io.ByteArrayInputStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.Date;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
@ -162,8 +163,7 @@ public class MonitorService {
}
saveResultRunable(NetworkInterfaceModel.class.getName(),
changeCharsetToISO(httpResponse.getContent()),
testPlanRunId, hostName);
httpResponse.getContent(), testPlanRunId, hostName);
return extractNetworkInterfaceModel(httpResponse.getContent());
} catch (Exception e) {
logger.error(e.getMessage() + "where testPlanRunId = "
@ -181,8 +181,8 @@ public class MonitorService {
Unmarshaller unmarshaller = JAXBContext.newInstance(
NetworkInterfaceModel.class).createUnmarshaller();
return (NetworkInterfaceModel) unmarshaller
.unmarshal(new ByteArrayInputStream(changeCharsetToISO(content)
.getBytes()));
.unmarshal(new ByteArrayInputStream(content.getBytes(Charset
.forName("UTF-8"))));
}
public static String changeCharsetToISO(String content)

View File

@ -10,7 +10,7 @@ import javax.xml.bind.Unmarshaller;
import org.apache.log4j.Logger;
import org.bench4q.master.communication.agent.RunScenarioModel;
import org.bench4q.master.communication.agent.UserBehaviorModel;
import org.bench4q.master.communication.agent.scriptrecord.UserBehaviorModel;
import org.bench4q.master.entity.db.Script;
import org.bench4q.master.entity.db.User;
import org.bench4q.master.helper.SessionHelper;

View File

@ -163,16 +163,25 @@ public class TestPlanScriptService {
}
private TestPlanScriptResult buildScriptResultWithModel(
ScriptBriefResultModel resultModel, TestPlanScript testPlanScript,
ScriptBriefResultModel model, TestPlanScript testPlanScript,
Date createDatetime) {
TestPlanScriptResult result = new TestPlanScriptResult();
result.setTestPlanScript(testPlanScript);
result.setTotalFailCount(resultModel.getTotalFailCountFromBegin());
result.setTotalFinishedCount(resultModel
result.setAverageElapsedTime(model.getAverageElapsedTime());
result.setAverageResponseTime(model.getAverageResponseTime());
result.setFailRateThisTime(model.getFailRateThisTime());
result.setFailThroughputThisTime(model.getFailThroughputThisTime());
result.setMaxResponseTime(model.getMaxResponseTime());
result.setMinResposneTime(model.getMinResponseTime());
result.setResponseTimeDeviationThisTime(model
.getResponseTimeDeviationThisTime());
result.setSuccessThroughputThisTime(model
.getSuccessThroughputThisTime());
result.setTotalFailCountFromBegin(model.getTotalFailCountFromBegin());
result.setTotalSuccessCountFromBegin(model
.getTotalSuccessCountFromBegin());
result.setTotalSuccessCount(resultModel.getTotalSuccessCountFromBegin());
result.setAverageElapsedTime(resultModel.getAverageElapsedTime());
result.setAverageResponseTime(resultModel.getAverageResponseTime());
result.setCreateDatetime(createDatetime);
return result;
}

View File

@ -15,6 +15,7 @@ import org.bench4q.master.api.model.RunningScriptModel;
import org.bench4q.master.api.model.TestPlanModel;
import org.bench4q.master.api.model.TestScriptConfig;
import org.bench4q.master.entity.db.PlanedConfig;
import org.bench4q.master.entity.db.Script;
import org.bench4q.master.entity.db.TestPlan;
import org.bench4q.master.entity.db.TestPlanScript;
import org.bench4q.master.entity.db.User;
@ -99,6 +100,13 @@ public class TestPlanService {
testPlanScript = new TestPlanScript();
testPlanScript.setTestPlan(testPlan);
Script script = this.scriptService.getScript(runningScriptModel
.getScriptId());
if (script == null) {
logger.error("There is no this script with id "
+ runningScriptModel.getScriptId());
return false;
}
testPlanScript.setScript(this.scriptService
.getScript(runningScriptModel.getScriptId()));
testPlanScript.setRequireLoad(runningScriptModel.getRequireLoad());

View File

@ -24,5 +24,6 @@
<mapping class="org.bench4q.master.entity.db.TestPlanScript" />
<mapping class="org.bench4q.master.entity.db.TestPlanScriptResult" />
<mapping class="org.bench4q.master.entity.db.MonitorResult" />
<mapping class="org.bench4q.master.entity.db.ForTest" />
</session-factory>
</hibernate-configuration>

View File

@ -0,0 +1,40 @@
package org.bench4q.master.test;
import org.bench4q.master.entity.db.ForTest;
import org.bench4q.master.helper.SessionHelper;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.junit.Test;
public class MysqlTest {
private SessionHelper sessionHelper;
public SessionHelper getSessionHelper() {
return sessionHelper;
}
public void setSessionHelper(SessionHelper sessionHelper) {
this.sessionHelper = sessionHelper;
}
public MysqlTest() {
this.setSessionHelper(new SessionHelper());
}
@Test
public void testForChinese() {
Session session = this.getSessionHelper().openSession();
Transaction transaction = session.beginTransaction();
try {
ForTest test = new ForTest();
test.setContent("³ÂÌú°´Å¥");
session.merge(test);
transaction.commit();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
transaction.rollback();
}
}
}

View File

@ -27,12 +27,12 @@ public class TestPlanTester extends TestBase {
private TestPlanModel testPlan = new TestPlanModel();
private String _url = TestBase.BASE_URL + "/testPlan";
private int scriptSumNum;
private static int SCRIPTID1 = 18;
private static int SCRIPTID1 = 1;
private static int SCRIPTID2 = 2;
// private static int EACH_SCRIPT_LOAD_LargeSCALE = 12000;
private static int EACH_SCRIPT_LOAD_SMALLSCALE = 400;
// private static int EACH_SCRIPT_LOAD_MIDDLESCALE = 800;
private static String Monitor_Host_Name = "133.133.12.3";
private static String Monitor_Host_Name = "127.0.0.1";
private static String monitor_port = "5556";
public TestPlanModel getTestPlan() {
@ -70,7 +70,7 @@ public class TestPlanTester extends TestBase {
while (this.getRunningInfo(testPlanID).getCurrentStatus() != TestPlanStatus.InRunning) {
Thread.sleep(6000);
}
for (int i = 0; i < 300; i++) {
for (int i = 0; i < 3; i++) {
Thread.sleep(2000);
this.getScriptBrief(testPlanID, SCRIPTID1);
}
@ -205,7 +205,7 @@ public class TestPlanTester extends TestBase {
public void getMonitorBrief(UUID testPlanID, String hostName, String port)
throws IOException, InterruptedException {
for (int i = 0; i < 2; i++) {
for (int i = 0; i < 1; i++) {
getMonitorMemoryResult(testPlanID, hostName, port);
getProcessorResult(testPlanID, hostName, port);
getLogicalDiskResult(testPlanID, hostName, port);

View File

@ -0,0 +1,55 @@
package org.bench4q.master.test.report;
import static org.junit.Assert.*;
import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import org.bench4q.master.report.ReportService;
import org.jfree.data.time.Second;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.junit.Test;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.pdf.PdfWriter;
public class ReportFontTest {
@Test
public void test() {
fail("Not yet implemented");
}
public void createReportTest() throws FileNotFoundException,
DocumentException {
Document document = new Document();
PdfWriter.getInstance(
document,
new FileOutputStream(ReportService.buildFilePath(UUID
.randomUUID())));
document.open();
}
public void createTestImage(UUID id, Document document) throws IOException, Exception {
List<TimeSeries> timeSeriesList = new ArrayList<TimeSeries>();
TimeSeries timeSeries = new TimeSeries("test");
long now = System.currentTimeMillis();
timeSeries.add(new Second(new Date(now)), 3000);
timeSeries.add(new Second(new Date(now + 100)), 4000);
timeSeriesList.add(timeSeries);
ReportService.buildSeries(1, "test");
ReportService.writeImageIntoPdf(
ReportService.buildChartStream(document, 1, timeSeriesList,
"test").toByteArray(), document);
}
}