totally use the new way to calculate brief information of test
This commit is contained in:
parent
0df812dae1
commit
9a4daa564b
|
@ -4,3 +4,4 @@
|
||||||
/target
|
/target
|
||||||
/logs
|
/logs
|
||||||
/scripts
|
/scripts
|
||||||
|
/DetailResults
|
||||||
|
|
|
@ -11,12 +11,12 @@ import javax.xml.bind.JAXBException;
|
||||||
import javax.xml.bind.Marshaller;
|
import javax.xml.bind.Marshaller;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
import org.bench4q.agent.api.model.AgentBriefStatusModel;
|
||||||
import org.bench4q.agent.api.model.CleanTestResultModel;
|
import org.bench4q.agent.api.model.CleanTestResultModel;
|
||||||
import org.bench4q.agent.api.model.ParameterModel;
|
import org.bench4q.agent.api.model.ParameterModel;
|
||||||
import org.bench4q.agent.api.model.RunScenarioModel;
|
import org.bench4q.agent.api.model.RunScenarioModel;
|
||||||
import org.bench4q.agent.api.model.RunScenarioResultModel;
|
import org.bench4q.agent.api.model.RunScenarioResultModel;
|
||||||
import org.bench4q.agent.api.model.StopTestModel;
|
import org.bench4q.agent.api.model.StopTestModel;
|
||||||
import org.bench4q.agent.api.model.TestBriefStatusModel;
|
|
||||||
import org.bench4q.agent.api.model.TestDetailModel;
|
import org.bench4q.agent.api.model.TestDetailModel;
|
||||||
import org.bench4q.agent.api.model.TestDetailStatusModel;
|
import org.bench4q.agent.api.model.TestDetailStatusModel;
|
||||||
import org.bench4q.agent.api.model.UsePluginModel;
|
import org.bench4q.agent.api.model.UsePluginModel;
|
||||||
|
@ -211,67 +211,14 @@ public class TestController {
|
||||||
|
|
||||||
@RequestMapping(value = "/brief/{runId}", method = RequestMethod.GET)
|
@RequestMapping(value = "/brief/{runId}", method = RequestMethod.GET)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public TestBriefStatusModel brief(@PathVariable UUID runId) {
|
public AgentBriefStatusModel brief(@PathVariable UUID runId) {
|
||||||
ScenarioContext scenarioContext = this.getScenarioEngine()
|
ScenarioContext scenarioContext = this.getScenarioEngine()
|
||||||
.getRunningTests().get(runId);
|
.getRunningTests().get(runId);
|
||||||
if (scenarioContext == null) {
|
if (scenarioContext == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
TestBriefStatusModel testBriefStatusModel = new TestBriefStatusModel();
|
return (AgentBriefStatusModel) scenarioContext.getDataStatistics()
|
||||||
testBriefStatusModel.setStartDate(scenarioContext.getStartDate());
|
.getBriefStatistics();
|
||||||
int failCount = 0;
|
|
||||||
int successCount = 0;
|
|
||||||
long totalResponseTime = 0;
|
|
||||||
long maxResponseTime = 0, minResponseTime = Long.MAX_VALUE;
|
|
||||||
List<BehaviorResult> behaviorResults = new ArrayList<BehaviorResult>(
|
|
||||||
scenarioContext.getResults());
|
|
||||||
long maxDate = 0, minDate = Long.MAX_VALUE;
|
|
||||||
int validCount = 0;
|
|
||||||
for (BehaviorResult behaviorResult : behaviorResults) {
|
|
||||||
if (behaviorResult.getEndDate().getTime() > maxDate) {
|
|
||||||
maxDate = behaviorResult.getEndDate().getTime();
|
|
||||||
}
|
|
||||||
if (behaviorResult.getStartDate().getTime() < minDate) {
|
|
||||||
minDate = behaviorResult.getStartDate().getTime();
|
|
||||||
}
|
|
||||||
if (behaviorResult.isSuccess()) {
|
|
||||||
successCount++;
|
|
||||||
} else {
|
|
||||||
failCount++;
|
|
||||||
}
|
|
||||||
if (behaviorResult.getPluginName().contains("Timer")) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (behaviorResult.isCalculated()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (behaviorResult.getResponseTime() > maxResponseTime) {
|
|
||||||
maxResponseTime = behaviorResult.getResponseTime();
|
|
||||||
}
|
|
||||||
if (behaviorResult.getResponseTime() < minResponseTime) {
|
|
||||||
minResponseTime = behaviorResult.getResponseTime();
|
|
||||||
}
|
|
||||||
totalResponseTime += behaviorResult.getResponseTime();
|
|
||||||
validCount++;
|
|
||||||
behaviorResult.setCalculated(true);
|
|
||||||
}
|
|
||||||
if (validCount == 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
testBriefStatusModel.setAverageResponseTime((totalResponseTime + 0.0)
|
|
||||||
/ validCount);
|
|
||||||
testBriefStatusModel.setElapsedTime(maxDate
|
|
||||||
- testBriefStatusModel.getStartDate().getTime());
|
|
||||||
testBriefStatusModel.setRunningTime(maxDate
|
|
||||||
- scenarioContext.getStartDate().getTime());
|
|
||||||
testBriefStatusModel.setFailCount(failCount);
|
|
||||||
testBriefStatusModel.setSuccessCount(successCount);
|
|
||||||
testBriefStatusModel.setFinishedCount(behaviorResults.size());
|
|
||||||
testBriefStatusModel.setScenarioBehaviorCount(scenarioContext
|
|
||||||
.getScenario().getUserBehaviors().length);
|
|
||||||
testBriefStatusModel.setRunningTime(maxDate - minDate);
|
|
||||||
testBriefStatusModel.setFinished(scenarioContext.isFinished());
|
|
||||||
return testBriefStatusModel;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/stop/{runId}", method = { RequestMethod.GET,
|
@RequestMapping(value = "/stop/{runId}", method = { RequestMethod.GET,
|
||||||
|
|
|
@ -7,9 +7,9 @@ import java.util.List;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.bench4q.agent.api.model.TestDetailModel;
|
import org.bench4q.agent.api.model.TestDetailModel;
|
||||||
import org.bench4q.agent.datacollector.interfaces.DataStatistics;
|
import org.bench4q.agent.datacollector.interfaces.DataStatistics;
|
||||||
|
import org.bench4q.agent.helper.ApplicationContextHelper;
|
||||||
import org.bench4q.agent.scenario.BehaviorResult;
|
import org.bench4q.agent.scenario.BehaviorResult;
|
||||||
import org.bench4q.agent.storage.StorageHelper;
|
import org.bench4q.agent.storage.StorageHelper;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
|
|
||||||
public abstract class AbstractDataCollector implements DataStatistics {
|
public abstract class AbstractDataCollector implements DataStatistics {
|
||||||
protected StorageHelper storageHelper;
|
protected StorageHelper storageHelper;
|
||||||
|
@ -19,11 +19,16 @@ public abstract class AbstractDataCollector implements DataStatistics {
|
||||||
return storageHelper;
|
return storageHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public void setStorageHelper(StorageHelper storageHelper) {
|
public void setStorageHelper(StorageHelper storageHelper) {
|
||||||
this.storageHelper = storageHelper;
|
this.storageHelper = storageHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Each sub class should call this in their constructor
|
||||||
|
protected void mustDoWhenIniti() {
|
||||||
|
this.setStorageHelper(ApplicationContextHelper.getContext().getBean(
|
||||||
|
StorageHelper.class));
|
||||||
|
}
|
||||||
|
|
||||||
protected String getHostName() {
|
protected String getHostName() {
|
||||||
InetAddress addr;
|
InetAddress addr;
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -82,11 +82,13 @@ public class AgentResultDataCollector extends AbstractDataCollector {
|
||||||
this.testID = testID;
|
this.testID = testID;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AgentResultDataCollector() {
|
public AgentResultDataCollector(UUID testId) {
|
||||||
init();
|
super.mustDoWhenIniti();
|
||||||
|
this.setTestID(testId);
|
||||||
|
mustDoWhenIniti();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void init() {
|
public void mustDoWhenIniti() {
|
||||||
reset();
|
reset();
|
||||||
this.setCumulativeFailCount(0);
|
this.setCumulativeFailCount(0);
|
||||||
this.setCumulativeSucessfulCount(0);
|
this.setCumulativeSucessfulCount(0);
|
||||||
|
@ -149,8 +151,8 @@ public class AgentResultDataCollector extends AbstractDataCollector {
|
||||||
result.setSuccessThroughput(0);
|
result.setSuccessThroughput(0);
|
||||||
result.setFailThroughput(0);
|
result.setFailThroughput(0);
|
||||||
} else {
|
} else {
|
||||||
result.setSuccessThroughput(this.successCountOfThisCall
|
result.setSuccessThroughput(this.successCountOfThisCall * TIME_UNIT
|
||||||
* TIME_UNIT / result.getTimeFrame());
|
/ result.getTimeFrame());
|
||||||
result.setFailThroughput(this.failCountOfThisCall * TIME_UNIT
|
result.setFailThroughput(this.failCountOfThisCall * TIME_UNIT
|
||||||
/ result.getTimeFrame());
|
/ result.getTimeFrame());
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
package org.bench4q.agent.helper;
|
||||||
|
|
||||||
|
import org.springframework.beans.BeansException;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.context.ApplicationContextAware;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class ApplicationContextHelper implements ApplicationContextAware {
|
||||||
|
|
||||||
|
private static ApplicationContext context;
|
||||||
|
|
||||||
|
public static ApplicationContext getContext() {
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setContext(ApplicationContext context) {
|
||||||
|
ApplicationContextHelper.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setApplicationContext(ApplicationContext applicationContext)
|
||||||
|
throws BeansException {
|
||||||
|
this.setContext(applicationContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -2,6 +2,7 @@ package org.bench4q.agent.scenario;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
|
|
||||||
import org.bench4q.agent.datacollector.impl.AgentResultDataCollector;
|
import org.bench4q.agent.datacollector.impl.AgentResultDataCollector;
|
||||||
|
@ -66,15 +67,16 @@ public class ScenarioContext {
|
||||||
private ScenarioContext() {
|
private ScenarioContext() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ScenarioContext buildScenarioContext(final Scenario scenario,
|
public static ScenarioContext buildScenarioContext(UUID testId,
|
||||||
int poolSize, ExecutorService executorService,
|
final Scenario scenario, int poolSize,
|
||||||
final List<BehaviorResult> ret) {
|
ExecutorService executorService, final List<BehaviorResult> ret) {
|
||||||
ScenarioContext scenarioContext = new ScenarioContext();
|
ScenarioContext scenarioContext = new ScenarioContext();
|
||||||
scenarioContext.setScenario(scenario);
|
scenarioContext.setScenario(scenario);
|
||||||
scenarioContext.setStartDate(new Date(System.currentTimeMillis()));
|
scenarioContext.setStartDate(new Date(System.currentTimeMillis()));
|
||||||
scenarioContext.setExecutorService(executorService);
|
scenarioContext.setExecutorService(executorService);
|
||||||
scenarioContext.setResults(ret);
|
scenarioContext.setResults(ret);
|
||||||
scenarioContext.setDataStatistics(new AgentResultDataCollector());
|
// TODO:remove this direct dependency
|
||||||
|
scenarioContext.setDataStatistics(new AgentResultDataCollector(testId));
|
||||||
return scenarioContext;
|
return scenarioContext;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package org.bench4q.agent.scenario;
|
package org.bench4q.agent.scenario;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
@ -25,6 +24,7 @@ public class ScenarioEngine {
|
||||||
private StorageHelper storageHelper;
|
private StorageHelper storageHelper;
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
private Logger getLogger() {
|
private Logger getLogger() {
|
||||||
return logger;
|
return logger;
|
||||||
}
|
}
|
||||||
|
@ -71,14 +71,16 @@ public class ScenarioEngine {
|
||||||
final List<BehaviorResult> ret = Collections
|
final List<BehaviorResult> ret = Collections
|
||||||
.synchronizedList(new ArrayList<BehaviorResult>());
|
.synchronizedList(new ArrayList<BehaviorResult>());
|
||||||
final ScenarioContext scenarioContext = ScenarioContext
|
final ScenarioContext scenarioContext = ScenarioContext
|
||||||
.buildScenarioContext(scenario, poolSize, executorService,
|
.buildScenarioContext(runId, scenario, poolSize,
|
||||||
ret);
|
executorService, ret);
|
||||||
int i;
|
int i;
|
||||||
this.getRunningTests().put(runId, scenarioContext);
|
this.getRunningTests().put(runId, scenarioContext);
|
||||||
Runnable runnable = new Runnable() {
|
Runnable runnable = new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
while (!scenarioContext.getExecutorService().isShutdown()) {
|
while (!scenarioContext.getExecutorService().isShutdown()) {
|
||||||
ret.addAll(doRunScenario(scenario));
|
// ret.addAll(doRunScenario(scenario));
|
||||||
|
scenarioContext.getDataStatistics().add(
|
||||||
|
doRunScenario(scenario));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -98,8 +100,8 @@ public class ScenarioEngine {
|
||||||
for (UserBehavior userBehavior : scenario.getUserBehaviors()) {
|
for (UserBehavior userBehavior : scenario.getUserBehaviors()) {
|
||||||
Object plugin = plugins.get(userBehavior.getUse());
|
Object plugin = plugins.get(userBehavior.getUse());
|
||||||
String behaviorName = userBehavior.getName();
|
String behaviorName = userBehavior.getName();
|
||||||
this.getLogger().info(
|
// this.getLogger().info(
|
||||||
"this step's behaviorName is : " + behaviorName);
|
// "this step's behaviorName is : " + behaviorName);
|
||||||
Map<String, String> behaviorParameters = prepareBehaviorParameters(userBehavior);
|
Map<String, String> behaviorParameters = prepareBehaviorParameters(userBehavior);
|
||||||
Date startDate = new Date(System.currentTimeMillis());
|
Date startDate = new Date(System.currentTimeMillis());
|
||||||
boolean success = (Boolean) this.getPluginManager().doBehavior(
|
boolean success = (Boolean) this.getPluginManager().doBehavior(
|
||||||
|
@ -153,25 +155,4 @@ public class ScenarioEngine {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getHdfsPath() {
|
|
||||||
return "hdfs://133.133.12.21:9000/home/bench4q/results";
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLocalPath() {
|
|
||||||
String directory = this.getClass().getProtectionDomain()
|
|
||||||
.getCodeSource().getLocation().getFile().replace("\\", "/");
|
|
||||||
File file = new File(directory);
|
|
||||||
if (!file.isDirectory()) {
|
|
||||||
directory = directory.substring(0, directory.lastIndexOf("/"));
|
|
||||||
}
|
|
||||||
if (!directory.endsWith("/")) {
|
|
||||||
directory += "/";
|
|
||||||
}
|
|
||||||
directory += "results";
|
|
||||||
File toCreate = new File(directory);
|
|
||||||
if (!toCreate.exists()) {
|
|
||||||
toCreate.mkdirs();
|
|
||||||
}
|
|
||||||
return directory;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,8 @@ public class DataStatisticsTest {
|
||||||
@SuppressWarnings("resource")
|
@SuppressWarnings("resource")
|
||||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||||
"classpath*:/org/bench4q/agent/config/application-context.xml");
|
"classpath*:/org/bench4q/agent/config/application-context.xml");
|
||||||
AgentResultDataCollector agentResultDataCollector = new AgentResultDataCollector();
|
AgentResultDataCollector agentResultDataCollector = new AgentResultDataCollector(
|
||||||
|
UUID.randomUUID());
|
||||||
agentResultDataCollector.setStorageHelper((StorageHelper) context
|
agentResultDataCollector.setStorageHelper((StorageHelper) context
|
||||||
.getBean(StorageHelper.class));
|
.getBean(StorageHelper.class));
|
||||||
this.setDataStatistics(agentResultDataCollector);
|
this.setDataStatistics(agentResultDataCollector);
|
||||||
|
|
|
@ -38,7 +38,7 @@ public class TestWithScriptFile {
|
||||||
|
|
||||||
public TestWithScriptFile() {
|
public TestWithScriptFile() {
|
||||||
this.setFilePath("scripts" + System.getProperty("file.separator")
|
this.setFilePath("scripts" + System.getProperty("file.separator")
|
||||||
+ "scriptwithError.xml");
|
+ "script.xml");
|
||||||
this.setHttpRequester(new HttpRequester());
|
this.setHttpRequester(new HttpRequester());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue