add vUserCount for ScriptBriefResultModel
This commit is contained in:
parent
18d02acba6
commit
09fc24e0a9
|
@ -1,37 +1,37 @@
|
|||
package org.bench4q.master.helper;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public final class SessionHelper {
|
||||
private SessionFactory sessionFactory;
|
||||
|
||||
public SessionFactory getSessionFactory() {
|
||||
return sessionFactory;
|
||||
}
|
||||
|
||||
public void setSessionFactory(SessionFactory sessionFactory) {
|
||||
this.sessionFactory = sessionFactory;
|
||||
}
|
||||
|
||||
public SessionHelper() {
|
||||
try {
|
||||
Configuration cfg = new Configuration()
|
||||
.configure("org/bench4q/master/config/hibernate.cfg.xml");
|
||||
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
|
||||
.applySettings(cfg.getProperties()).build();
|
||||
this.setSessionFactory(cfg.buildSessionFactory(serviceRegistry));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public Session openSession() {
|
||||
return this.getSessionFactory().openSession();
|
||||
}
|
||||
}
|
||||
package org.bench4q.master.helper;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public final class SessionHelper {
|
||||
private SessionFactory sessionFactory;
|
||||
|
||||
public SessionFactory getSessionFactory() {
|
||||
return sessionFactory;
|
||||
}
|
||||
|
||||
public void setSessionFactory(SessionFactory sessionFactory) {
|
||||
this.sessionFactory = sessionFactory;
|
||||
}
|
||||
|
||||
public SessionHelper() {
|
||||
try {
|
||||
Configuration cfg = new Configuration()
|
||||
.configure("org/bench4q/master/config/hibernate.cfg.xml");
|
||||
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
|
||||
.applySettings(cfg.getProperties()).build();
|
||||
this.setSessionFactory(cfg.buildSessionFactory(serviceRegistry));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public Session openSession() {
|
||||
return this.getSessionFactory().openSession();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,206 +1,214 @@
|
|||
package org.bench4q.master.testplan.datastatistics;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.bench4q.share.models.agent.statistics.AgentBriefStatusModel;
|
||||
import org.bench4q.share.models.agent.statistics.DataStatisticsModel;
|
||||
import org.bench4q.share.models.master.statistics.ScriptBriefResultModel;
|
||||
|
||||
public class ScriptBriefStatistics extends ScriptStatistics {
|
||||
private long totalFailCountThisTime;
|
||||
private long totalSuccessCountThisTime;
|
||||
private long totalSquareResponseTime;
|
||||
private long totalFailThroughputThisTime;
|
||||
private long totalSuccessThroughputThisTime;
|
||||
private long minResponseTimeThisTime;
|
||||
private long maxResponseTimeThisTime;
|
||||
private long totalResponseTimeThisTime;
|
||||
private long totalFailCountFromBegin;
|
||||
private long totalSuccessCountFromBegin;
|
||||
|
||||
private long totalElapsedTime;
|
||||
private long effectiveCount;
|
||||
|
||||
private ScriptBriefResultModel lastValidBriefResultModel;
|
||||
|
||||
private void setTotalFailCountThisTime(long totalFailCountThisTime) {
|
||||
this.totalFailCountThisTime = totalFailCountThisTime;
|
||||
}
|
||||
|
||||
private void setTotalSuccessCountThisTime(long totalSuccessCountThisTime) {
|
||||
this.totalSuccessCountThisTime = totalSuccessCountThisTime;
|
||||
}
|
||||
|
||||
private void setTotalSquareResponseTime(long totalSquareResponseTime) {
|
||||
this.totalSquareResponseTime = totalSquareResponseTime;
|
||||
}
|
||||
|
||||
private void setTotalFailThroughputThisTime(long totalFailThroughputThisTime) {
|
||||
this.totalFailThroughputThisTime = totalFailThroughputThisTime;
|
||||
}
|
||||
|
||||
private void setTotalSuccessThroughputThisTime(
|
||||
long totalSuccessThroughputThisTime) {
|
||||
this.totalSuccessThroughputThisTime = totalSuccessThroughputThisTime;
|
||||
}
|
||||
|
||||
private void setMinResponseTimeThisTime(long minResponseTimeThisTime) {
|
||||
this.minResponseTimeThisTime = minResponseTimeThisTime;
|
||||
}
|
||||
|
||||
private void setMaxResponseTimeThisTime(long maxResponseTimeThisTime) {
|
||||
this.maxResponseTimeThisTime = maxResponseTimeThisTime;
|
||||
}
|
||||
|
||||
private void setTotalResponseTimeThisTime(long totalResponseTimeThisTime) {
|
||||
this.totalResponseTimeThisTime = totalResponseTimeThisTime;
|
||||
}
|
||||
|
||||
private void setTotalFailCountFromBegin(long totalFailCountFromBegin) {
|
||||
this.totalFailCountFromBegin = totalFailCountFromBegin;
|
||||
}
|
||||
|
||||
private void setTotalSuccessCoutFromBegin(long totalSuccessCoutFromBegin) {
|
||||
this.totalSuccessCountFromBegin = totalSuccessCoutFromBegin;
|
||||
}
|
||||
|
||||
private void setTotalElapsedTime(long totalElapsedTime) {
|
||||
this.totalElapsedTime = totalElapsedTime;
|
||||
}
|
||||
|
||||
private void setEffectiveCounte(long effetiveCount) {
|
||||
this.effectiveCount = effetiveCount;
|
||||
}
|
||||
|
||||
private ScriptBriefResultModel getLastValidBriefResultModel() {
|
||||
return lastValidBriefResultModel;
|
||||
}
|
||||
|
||||
private void setLastValidBriefResultModel(
|
||||
ScriptBriefResultModel lastValidBriefResultModel) {
|
||||
this.lastValidBriefResultModel = lastValidBriefResultModel;
|
||||
}
|
||||
|
||||
public ScriptBriefStatistics() {
|
||||
reset();
|
||||
initLastValidBriefResultModel();
|
||||
}
|
||||
|
||||
private void reset() {
|
||||
this.setTotalFailCountFromBegin(0);
|
||||
this.setTotalFailCountThisTime(0);
|
||||
this.setTotalFailThroughputThisTime(0);
|
||||
this.setTotalResponseTimeThisTime(0);
|
||||
this.setTotalSquareResponseTime(0);
|
||||
this.setTotalSuccessCountThisTime(0);
|
||||
this.setTotalSuccessCoutFromBegin(0);
|
||||
this.setTotalSuccessThroughputThisTime(0);
|
||||
this.setTotalElapsedTime(0);
|
||||
this.setEffectiveCounte(0);
|
||||
this.setMaxResponseTimeThisTime(Long.MIN_VALUE);
|
||||
this.setMinResponseTimeThisTime(Long.MAX_VALUE);
|
||||
}
|
||||
|
||||
private void initLastValidBriefResultModel() {
|
||||
ScriptBriefResultModel initBriefModel = new ScriptBriefResultModel();
|
||||
initBriefModel.setAverageElapsedTime(0);
|
||||
initBriefModel.setAverageResponseTime(0);
|
||||
initBriefModel.setFailRateThisTime(0);
|
||||
initBriefModel.setFailThroughputThisTime(0);
|
||||
initBriefModel.setFinished(false);
|
||||
initBriefModel.setMaxResponseTime(0);
|
||||
initBriefModel.setMinResponseTime(0);
|
||||
initBriefModel.setPlanedRunningTime(0);
|
||||
initBriefModel.setResponseTimeDeviationThisTime(0);
|
||||
initBriefModel.setSuccessThroughputThisTime(0);
|
||||
initBriefModel.setTotalFailCountFromBegin(0);
|
||||
initBriefModel.setTotalSuccessCountFromBegin(0);
|
||||
this.setLastValidBriefResultModel(initBriefModel);
|
||||
}
|
||||
|
||||
public void add(DataStatisticsModel dataUnit) {
|
||||
if (!(dataUnit instanceof AgentBriefStatusModel)) {
|
||||
return;
|
||||
}
|
||||
add((AgentBriefStatusModel) dataUnit);
|
||||
}
|
||||
|
||||
private void add(AgentBriefStatusModel briefModel) {
|
||||
if (briefModel == null) {
|
||||
return;
|
||||
}
|
||||
this.effectiveCount++;
|
||||
if (briefModel.getMaxResponseTime() > this.maxResponseTimeThisTime) {
|
||||
this.setMaxResponseTimeThisTime(briefModel.getMaxResponseTime());
|
||||
}
|
||||
if (briefModel.getMinResponseTime() < this.minResponseTimeThisTime) {
|
||||
this.setMinResponseTimeThisTime(briefModel.getMinResponseTime());
|
||||
}
|
||||
this.totalFailCountFromBegin += briefModel.getFailCountFromBegin();
|
||||
this.totalFailCountThisTime += briefModel.getFailCountThisTime();
|
||||
this.totalFailThroughputThisTime += briefModel
|
||||
.getFailThroughputThisTime();
|
||||
this.totalResponseTimeThisTime += briefModel
|
||||
.getTotalResponseTimeThisTime();
|
||||
this.totalSquareResponseTime += briefModel
|
||||
.getTotalSqureResponseTimeThisTime();
|
||||
this.totalSuccessCountThisTime += briefModel.getSuccessCountThisTime();
|
||||
this.totalSuccessCountFromBegin += briefModel
|
||||
.getSuccessCountFromBegin();
|
||||
this.totalSuccessThroughputThisTime += briefModel
|
||||
.getSuccessThroughputThisTime();
|
||||
}
|
||||
|
||||
public ScriptBriefResultModel getStatistics() {
|
||||
ScriptBriefResultModel result = new ScriptBriefResultModel();
|
||||
long averageResponseTime = 0;
|
||||
if (this.totalSuccessCountThisTime == 0) {
|
||||
result.setAverageResponseTime(0);
|
||||
result.setMaxResponseTime(0);
|
||||
result.setMinResponseTime(0);
|
||||
result.setResponseTimeDeviationThisTime(0);
|
||||
if (this.totalFailCountThisTime == 0) {
|
||||
result.setFailRateThisTime(0);
|
||||
} else {
|
||||
result.setFailRateThisTime(100);
|
||||
}
|
||||
} else {
|
||||
averageResponseTime = this.totalResponseTimeThisTime
|
||||
/ this.totalSuccessCountThisTime;
|
||||
result.setAverageResponseTime(averageResponseTime);
|
||||
result.setMaxResponseTime(this.maxResponseTimeThisTime);
|
||||
result.setMinResponseTime(this.minResponseTimeThisTime);
|
||||
result.setResponseTimeDeviationThisTime(Math.round(Math
|
||||
.sqrt(this.totalSquareResponseTime
|
||||
/ this.totalSuccessCountThisTime
|
||||
- averageResponseTime * averageResponseTime)));
|
||||
result.setFailRateThisTime(this.totalFailCountThisTime
|
||||
* 100
|
||||
/ (this.totalFailCountThisTime + this.totalSuccessCountThisTime));
|
||||
}
|
||||
result.setFailThroughputThisTime(this.totalFailThroughputThisTime);
|
||||
result.setSuccessThroughputThisTime(this.totalSuccessThroughputThisTime);
|
||||
result.setTotalFailCountFromBegin(this.totalFailCountFromBegin);
|
||||
result.setTotalSuccessCountFromBegin(this.totalSuccessCountFromBegin);
|
||||
if (this.effectiveCount == 0) {
|
||||
result.setAverageElapsedTime(0);
|
||||
} else {
|
||||
result.setAverageElapsedTime(this.totalElapsedTime
|
||||
/ this.effectiveCount);
|
||||
}
|
||||
result = dealWithInvalidSamplePoint(result);
|
||||
result.setSamplingTime(new Date());
|
||||
reset();
|
||||
return result;
|
||||
}
|
||||
|
||||
private ScriptBriefResultModel dealWithInvalidSamplePoint(
|
||||
ScriptBriefResultModel inputModel) {
|
||||
if (this.totalFailCountThisTime == 0
|
||||
&& this.totalSuccessCountThisTime == 0) {
|
||||
return this.getLastValidBriefResultModel();
|
||||
}
|
||||
this.setLastValidBriefResultModel(inputModel);
|
||||
return inputModel;
|
||||
}
|
||||
}
|
||||
package org.bench4q.master.testplan.datastatistics;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.bench4q.share.models.agent.statistics.AgentBriefStatusModel;
|
||||
import org.bench4q.share.models.agent.statistics.DataStatisticsModel;
|
||||
import org.bench4q.share.models.master.statistics.ScriptBriefResultModel;
|
||||
|
||||
public class ScriptBriefStatistics extends ScriptStatistics {
|
||||
private long totalFailCountThisTime;
|
||||
private long totalSuccessCountThisTime;
|
||||
private long totalSquareResponseTime;
|
||||
private long totalFailThroughputThisTime;
|
||||
private long totalSuccessThroughputThisTime;
|
||||
private long minResponseTimeThisTime;
|
||||
private long maxResponseTimeThisTime;
|
||||
private long totalResponseTimeThisTime;
|
||||
private long totalFailCountFromBegin;
|
||||
private long totalSuccessCountFromBegin;
|
||||
|
||||
private long totalElapsedTime;
|
||||
private long activeVUserCountThisTime;
|
||||
private long effectiveCount;
|
||||
|
||||
private ScriptBriefResultModel lastValidBriefResultModel;
|
||||
|
||||
private void setTotalFailCountThisTime(long totalFailCountThisTime) {
|
||||
this.totalFailCountThisTime = totalFailCountThisTime;
|
||||
}
|
||||
|
||||
private void setTotalSuccessCountThisTime(long totalSuccessCountThisTime) {
|
||||
this.totalSuccessCountThisTime = totalSuccessCountThisTime;
|
||||
}
|
||||
|
||||
private void setTotalSquareResponseTime(long totalSquareResponseTime) {
|
||||
this.totalSquareResponseTime = totalSquareResponseTime;
|
||||
}
|
||||
|
||||
private void setTotalFailThroughputThisTime(long totalFailThroughputThisTime) {
|
||||
this.totalFailThroughputThisTime = totalFailThroughputThisTime;
|
||||
}
|
||||
|
||||
private void setTotalSuccessThroughputThisTime(
|
||||
long totalSuccessThroughputThisTime) {
|
||||
this.totalSuccessThroughputThisTime = totalSuccessThroughputThisTime;
|
||||
}
|
||||
|
||||
private void setMinResponseTimeThisTime(long minResponseTimeThisTime) {
|
||||
this.minResponseTimeThisTime = minResponseTimeThisTime;
|
||||
}
|
||||
|
||||
private void setMaxResponseTimeThisTime(long maxResponseTimeThisTime) {
|
||||
this.maxResponseTimeThisTime = maxResponseTimeThisTime;
|
||||
}
|
||||
|
||||
private void setTotalResponseTimeThisTime(long totalResponseTimeThisTime) {
|
||||
this.totalResponseTimeThisTime = totalResponseTimeThisTime;
|
||||
}
|
||||
|
||||
private void setTotalFailCountFromBegin(long totalFailCountFromBegin) {
|
||||
this.totalFailCountFromBegin = totalFailCountFromBegin;
|
||||
}
|
||||
|
||||
private void setTotalSuccessCoutFromBegin(long totalSuccessCoutFromBegin) {
|
||||
this.totalSuccessCountFromBegin = totalSuccessCoutFromBegin;
|
||||
}
|
||||
|
||||
private void setTotalElapsedTime(long totalElapsedTime) {
|
||||
this.totalElapsedTime = totalElapsedTime;
|
||||
}
|
||||
|
||||
private void setActiveVUserCountThisTime(long activeVUserCountThisTime) {
|
||||
this.activeVUserCountThisTime = activeVUserCountThisTime;
|
||||
}
|
||||
|
||||
private void setEffectiveCounte(long effetiveCount) {
|
||||
this.effectiveCount = effetiveCount;
|
||||
}
|
||||
|
||||
private ScriptBriefResultModel getLastValidBriefResultModel() {
|
||||
return lastValidBriefResultModel;
|
||||
}
|
||||
|
||||
private void setLastValidBriefResultModel(
|
||||
ScriptBriefResultModel lastValidBriefResultModel) {
|
||||
this.lastValidBriefResultModel = lastValidBriefResultModel;
|
||||
}
|
||||
|
||||
public ScriptBriefStatistics() {
|
||||
reset();
|
||||
initLastValidBriefResultModel();
|
||||
}
|
||||
|
||||
private void reset() {
|
||||
this.setTotalFailCountFromBegin(0);
|
||||
this.setTotalFailCountThisTime(0);
|
||||
this.setTotalFailThroughputThisTime(0);
|
||||
this.setTotalResponseTimeThisTime(0);
|
||||
this.setTotalSquareResponseTime(0);
|
||||
this.setTotalSuccessCountThisTime(0);
|
||||
this.setTotalSuccessCoutFromBegin(0);
|
||||
this.setTotalSuccessThroughputThisTime(0);
|
||||
this.setTotalElapsedTime(0);
|
||||
this.setEffectiveCounte(0);
|
||||
this.setMaxResponseTimeThisTime(Long.MIN_VALUE);
|
||||
this.setMinResponseTimeThisTime(Long.MAX_VALUE);
|
||||
this.setActiveVUserCountThisTime(0);
|
||||
}
|
||||
|
||||
private void initLastValidBriefResultModel() {
|
||||
ScriptBriefResultModel initBriefModel = new ScriptBriefResultModel();
|
||||
initBriefModel.setAverageElapsedTime(0);
|
||||
initBriefModel.setAverageResponseTime(0);
|
||||
initBriefModel.setFailRateThisTime(0);
|
||||
initBriefModel.setFailThroughputThisTime(0);
|
||||
initBriefModel.setFinished(false);
|
||||
initBriefModel.setMaxResponseTime(0);
|
||||
initBriefModel.setMinResponseTime(0);
|
||||
initBriefModel.setPlanedRunningTime(0);
|
||||
initBriefModel.setResponseTimeDeviationThisTime(0);
|
||||
initBriefModel.setSuccessThroughputThisTime(0);
|
||||
initBriefModel.setTotalFailCountFromBegin(0);
|
||||
initBriefModel.setTotalSuccessCountFromBegin(0);
|
||||
this.setLastValidBriefResultModel(initBriefModel);
|
||||
}
|
||||
|
||||
public void add(DataStatisticsModel dataUnit) {
|
||||
if (!(dataUnit instanceof AgentBriefStatusModel)) {
|
||||
return;
|
||||
}
|
||||
add((AgentBriefStatusModel) dataUnit);
|
||||
}
|
||||
|
||||
private void add(AgentBriefStatusModel briefModel) {
|
||||
if (briefModel == null) {
|
||||
return;
|
||||
}
|
||||
this.effectiveCount++;
|
||||
if (briefModel.getMaxResponseTime() > this.maxResponseTimeThisTime) {
|
||||
this.setMaxResponseTimeThisTime(briefModel.getMaxResponseTime());
|
||||
}
|
||||
if (briefModel.getMinResponseTime() < this.minResponseTimeThisTime) {
|
||||
this.setMinResponseTimeThisTime(briefModel.getMinResponseTime());
|
||||
}
|
||||
this.totalFailCountFromBegin += briefModel.getFailCountFromBegin();
|
||||
this.totalFailCountThisTime += briefModel.getFailCountThisTime();
|
||||
this.totalFailThroughputThisTime += briefModel
|
||||
.getFailThroughputThisTime();
|
||||
this.totalResponseTimeThisTime += briefModel
|
||||
.getTotalResponseTimeThisTime();
|
||||
this.totalSquareResponseTime += briefModel
|
||||
.getTotalSqureResponseTimeThisTime();
|
||||
this.totalSuccessCountThisTime += briefModel.getSuccessCountThisTime();
|
||||
this.totalSuccessCountFromBegin += briefModel
|
||||
.getSuccessCountFromBegin();
|
||||
this.totalSuccessThroughputThisTime += briefModel
|
||||
.getSuccessThroughputThisTime();
|
||||
this.activeVUserCountThisTime += briefModel.getvUserCount();
|
||||
}
|
||||
|
||||
public ScriptBriefResultModel getStatistics() {
|
||||
ScriptBriefResultModel result = new ScriptBriefResultModel();
|
||||
long averageResponseTime = 0;
|
||||
if (this.totalSuccessCountThisTime == 0) {
|
||||
result.setAverageResponseTime(0);
|
||||
result.setMaxResponseTime(0);
|
||||
result.setMinResponseTime(0);
|
||||
result.setResponseTimeDeviationThisTime(0);
|
||||
if (this.totalFailCountThisTime == 0) {
|
||||
result.setFailRateThisTime(0);
|
||||
} else {
|
||||
result.setFailRateThisTime(100);
|
||||
}
|
||||
} else {
|
||||
averageResponseTime = this.totalResponseTimeThisTime
|
||||
/ this.totalSuccessCountThisTime;
|
||||
result.setAverageResponseTime(averageResponseTime);
|
||||
result.setMaxResponseTime(this.maxResponseTimeThisTime);
|
||||
result.setMinResponseTime(this.minResponseTimeThisTime);
|
||||
result.setResponseTimeDeviationThisTime(Math.round(Math
|
||||
.sqrt(this.totalSquareResponseTime
|
||||
/ this.totalSuccessCountThisTime
|
||||
- averageResponseTime * averageResponseTime)));
|
||||
result.setFailRateThisTime(this.totalFailCountThisTime
|
||||
* 100
|
||||
/ (this.totalFailCountThisTime + this.totalSuccessCountThisTime));
|
||||
}
|
||||
result.setFailThroughputThisTime(this.totalFailThroughputThisTime);
|
||||
result.setSuccessThroughputThisTime(this.totalSuccessThroughputThisTime);
|
||||
result.setTotalFailCountFromBegin(this.totalFailCountFromBegin);
|
||||
result.setTotalSuccessCountFromBegin(this.totalSuccessCountFromBegin);
|
||||
if (this.effectiveCount == 0) {
|
||||
result.setAverageElapsedTime(0);
|
||||
} else {
|
||||
result.setAverageElapsedTime(this.totalElapsedTime
|
||||
/ this.effectiveCount);
|
||||
}
|
||||
result = dealWithInvalidSamplePoint(result);
|
||||
result.setSamplingTime(new Date());
|
||||
result.setvUserCount(this.activeVUserCountThisTime);
|
||||
reset();
|
||||
return result;
|
||||
}
|
||||
|
||||
private ScriptBriefResultModel dealWithInvalidSamplePoint(
|
||||
ScriptBriefResultModel inputModel) {
|
||||
if (this.totalFailCountThisTime == 0
|
||||
&& this.totalSuccessCountThisTime == 0) {
|
||||
return this.getLastValidBriefResultModel();
|
||||
}
|
||||
this.setLastValidBriefResultModel(inputModel);
|
||||
return inputModel;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,131 +1,145 @@
|
|||
package org.bench4q.master.test.datastatistics;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.bench4q.master.testplan.datastatistics.ScriptBriefStatistics;
|
||||
import org.bench4q.share.models.agent.statistics.AgentBriefStatusModel;
|
||||
import org.bench4q.share.models.master.statistics.ScriptBriefResultModel;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ScriptBriefStatisticsTest {
|
||||
private ScriptBriefStatistics briefStatistics;
|
||||
private static int TIME_UNIT_MS = 1000;
|
||||
private static int FAIL_COUNT = 1;
|
||||
|
||||
public ScriptBriefStatistics getBriefStatistics() {
|
||||
return briefStatistics;
|
||||
}
|
||||
|
||||
public void setBriefStatistics(ScriptBriefStatistics briefStatistics) {
|
||||
this.briefStatistics = briefStatistics;
|
||||
}
|
||||
|
||||
public ScriptBriefStatisticsTest() {
|
||||
this.setBriefStatistics(new ScriptBriefStatistics());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addNullTest() {
|
||||
this.getBriefStatistics().add(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addZeroTest() {
|
||||
briefStatistics.add(new AgentBriefStatusModel());
|
||||
ScriptBriefResultModel actualResult = briefStatistics.getStatistics();
|
||||
ScriptBriefResultModel expectedResult = makeExpectedModelForZeroAgent();
|
||||
assertTrue(actualResult.equals(expectedResult));
|
||||
}
|
||||
|
||||
private ScriptBriefResultModel makeExpectedModelForZeroAgent() {
|
||||
ScriptBriefResultModel result = new ScriptBriefResultModel();
|
||||
result.setAverageElapsedTime(0);
|
||||
result.setAverageResponseTime(0);
|
||||
result.setFailRateThisTime(0);
|
||||
result.setFailThroughputThisTime(0);
|
||||
result.setMaxResponseTime(0);
|
||||
result.setMinResponseTime(0);
|
||||
result.setResponseTimeDeviationThisTime(0);
|
||||
result.setSuccessThroughputThisTime(0);
|
||||
result.setTotalFailCountFromBegin(0);
|
||||
result.setTotalSuccessCountFromBegin(0);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addOneTest() {
|
||||
long timeFrame = 200;
|
||||
this.getBriefStatistics().add(
|
||||
buildOneInputModel(timeFrame, 200, 200, 200, 40000, 1));
|
||||
ScriptBriefResultModel actualModel = this.getBriefStatistics()
|
||||
.getStatistics();
|
||||
ScriptBriefResultModel expectedModel = this
|
||||
.makeExepectedModelForOneAgent();
|
||||
assertTrue(actualModel.equals(expectedModel));
|
||||
}
|
||||
|
||||
public static AgentBriefStatusModel buildOneInputModel(long timeFrame,
|
||||
long minRT, long maxRT, long totalRT, long totalSqureRT,
|
||||
long successCount) {
|
||||
AgentBriefStatusModel model = new AgentBriefStatusModel();
|
||||
model.setTimeFrame(timeFrame);
|
||||
model.setSuccessCountFromBegin(successCount);
|
||||
model.setFailCountFromBegin(FAIL_COUNT);
|
||||
model.setSuccessThroughputThisTime(successCount * TIME_UNIT_MS
|
||||
/ timeFrame);
|
||||
model.setFailThroughputThisTime(FAIL_COUNT * TIME_UNIT_MS / timeFrame);
|
||||
model.setMaxResponseTime(maxRT);
|
||||
model.setMinResponseTime(minRT);
|
||||
model.setSuccessCountThisTime(successCount);
|
||||
model.setFailCountThisTime(FAIL_COUNT);
|
||||
model.setTotalResponseTimeThisTime(totalRT);
|
||||
model.setTotalSqureResponseTimeThisTime(totalSqureRT);
|
||||
return model;
|
||||
}
|
||||
|
||||
private ScriptBriefResultModel makeExepectedModelForOneAgent() {
|
||||
ScriptBriefResultModel result = new ScriptBriefResultModel();
|
||||
result.setAverageResponseTime(200);
|
||||
result.setFailRateThisTime(50);
|
||||
result.setFailThroughputThisTime(1 * TIME_UNIT_MS / 200);
|
||||
result.setMaxResponseTime(200);
|
||||
result.setMinResponseTime(200);
|
||||
result.setResponseTimeDeviationThisTime(0);
|
||||
result.setSuccessThroughputThisTime(1 * TIME_UNIT_MS / 200);
|
||||
result.setTotalFailCountFromBegin(1);
|
||||
result.setTotalSuccessCountFromBegin(1);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addTwoTest() {
|
||||
long timeFrame1 = 200, timeFrame2 = 500;
|
||||
this.briefStatistics.add(buildOneInputModel(timeFrame1, 200, 200, 200,
|
||||
40000, 1));
|
||||
this.briefStatistics.add(buildOneInputModel(timeFrame2, 190, 210, 400,
|
||||
80200, 2));
|
||||
ScriptBriefResultModel actualModel = this.briefStatistics
|
||||
.getStatistics();
|
||||
ScriptBriefResultModel expectedModel = makeExpectedModelForTwoAgent();
|
||||
assertTrue(actualModel.equals(expectedModel));
|
||||
}
|
||||
|
||||
private ScriptBriefResultModel makeExpectedModelForTwoAgent() {
|
||||
ScriptBriefResultModel result = new ScriptBriefResultModel();
|
||||
result.setAverageResponseTime(200);
|
||||
result.setFailRateThisTime(40);
|
||||
result.setFailThroughputThisTime(7);
|
||||
result.setMaxResponseTime(210);
|
||||
result.setMinResponseTime(190);
|
||||
result.setResponseTimeDeviationThisTime(8);
|
||||
result.setSuccessThroughputThisTime(9);
|
||||
result.setTotalFailCountFromBegin(2);
|
||||
result.setTotalSuccessCountFromBegin(3);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddOneRealModel() {
|
||||
|
||||
}
|
||||
}
|
||||
package org.bench4q.master.test.datastatistics;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.bench4q.master.testplan.datastatistics.ScriptBriefStatistics;
|
||||
import org.bench4q.share.models.agent.statistics.AgentBriefStatusModel;
|
||||
import org.bench4q.share.models.master.statistics.ScriptBriefResultModel;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ScriptBriefStatisticsTest {
|
||||
private ScriptBriefStatistics briefStatistics;
|
||||
private static int TIME_UNIT_MS = 1000;
|
||||
private static int FAIL_COUNT = 1;
|
||||
|
||||
public ScriptBriefStatistics getBriefStatistics() {
|
||||
return briefStatistics;
|
||||
}
|
||||
|
||||
public void setBriefStatistics(ScriptBriefStatistics briefStatistics) {
|
||||
this.briefStatistics = briefStatistics;
|
||||
}
|
||||
|
||||
public ScriptBriefStatisticsTest() {
|
||||
this.setBriefStatistics(new ScriptBriefStatistics());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addNullTest() {
|
||||
this.getBriefStatistics().add(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addZeroTest() {
|
||||
briefStatistics.add(new AgentBriefStatusModel());
|
||||
ScriptBriefResultModel actualResult = briefStatistics.getStatistics();
|
||||
ScriptBriefResultModel expectedResult = makeExpectedModelForZeroAgent();
|
||||
assertTrue(actualResult.equals(expectedResult));
|
||||
assertEquals(0, actualResult.getvUserCount());
|
||||
}
|
||||
|
||||
private ScriptBriefResultModel makeExpectedModelForZeroAgent() {
|
||||
ScriptBriefResultModel result = new ScriptBriefResultModel();
|
||||
result.setAverageElapsedTime(0);
|
||||
result.setAverageResponseTime(0);
|
||||
result.setFailRateThisTime(0);
|
||||
result.setFailThroughputThisTime(0);
|
||||
result.setMaxResponseTime(0);
|
||||
result.setMinResponseTime(0);
|
||||
result.setResponseTimeDeviationThisTime(0);
|
||||
result.setSuccessThroughputThisTime(0);
|
||||
result.setTotalFailCountFromBegin(0);
|
||||
result.setTotalSuccessCountFromBegin(0);
|
||||
result.setvUserCount(0);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addOneTest() {
|
||||
long timeFrame = 200;
|
||||
this.getBriefStatistics().add(
|
||||
buildOneInputModel(timeFrame, 200, 200, 200, 40000, 1, 10));
|
||||
ScriptBriefResultModel actualModel = this.getBriefStatistics()
|
||||
.getStatistics();
|
||||
ScriptBriefResultModel expectedModel = this
|
||||
.makeExepectedModelForOneAgent();
|
||||
assertTrue(actualModel.equals(expectedModel));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addOneTestWithNegativeVUser() {
|
||||
long timeFrame = 200;
|
||||
this.getBriefStatistics().add(
|
||||
buildOneInputModel(timeFrame, 200, 200, 200, 40000, 1, -2));
|
||||
ScriptBriefResultModel actualModel = this.getBriefStatistics()
|
||||
.getStatistics();
|
||||
ScriptBriefResultModel expectedBriefResultModel = this
|
||||
.makeExepectedModelForOneAgent();
|
||||
expectedBriefResultModel.setvUserCount(-2);
|
||||
assertTrue(actualModel.equals(expectedBriefResultModel));
|
||||
}
|
||||
|
||||
public static AgentBriefStatusModel buildOneInputModel(long timeFrame,
|
||||
long minRT, long maxRT, long totalRT, long totalSqureRT,
|
||||
long successCount, long vUserCount) {
|
||||
AgentBriefStatusModel model = new AgentBriefStatusModel();
|
||||
model.setTimeFrame(timeFrame);
|
||||
model.setSuccessCountFromBegin(successCount);
|
||||
model.setFailCountFromBegin(FAIL_COUNT);
|
||||
model.setSuccessThroughputThisTime(successCount * TIME_UNIT_MS
|
||||
/ timeFrame);
|
||||
model.setFailThroughputThisTime(FAIL_COUNT * TIME_UNIT_MS / timeFrame);
|
||||
model.setMaxResponseTime(maxRT);
|
||||
model.setMinResponseTime(minRT);
|
||||
model.setSuccessCountThisTime(successCount);
|
||||
model.setFailCountThisTime(FAIL_COUNT);
|
||||
model.setTotalResponseTimeThisTime(totalRT);
|
||||
model.setTotalSqureResponseTimeThisTime(totalSqureRT);
|
||||
model.setvUserCount(vUserCount);
|
||||
return model;
|
||||
}
|
||||
|
||||
private ScriptBriefResultModel makeExepectedModelForOneAgent() {
|
||||
ScriptBriefResultModel result = new ScriptBriefResultModel();
|
||||
result.setAverageResponseTime(200);
|
||||
result.setFailRateThisTime(50);
|
||||
result.setFailThroughputThisTime(1 * TIME_UNIT_MS / 200);
|
||||
result.setMaxResponseTime(200);
|
||||
result.setMinResponseTime(200);
|
||||
result.setResponseTimeDeviationThisTime(0);
|
||||
result.setSuccessThroughputThisTime(1 * TIME_UNIT_MS / 200);
|
||||
result.setTotalFailCountFromBegin(1);
|
||||
result.setTotalSuccessCountFromBegin(1);
|
||||
result.setvUserCount(10);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addTwoTest() {
|
||||
long timeFrame1 = 200, timeFrame2 = 500;
|
||||
this.briefStatistics.add(buildOneInputModel(timeFrame1, 200, 200, 200,
|
||||
40000, 1, 10));
|
||||
this.briefStatistics.add(buildOneInputModel(timeFrame2, 190, 210, 400,
|
||||
80200, 2, 20));
|
||||
ScriptBriefResultModel actualModel = this.briefStatistics
|
||||
.getStatistics();
|
||||
ScriptBriefResultModel expectedModel = makeExpectedModelForTwoAgent();
|
||||
assertTrue(actualModel.equals(expectedModel));
|
||||
}
|
||||
|
||||
private ScriptBriefResultModel makeExpectedModelForTwoAgent() {
|
||||
ScriptBriefResultModel result = new ScriptBriefResultModel();
|
||||
result.setAverageResponseTime(200);
|
||||
result.setFailRateThisTime(40);
|
||||
result.setFailThroughputThisTime(7);
|
||||
result.setMaxResponseTime(210);
|
||||
result.setMinResponseTime(190);
|
||||
result.setResponseTimeDeviationThisTime(8);
|
||||
result.setSuccessThroughputThisTime(9);
|
||||
result.setTotalFailCountFromBegin(2);
|
||||
result.setTotalSuccessCountFromBegin(3);
|
||||
result.setvUserCount(30);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue