remove those Unnecessary dependency, and do as a factory
This commit is contained in:
parent
68c7aaa311
commit
8f5e5aa8b5
|
@ -28,6 +28,7 @@ import org.bench4q.agent.scenario.ScenarioContext;
|
|||
import org.bench4q.agent.scenario.ScenarioEngine;
|
||||
import org.bench4q.agent.scenario.UsePlugin;
|
||||
import org.bench4q.agent.scenario.behavior.Behavior;
|
||||
import org.bench4q.agent.scenario.behavior.BehaviorFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
|
@ -120,7 +121,7 @@ public class TestController {
|
|||
}
|
||||
|
||||
private Behavior extractBehavior(BehaviorBaseModel behaviorModel) {
|
||||
Behavior behavior = (Behavior) behaviorModel.getBuisinessInstance();
|
||||
Behavior behavior = BehaviorFactory.getBuisinessObject(behaviorModel);
|
||||
behavior.setName(behaviorModel.getName());
|
||||
behavior.setUse(behaviorModel.getUse());
|
||||
behavior.setParameters(new Parameter[behaviorModel.getParameters()
|
||||
|
|
|
@ -40,5 +40,4 @@ public abstract class BehaviorBaseModel {
|
|||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
public abstract Object getBuisinessInstance();
|
||||
}
|
||||
|
|
|
@ -6,8 +6,6 @@ import javax.xml.bind.JAXBContext;
|
|||
import javax.xml.bind.Marshaller;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import org.bench4q.agent.scenario.behavior.TimerBehavior;
|
||||
|
||||
@XmlRootElement(name = "timerBehavior")
|
||||
public class TimerBehaviorModel extends BehaviorBaseModel {
|
||||
|
||||
|
@ -23,9 +21,4 @@ public class TimerBehaviorModel extends BehaviorBaseModel {
|
|||
return os.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getBuisinessInstance() {
|
||||
return new TimerBehavior();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,8 +7,6 @@ import javax.xml.bind.JAXBException;
|
|||
import javax.xml.bind.Marshaller;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import org.bench4q.agent.scenario.behavior.UserBehavior;
|
||||
|
||||
@XmlRootElement(name = "userBehavior")
|
||||
public class UserBehaviorModel extends BehaviorBaseModel {
|
||||
public String getModelString() throws JAXBException {
|
||||
|
@ -19,9 +17,4 @@ public class UserBehaviorModel extends BehaviorBaseModel {
|
|||
return os.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getBuisinessInstance() {
|
||||
return new UserBehavior();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -69,12 +69,11 @@ public class ScenarioContext {
|
|||
|
||||
public static ScenarioContext buildScenarioContext(UUID testId,
|
||||
final Scenario scenario, int poolSize,
|
||||
ExecutorService executorService, final List<BehaviorResult> ret) {
|
||||
ExecutorService executorService) {
|
||||
ScenarioContext scenarioContext = new ScenarioContext();
|
||||
scenarioContext.setScenario(scenario);
|
||||
scenarioContext.setStartDate(new Date(System.currentTimeMillis()));
|
||||
scenarioContext.setExecutorService(executorService);
|
||||
scenarioContext.setResults(ret);
|
||||
// TODO:remove this direct dependency
|
||||
scenarioContext.setDataStatistics(new AgentResultDataCollector(testId));
|
||||
return scenarioContext;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.bench4q.agent.scenario;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -68,11 +67,9 @@ public class ScenarioEngine {
|
|||
try {
|
||||
ExecutorService executorService = Executors
|
||||
.newFixedThreadPool(poolSize);
|
||||
final List<BehaviorResult> ret = Collections
|
||||
.synchronizedList(new ArrayList<BehaviorResult>());
|
||||
final ScenarioContext scenarioContext = ScenarioContext
|
||||
.buildScenarioContext(runId, scenario, poolSize,
|
||||
executorService, ret);
|
||||
executorService);
|
||||
int i;
|
||||
this.getRunningTests().put(runId, scenarioContext);
|
||||
Runnable runnable = new Runnable() {
|
||||
|
@ -105,9 +102,12 @@ public class ScenarioEngine {
|
|||
boolean success = (Boolean) this.getPluginManager().doBehavior(
|
||||
plugin, behavior.getName(), behaviorParameters);
|
||||
Date endDate = new Date(System.currentTimeMillis());
|
||||
// TODO: refactor, collect result here, and judge if to calculate
|
||||
// that
|
||||
// behavior's result,because it may be a userBehavior or
|
||||
// timerBehavior
|
||||
behavior.buildBehaviorResultAndAdd(plugin, startDate, success,
|
||||
endDate, ret);
|
||||
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package org.bench4q.agent.scenario.behavior;
|
||||
|
||||
import org.bench4q.agent.api.model.behavior.BehaviorBaseModel;
|
||||
import org.bench4q.agent.api.model.behavior.TimerBehaviorModel;
|
||||
import org.bench4q.agent.api.model.behavior.UserBehaviorModel;
|
||||
|
||||
public class BehaviorFactory {
|
||||
public static Behavior getBuisinessObject(BehaviorBaseModel modelInput) {
|
||||
if (modelInput instanceof TimerBehaviorModel) {
|
||||
return new TimerBehavior();
|
||||
} else if (modelInput instanceof UserBehaviorModel) {
|
||||
return new UserBehavior();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -53,10 +53,11 @@ public class DataStatisticsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void addOneTest() {
|
||||
public void addOneTest() throws InterruptedException {
|
||||
this.getDataStatistics().add(makeBehaviorResultList(1));
|
||||
AgentBriefStatusModel model = (AgentBriefStatusModel) this
|
||||
.getDataStatistics().getBriefStatistics();
|
||||
Thread.sleep(100);
|
||||
AgentBriefStatusModel modelExpect = new AgentBriefStatusModel();
|
||||
modelExpect.setTimeFrame(model.getTimeFrame());
|
||||
makeUpStatusModelForOneBehavior(modelExpect);
|
||||
|
@ -64,8 +65,9 @@ public class DataStatisticsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void addTwoTest() {
|
||||
public void addTwoTest() throws InterruptedException {
|
||||
this.getDataStatistics().add(makeBehaviorResultList(2));
|
||||
Thread.sleep(100);
|
||||
AgentBriefStatusModel model = (AgentBriefStatusModel) this
|
||||
.getDataStatistics().getBriefStatistics();
|
||||
AgentBriefStatusModel modelExpect = makeUpStatusModelForTwoBehavior(model
|
||||
|
|
|
@ -9,7 +9,6 @@ import javax.xml.bind.JAXBException;
|
|||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import org.bench4q.agent.api.model.behavior.BehaviorBaseModel;
|
||||
import org.bench4q.agent.scenario.behavior.Behavior;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
@ -50,9 +49,4 @@ public class ModelTest extends BehaviorBaseModel {
|
|||
assertTrue(object instanceof ModelTest);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Behavior getBuisinessInstance() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue