Merge branch 'master' of https://github.com/lostcharlie/Bench4Q.git
Conflicts: Bench4Q-Master/src/main/java/org/bench4q/master/api/TestPlanController.java Bench4Q-Share/src/main/java/org/bench4q/share/models/agent/RunScenarioModel.java Bench4Q-Web/src/main/java/org/bench4q/web/masterMessager/TestPlanMessager.java
This commit is contained in:
commit
dd93e0321f
|
@ -1,7 +1,6 @@
|
|||
package org.bench4q.agent.api;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
@ -21,7 +20,6 @@ import org.bench4q.share.models.agent.RunScenarioModel;
|
|||
import org.bench4q.share.models.agent.RunScenarioResultModel;
|
||||
import org.bench4q.share.models.agent.StopTestModel;
|
||||
import org.bench4q.share.models.agent.TestBriefStatusModel;
|
||||
import org.bench4q.share.models.agent.UpdatePopulationModel;
|
||||
import org.bench4q.share.models.agent.statistics.AgentBriefStatusModel;
|
||||
import org.bench4q.share.models.agent.statistics.AgentBehaviorsBriefModel;
|
||||
import org.bench4q.share.models.agent.statistics.AgentPageBriefModel;
|
||||
|
@ -77,10 +75,11 @@ public class TestController {
|
|||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/submitScenarioWithParams/{runId}", method = RequestMethod.POST)
|
||||
@RequestMapping(value = "/submitScenarioWithParams/{runId}/{realStartTime}", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public String submitParams(
|
||||
@PathVariable UUID runId,
|
||||
@PathVariable long realStartTime,
|
||||
@RequestParam(value = "files[]", required = false) List<MultipartFile> files,
|
||||
@RequestParam(value = "testShedule", required = false) String scheduleContent,
|
||||
@RequestParam(value = "scenarioModel") String scenarioModel) {
|
||||
|
@ -90,7 +89,7 @@ public class TestController {
|
|||
RunScenarioModel runScenarioModel = (RunScenarioModel) MarshalHelper
|
||||
.unmarshal(RunScenarioModel.class, scenarioModel);
|
||||
this.getScenarioEngine().submitScenario(runId,
|
||||
Scenario.scenarioBuilderWithCompile(runScenarioModel));
|
||||
Scenario.scenarioBuilderWithCompile(runScenarioModel), realStartTime);
|
||||
return MarshalHelper.tryMarshal(buildWith(runId));
|
||||
} catch (Exception e) {
|
||||
logger.error("/submitScenarioWithParams", e);
|
||||
|
@ -247,32 +246,20 @@ public class TestController {
|
|||
if (scenarioContext == null) {
|
||||
return null;
|
||||
}
|
||||
scenarioContext.setEndDate(new Date(System.currentTimeMillis()));
|
||||
System.out.println("when before stop, classId:"
|
||||
+ scenarioContext.getExecutor().toString());
|
||||
scenarioContext.getExecutor().shutdown();
|
||||
scenarioContext.getExecutor().shutdownNow();
|
||||
System.out.println("when after stop, classId:"
|
||||
+ scenarioContext.getExecutor().toString());
|
||||
scenarioContext.setFinished(true);
|
||||
clean(runId);
|
||||
scenarioContext.stop();
|
||||
clean();
|
||||
return new StopTestModel(true);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/clean/{runId}", method = RequestMethod.GET)
|
||||
@RequestMapping(value = "/clean", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CleanTestResultModel clean(@PathVariable UUID runId) {
|
||||
this.getScenarioEngine().getRunningTests().remove(runId);
|
||||
public CleanTestResultModel clean() {
|
||||
System.gc();
|
||||
return new CleanTestResultModel(true);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/updatePopulation/{runId}/{requiredLoad}", method = {
|
||||
RequestMethod.POST, RequestMethod.GET })
|
||||
@ResponseBody
|
||||
public UpdatePopulationModel updatePopulation(@PathVariable UUID runId,
|
||||
@PathVariable int requiredLoad) {
|
||||
this.getScenarioEngine().updatePopulation(runId, requiredLoad);
|
||||
return new UpdatePopulationModel(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,6 @@ import com.mongodb.ServerAddress;
|
|||
@Plugin("MongoDBPlugin")
|
||||
public class MongoDBPlugin {
|
||||
private final String hostName;
|
||||
private final int port;
|
||||
private final String dbName;
|
||||
private final String tableUnderTest = "users";
|
||||
|
||||
|
@ -38,7 +37,6 @@ public class MongoDBPlugin {
|
|||
@Parameter(value = "port", type = SupportTypes.Field) int port,
|
||||
@Parameter(value = "dbName", type = SupportTypes.Field) String dbName) {
|
||||
this.hostName = hostName;
|
||||
this.port = port;
|
||||
this.dbName = dbName;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
|
||||
import org.bench4q.agent.scenario.behavior.Behavior;
|
||||
import org.bench4q.agent.scenario.engine.Schedule;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.agent.ParameterModel;
|
||||
import org.bench4q.share.models.agent.RunScenarioModel;
|
||||
|
@ -16,7 +17,7 @@ public class Scenario {
|
|||
private UsePlugin[] usePlugins;
|
||||
private Page[] pages;
|
||||
private List<Behavior> behaviors;
|
||||
private TestSchedule schedule;
|
||||
private Schedule schedule;
|
||||
|
||||
public UsePlugin[] getUsePlugins() {
|
||||
return usePlugins;
|
||||
|
@ -42,11 +43,11 @@ public class Scenario {
|
|||
this.behaviors = behaviors;
|
||||
}
|
||||
|
||||
public TestSchedule getSchedule() {
|
||||
public Schedule getSchedule() {
|
||||
return schedule;
|
||||
}
|
||||
|
||||
private void setSchedule(TestSchedule schedule) {
|
||||
private void setSchedule(Schedule schedule) {
|
||||
this.schedule = schedule;
|
||||
}
|
||||
|
||||
|
@ -97,7 +98,7 @@ public class Scenario {
|
|||
scenario.setPages(new Page[runScenarioModel.getPages().size()]);
|
||||
extractUsePlugins(runScenarioModel, scenario);
|
||||
extractPages(runScenarioModel, scenario);
|
||||
scenario.setSchedule(TestSchedule.build(runScenarioModel.getScheduleModel()));
|
||||
scenario.setSchedule(Schedule.build(runScenarioModel.getScheduleModel()));
|
||||
return scenario;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,63 +0,0 @@
|
|||
package org.bench4q.agent.scenario;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bench4q.share.models.agent.scriptrecord.TestScheduleModel;
|
||||
import org.bench4q.share.models.agent.scriptrecord.TestScheduleModel.PointModel;
|
||||
|
||||
public class TestSchedule {
|
||||
private List<Segment> points;
|
||||
|
||||
public List<Segment> getPoints() {
|
||||
return points;
|
||||
}
|
||||
|
||||
public void setPoints(List<Segment> points) {
|
||||
this.points = points;
|
||||
}
|
||||
|
||||
public static class Segment {
|
||||
private final Point start;
|
||||
private Point end;
|
||||
private final int growthUnit = 0;
|
||||
|
||||
public Segment(Point startPoint, Point endPoint, int growthUnit) {
|
||||
this.start = new Point(startPoint.time, startPoint.load);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Point {
|
||||
private final int time;
|
||||
private final int load;
|
||||
|
||||
public int getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public int getLoad() {
|
||||
return load;
|
||||
}
|
||||
|
||||
public Point(int time, int load) {
|
||||
// TODO Auto-generated constructor stub
|
||||
this.time = time;
|
||||
this.load = load;
|
||||
}
|
||||
}
|
||||
|
||||
public static TestSchedule build(TestScheduleModel scheduleModel) {
|
||||
TestSchedule schedule = new TestSchedule();
|
||||
// schedule.setPoints(extractPoints(scheduleModel.getPoints()));
|
||||
return null;
|
||||
}
|
||||
|
||||
private static List<Point> extractPoints(List<PointModel> points) {
|
||||
List<Point> result = new LinkedList<TestSchedule.Point>();
|
||||
for (PointModel model : points) {
|
||||
result.add(new Point(model.getTime(), model.getLoad()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,149 +1,155 @@
|
|||
package org.bench4q.agent.scenario.engine;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.ThreadPoolExecutor.DiscardPolicy;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.agent.datacollector.DataCollector;
|
||||
import org.bench4q.agent.datacollector.impl.ScenarioResultCollector;
|
||||
import org.bench4q.agent.plugin.PluginManager;
|
||||
import org.bench4q.agent.scenario.Scenario;
|
||||
|
||||
public class ScenarioContext {
|
||||
private static final long keepAliveTime = 10;
|
||||
private UUID testId;
|
||||
private Date startDate;
|
||||
private Date endDate;
|
||||
private ThreadPoolExecutor executor;
|
||||
private Scenario scenario;
|
||||
private boolean finished;
|
||||
private DataCollector dataStatistics;
|
||||
private PluginManager pluginManager;
|
||||
|
||||
public UUID getTestId() {
|
||||
return testId;
|
||||
}
|
||||
|
||||
private void setTestId(UUID testId) {
|
||||
this.testId = testId;
|
||||
}
|
||||
|
||||
public Date getStartDate() {
|
||||
return startDate;
|
||||
}
|
||||
|
||||
public void setStartDate(Date saveStartDate) {
|
||||
this.startDate = saveStartDate;
|
||||
}
|
||||
|
||||
public Date getEndDate() {
|
||||
return endDate;
|
||||
}
|
||||
|
||||
public void setEndDate(Date endDate) {
|
||||
this.endDate = endDate;
|
||||
}
|
||||
|
||||
public ThreadPoolExecutor getExecutor() {
|
||||
return executor;
|
||||
}
|
||||
|
||||
public void setExecutorService(ThreadPoolExecutor executor) {
|
||||
this.executor = executor;
|
||||
}
|
||||
|
||||
public Scenario getScenario() {
|
||||
return scenario;
|
||||
}
|
||||
|
||||
public void setScenario(Scenario scenario) {
|
||||
this.scenario = scenario;
|
||||
}
|
||||
|
||||
public boolean isFinished() {
|
||||
return finished;
|
||||
}
|
||||
|
||||
public void setFinished(boolean finished) {
|
||||
this.finished = finished;
|
||||
}
|
||||
|
||||
public DataCollector getDataStatistics() {
|
||||
return dataStatistics;
|
||||
}
|
||||
|
||||
private void setDataStatistics(DataCollector dataStatistics) {
|
||||
this.dataStatistics = dataStatistics;
|
||||
}
|
||||
|
||||
private PluginManager getPluginManager() {
|
||||
return pluginManager;
|
||||
}
|
||||
|
||||
private void setPluginManager(PluginManager pluginManager) {
|
||||
this.pluginManager = pluginManager;
|
||||
}
|
||||
|
||||
private ScenarioContext() {
|
||||
}
|
||||
|
||||
public static ScenarioContext buildScenarioContext(UUID testId,
|
||||
final Scenario scenario, int poolSize, PluginManager pluginManager) {
|
||||
ScenarioContext scenarioContext = buildScenarioContextWithoutScenario(
|
||||
testId, poolSize, pluginManager);
|
||||
scenarioContext.setScenario(scenario);
|
||||
return scenarioContext;
|
||||
}
|
||||
|
||||
public static ScenarioContext buildScenarioContextWithoutScenario(
|
||||
UUID testId, int poolSize, PluginManager pluginManager) {
|
||||
ScenarioContext scenarioContext = new ScenarioContext();
|
||||
scenarioContext.setTestId(testId);
|
||||
scenarioContext.setPluginManager(pluginManager);
|
||||
final ArrayBlockingQueue<Runnable> workQueue = new ArrayBlockingQueue<Runnable>(
|
||||
poolSize);
|
||||
ThreadPoolExecutor executor = new ThreadPoolExecutor(poolSize,
|
||||
poolSize, keepAliveTime, TimeUnit.MINUTES, workQueue,
|
||||
new DiscardPolicy());
|
||||
scenarioContext.setStartDate(new Date(System.currentTimeMillis()));
|
||||
scenarioContext.setExecutorService(executor);
|
||||
scenarioContext.setDataStatistics(new ScenarioResultCollector(testId));
|
||||
return scenarioContext;
|
||||
}
|
||||
|
||||
public ScenarioContext addScenrio(Scenario scenario) {
|
||||
this.setScenario(scenario);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Now, I tolerate that if the requiredLoad <
|
||||
* this.getExecutor.getCorePoolSize(), then the excess threads will be
|
||||
* killed when its current task complete
|
||||
*
|
||||
* @param requiredLoad
|
||||
*/
|
||||
void updatePopulation(int requiredLoad) {
|
||||
this.getExecutor().setCorePoolSize(requiredLoad);
|
||||
this.getExecutor().setMaximumPoolSize(requiredLoad);
|
||||
}
|
||||
|
||||
public void addTask() {
|
||||
if (this.isFinished()) {
|
||||
return;
|
||||
}
|
||||
this.getExecutor().execute(new VUser(this, 1, getPluginManager()));
|
||||
Logger.getLogger(this.getClass()).info(
|
||||
this.getExecutor().getActiveCount());
|
||||
}
|
||||
|
||||
public void initTasks() {
|
||||
for (int i = 0; i < this.getExecutor().getCorePoolSize(); i++) {
|
||||
addTask();
|
||||
}
|
||||
}
|
||||
}
|
||||
package org.bench4q.agent.scenario.engine;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Observable;
|
||||
import java.util.Observer;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.ThreadPoolExecutor.DiscardPolicy;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.agent.datacollector.DataCollector;
|
||||
import org.bench4q.agent.datacollector.impl.ScenarioResultCollector;
|
||||
import org.bench4q.agent.plugin.PluginManager;
|
||||
import org.bench4q.agent.scenario.Scenario;
|
||||
|
||||
public class ScenarioContext implements Observer {
|
||||
private static final long keepAliveTime = 10;
|
||||
private final UUID testId;
|
||||
private final Date startDate;
|
||||
private Date endDate;
|
||||
private final ThreadPoolExecutor executor;
|
||||
private Scenario scenario;
|
||||
private boolean finished;
|
||||
private final DataCollector dataCollector;
|
||||
private final PluginManager pluginManager;
|
||||
|
||||
public ScenarioContext(UUID testId, Date startDate,
|
||||
ThreadPoolExecutor executor, DataCollector dataCollector, PluginManager pluginManager) {
|
||||
this.testId = testId;
|
||||
this.startDate = startDate;
|
||||
this.executor = executor;
|
||||
this.dataCollector = dataCollector;
|
||||
this.pluginManager = pluginManager;
|
||||
}
|
||||
|
||||
public UUID getTestId() {
|
||||
return testId;
|
||||
}
|
||||
|
||||
public Date getStartDate() {
|
||||
return startDate;
|
||||
}
|
||||
|
||||
public Date getEndDate() {
|
||||
return endDate;
|
||||
}
|
||||
|
||||
public void setEndDate(Date endDate) {
|
||||
this.endDate = endDate;
|
||||
}
|
||||
|
||||
public ThreadPoolExecutor getExecutor() {
|
||||
return executor;
|
||||
}
|
||||
|
||||
public Scenario getScenario() {
|
||||
return scenario;
|
||||
}
|
||||
|
||||
public void setScenario(Scenario scenario) {
|
||||
this.scenario = scenario;
|
||||
}
|
||||
|
||||
public boolean isFinished() {
|
||||
return finished;
|
||||
}
|
||||
|
||||
public void setFinished(boolean finished) {
|
||||
this.finished = finished;
|
||||
}
|
||||
|
||||
public DataCollector getDataStatistics() {
|
||||
return dataCollector;
|
||||
}
|
||||
|
||||
private PluginManager getPluginManager() {
|
||||
return pluginManager;
|
||||
}
|
||||
|
||||
public static ScenarioContext buildScenarioContext(UUID testId,
|
||||
final Scenario scenario, int poolSize, PluginManager pluginManager) {
|
||||
ScenarioContext scenarioContext = buildScenarioContextWithoutScenario(
|
||||
testId, poolSize, pluginManager);
|
||||
scenarioContext.setScenario(scenario);
|
||||
scenario.getSchedule().addObserver(scenarioContext);
|
||||
return scenarioContext;
|
||||
}
|
||||
|
||||
public static ScenarioContext buildScenarioContextWithoutScenario(
|
||||
UUID testId, int poolSize, PluginManager pluginManager) {
|
||||
final ArrayBlockingQueue<Runnable> workQueue = new ArrayBlockingQueue<Runnable>(
|
||||
poolSize);
|
||||
ThreadPoolExecutor executor = new ThreadPoolExecutor(poolSize,
|
||||
poolSize, keepAliveTime, TimeUnit.MINUTES, workQueue,
|
||||
new DiscardPolicy());
|
||||
ScenarioContext scenarioContext = new ScenarioContext(testId, new Date(
|
||||
System.currentTimeMillis()), executor,
|
||||
new ScenarioResultCollector(testId), pluginManager);
|
||||
return scenarioContext;
|
||||
}
|
||||
|
||||
public ScenarioContext addScenrio(final Scenario scenario, final long realStartTime) {
|
||||
ScenarioContext result = new ScenarioContext(this.testId, new Date(realStartTime), executor, this.dataCollector, pluginManager);
|
||||
result.setEndDate(new Date(scenario.getSchedule().getScheduleRange() + this.getStartDate().getTime()));
|
||||
result.setFinished(this.isFinished());
|
||||
result.setScenario(scenario);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Now, I tolerate that if the requiredLoad <
|
||||
* this.getExecutor.getCorePoolSize(), then the excess threads will be
|
||||
* killed when its current task complete
|
||||
*
|
||||
* @param requiredLoad
|
||||
*/
|
||||
public void updatePopulation(int requiredLoad) {
|
||||
this.getExecutor().setCorePoolSize(requiredLoad);
|
||||
this.getExecutor().setMaximumPoolSize(requiredLoad);
|
||||
}
|
||||
|
||||
public void addTask() {
|
||||
if (this.isFinished()) {
|
||||
return;
|
||||
}
|
||||
this.getExecutor().execute(new VUser(this, 1, getPluginManager()));
|
||||
Logger.getLogger(this.getClass()).info(
|
||||
this.getExecutor().getActiveCount());
|
||||
}
|
||||
|
||||
public void initTasks(int currentLoad) {
|
||||
this.updatePopulation(currentLoad);
|
||||
for (int i = 0; i < currentLoad; i++) {
|
||||
addTask();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Observable o, Object arg) {
|
||||
Schedule schedule = (Schedule) o;
|
||||
if (schedule.hasReachEnd()) {
|
||||
stop();
|
||||
} else {
|
||||
this.updatePopulation((Integer) arg);
|
||||
}
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
this.setFinished(true);
|
||||
this.setEndDate(new Date());
|
||||
this.getExecutor().shutdownNow();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,79 +1,100 @@
|
|||
package org.bench4q.agent.scenario.engine;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.agent.plugin.PluginManager;
|
||||
import org.bench4q.agent.scenario.Scenario;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ScenarioEngine {
|
||||
private Map<UUID, ScenarioContext> runningTests;
|
||||
private Logger logger = Logger.getLogger(ScenarioEngine.class);
|
||||
private PluginManager pluginManager;
|
||||
|
||||
public ScenarioEngine() {
|
||||
this.setRunningTests(new HashMap<UUID, ScenarioContext>());
|
||||
}
|
||||
|
||||
public Map<UUID, ScenarioContext> getRunningTests() {
|
||||
return runningTests;
|
||||
}
|
||||
|
||||
private void setRunningTests(Map<UUID, ScenarioContext> runningTests) {
|
||||
this.runningTests = runningTests;
|
||||
}
|
||||
|
||||
private PluginManager getPluginManager() {
|
||||
return pluginManager;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setPluginManager(PluginManager pluginManager) {
|
||||
this.pluginManager = pluginManager;
|
||||
}
|
||||
|
||||
public void addRunningTestWithoutScenario(UUID runId, int poolSize) {
|
||||
try {
|
||||
final ScenarioContext scenarioContext = ScenarioContext
|
||||
.buildScenarioContextWithoutScenario(runId, poolSize,
|
||||
getPluginManager());
|
||||
this.getRunningTests().put(runId, scenarioContext);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void submitScenario(UUID runId, final Scenario scenario) {
|
||||
try {
|
||||
this.getRunningTests().get(runId).addScenrio(scenario);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean runWith(UUID runId) {
|
||||
if (!this.getRunningTests().containsKey(runId)) {
|
||||
return false;
|
||||
}
|
||||
final ScenarioContext context = this.getRunningTests().get(runId);
|
||||
return runWith(context);
|
||||
}
|
||||
|
||||
private boolean runWith(final ScenarioContext scenarioContext) {
|
||||
if (scenarioContext == null) {
|
||||
logger.error("The context required is null");
|
||||
return false;
|
||||
}
|
||||
scenarioContext.initTasks();
|
||||
return true;
|
||||
}
|
||||
|
||||
public void updatePopulation(UUID testId, int requiredLoad) {
|
||||
ScenarioContext context = this.getRunningTests().get(testId);
|
||||
context.updatePopulation(requiredLoad);
|
||||
}
|
||||
}
|
||||
package org.bench4q.agent.scenario.engine;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Observable;
|
||||
import java.util.Observer;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.agent.plugin.PluginManager;
|
||||
import org.bench4q.agent.scenario.Scenario;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ScenarioEngine implements Observer {
|
||||
private Map<UUID, ScenarioContext> runningTests;
|
||||
private final Logger logger = Logger.getLogger(ScenarioEngine.class);
|
||||
private PluginManager pluginManager;
|
||||
|
||||
public ScenarioEngine() {
|
||||
this.setRunningTests(new HashMap<UUID, ScenarioContext>());
|
||||
}
|
||||
|
||||
public Map<UUID, ScenarioContext> getRunningTests() {
|
||||
return runningTests;
|
||||
}
|
||||
|
||||
private void setRunningTests(Map<UUID, ScenarioContext> runningTests) {
|
||||
this.runningTests = runningTests;
|
||||
}
|
||||
|
||||
private PluginManager getPluginManager() {
|
||||
return pluginManager;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setPluginManager(PluginManager pluginManager) {
|
||||
this.pluginManager = pluginManager;
|
||||
}
|
||||
|
||||
public void addRunningTestWithoutScenario(UUID runId, int poolSize) {
|
||||
try {
|
||||
final ScenarioContext scenarioContext = ScenarioContext
|
||||
.buildScenarioContextWithoutScenario(runId, poolSize,
|
||||
getPluginManager());
|
||||
this.getRunningTests().put(runId, scenarioContext);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void submitScenario(final UUID runId, final Scenario scenario, final long realStartTime) {
|
||||
try {
|
||||
ScenarioContext old = this.getRunningTests().get(runId);
|
||||
this.getRunningTests().put(runId, old.addScenrio(scenario, realStartTime));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean runWith(UUID runId) {
|
||||
if (!this.getRunningTests().containsKey(runId)) {
|
||||
return false;
|
||||
}
|
||||
final ScenarioContext context = this.getRunningTests().get(runId);
|
||||
return runWith(context);
|
||||
}
|
||||
|
||||
private boolean runWith(final ScenarioContext scenarioContext) {
|
||||
if (scenarioContext == null) {
|
||||
logger.error("The context required is null");
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
int currentLoad = scenarioContext
|
||||
.getScenario()
|
||||
.getSchedule()
|
||||
.loadFor(
|
||||
System.currentTimeMillis()
|
||||
- scenarioContext.getStartDate().getTime());
|
||||
scenarioContext.initTasks(currentLoad);
|
||||
new Supervisor(scenarioContext).start();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
this.logger.info(e, e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Observable o, Object arg) {
|
||||
if (!(o instanceof Supervisor)) {
|
||||
return;
|
||||
}
|
||||
UUID testId = (UUID) arg;
|
||||
this.getRunningTests().remove(testId);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,201 @@
|
|||
package org.bench4q.agent.scenario.engine;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Observable;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import org.bench4q.share.exception.Bench4QRunTimeException;
|
||||
import org.bench4q.share.models.agent.scriptrecord.ScheduleModel;
|
||||
import org.bench4q.share.models.agent.scriptrecord.ScheduleModel.PointModel;
|
||||
/*
|
||||
* Segments in Schedule is sorted asc by Segment.start.time
|
||||
*/
|
||||
public class Schedule extends Observable {
|
||||
private static final int SCHEDULE_CYCLE = 3000;
|
||||
private final List<Segment> segments;
|
||||
private final long beginTime;
|
||||
private final Timer timer = new Timer();
|
||||
private volatile boolean reachEnd;
|
||||
|
||||
public List<Segment> getSegments() {
|
||||
return segments;
|
||||
}
|
||||
|
||||
public boolean hasReachEnd() {
|
||||
return this.reachEnd;
|
||||
}
|
||||
|
||||
private void reachEnd() {
|
||||
this.reachEnd = true;
|
||||
}
|
||||
|
||||
public Schedule(List<Segment> segments) {
|
||||
if (segments == null || segments.size() == 0) {
|
||||
throw new Bench4QRunTimeException(
|
||||
"Can't init a schedul with zero segment");
|
||||
}
|
||||
this.segments = segments;
|
||||
this.beginTime = System.currentTimeMillis();
|
||||
this.reachEnd = false;
|
||||
beginSchedul();
|
||||
}
|
||||
|
||||
public long getScheduleRange() {
|
||||
return this.getSegments().get(this.getSegments().size()).end.getTime()
|
||||
- this.getSegments().get(0).start.getTime();
|
||||
}
|
||||
|
||||
private void beginSchedul() {
|
||||
timer.scheduleAtFixedRate(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
long time = System.currentTimeMillis();
|
||||
Segment segment = getSegment(time - beginTime);
|
||||
if (segment == null) {
|
||||
// exceed the range of execute, should let the context stop
|
||||
// the test
|
||||
notifyObservers(0);
|
||||
return;
|
||||
}
|
||||
notifyObservers(segment.loadFor(time - beginTime));
|
||||
}
|
||||
}, 0, SCHEDULE_CYCLE);
|
||||
}
|
||||
|
||||
void stop(){
|
||||
this.timer.cancel();
|
||||
}
|
||||
|
||||
/**
|
||||
* ß
|
||||
* @param time, is the relative time from begin
|
||||
* @return get the segment by binary search
|
||||
*/
|
||||
public Segment getSegment(long time) {
|
||||
if (this.getSegments() == null || this.getSegments().size() < 1
|
||||
|| time < this.getSegments().get(0).start.getTime()) {
|
||||
throw new Bench4QRunTimeException(
|
||||
"can't getSegment when segments' size is LT 2");
|
||||
}
|
||||
if (time >= this.getSegments().get(this.getSegments().size() - 1).end
|
||||
.getTime()) {
|
||||
this.reachEnd();
|
||||
return null;
|
||||
}
|
||||
int begin = 0, end = this.getSegments().size(), mid = (begin + end) / 2;
|
||||
while (begin <= end) {
|
||||
Segment midSegment = this.getSegments().get(mid);
|
||||
if (midSegment.end.getTime() < time) {
|
||||
begin = mid + 1;
|
||||
} else if (midSegment.start.getTime() > time) {
|
||||
end = mid - 1;
|
||||
} else {
|
||||
return midSegment;
|
||||
}
|
||||
mid = (begin + end) / 2;
|
||||
}
|
||||
throw new Bench4QRunTimeException("Should not come to this place");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param relativeTime, relativeTime from beginDate
|
||||
* @return
|
||||
*/
|
||||
public int loadFor(long relativeTime){
|
||||
Segment segment = getSegment(relativeTime);
|
||||
if (segment == null) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
return segment.loadFor(relativeTime);
|
||||
}
|
||||
|
||||
public static class Segment {
|
||||
private final Point start;
|
||||
private final Point end;
|
||||
// growthUnit is the amount that'll increase per second
|
||||
private final float growthUnit;
|
||||
|
||||
public Segment(Point startPoint, Point endPoint) {
|
||||
this.start = startPoint.copy();
|
||||
this.end = endPoint.copy();
|
||||
long timeDifference = this.end.getTime() / 1000
|
||||
- this.start.getTime() / 1000;
|
||||
if (timeDifference < 0 || this.start.getTime() < 0l
|
||||
|| this.end.getTime() < 0l) {
|
||||
throw new Bench4QRunTimeException(
|
||||
"The end time in TestScehdul cannot be less than start time");
|
||||
}
|
||||
this.growthUnit = (float) (timeDifference == 0 ? 0
|
||||
: (double) (this.end.getLoad() - this.start.getLoad())
|
||||
/ (double) (timeDifference));
|
||||
}
|
||||
|
||||
public int loadFor(long timeFromBegin) {
|
||||
if (timeFromBegin < this.start.getTime()
|
||||
|| timeFromBegin > this.end.getTime()) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
long diffFromStart = timeFromBegin - this.start.getTime();
|
||||
return (int) (this.start.getLoad() + (diffFromStart * growthUnit / 1000));
|
||||
}
|
||||
}
|
||||
|
||||
public static class Point {
|
||||
// This time is the relative value from begin
|
||||
private final long time;
|
||||
private final int load;
|
||||
|
||||
public long getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public int getLoad() {
|
||||
return load;
|
||||
}
|
||||
|
||||
public Point(long time, int load) {
|
||||
if (load < 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"Load can't be negtive number!");
|
||||
}
|
||||
this.time = time;
|
||||
this.load = load;
|
||||
}
|
||||
|
||||
public Point copy() {
|
||||
return new Point(this.getTime(), this.getLoad());
|
||||
}
|
||||
}
|
||||
|
||||
public static Schedule build(ScheduleModel scheduleModel) {
|
||||
Schedule schedule = new Schedule(
|
||||
extractSegments(scheduleModel.getPoints()));
|
||||
return schedule;
|
||||
}
|
||||
|
||||
private static List<Segment> extractSegments(List<PointModel> pointModels) {
|
||||
List<Point> points = new LinkedList<Schedule.Point>();
|
||||
for (PointModel model : pointModels) {
|
||||
points.add(new Point(model.getTime(), model.getLoad()));
|
||||
}
|
||||
Collections.sort(points, new Comparator<Point>() {
|
||||
|
||||
@Override
|
||||
public int compare(Point o1, Point o2) {
|
||||
return (int) (o1.getTime() - o2.getTime());
|
||||
}
|
||||
|
||||
});
|
||||
List<Segment> result = new LinkedList<Schedule.Segment>();
|
||||
for (int i = 0; i < points.size() - 1; i++) {
|
||||
result.add(new Segment(points.get(i), points.get(i + 1)));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package org.bench4q.agent.scenario.engine;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Observable;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
|
||||
public class Supervisor extends Observable {
|
||||
private final ScenarioContext context;
|
||||
private final Timer timer = new Timer();
|
||||
|
||||
public Supervisor(final ScenarioContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
void start(){
|
||||
long time = context.getScenario().getSchedule().getScheduleRange()
|
||||
+ context.getStartDate().getTime();
|
||||
this.timer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
context.getScenario().getSchedule().stop();
|
||||
}
|
||||
}, new Date(time));
|
||||
}
|
||||
|
||||
void stop(){
|
||||
this.context.getScenario().getSchedule().stop();
|
||||
this.context.stop();
|
||||
this.timer.cancel();
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
package org.bench4q.agent.scenario.engine;
|
||||
|
||||
public class TaskMonitor {
|
||||
|
||||
public static class TaskProducer implements Runnable {
|
||||
private ScenarioContext context;
|
||||
|
||||
public TaskProducer(ScenarioContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
int poolSize = context.getExecutor().getCorePoolSize();
|
||||
try {
|
||||
if (context.getExecutor().getTaskCount() > poolSize * 2) {
|
||||
this.wait();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
} finally {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ package org.bench4q.agent.test;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
|
@ -18,7 +19,9 @@ import org.bench4q.share.models.agent.RunScenarioModel;
|
|||
import org.bench4q.share.models.agent.scriptrecord.BatchModel;
|
||||
import org.bench4q.share.models.agent.scriptrecord.BehaviorModel;
|
||||
import org.bench4q.share.models.agent.scriptrecord.PageModel;
|
||||
import org.bench4q.share.models.agent.scriptrecord.ScheduleModel;
|
||||
import org.bench4q.share.models.agent.scriptrecord.UsePluginModel;
|
||||
import org.bench4q.share.models.agent.scriptrecord.ScheduleModel.PointModel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
public abstract class TestBase {
|
||||
|
@ -105,6 +108,12 @@ public abstract class TestBase {
|
|||
batch.getBehaviors().add(behavior);
|
||||
}
|
||||
page.getBatches().add(batch);
|
||||
ScheduleModel scheduleModel = new ScheduleModel();
|
||||
List<PointModel> points = new LinkedList<ScheduleModel.PointModel>();
|
||||
points.add(new PointModel(0, 0));
|
||||
points.add(new PointModel(10000, 10));
|
||||
scheduleModel.setPoints(points);
|
||||
runScenarioModel.setScheduleModel(scheduleModel);
|
||||
runScenarioModel.getPages().add(page);
|
||||
return runScenarioModel;
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ public class Test_ScenarioEngine extends TestBase {
|
|||
new ArrayList<ParameterModel>()))),
|
||||
100, this.pluginManager);
|
||||
this.getScenarioEngine().getRunningTests().put(testId, scenarioContext);
|
||||
this.getScenarioEngine().updatePopulation(testId, 20);
|
||||
scenarioContext.updatePopulation(20);
|
||||
assertEquals(20, scenarioContext.getExecutor().getMaximumPoolSize());
|
||||
System.out.println(scenarioContext.getExecutor().getActiveCount());
|
||||
}
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
package org.bench4q.agent.test.scenario.engine;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.bench4q.agent.scenario.engine.Schedule;
|
||||
import org.bench4q.agent.scenario.engine.Schedule.Segment;
|
||||
import org.bench4q.share.exception.Bench4QRunTimeException;
|
||||
import org.bench4q.share.models.agent.scriptrecord.ScheduleModel;
|
||||
import org.bench4q.share.models.agent.scriptrecord.ScheduleModel.PointModel;
|
||||
import org.junit.Test;
|
||||
|
||||
public class Test_Shedule {
|
||||
|
||||
@Test(expected = Bench4QRunTimeException.class)
|
||||
public void test_InitWithZeroPointModels(){
|
||||
Schedule.build(new ScheduleModel());
|
||||
}
|
||||
|
||||
@Test(expected = Bench4QRunTimeException.class)
|
||||
public void test_InitWithOnePointModels(){
|
||||
ScheduleModel model = new ScheduleModel();
|
||||
model.getPoints().add(new PointModel(new Date().getTime(), 100));
|
||||
Schedule.build(model);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_InitWithTwoPoint_WhereSecondTime_LT_FirstTime(){
|
||||
ScheduleModel model = new ScheduleModel();
|
||||
long firstTime = new Date().getTime();
|
||||
model.getPoints().add(new PointModel(firstTime, 100));
|
||||
model.getPoints().add(new PointModel(firstTime - 1000000, 50));
|
||||
Schedule schedule = Schedule.build(model);
|
||||
assertEquals(1, schedule.getSegments().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_InitWith5Point(){
|
||||
long firstTime = new Date().getTime();
|
||||
ScheduleModel model = new ScheduleModel();
|
||||
for (int i = 0; i < 5; i++) {
|
||||
model.getPoints().add(new PointModel(firstTime - 10000 * i, 190 + 10 * i));
|
||||
}
|
||||
model.getPoints().add(new PointModel(new Date().getTime(), 600));
|
||||
Schedule schedule = Schedule.build(model);
|
||||
assertEquals(5, schedule.getSegments().size());
|
||||
}
|
||||
|
||||
@Test(expected = Bench4QRunTimeException.class)
|
||||
public void test_InitWith_MinusTime(){
|
||||
long firstTime = -1000000000;
|
||||
ScheduleModel model = new ScheduleModel();
|
||||
model.getPoints().add(new PointModel(firstTime, 100));
|
||||
Schedule.build(model);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void test_LoadFor_WithIlegalArgument(){
|
||||
ScheduleModel model = new ScheduleModel();
|
||||
long firstTime = new Date().getTime();
|
||||
model.getPoints().add(new PointModel(firstTime, 100));
|
||||
model.getPoints().add(new PointModel(firstTime - 1000000, 50));
|
||||
Schedule schedule = Schedule.build(model);
|
||||
schedule.getSegments().get(0).loadFor(-1000);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_loadFor(){
|
||||
ScheduleModel model = new ScheduleModel();
|
||||
model.getPoints().add(new PointModel(1000000, 100));
|
||||
model.getPoints().add(new PointModel(0, 50));
|
||||
Schedule schedule = Schedule.build(model);
|
||||
int load = schedule.getSegments().get(0).loadFor(500 * 1000);
|
||||
assertEquals(75, load);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_getSegment(){
|
||||
ScheduleModel model = new ScheduleModel();
|
||||
model.getPoints().add(new PointModel(1000000, 100));
|
||||
model.getPoints().add(new PointModel(0, 50));
|
||||
Schedule schedule = Schedule.build(model);
|
||||
Segment segment = schedule.getSegment(500 * 1000);
|
||||
assertNotNull(segment);
|
||||
}
|
||||
}
|
|
@ -21,13 +21,12 @@ import org.bench4q.master.exception.Bench4QException;
|
|||
import org.bench4q.master.exception.Bench4QRunTimeException;
|
||||
import org.bench4q.share.enums.master.TestPlanStatus;
|
||||
import org.bench4q.share.models.master.MonitorModel;
|
||||
import org.bench4q.share.models.master.OperateScriptServerResponseModel;
|
||||
import org.bench4q.share.models.master.ScriptHandleModel;
|
||||
import org.bench4q.share.models.master.TestPlanScriptBriefResultModel;
|
||||
import org.bench4q.share.models.master.TestPlanModel;
|
||||
import org.bench4q.share.models.master.TestPlanDBModel;
|
||||
import org.bench4q.share.models.master.TestPlanModel;
|
||||
import org.bench4q.share.models.master.TestPlanResponseModel;
|
||||
import org.bench4q.share.models.master.TestPlanResultModel;
|
||||
import org.bench4q.share.models.master.TestPlanScriptBriefResultModel;
|
||||
import org.bench4q.share.models.master.statistics.ScriptBehaviorsBriefModel;
|
||||
import org.bench4q.share.models.master.statistics.ScriptBriefResultModel;
|
||||
import org.bench4q.share.models.master.statistics.ScriptPagesBriefModel;
|
||||
|
|
|
@ -26,4 +26,6 @@ public interface RunningScriptInterface {
|
|||
|
||||
public List<TestPlanScriptResult> doAfterRun(Date sampleTime);
|
||||
|
||||
public Date getStartTime();
|
||||
|
||||
}
|
||||
|
|
|
@ -185,7 +185,7 @@ public class RunningAgentDB implements RunningAgentInterface {
|
|||
RunScenarioResultModel runScenarioResultModel = this
|
||||
.getAgentMessenger().submitScenrioWithParams(this.getAgent(),
|
||||
this.getAgentRunId(), script2.loadParamFiles(),
|
||||
runScenarioModel);
|
||||
runScenarioModel, this.getRunningScript().getStartTime());
|
||||
if (runScenarioResultModel == null) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -316,4 +316,8 @@ public class TestPlan implements IAggregate {
|
|||
return true;
|
||||
}
|
||||
|
||||
public Date getCurrentStartTime() {
|
||||
return getLastRunningTime();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -312,4 +312,9 @@ public class TestPlanScript implements RunningScriptInterface {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getStartTime() {
|
||||
return this.getTestPlan().getCurrentStartTime();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.bench4q.master.infrastructure.communication;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Future;
|
||||
|
@ -17,7 +18,7 @@ public interface AgentMessenger {
|
|||
|
||||
public RunScenarioResultModel submitScenrioWithParams(Agent agent,
|
||||
UUID agentRunId, List<File> paramFiles,
|
||||
final RunScenarioModel runScenarioModel);
|
||||
final RunScenarioModel runScenarioModel, Date realStartDate);
|
||||
|
||||
public RunScenarioResultModel runWithParams(Agent agent, UUID agentRunId);
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.bench4q.master.infrastructure.communication.impl;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
@ -73,14 +74,14 @@ public class AgentMessengerImpl implements AgentMessenger {
|
|||
|
||||
public RunScenarioResultModel submitScenrioWithParams(Agent agent,
|
||||
UUID agentRunId, List<File> paramFiles,
|
||||
final RunScenarioModel runScenarioModel) {
|
||||
final RunScenarioModel runScenarioModel, Date realStartDate) {
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
final String modelContent = MarshalHelper
|
||||
.tryMarshal(runScenarioModel);
|
||||
httpResponse = this.httpRequester.postFiles(null,
|
||||
buildBaseUrl(agent) + "/test/submitScenarioWithParams/"
|
||||
+ agentRunId, "files[]", paramFiles,
|
||||
+ agentRunId+ "/" + realStartDate.getTime(), "files[]", paramFiles,
|
||||
"scenarioModel", new LinkedList<String>() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
{
|
||||
|
@ -97,13 +98,13 @@ public class AgentMessengerImpl implements AgentMessenger {
|
|||
|
||||
public Future<RunScenarioResultModel> submitScenarioWithParamsAsync(
|
||||
final Agent agent, final UUID agentRunId,
|
||||
final List<File> paramFiles, final RunScenarioModel runScenarioModel) {
|
||||
final List<File> paramFiles, final RunScenarioModel runScenarioModel, final Date realStartDate) {
|
||||
return this.executorService
|
||||
.submit(new Callable<RunScenarioResultModel>() {
|
||||
@Override
|
||||
public RunScenarioResultModel call() throws Exception {
|
||||
return submitScenrioWithParams(agent, agentRunId,
|
||||
paramFiles, runScenarioModel);
|
||||
paramFiles, runScenarioModel, realStartDate);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -5,7 +5,9 @@ import static org.junit.Assert.*;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
@ -72,7 +74,7 @@ public class Test_AgentMessenger extends TestBase_MakeUpTestPlan {
|
|||
System.out.println(model.getRunId());
|
||||
RunScenarioResultModel modelAfter = this.getAgentMessenger()
|
||||
.submitScenrioWithParams(agent, model.getRunId(), paramFiles,
|
||||
inputModel);
|
||||
inputModel, new Date());
|
||||
assertEquals(model.getRunId(), modelAfter.getRunId());
|
||||
model = this.getAgentMessenger().runWithParams(agent, model.getRunId());
|
||||
assertNotNull(model);
|
||||
|
|
|
@ -2,6 +2,7 @@ package stubs;
|
|||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Future;
|
||||
|
@ -34,7 +35,7 @@ public class Mock_AgentMessenger implements AgentMessenger {
|
|||
@Override
|
||||
public RunScenarioResultModel submitScenrioWithParams(Agent agent,
|
||||
UUID agentRunId, List<File> paramFiles,
|
||||
RunScenarioModel runScenarioModel) {
|
||||
RunScenarioModel runScenarioModel, Date realStartTime) {
|
||||
return new RunScenarioResultModel(this.testId);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,29 +1,29 @@
|
|||
package org.bench4q.recorder.httpcapture;
|
||||
|
||||
import java.net.HttpURLConnection;
|
||||
|
||||
public class ResponseModel {
|
||||
private byte[] response;
|
||||
private HttpURLConnection conn;
|
||||
|
||||
public byte[] getResponse() {
|
||||
return response;
|
||||
}
|
||||
|
||||
public void setResponse(byte[] response) {
|
||||
this.response = response;
|
||||
}
|
||||
|
||||
public ResponseModel(byte[] response, HttpURLConnection conn) {
|
||||
this.setConn(conn);
|
||||
this.response = response;
|
||||
}
|
||||
|
||||
public HttpURLConnection getConn() {
|
||||
return conn;
|
||||
}
|
||||
|
||||
public void setConn(HttpURLConnection conn) {
|
||||
this.conn = conn;
|
||||
}
|
||||
}
|
||||
package org.bench4q.recorder.httpcapture;
|
||||
|
||||
import java.net.HttpURLConnection;
|
||||
|
||||
public class ResponseModel {
|
||||
private byte[] response;
|
||||
private HttpURLConnection conn;
|
||||
|
||||
public byte[] getResponse() {
|
||||
return response;
|
||||
}
|
||||
|
||||
public void setResponse(byte[] response) {
|
||||
this.response = response;
|
||||
}
|
||||
|
||||
public ResponseModel(byte[] response, HttpURLConnection conn) {
|
||||
this.setConn(conn);
|
||||
this.response = response;
|
||||
}
|
||||
|
||||
public HttpURLConnection getConn() {
|
||||
return conn;
|
||||
}
|
||||
|
||||
public void setConn(HttpURLConnection conn) {
|
||||
this.conn = conn;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,25 +1,25 @@
|
|||
package org.bench4q.recorder.httpcapture.generator;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
public class ContentEncoder {
|
||||
protected Logger logger = Logger.getLogger(ContentEncoder.class);
|
||||
protected ContentEncoder() {
|
||||
}
|
||||
|
||||
public static ContentEncoder createEncoder(String encodeType) {
|
||||
if (encodeType == null) {
|
||||
return new ContentEncoder();
|
||||
}
|
||||
|
||||
if (encodeType.equalsIgnoreCase("gzip")) {
|
||||
return new GzipEncoder();
|
||||
} else {
|
||||
return new ContentEncoder();
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] encoderContent(byte[] content){
|
||||
return content;
|
||||
}
|
||||
}
|
||||
package org.bench4q.recorder.httpcapture.generator;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
public class ContentEncoder {
|
||||
protected Logger logger = Logger.getLogger(ContentEncoder.class);
|
||||
protected ContentEncoder() {
|
||||
}
|
||||
|
||||
public static ContentEncoder createEncoder(String encodeType) {
|
||||
if (encodeType == null) {
|
||||
return new ContentEncoder();
|
||||
}
|
||||
|
||||
if (encodeType.equalsIgnoreCase("gzip")) {
|
||||
return new GzipEncoder();
|
||||
} else {
|
||||
return new ContentEncoder();
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] encoderContent(byte[] content){
|
||||
return content;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,25 +1,25 @@
|
|||
package org.bench4q.recorder.httpcapture.generator;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
public class GzipEncoder extends ContentEncoder{
|
||||
|
||||
public byte[] encoderContent(byte[] content){
|
||||
try {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
GZIPOutputStream gzipOutputStream = new GZIPOutputStream(outputStream);
|
||||
|
||||
gzipOutputStream.write(content, 0, content.length);
|
||||
gzipOutputStream.finish();
|
||||
|
||||
gzipOutputStream.flush();
|
||||
gzipOutputStream.close();
|
||||
return outputStream.toByteArray();
|
||||
} catch (IOException e) {
|
||||
logger.error("decodeContent", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
package org.bench4q.recorder.httpcapture.generator;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
public class GzipEncoder extends ContentEncoder{
|
||||
|
||||
public byte[] encoderContent(byte[] content){
|
||||
try {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
GZIPOutputStream gzipOutputStream = new GZIPOutputStream(outputStream);
|
||||
|
||||
gzipOutputStream.write(content, 0, content.length);
|
||||
gzipOutputStream.finish();
|
||||
|
||||
gzipOutputStream.flush();
|
||||
gzipOutputStream.close();
|
||||
return outputStream.toByteArray();
|
||||
} catch (IOException e) {
|
||||
logger.error("decodeContent", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import javax.xml.bind.annotation.XmlElementWrapper;
|
|||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import org.bench4q.share.models.agent.scriptrecord.PageModel;
|
||||
import org.bench4q.share.models.agent.scriptrecord.TestScheduleModel;
|
||||
import org.bench4q.share.models.agent.scriptrecord.ScheduleModel;
|
||||
import org.bench4q.share.models.agent.scriptrecord.UsePluginModel;
|
||||
|
||||
@XmlRootElement(name = "runScenario")
|
||||
|
@ -16,7 +16,7 @@ public class RunScenarioModel {
|
|||
private int poolSize;
|
||||
private List<UsePluginModel> usePlugins;
|
||||
private List<PageModel> pages;
|
||||
private TestScheduleModel scheduleModel;
|
||||
private ScheduleModel scheduleModel;
|
||||
@XmlElement
|
||||
public int getPoolSize() {
|
||||
return poolSize;
|
||||
|
@ -47,11 +47,11 @@ public class RunScenarioModel {
|
|||
}
|
||||
|
||||
@XmlElement
|
||||
public TestScheduleModel getScheduleModel() {
|
||||
public ScheduleModel getScheduleModel() {
|
||||
return scheduleModel;
|
||||
}
|
||||
|
||||
public void setScheduleModel(TestScheduleModel scheduleModel) {
|
||||
public void setScheduleModel(ScheduleModel scheduleModel) {
|
||||
this.scheduleModel = scheduleModel;
|
||||
}
|
||||
|
||||
|
@ -59,5 +59,4 @@ public class RunScenarioModel {
|
|||
this.setUsePlugins(new LinkedList<UsePluginModel>());
|
||||
this.setPages(new LinkedList<PageModel>());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import javax.xml.bind.annotation.XmlElementWrapper;
|
|||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement
|
||||
public class TestScheduleModel {
|
||||
public class ScheduleModel {
|
||||
private List<PointModel> points;
|
||||
|
||||
@XmlElementWrapper(name = "points")
|
||||
|
@ -21,21 +21,21 @@ public class TestScheduleModel {
|
|||
this.points = points;
|
||||
}
|
||||
|
||||
public TestScheduleModel() {
|
||||
public ScheduleModel() {
|
||||
this.points = new LinkedList<PointModel>();
|
||||
}
|
||||
|
||||
@XmlRootElement
|
||||
public static class PointModel {
|
||||
private int time;
|
||||
private long time;
|
||||
private int load;
|
||||
|
||||
@XmlElement
|
||||
public int getTime() {
|
||||
public long getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(int time) {
|
||||
public void setTime(long time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
|
@ -48,5 +48,10 @@ public class TestScheduleModel {
|
|||
this.load = load;
|
||||
}
|
||||
|
||||
public PointModel(){}
|
||||
public PointModel(long time, int load){
|
||||
this.time = time;
|
||||
this.load = load;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,276 +1,273 @@
|
|||
package org.bench4q.web.masterMessager;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.bench4q.share.communication.HttpRequester.HttpResponse;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.master.OperateScriptServerResponseModel;
|
||||
import org.bench4q.share.models.master.TestPlanDBModel;
|
||||
import org.bench4q.share.models.master.TestPlanResponseModel;
|
||||
import org.bench4q.share.models.master.TestPlanResultModel;
|
||||
import org.bench4q.share.models.master.TestPlanScriptBriefResultModel;
|
||||
import org.bench4q.share.models.master.statistics.ScriptBehaviorsBriefModel;
|
||||
import org.bench4q.share.models.master.statistics.ScriptBriefResultModel;
|
||||
import org.bench4q.share.models.master.statistics.ScriptPagesBriefModel;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class TestPlanMessager extends MasterMessager {
|
||||
|
||||
public TestPlanMessager() {
|
||||
super(MasterAddressManamger.getMasterAddress() + "/testPlan");
|
||||
}
|
||||
|
||||
public HttpResponse loadReport(String accessToken, String testPlanId) {
|
||||
String url = this.getBaseUrl() + "/getTestPlanReport";
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("testPlanRunID", testPlanId);
|
||||
httpResponse = this.getHttpRequester().sendGet(url, params,
|
||||
makeAccessTockenMap(accessToken));
|
||||
if (!validateHttpResponse(httpResponse)) {
|
||||
return null;
|
||||
}
|
||||
return httpResponse;
|
||||
} catch (Exception e) {
|
||||
this.handleException(httpResponse, e);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public TestPlanResultModel runTestPlan(String accessToken,
|
||||
String testPlanXmlContent) {
|
||||
|
||||
String url = this.getBaseUrl() + "/run";
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
httpResponse = this.getHttpRequester().sendPostXml(url,
|
||||
testPlanXmlContent, makeAccessTockenMap(accessToken));
|
||||
if (!validateHttpResponse(httpResponse))
|
||||
return null;
|
||||
return extractTestPlanResultModel(httpResponse);
|
||||
} catch (Exception e) {
|
||||
this.handleException(httpResponse, e);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public TestPlanResultModel getRunningTestInfo(String accessToken,
|
||||
String testPlanId) {
|
||||
String url = this.getBaseUrl() + "/getRunningInfo";
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("testPlanId", testPlanId);
|
||||
return this.getTestPlanResultModelByPost(url, params, accessToken);
|
||||
|
||||
}
|
||||
|
||||
public TestPlanScriptBriefResultModel getScriptBriefResult(
|
||||
String accessToken, String testPlanId, String scriptId,
|
||||
String duationBegin) {
|
||||
String url = this.getBaseUrl() + "/scriptBrief" + "/" + testPlanId
|
||||
+ "/" + scriptId + "/" + duationBegin;
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
httpResponse = this.getHttpRequester().sendGet(url, null,
|
||||
makeAccessTockenMap(accessToken));
|
||||
if (!validateHttpResponse(httpResponse)) {
|
||||
handleInvalidatedResponse(url);
|
||||
return null;
|
||||
}
|
||||
|
||||
return (TestPlanScriptBriefResultModel) MarshalHelper.unmarshal(
|
||||
TestPlanScriptBriefResultModel.class,
|
||||
httpResponse.getContent());
|
||||
} catch (Exception e) {
|
||||
this.handleException(httpResponse, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public ScriptBehaviorsBriefModel getScriptBehaviorsBriefResult(
|
||||
String accessToken, String testPlanId, String scriptId) {
|
||||
String url = this.getBaseUrl() + "/getBehaviorsBrief" + "/"
|
||||
+ testPlanId + "/" + scriptId;
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
httpResponse = this.getHttpRequester().sendGet(url, null,
|
||||
makeAccessTockenMap(accessToken));
|
||||
if (!validateHttpResponse(httpResponse))
|
||||
return null;
|
||||
return (ScriptBehaviorsBriefModel) MarshalHelper.unmarshal(
|
||||
ScriptBehaviorsBriefModel.class, httpResponse.getContent());
|
||||
} catch (Exception e) {
|
||||
this.handleException(httpResponse, e);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public TestPlanDBModel queryTestPlanById(String accessToken,
|
||||
String testPlanRunId) {
|
||||
String url = this.getBaseUrl() + "/queryTestPlan" + "/" + testPlanRunId;
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
httpResponse = this.getHttpRequester().sendGet(url, null,
|
||||
makeAccessTockenMap(accessToken));
|
||||
if (!validateHttpResponse(httpResponse)) {
|
||||
handleInvalidatedResponse(url);
|
||||
return null;
|
||||
}
|
||||
return (TestPlanDBModel) MarshalHelper.unmarshal(
|
||||
TestPlanDBModel.class, httpResponse.getContent());
|
||||
} catch (Exception e) {
|
||||
handleException(httpResponse, e);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public TestPlanResponseModel deleteTestPlan(String accessToken,
|
||||
String testPlanId) {
|
||||
String url = this.getBaseUrl() + "/removeTestPlanFromPool";
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("testPlanId", testPlanId);
|
||||
return getTestPlanResponseModel(url, params, accessToken);
|
||||
|
||||
}
|
||||
|
||||
public TestPlanResponseModel loadTestPlans(String accessToken) {
|
||||
String url = this.getBaseUrl() + "/loadTestPlans";
|
||||
return getTestPlanResponseModel(url, null, accessToken);
|
||||
}
|
||||
|
||||
public HttpResponse getTestPlanReport(String accessToken,
|
||||
String testPlanRunId) {
|
||||
String url = this.getBaseUrl() + "/getTestPlanReport";
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("testPlanRunID", testPlanRunId);
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
httpResponse = this.getHttpRequester().sendPost(url, params,
|
||||
makeAccessTockenMap(accessToken));
|
||||
if (!validateHttpResponse(httpResponse))
|
||||
return null;
|
||||
return httpResponse;
|
||||
|
||||
} catch (IOException e) {
|
||||
this.handleException(httpResponse, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private TestPlanResponseModel getTestPlanResponseModel(String url,
|
||||
Map<String, String> params, String accessToken) {
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
httpResponse = this.getHttpRequester().sendPost(url, params,
|
||||
makeAccessTockenMap(accessToken));
|
||||
if (!validateHttpResponse(httpResponse)) {
|
||||
handleInvalidatedResponse(url);
|
||||
return null;
|
||||
}
|
||||
|
||||
return extractTestPlanResponseModel(httpResponse);
|
||||
|
||||
} catch (Exception e) {
|
||||
this.handleException(httpResponse, e);
|
||||
return createFailTestPlanResponseModel();
|
||||
}
|
||||
}
|
||||
|
||||
private TestPlanResponseModel createFailTestPlanResponseModel() {
|
||||
TestPlanResponseModel testPlanResponseModel = new TestPlanResponseModel();
|
||||
testPlanResponseModel.setSuccess(false);
|
||||
testPlanResponseModel.setFailCause("");
|
||||
return testPlanResponseModel;
|
||||
}
|
||||
|
||||
private TestPlanResultModel getTestPlanResultModelByPost(String url,
|
||||
Map<String, String> params, String accessToken) {
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
|
||||
httpResponse = this.getHttpRequester().sendPost(url, params,
|
||||
makeAccessTockenMap(accessToken));
|
||||
if (!validateHttpResponse(httpResponse))
|
||||
return null;
|
||||
return extractTestPlanResultModel(httpResponse);
|
||||
} catch (Exception e) {
|
||||
this.handleException(httpResponse, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private TestPlanResponseModel extractTestPlanResponseModel(
|
||||
HttpResponse httpResponse) throws JAXBException,
|
||||
UnsupportedEncodingException {
|
||||
return (TestPlanResponseModel) MarshalHelper.unmarshal(
|
||||
TestPlanResponseModel.class, httpResponse.getContent());
|
||||
}
|
||||
|
||||
private TestPlanResultModel extractTestPlanResultModel(
|
||||
HttpResponse httpResponse) throws JAXBException,
|
||||
UnsupportedEncodingException {
|
||||
return (TestPlanResultModel) MarshalHelper.unmarshal(
|
||||
TestPlanResultModel.class, httpResponse.getContent());
|
||||
|
||||
}
|
||||
|
||||
public ScriptBriefResultModel getLatestScriptBriefResult(
|
||||
String accessToken, String testPlanId, String scriptId) {
|
||||
String url = this.baseUrl + "/scriptBrief" + "/" + testPlanId + "/"
|
||||
+ scriptId + "/latestResult";
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
httpResponse = this.getHttpRequester().sendGet(url, null,
|
||||
makeAccessTockenMap(accessToken));
|
||||
if (!validateHttpResponse(httpResponse)) {
|
||||
handleInvalidatedResponse(url);
|
||||
return null;
|
||||
}
|
||||
return (ScriptBriefResultModel) MarshalHelper.tryUnmarshal(
|
||||
ScriptBriefResultModel.class, httpResponse.getContent());
|
||||
|
||||
} catch (Exception e) {
|
||||
handleException(httpResponse, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public ScriptPagesBriefModel getScriptPageBriefModel(String accessToken,
|
||||
String testPlanId, String scriptId) {
|
||||
String url = this.baseUrl + "/pagesBrief" + "/" + testPlanId + "/"
|
||||
+ scriptId;
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
httpResponse = this.getHttpRequester().sendGet(url, null,
|
||||
makeAccessTockenMap(accessToken));
|
||||
if (!validateHttpResponse(httpResponse)) {
|
||||
handleInvalidatedResponse(url);
|
||||
return null;
|
||||
}
|
||||
return (ScriptPagesBriefModel) MarshalHelper.unmarshal(
|
||||
ScriptPagesBriefModel.class, httpResponse.getContent());
|
||||
|
||||
} catch (Exception e) {
|
||||
handleException(httpResponse, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public TestPlanResponseModel stopTestPlan(String accessToken,
|
||||
String testPlanRunId) {
|
||||
String url = this.baseUrl + "/stop" + "/" + testPlanRunId;
|
||||
return getTestPlanResponseModel(url, null, accessToken);
|
||||
}
|
||||
package org.bench4q.web.masterMessager;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import org.bench4q.share.communication.HttpRequester.HttpResponse;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.master.TestPlanDBModel;
|
||||
import org.bench4q.share.models.master.TestPlanResponseModel;
|
||||
import org.bench4q.share.models.master.TestPlanResultModel;
|
||||
import org.bench4q.share.models.master.TestPlanScriptBriefResultModel;
|
||||
import org.bench4q.share.models.master.statistics.ScriptBehaviorsBriefModel;
|
||||
import org.bench4q.share.models.master.statistics.ScriptBriefResultModel;
|
||||
import org.bench4q.share.models.master.statistics.ScriptPagesBriefModel;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class TestPlanMessager extends MasterMessager {
|
||||
|
||||
public TestPlanMessager() {
|
||||
super(MasterAddressManamger.getMasterAddress() + "/testPlan");
|
||||
}
|
||||
|
||||
public HttpResponse loadReport(String accessToken, String testPlanId) {
|
||||
String url = this.getBaseUrl() + "/getTestPlanReport";
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("testPlanRunID", testPlanId);
|
||||
httpResponse = this.getHttpRequester().sendGet(url, params,
|
||||
makeAccessTockenMap(accessToken));
|
||||
if (!validateHttpResponse(httpResponse)) {
|
||||
return null;
|
||||
}
|
||||
return httpResponse;
|
||||
} catch (Exception e) {
|
||||
this.handleException(httpResponse, e);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public TestPlanResultModel runTestPlan(String accessToken,
|
||||
String testPlanXmlContent) {
|
||||
|
||||
String url = this.getBaseUrl() + "/run";
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
httpResponse = this.getHttpRequester().sendPostXml(url,
|
||||
testPlanXmlContent, makeAccessTockenMap(accessToken));
|
||||
if (!validateHttpResponse(httpResponse))
|
||||
return null;
|
||||
return extractTestPlanResultModel(httpResponse);
|
||||
} catch (Exception e) {
|
||||
this.handleException(httpResponse, e);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public TestPlanResultModel getRunningTestInfo(String accessToken,
|
||||
String testPlanId) {
|
||||
String url = this.getBaseUrl() + "/getRunningInfo";
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("testPlanId", testPlanId);
|
||||
return this.getTestPlanResultModelByPost(url, params, accessToken);
|
||||
|
||||
}
|
||||
|
||||
public TestPlanScriptBriefResultModel getScriptBriefResult(
|
||||
String accessToken, String testPlanId, String scriptId,
|
||||
String duationBegin) {
|
||||
String url = this.getBaseUrl() + "/scriptBrief" + "/" + testPlanId
|
||||
+ "/" + scriptId + "/" + duationBegin;
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
httpResponse = this.getHttpRequester().sendGet(url, null,
|
||||
makeAccessTockenMap(accessToken));
|
||||
if (!validateHttpResponse(httpResponse)) {
|
||||
handleInvalidatedResponse(url);
|
||||
return null;
|
||||
}
|
||||
|
||||
return (TestPlanScriptBriefResultModel) MarshalHelper.unmarshal(
|
||||
TestPlanScriptBriefResultModel.class,
|
||||
httpResponse.getContent());
|
||||
} catch (Exception e) {
|
||||
this.handleException(httpResponse, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public ScriptBehaviorsBriefModel getScriptBehaviorsBriefResult(
|
||||
String accessToken, String testPlanId, String scriptId) {
|
||||
String url = this.getBaseUrl() + "/getBehaviorsBrief" + "/"
|
||||
+ testPlanId + "/" + scriptId;
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
httpResponse = this.getHttpRequester().sendGet(url, null,
|
||||
makeAccessTockenMap(accessToken));
|
||||
if (!validateHttpResponse(httpResponse))
|
||||
return null;
|
||||
return (ScriptBehaviorsBriefModel) MarshalHelper.unmarshal(
|
||||
ScriptBehaviorsBriefModel.class, httpResponse.getContent());
|
||||
} catch (Exception e) {
|
||||
this.handleException(httpResponse, e);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public TestPlanDBModel queryTestPlanById(String accessToken,
|
||||
String testPlanRunId) {
|
||||
String url = this.getBaseUrl() + "/queryTestPlan" + "/" + testPlanRunId;
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
httpResponse = this.getHttpRequester().sendGet(url, null,
|
||||
makeAccessTockenMap(accessToken));
|
||||
if (!validateHttpResponse(httpResponse)) {
|
||||
handleInvalidatedResponse(url);
|
||||
return null;
|
||||
}
|
||||
return (TestPlanDBModel) MarshalHelper.unmarshal(
|
||||
TestPlanDBModel.class, httpResponse.getContent());
|
||||
} catch (Exception e) {
|
||||
handleException(httpResponse, e);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public TestPlanResponseModel deleteTestPlan(String accessToken,
|
||||
String testPlanId) {
|
||||
String url = this.getBaseUrl() + "/removeTestPlanFromPool";
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("testPlanId", testPlanId);
|
||||
return getTestPlanResponseModel(url, params, accessToken);
|
||||
|
||||
}
|
||||
|
||||
public TestPlanResponseModel loadTestPlans(String accessToken) {
|
||||
String url = this.getBaseUrl() + "/loadTestPlans";
|
||||
return getTestPlanResponseModel(url, null, accessToken);
|
||||
}
|
||||
|
||||
public HttpResponse getTestPlanReport(String accessToken,
|
||||
String testPlanRunId) {
|
||||
String url = this.getBaseUrl() + "/getTestPlanReport";
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("testPlanRunID", testPlanRunId);
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
httpResponse = this.getHttpRequester().sendPost(url, params,
|
||||
makeAccessTockenMap(accessToken));
|
||||
if (!validateHttpResponse(httpResponse))
|
||||
return null;
|
||||
return httpResponse;
|
||||
|
||||
} catch (IOException e) {
|
||||
this.handleException(httpResponse, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private TestPlanResponseModel getTestPlanResponseModel(String url,
|
||||
Map<String, String> params, String accessToken) {
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
httpResponse = this.getHttpRequester().sendPost(url, params,
|
||||
makeAccessTockenMap(accessToken));
|
||||
if (!validateHttpResponse(httpResponse)) {
|
||||
handleInvalidatedResponse(url);
|
||||
return null;
|
||||
}
|
||||
|
||||
return extractTestPlanResponseModel(httpResponse);
|
||||
|
||||
} catch (Exception e) {
|
||||
this.handleException(httpResponse, e);
|
||||
return createFailTestPlanResponseModel();
|
||||
}
|
||||
}
|
||||
|
||||
private TestPlanResponseModel createFailTestPlanResponseModel() {
|
||||
TestPlanResponseModel testPlanResponseModel = new TestPlanResponseModel();
|
||||
testPlanResponseModel.setSuccess(false);
|
||||
testPlanResponseModel.setFailCause("");
|
||||
return testPlanResponseModel;
|
||||
}
|
||||
|
||||
private TestPlanResultModel getTestPlanResultModelByPost(String url,
|
||||
Map<String, String> params, String accessToken) {
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
|
||||
httpResponse = this.getHttpRequester().sendPost(url, params,
|
||||
makeAccessTockenMap(accessToken));
|
||||
if (!validateHttpResponse(httpResponse))
|
||||
return null;
|
||||
return extractTestPlanResultModel(httpResponse);
|
||||
} catch (Exception e) {
|
||||
this.handleException(httpResponse, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private TestPlanResponseModel extractTestPlanResponseModel(
|
||||
HttpResponse httpResponse) throws JAXBException,
|
||||
UnsupportedEncodingException {
|
||||
return (TestPlanResponseModel) MarshalHelper.unmarshal(
|
||||
TestPlanResponseModel.class, httpResponse.getContent());
|
||||
}
|
||||
|
||||
private TestPlanResultModel extractTestPlanResultModel(
|
||||
HttpResponse httpResponse) throws JAXBException,
|
||||
UnsupportedEncodingException {
|
||||
return (TestPlanResultModel) MarshalHelper.unmarshal(
|
||||
TestPlanResultModel.class, httpResponse.getContent());
|
||||
|
||||
}
|
||||
|
||||
public ScriptBriefResultModel getLatestScriptBriefResult(
|
||||
String accessToken, String testPlanId, String scriptId) {
|
||||
String url = this.baseUrl + "/scriptBrief" + "/" + testPlanId + "/"
|
||||
+ scriptId + "/latestResult";
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
httpResponse = this.getHttpRequester().sendGet(url, null,
|
||||
makeAccessTockenMap(accessToken));
|
||||
if (!validateHttpResponse(httpResponse)) {
|
||||
handleInvalidatedResponse(url);
|
||||
return null;
|
||||
}
|
||||
return (ScriptBriefResultModel) MarshalHelper.tryUnmarshal(
|
||||
ScriptBriefResultModel.class, httpResponse.getContent());
|
||||
|
||||
} catch (Exception e) {
|
||||
handleException(httpResponse, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public ScriptPagesBriefModel getScriptPageBriefModel(String accessToken,
|
||||
String testPlanId, String scriptId) {
|
||||
String url = this.baseUrl + "/pagesBrief" + "/" + testPlanId + "/"
|
||||
+ scriptId;
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
httpResponse = this.getHttpRequester().sendGet(url, null,
|
||||
makeAccessTockenMap(accessToken));
|
||||
if (!validateHttpResponse(httpResponse)) {
|
||||
handleInvalidatedResponse(url);
|
||||
return null;
|
||||
}
|
||||
return (ScriptPagesBriefModel) MarshalHelper.unmarshal(
|
||||
ScriptPagesBriefModel.class, httpResponse.getContent());
|
||||
|
||||
} catch (Exception e) {
|
||||
handleException(httpResponse, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public TestPlanResponseModel stopTestPlan(String accessToken,
|
||||
String testPlanRunId) {
|
||||
String url = this.baseUrl + "/stop" + "/" + testPlanRunId;
|
||||
return getTestPlanResponseModel(url, null, accessToken);
|
||||
}
|
||||
|
||||
public TestPlanResponseModel loadFilterTypeList(String accessToken) {
|
||||
String url = this.getBaseUrl() + "/loadFilterTypeList";
|
||||
|
|
|
@ -1,176 +1,176 @@
|
|||
package org.bench4q.web.test.masterMessager;
|
||||
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.*;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.master.TestPlanResponseModel;
|
||||
import org.bench4q.share.models.master.TestPlanResultModel;
|
||||
import org.bench4q.share.models.master.statistics.ScriptBehaviorsBriefModel;
|
||||
import org.bench4q.web.masterMessager.TestPlanMessager;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("file:src/test/resources/bench4qweb-servlet.xml")
|
||||
public class TestPlanMessageTest extends MessagerTestBase {
|
||||
private TestPlanMessager testPlanMessager;
|
||||
private String baseUrl = "/testPlan";
|
||||
private String testPlanId = "testPlanId";
|
||||
private String scriptId = "scriptId";
|
||||
|
||||
public TestPlanMessager getTestPlanMessager() {
|
||||
return testPlanMessager;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setTestPlanMessager(TestPlanMessager testPlanMessager) {
|
||||
this.testPlanMessager = testPlanMessager;
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() {
|
||||
startServer();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void clear() {
|
||||
stopServer();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_runTestPlan() {
|
||||
String url = baseUrl + "/run";
|
||||
this.getWireMock().register(
|
||||
post(urlEqualTo(url)).willReturn(
|
||||
aResponse().withStatus(200)
|
||||
.withHeader("Content-Type", "text/xml")
|
||||
.withBody(this.createResponse())));
|
||||
assertNotNull(this.testPlanMessager.runTestPlan(null, ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_getRunningTestInfo() {
|
||||
String url = baseUrl + "/getRunningInfo";
|
||||
this.getWireMock().register(
|
||||
post(urlEqualTo(url)).withRequestBody(containing("testPlanId"))
|
||||
.willReturn(
|
||||
aResponse().withStatus(200)
|
||||
.withHeader("Content-Type", "text/xml")
|
||||
.withBody(this.createResponse())));
|
||||
assertNotNull(this.testPlanMessager.getRunningTestInfo(null, ""));
|
||||
}
|
||||
|
||||
// @Test
|
||||
// public void test_getScriptBriefResult() {
|
||||
// TestPlanScriptBriefResultModel testPlanScriptBriefResultModel = new
|
||||
// TestPlanScriptBriefResultModel();
|
||||
// String response = MarshalHelper
|
||||
// .tryMarshal(testPlanScriptBriefResultModel);
|
||||
// String url = baseUrl + '/' + testPlanId + '/' + scriptId + '/'
|
||||
// + duationBegin;
|
||||
// System.out.println(url);
|
||||
// this.getWireMock().register(
|
||||
// get(urlEqualTo(url)).willReturn(
|
||||
// aResponse().withStatus(200)
|
||||
// .withHeader("Content-Type", "text/xml")
|
||||
// .withBody(response)));
|
||||
// assertNotNull(this.testPlanMessager.getScriptBriefResult(null,
|
||||
// testPlanId, scriptId, duationBegin));
|
||||
// }
|
||||
|
||||
@Test
|
||||
public void test_getScriptBehaviorsBriefResult() {
|
||||
ScriptBehaviorsBriefModel scriptBehaviorsBriefModel = new ScriptBehaviorsBriefModel();
|
||||
scriptBehaviorsBriefModel.setFinished(true);
|
||||
String response = MarshalHelper.tryMarshal(scriptBehaviorsBriefModel);
|
||||
String url = baseUrl +"/getBehaviorsBrief"+ '/' + testPlanId + '/' + scriptId;
|
||||
this.getWireMock().register(
|
||||
get(urlEqualTo(url)).willReturn(
|
||||
aResponse().withStatus(200)
|
||||
.withHeader("Content-Type", "text/xml")
|
||||
.withBody(response)));
|
||||
assertNotNull(this.testPlanMessager.getScriptBehaviorsBriefResult(null,
|
||||
testPlanId, scriptId));
|
||||
assertTrue(this.testPlanMessager.getScriptBehaviorsBriefResult(null,
|
||||
testPlanId, scriptId).isFinished());
|
||||
}
|
||||
|
||||
// @Test
|
||||
// public void test_getPageBriefResult() {
|
||||
// ScriptPagesBriefModel scriptPagesBriefModel = new ScriptPagesBriefModel();
|
||||
// String response = MarshalHelper.tryMarshal(scriptPagesBriefModel);
|
||||
// String url = baseUrl + '/' + testPlanId + '/' + scriptId;
|
||||
// this.getWireMock().register(
|
||||
// get(urlEqualTo(url)).willReturn(
|
||||
// aResponse().withStatus(200)
|
||||
// .withHeader("Content-Type", "text/xml")
|
||||
// .withBody(response)));
|
||||
// assertNotNull(this.testPlanMessager.getPageBriefResult(null,
|
||||
// testPlanId, scriptId));
|
||||
// }
|
||||
|
||||
// @Test
|
||||
// public void test_queryTestPlanById() {
|
||||
// String testPlanRunId = "testPlanRunId";
|
||||
// String url = baseUrl + "/queryTestPlan/" + testPlanRunId;
|
||||
// this.getWireMock().register(
|
||||
// get(urlEqualTo(url)).willReturn(
|
||||
// aResponse().withStatus(200)
|
||||
// .withHeader("Content-Type", "text/xml")
|
||||
// .withBody(this.createResponse())));
|
||||
// assertNotNull(this.testPlanMessager.queryTestPlanById(null,
|
||||
// testPlanRunId));
|
||||
// }
|
||||
|
||||
@Test
|
||||
public void test_deleteTestPlan() {
|
||||
TestPlanResponseModel testPlanResponseModel = new TestPlanResponseModel();
|
||||
testPlanResponseModel.setSuccess(true);
|
||||
String response = MarshalHelper.tryMarshal(testPlanResponseModel);
|
||||
String url = baseUrl + "/removeTestPlanFromPool";
|
||||
this.getWireMock().register(
|
||||
post(urlEqualTo(url)).withRequestBody(containing("testPlanId"))
|
||||
.willReturn(
|
||||
aResponse().withStatus(200)
|
||||
.withHeader("Content-Type", "text/xml")
|
||||
.withBody(response)));
|
||||
assertNotNull(this.testPlanMessager.deleteTestPlan(null, testPlanId));
|
||||
assertTrue(this.testPlanMessager.deleteTestPlan(null, testPlanId)
|
||||
.isSuccess());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_loadTestPlans() {
|
||||
String url = baseUrl + "/loadTestPlans";
|
||||
TestPlanResponseModel testPlanResponseModel = new TestPlanResponseModel();
|
||||
testPlanResponseModel.setSuccess(true);
|
||||
String response = MarshalHelper.tryMarshal(testPlanResponseModel);
|
||||
this.getWireMock().register(
|
||||
post(urlEqualTo(url)).willReturn(
|
||||
aResponse().withStatus(200)
|
||||
.withHeader("Content-Type", "text/xml")
|
||||
.withBody(response)));
|
||||
assertNotNull(this.testPlanMessager.loadTestPlans(null));
|
||||
assertTrue(this.testPlanMessager.loadTestPlans(null).isSuccess());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_getTestPlanReport() {
|
||||
|
||||
}
|
||||
|
||||
public String createResponse() {
|
||||
TestPlanResultModel testPlanResultModel = new TestPlanResultModel();
|
||||
return MarshalHelper.tryMarshal(testPlanResultModel);
|
||||
}
|
||||
}
|
||||
package org.bench4q.web.test.masterMessager;
|
||||
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.*;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.master.TestPlanResponseModel;
|
||||
import org.bench4q.share.models.master.TestPlanResultModel;
|
||||
import org.bench4q.share.models.master.statistics.ScriptBehaviorsBriefModel;
|
||||
import org.bench4q.web.masterMessager.TestPlanMessager;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("file:src/test/resources/bench4qweb-servlet.xml")
|
||||
public class TestPlanMessageTest extends MessagerTestBase {
|
||||
private TestPlanMessager testPlanMessager;
|
||||
private String baseUrl = "/testPlan";
|
||||
private String testPlanId = "testPlanId";
|
||||
private String scriptId = "scriptId";
|
||||
|
||||
public TestPlanMessager getTestPlanMessager() {
|
||||
return testPlanMessager;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setTestPlanMessager(TestPlanMessager testPlanMessager) {
|
||||
this.testPlanMessager = testPlanMessager;
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() {
|
||||
startServer();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void clear() {
|
||||
stopServer();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_runTestPlan() {
|
||||
String url = baseUrl + "/run";
|
||||
this.getWireMock().register(
|
||||
post(urlEqualTo(url)).willReturn(
|
||||
aResponse().withStatus(200)
|
||||
.withHeader("Content-Type", "text/xml")
|
||||
.withBody(this.createResponse())));
|
||||
assertNotNull(this.testPlanMessager.runTestPlan(null, ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_getRunningTestInfo() {
|
||||
String url = baseUrl + "/getRunningInfo";
|
||||
this.getWireMock().register(
|
||||
post(urlEqualTo(url)).withRequestBody(containing("testPlanId"))
|
||||
.willReturn(
|
||||
aResponse().withStatus(200)
|
||||
.withHeader("Content-Type", "text/xml")
|
||||
.withBody(this.createResponse())));
|
||||
assertNotNull(this.testPlanMessager.getRunningTestInfo(null, ""));
|
||||
}
|
||||
|
||||
// @Test
|
||||
// public void test_getScriptBriefResult() {
|
||||
// TestPlanScriptBriefResultModel testPlanScriptBriefResultModel = new
|
||||
// TestPlanScriptBriefResultModel();
|
||||
// String response = MarshalHelper
|
||||
// .tryMarshal(testPlanScriptBriefResultModel);
|
||||
// String url = baseUrl + '/' + testPlanId + '/' + scriptId + '/'
|
||||
// + duationBegin;
|
||||
// System.out.println(url);
|
||||
// this.getWireMock().register(
|
||||
// get(urlEqualTo(url)).willReturn(
|
||||
// aResponse().withStatus(200)
|
||||
// .withHeader("Content-Type", "text/xml")
|
||||
// .withBody(response)));
|
||||
// assertNotNull(this.testPlanMessager.getScriptBriefResult(null,
|
||||
// testPlanId, scriptId, duationBegin));
|
||||
// }
|
||||
|
||||
@Test
|
||||
public void test_getScriptBehaviorsBriefResult() {
|
||||
ScriptBehaviorsBriefModel scriptBehaviorsBriefModel = new ScriptBehaviorsBriefModel();
|
||||
scriptBehaviorsBriefModel.setFinished(true);
|
||||
String response = MarshalHelper.tryMarshal(scriptBehaviorsBriefModel);
|
||||
String url = baseUrl +"/getBehaviorsBrief"+ '/' + testPlanId + '/' + scriptId;
|
||||
this.getWireMock().register(
|
||||
get(urlEqualTo(url)).willReturn(
|
||||
aResponse().withStatus(200)
|
||||
.withHeader("Content-Type", "text/xml")
|
||||
.withBody(response)));
|
||||
assertNotNull(this.testPlanMessager.getScriptBehaviorsBriefResult(null,
|
||||
testPlanId, scriptId));
|
||||
assertTrue(this.testPlanMessager.getScriptBehaviorsBriefResult(null,
|
||||
testPlanId, scriptId).isFinished());
|
||||
}
|
||||
|
||||
// @Test
|
||||
// public void test_getPageBriefResult() {
|
||||
// ScriptPagesBriefModel scriptPagesBriefModel = new ScriptPagesBriefModel();
|
||||
// String response = MarshalHelper.tryMarshal(scriptPagesBriefModel);
|
||||
// String url = baseUrl + '/' + testPlanId + '/' + scriptId;
|
||||
// this.getWireMock().register(
|
||||
// get(urlEqualTo(url)).willReturn(
|
||||
// aResponse().withStatus(200)
|
||||
// .withHeader("Content-Type", "text/xml")
|
||||
// .withBody(response)));
|
||||
// assertNotNull(this.testPlanMessager.getPageBriefResult(null,
|
||||
// testPlanId, scriptId));
|
||||
// }
|
||||
|
||||
// @Test
|
||||
// public void test_queryTestPlanById() {
|
||||
// String testPlanRunId = "testPlanRunId";
|
||||
// String url = baseUrl + "/queryTestPlan/" + testPlanRunId;
|
||||
// this.getWireMock().register(
|
||||
// get(urlEqualTo(url)).willReturn(
|
||||
// aResponse().withStatus(200)
|
||||
// .withHeader("Content-Type", "text/xml")
|
||||
// .withBody(this.createResponse())));
|
||||
// assertNotNull(this.testPlanMessager.queryTestPlanById(null,
|
||||
// testPlanRunId));
|
||||
// }
|
||||
|
||||
@Test
|
||||
public void test_deleteTestPlan() {
|
||||
TestPlanResponseModel testPlanResponseModel = new TestPlanResponseModel();
|
||||
testPlanResponseModel.setSuccess(true);
|
||||
String response = MarshalHelper.tryMarshal(testPlanResponseModel);
|
||||
String url = baseUrl + "/removeTestPlanFromPool";
|
||||
this.getWireMock().register(
|
||||
post(urlEqualTo(url)).withRequestBody(containing("testPlanId"))
|
||||
.willReturn(
|
||||
aResponse().withStatus(200)
|
||||
.withHeader("Content-Type", "text/xml")
|
||||
.withBody(response)));
|
||||
assertNotNull(this.testPlanMessager.deleteTestPlan(null, testPlanId));
|
||||
assertTrue(this.testPlanMessager.deleteTestPlan(null, testPlanId)
|
||||
.isSuccess());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_loadTestPlans() {
|
||||
String url = baseUrl + "/loadTestPlans";
|
||||
TestPlanResponseModel testPlanResponseModel = new TestPlanResponseModel();
|
||||
testPlanResponseModel.setSuccess(true);
|
||||
String response = MarshalHelper.tryMarshal(testPlanResponseModel);
|
||||
this.getWireMock().register(
|
||||
post(urlEqualTo(url)).willReturn(
|
||||
aResponse().withStatus(200)
|
||||
.withHeader("Content-Type", "text/xml")
|
||||
.withBody(response)));
|
||||
assertNotNull(this.testPlanMessager.loadTestPlans(null));
|
||||
assertTrue(this.testPlanMessager.loadTestPlans(null).isSuccess());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_getTestPlanReport() {
|
||||
|
||||
}
|
||||
|
||||
public String createResponse() {
|
||||
TestPlanResultModel testPlanResultModel = new TestPlanResultModel();
|
||||
return MarshalHelper.tryMarshal(testPlanResultModel);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue