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
|
||||
/logs
|
||||
/scripts
|
||||
/DetailResults
|
||||
|
|
|
@ -11,12 +11,12 @@ import javax.xml.bind.JAXBException;
|
|||
import javax.xml.bind.Marshaller;
|
||||
|
||||
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.ParameterModel;
|
||||
import org.bench4q.agent.api.model.RunScenarioModel;
|
||||
import org.bench4q.agent.api.model.RunScenarioResultModel;
|
||||
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.TestDetailStatusModel;
|
||||
import org.bench4q.agent.api.model.UsePluginModel;
|
||||
|
@ -211,67 +211,14 @@ public class TestController {
|
|||
|
||||
@RequestMapping(value = "/brief/{runId}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public TestBriefStatusModel brief(@PathVariable UUID runId) {
|
||||
public AgentBriefStatusModel brief(@PathVariable UUID runId) {
|
||||
ScenarioContext scenarioContext = this.getScenarioEngine()
|
||||
.getRunningTests().get(runId);
|
||||
if (scenarioContext == null) {
|
||||
return null;
|
||||
}
|
||||
TestBriefStatusModel testBriefStatusModel = new TestBriefStatusModel();
|
||||
testBriefStatusModel.setStartDate(scenarioContext.getStartDate());
|
||||
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;
|
||||
return (AgentBriefStatusModel) scenarioContext.getDataStatistics()
|
||||
.getBriefStatistics();
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/stop/{runId}", method = { RequestMethod.GET,
|
||||
|
|
|
@ -7,9 +7,9 @@ import java.util.List;
|
|||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.agent.api.model.TestDetailModel;
|
||||
import org.bench4q.agent.datacollector.interfaces.DataStatistics;
|
||||
import org.bench4q.agent.helper.ApplicationContextHelper;
|
||||
import org.bench4q.agent.scenario.BehaviorResult;
|
||||
import org.bench4q.agent.storage.StorageHelper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
public abstract class AbstractDataCollector implements DataStatistics {
|
||||
protected StorageHelper storageHelper;
|
||||
|
@ -19,11 +19,16 @@ public abstract class AbstractDataCollector implements DataStatistics {
|
|||
return storageHelper;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setStorageHelper(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() {
|
||||
InetAddress addr;
|
||||
try {
|
||||
|
|
|
@ -82,11 +82,13 @@ public class AgentResultDataCollector extends AbstractDataCollector {
|
|||
this.testID = testID;
|
||||
}
|
||||
|
||||
public AgentResultDataCollector() {
|
||||
init();
|
||||
public AgentResultDataCollector(UUID testId) {
|
||||
super.mustDoWhenIniti();
|
||||
this.setTestID(testId);
|
||||
mustDoWhenIniti();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
public void mustDoWhenIniti() {
|
||||
reset();
|
||||
this.setCumulativeFailCount(0);
|
||||
this.setCumulativeSucessfulCount(0);
|
||||
|
@ -149,8 +151,8 @@ public class AgentResultDataCollector extends AbstractDataCollector {
|
|||
result.setSuccessThroughput(0);
|
||||
result.setFailThroughput(0);
|
||||
} else {
|
||||
result.setSuccessThroughput(this.successCountOfThisCall
|
||||
* TIME_UNIT / result.getTimeFrame());
|
||||
result.setSuccessThroughput(this.successCountOfThisCall * TIME_UNIT
|
||||
/ result.getTimeFrame());
|
||||
result.setFailThroughput(this.failCountOfThisCall * TIME_UNIT
|
||||
/ 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.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
import org.bench4q.agent.datacollector.impl.AgentResultDataCollector;
|
||||
|
@ -66,15 +67,16 @@ public class ScenarioContext {
|
|||
private ScenarioContext() {
|
||||
}
|
||||
|
||||
public static ScenarioContext buildScenarioContext(final Scenario scenario,
|
||||
int poolSize, ExecutorService executorService,
|
||||
final List<BehaviorResult> ret) {
|
||||
public static ScenarioContext buildScenarioContext(UUID testId,
|
||||
final Scenario scenario, int poolSize,
|
||||
ExecutorService executorService, final List<BehaviorResult> ret) {
|
||||
ScenarioContext scenarioContext = new ScenarioContext();
|
||||
scenarioContext.setScenario(scenario);
|
||||
scenarioContext.setStartDate(new Date(System.currentTimeMillis()));
|
||||
scenarioContext.setExecutorService(executorService);
|
||||
scenarioContext.setResults(ret);
|
||||
scenarioContext.setDataStatistics(new AgentResultDataCollector());
|
||||
// TODO:remove this direct dependency
|
||||
scenarioContext.setDataStatistics(new AgentResultDataCollector(testId));
|
||||
return scenarioContext;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package org.bench4q.agent.scenario;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
|
@ -25,6 +24,7 @@ public class ScenarioEngine {
|
|||
private StorageHelper storageHelper;
|
||||
private Logger logger;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private Logger getLogger() {
|
||||
return logger;
|
||||
}
|
||||
|
@ -71,14 +71,16 @@ public class ScenarioEngine {
|
|||
final List<BehaviorResult> ret = Collections
|
||||
.synchronizedList(new ArrayList<BehaviorResult>());
|
||||
final ScenarioContext scenarioContext = ScenarioContext
|
||||
.buildScenarioContext(scenario, poolSize, executorService,
|
||||
ret);
|
||||
.buildScenarioContext(runId, scenario, poolSize,
|
||||
executorService, ret);
|
||||
int i;
|
||||
this.getRunningTests().put(runId, scenarioContext);
|
||||
Runnable runnable = new Runnable() {
|
||||
public void run() {
|
||||
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()) {
|
||||
Object plugin = plugins.get(userBehavior.getUse());
|
||||
String behaviorName = userBehavior.getName();
|
||||
this.getLogger().info(
|
||||
"this step's behaviorName is : " + behaviorName);
|
||||
// this.getLogger().info(
|
||||
// "this step's behaviorName is : " + behaviorName);
|
||||
Map<String, String> behaviorParameters = prepareBehaviorParameters(userBehavior);
|
||||
Date startDate = new Date(System.currentTimeMillis());
|
||||
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")
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"classpath*:/org/bench4q/agent/config/application-context.xml");
|
||||
AgentResultDataCollector agentResultDataCollector = new AgentResultDataCollector();
|
||||
AgentResultDataCollector agentResultDataCollector = new AgentResultDataCollector(
|
||||
UUID.randomUUID());
|
||||
agentResultDataCollector.setStorageHelper((StorageHelper) context
|
||||
.getBean(StorageHelper.class));
|
||||
this.setDataStatistics(agentResultDataCollector);
|
||||
|
|
|
@ -38,7 +38,7 @@ public class TestWithScriptFile {
|
|||
|
||||
public TestWithScriptFile() {
|
||||
this.setFilePath("scripts" + System.getProperty("file.separator")
|
||||
+ "scriptwithError.xml");
|
||||
+ "script.xml");
|
||||
this.setHttpRequester(new HttpRequester());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue