remove testplanInBusiness

This commit is contained in:
coderfengyun 2014-02-24 10:16:28 +08:00
parent 456ce88646
commit 483c729cce
13 changed files with 90 additions and 136 deletions

View File

@ -9,7 +9,6 @@ import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.bench4q.master.domain.TestPlanInBusiness;
import org.bench4q.master.domain.entity.TestPlanDB;
import org.bench4q.master.domain.factory.BusinessModelMapFactory;
import org.bench4q.master.domain.service.TestPlanEngine;
@ -121,10 +120,10 @@ public class TestPlanController extends BaseController {
"You don't have enough power to run a test plan!",
"/runTestPlanWithTestPlanModel");
}
TestPlanInBusiness testPlanInBusiness = BusinessModelMapFactory
.toBusiness(testPlanBusinessModel);
// TestPlanInBusiness testPlanInBusiness = BusinessModelMapFactory
// .toBusiness(testPlanBusinessModel);
UUID testPlanRunID = this.getTestPlanRunner().runTestPlanWithModel(
testPlanInBusiness, this.getPrincipal());
testPlanBusinessModel, this.getPrincipal());
if (testPlanRunID == null) {
throw new Bench4QException("TestPlan_Commit_Error",
"There is an exception when commit the test plan",

View File

@ -3,26 +3,21 @@ package org.bench4q.master.domain;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.bench4q.master.domain.factory.BusinessModelMapFactory;
import org.bench4q.master.domain.service.TestPlanScriptService;
import org.bench4q.master.helper.ApplicationContextHelper;
import org.bench4q.share.models.master.RunningScriptModel;
import org.bench4q.share.models.master.TestPlanBusinessModel;
public class TestPlanContext {
private Map<Integer, RunningScript> runningScriptMap;
private TestPlanInBusiness testPlan;
private boolean finish;
public TestPlanInBusiness getTestPlan() {
return testPlan;
}
public void setTestPlan(TestPlanInBusiness testPlan) {
this.testPlan = testPlan;
}
private Map<Integer, RunningScript> getRunningScriptMap() {
return runningScriptMap;
}
@ -40,16 +35,21 @@ public class TestPlanContext {
this.finish = finish;
}
public TestPlanContext(TestPlanInBusiness testPlan, UUID testPlanID) {
public TestPlanContext(TestPlanBusinessModel testPlanModel, UUID testPlanID) {
this.setRunningScriptMap(new HashMap<Integer, RunningScript>());
this.fillScriptMapAndAssignTestPlanIdAndScenario(
testPlan.getRunningScripts(), testPlanID);
this.setTestPlan(testPlan);
List<RunningScript> runningScripts = new LinkedList<RunningScript>();
for (RunningScriptModel runningScriptModel : testPlanModel
.getRunningScriptModels()) {
runningScripts.add(BusinessModelMapFactory
.toBusiness(runningScriptModel));
}
testPlanModel = null;
this.fillScriptMapAndAssignTestPlanIdAndScenario(runningScripts,
testPlanID);
}
public void cleanUpFinishedContext() {
this.setFinish(true);
this.setTestPlan(null);
this.setRunningScriptMap(new HashMap<Integer, RunningScript>());
System.gc();
}

View File

@ -1,36 +0,0 @@
package org.bench4q.master.domain;
import java.util.List;
import org.bench4q.master.domain.entity.Monitor;
public class TestPlanInBusiness {
private String name = "";
private List<RunningScript> runningScripts;
private List<Monitor> monitors;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<RunningScript> getRunningScripts() {
return runningScripts;
}
public void setRunningScripts(List<RunningScript> runningScripts) {
this.runningScripts = runningScripts;
}
public List<Monitor> getMonitors() {
return monitors;
}
public void setMonitors(List<Monitor> monitors) {
this.monitors = monitors;
}
}

View File

@ -5,7 +5,6 @@ import java.util.List;
import org.bench4q.master.domain.RunningAgent;
import org.bench4q.master.domain.RunningScript;
import org.bench4q.master.domain.TestPlanInBusiness;
import org.bench4q.master.domain.entity.Agent;
import org.bench4q.master.domain.entity.Monitor;
import org.bench4q.master.domain.entity.Port;
@ -19,7 +18,6 @@ import org.bench4q.share.models.master.PortModel;
import org.bench4q.share.models.master.RunningAgentModel;
import org.bench4q.share.models.master.RunningScriptModel;
import org.bench4q.share.models.master.ScriptModel;
import org.bench4q.share.models.master.TestPlanBusinessModel;
import org.bench4q.share.models.master.TestPlanDBModel;
import org.bench4q.share.models.master.UserModel;
import org.springframework.beans.factory.annotation.Autowired;
@ -118,52 +116,54 @@ public class BusinessModelMapFactory {
return ret;
}
public static TestPlanInBusiness toBusiness(
TestPlanBusinessModel testPlanModel) {
TestPlanInBusiness ret = new TestPlanInBusiness();
List<Monitor> monitors = new ArrayList<Monitor>();
guardMonitorListNotNull(testPlanModel);
if (testPlanModel.getMonitorModels() != null) {
for (MonitorModel monitorModel : testPlanModel.getMonitorModels()) {
Monitor monitorInBusiness = toBusiness(monitorModel);
monitors.add(monitorInBusiness);
}
}
ret.setMonitors(monitors);
ret.setName(testPlanModel.getName());
List<RunningScript> runningScripts = new ArrayList<RunningScript>();
for (RunningScriptModel runningScriptModel : testPlanModel
.getRunningScriptModels()) {
RunningScript runningScript = toBusiness(runningScriptModel);
runningScripts.add(runningScript);
}
ret.setRunningScripts(runningScripts);
return ret;
}
// public static TestPlanInBusiness toBusiness(
// TestPlanBusinessModel testPlanModel) {
// TestPlanInBusiness ret = new TestPlanInBusiness();
// List<Monitor> monitors = new ArrayList<Monitor>();
// guardMonitorListNotNull(testPlanModel);
// if (testPlanModel.getMonitorModels() != null) {
// for (MonitorModel monitorModel : testPlanModel.getMonitorModels()) {
// Monitor monitorInBusiness = toBusiness(monitorModel);
// monitors.add(monitorInBusiness);
// }
// }
// ret.setMonitors(monitors);
// ret.setName(testPlanModel.getName());
// List<RunningScript> runningScripts = new ArrayList<RunningScript>();
// for (RunningScriptModel runningScriptModel : testPlanModel
// .getRunningScriptModels()) {
// RunningScript runningScript = toBusiness(runningScriptModel);
// runningScripts.add(runningScript);
// }
// ret.setRunningScripts(runningScripts);
// return ret;
// }
private static void guardMonitorListNotNull(
TestPlanBusinessModel testPlanModel) {
if (testPlanModel.getMonitorModels() == null) {
testPlanModel.setMonitorModels(new ArrayList<MonitorModel>());
}
}
// private static void guardMonitorListNotNull(
// TestPlanBusinessModel testPlanModel) {
// if (testPlanModel.getMonitorModels() == null) {
// testPlanModel.setMonitorModels(new ArrayList<MonitorModel>());
// }
// }
public TestPlanBusinessModel toModel(TestPlanInBusiness testPlanInBusiness) {
TestPlanBusinessModel ret = new TestPlanBusinessModel();
ret.setName(testPlanInBusiness.getName());
List<RunningScriptModel> runningScriptModels = new ArrayList<RunningScriptModel>();
for (RunningScript runningScript : testPlanInBusiness
.getRunningScripts()) {
runningScriptModels.add(toModel(runningScript));
}
ret.setRunningScriptModels(runningScriptModels);
List<MonitorModel> monitorModels = new ArrayList<MonitorModel>();
for (Monitor monitorInBusiness : testPlanInBusiness.getMonitors()) {
monitorModels.add(toModel(monitorInBusiness));
}
ret.setMonitorModels(monitorModels);
return ret;
}
// public TestPlanBusinessModel toModel(TestPlanInBusiness
// testPlanInBusiness) {
// TestPlanBusinessModel ret = new TestPlanBusinessModel();
// ret.setName(testPlanInBusiness.getName());
// List<RunningScriptModel> runningScriptModels = new
// ArrayList<RunningScriptModel>();
// for (RunningScript runningScript : testPlanInBusiness
// .getRunningScripts()) {
// runningScriptModels.add(toModel(runningScript));
// }
// ret.setRunningScriptModels(runningScriptModels);
// List<MonitorModel> monitorModels = new ArrayList<MonitorModel>();
// for (Monitor monitorInBusiness : testPlanInBusiness.getMonitors()) {
// monitorModels.add(toModel(monitorInBusiness));
// }
// ret.setMonitorModels(monitorModels);
// return ret;
// }
public static Monitor toBusiness(MonitorModel monitorModel) {
Monitor monitor = new Monitor();

View File

@ -7,13 +7,13 @@ import java.util.concurrent.Executors;
import org.apache.log4j.Logger;
import org.bench4q.master.domain.RunningScript;
import org.bench4q.master.domain.TestPlanContext;
import org.bench4q.master.domain.TestPlanInBusiness;
import org.bench4q.master.domain.entity.User;
import org.bench4q.master.testplan.LoadDistribute;
import org.bench4q.master.testplan.TestPlanContainer;
import org.bench4q.master.testplan.highavailable.CurrentLoadObserver;
import org.bench4q.master.testplan.highavailable.HighAvailablePool;
import org.bench4q.master.testplan.schedulscript.TaskCompleteCallback;
import org.bench4q.share.models.master.TestPlanBusinessModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@ -63,17 +63,17 @@ public class TestPlanEngine implements TaskCompleteCallback,
this.getHaPool().setObserver(this);
}
public UUID runTestPlanWithModel(final TestPlanInBusiness testPlan,
public UUID runTestPlanWithModel(final TestPlanBusinessModel testPlanModel,
User user) {
ExecutorService executorService = Executors.newCachedThreadPool();
final UUID testPlanId = UUID.randomUUID();
if (!this.getTestPlanService().submitTestPlan(testPlan, user,
if (!this.getTestPlanService().submitTestPlan(testPlanModel, user,
testPlanId)) {
return null;
}
final TestPlanContext testPlanContext = new TestPlanContext(testPlan,
final TestPlanContext testPlanContext = new TestPlanContext(testPlanModel,
testPlanId);
this.getContainer().addATask(testPlanId, testPlanContext);
Runnable runnable = new Runnable() {

View File

@ -4,7 +4,6 @@ import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
import org.bench4q.master.domain.TestPlanInBusiness;
import org.bench4q.master.domain.entity.Monitor;
import org.bench4q.master.domain.entity.TestPlanDB;
import org.bench4q.master.domain.entity.TestPlanScript;
@ -14,6 +13,7 @@ import org.bench4q.master.domain.factory.TestPlanFactory;
import org.bench4q.master.domain.repository.TestPlanRepository;
import org.bench4q.share.enums.master.TestPlanStatus;
import org.bench4q.share.models.master.MonitorModel;
import org.bench4q.share.models.master.TestPlanBusinessModel;
import org.bench4q.share.models.master.TestPlanDBModel;
import org.bench4q.share.models.master.TestPlanResultModel;
import org.springframework.beans.factory.annotation.Autowired;
@ -54,12 +54,12 @@ public class TestPlanService {
this.testPlanFactory = testPlanFactory;
}
public boolean submitTestPlan(final TestPlanInBusiness testPlanInParam,
final User user, final UUID testPlanRunId) {
public boolean submitTestPlan(
final TestPlanBusinessModel testPlanBusinessModel, final User user,
final UUID testPlanRunId) {
return this.getTestPlanRepository().attach(
this.getTestPlanFactory().createATestPlanWithoutIdentity(
this.getBusinessMapFactory().toModel(testPlanInParam),
user, testPlanRunId));
testPlanBusinessModel, user, testPlanRunId));
}
public List<TestPlanDB> loadTestPlans(User user) {

View File

@ -4,9 +4,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.bench4q.master.domain.TestPlanInBusiness;
import org.bench4q.master.domain.entity.User;
import org.bench4q.master.domain.factory.BusinessModelMapFactory;
import org.bench4q.master.domain.repository.TestPlanRepository;
import org.bench4q.master.domain.repository.UserRepository;
import org.bench4q.master.domain.service.ScriptService;
@ -166,8 +164,9 @@ public class TestBase_MakeUpTestPlan extends TestBase {
} else {
model = createATestPlanWithOneScript(scriptOne);
}
TestPlanInBusiness testPlan = BusinessModelMapFactory.toBusiness(model);
this.getTestPlanService().submitTestPlan(testPlan, user, testPlanRunId);
// TestPlanInBusiness testPlan =
// BusinessModelMapFactory.toBusiness(model);
this.getTestPlanService().submitTestPlan(model, user, testPlanRunId);
this.setTestPlanRunIdUuid(testPlanRunId);
return testPlanRunId;
}

View File

@ -7,9 +7,7 @@ import java.util.UUID;
import javax.xml.bind.JAXBException;
import org.bench4q.master.domain.TestPlanInBusiness;
import org.bench4q.master.domain.entity.User;
import org.bench4q.master.domain.factory.BusinessModelMapFactory;
import org.bench4q.master.test.TestBase_MakeUpTestPlan;
import org.bench4q.share.communication.HttpRequester.HttpResponse;
import org.bench4q.share.helper.MarshalHelper;
@ -48,8 +46,9 @@ public class TestPlanScriptResultControllerTest extends TestBase_MakeUpTestPlan
this.setScriptId(this.getUserFirstScript(user));
TestPlanBusinessModel model = createATestPlanWithOneScript(this
.getScriptId());
TestPlanInBusiness testPlan = BusinessModelMapFactory.toBusiness(model);
this.getTestPlanService().submitTestPlan(testPlan, user, testPlanRunId);
// TestPlanInBusiness testPlan =
// BusinessModelMapFactory.toBusiness(model);
this.getTestPlanService().submitTestPlan(model, user, testPlanRunId);
this.setTestPlanRunIdUuid(testPlanRunId);
for (int i = 0; i < 3; i++) {
this.getTestPlanScriptService().saveScriptBriefResult(

View File

@ -3,7 +3,6 @@ package org.bench4q.master.test.domain;
import java.util.UUID;
import org.bench4q.master.domain.TestPlanContext;
import org.bench4q.master.domain.factory.BusinessModelMapFactory;
import org.bench4q.master.test.TestBase_MakeUpTestPlan;
import org.junit.BeforeClass;
import org.junit.Test;
@ -31,9 +30,9 @@ public class Test_TestPlanContext extends TestBase_MakeUpTestPlan {
public Test_TestPlanContext() {
this.setTestPlanRunIdUuid(UUID.randomUUID());
this.setScriptId(USE_SCRIPT);
this.setTestPlanContext(new TestPlanContext(BusinessModelMapFactory
.toBusiness(createATestPlanWithOneScript(this.getScriptId())),
this.getTestPlanRunIdUuid()));
this.setTestPlanContext(new TestPlanContext(
createATestPlanWithOneScript(this.getScriptId()), this
.getTestPlanRunIdUuid()));
}
@SuppressWarnings("resource")

View File

@ -32,7 +32,6 @@ public class Test_TestPlanRepository extends TestBase_MakeUpTestPlan {
.loadEntities(this.getUserRepository().getUser("admin")).size();
assertTrue(size > 0);
System.out.println(size);
assertTrue(size < 10);
}
@Test

View File

@ -5,9 +5,7 @@ import static org.junit.Assert.*;
import java.util.List;
import java.util.UUID;
import org.bench4q.master.domain.TestPlanInBusiness;
import org.bench4q.master.domain.entity.User;
import org.bench4q.master.domain.factory.BusinessModelMapFactory;
import org.bench4q.master.domain.service.TestPlanScriptResultService;
import org.bench4q.master.test.TestBase_MakeUpTestPlan;
import org.bench4q.share.helper.TestHelper;
@ -116,9 +114,11 @@ public class Test_TestPlanScriptResultService extends TestBase_MakeUpTestPlan {
UUID testPlanRunId = UUID.randomUUID();
User user = this.getUserRepository().getUser("admin");
this.setScriptId(this.getUserFirstScript(user));
TestPlanBusinessModel model = createATestPlanWithOneScript(this.getScriptId());
TestPlanInBusiness testPlan = BusinessModelMapFactory.toBusiness(model);
this.getTestPlanService().submitTestPlan(testPlan, user, testPlanRunId);
TestPlanBusinessModel model = createATestPlanWithOneScript(this
.getScriptId());
// TestPlanInBusiness testPlan =
// BusinessModelMapFactory.toBusiness(model);
this.getTestPlanService().submitTestPlan(model, user, testPlanRunId);
this.setTestPlanRunIdUuid(testPlanRunId);
for (int i = 0; i < 3; i++) {
this.getTestPlanScriptService().saveScriptBriefResult(

View File

@ -5,11 +5,9 @@ import static org.junit.Assert.*;
import java.util.Set;
import java.util.UUID;
import org.bench4q.master.domain.TestPlanInBusiness;
import org.bench4q.master.domain.entity.TestPlanDB;
import org.bench4q.master.domain.entity.TestPlanScript;
import org.bench4q.master.domain.entity.User;
import org.bench4q.master.domain.factory.BusinessModelMapFactory;
import org.bench4q.master.test.TestBase_MakeUpTestPlan;
import org.bench4q.share.enums.master.TestPlanStatus;
import org.bench4q.share.models.master.TestPlanResultModel;
@ -96,10 +94,9 @@ public class Test_TestPlanService extends TestBase_MakeUpTestPlan {
.loadEntities(user).size();
System.out.println(planCountBeforeSubmit);
UUID randomUUID = UUID.randomUUID();
TestPlanInBusiness testPlanInBusiness = BusinessModelMapFactory
.toBusiness(createATestPlanWithOneScript(getUserFirstScript(user)));
assertTrue(this.getTestPlanService().submitTestPlan(testPlanInBusiness,
user, randomUUID));
assertTrue(this.getTestPlanService().submitTestPlan(
createATestPlanWithOneScript(getUserFirstScript(user)), user,
randomUUID));
int planCountAfterSubmit = this.getTestPlanRepository()
.loadEntities(user).size();
assertEquals(planCountBeforeSubmit + 1, planCountAfterSubmit);

View File

@ -5,7 +5,6 @@ import static org.junit.Assert.*;
import java.util.UUID;
import org.bench4q.master.domain.TestPlanContext;
import org.bench4q.master.domain.factory.BusinessModelMapFactory;
import org.bench4q.master.helper.ApplicationContextHelper;
import org.bench4q.master.test.TestBase_MakeUpTestPlan;
import org.bench4q.master.testplan.TestPlanContainer;
@ -53,8 +52,7 @@ public class Test_TestPlanContainer extends TestBase_MakeUpTestPlan {
testPlanBusinessModel.setMonitorModels(createOneMonitorList());
this.getTestPlanContainer().addATask(
this.getTestPlanRunIdUuid(),
new TestPlanContext(BusinessModelMapFactory
.toBusiness(testPlanBusinessModel), this
new TestPlanContext(testPlanBusinessModel, this
.getTestPlanRunIdUuid()));
}