refactor the test
there are two class to test : Test_RunningAgent, Test_RunningScript
This commit is contained in:
parent
5b28e3f189
commit
287eb2ad7d
|
@ -1,58 +0,0 @@
|
||||||
package org.bench4q.master.api;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import org.bench4q.master.domain.service.TestPlanScriptResultService;
|
|
||||||
import org.bench4q.master.domain.service.UserService;
|
|
||||||
import org.bench4q.master.exception.Bench4QException;
|
|
||||||
import org.bench4q.share.models.master.ResultLoadModel;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Controller;
|
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
|
||||||
|
|
||||||
@Controller
|
|
||||||
@RequestMapping("/testPlanResult")
|
|
||||||
public class TestPlanResultController extends BaseController {
|
|
||||||
private TestPlanScriptResultService testPlanScriptResultService;
|
|
||||||
|
|
||||||
public TestPlanScriptResultService getTestPlanScriptResultService() {
|
|
||||||
return testPlanScriptResultService;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public void setTestPlanScriptResultService(
|
|
||||||
TestPlanScriptResultService testPlanScriptResultService) {
|
|
||||||
this.testPlanScriptResultService = testPlanScriptResultService;
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequestMapping(value = "/{testPlanRunId}/loadScriptBirefResults/{scriptId}/{fieldName}", method = RequestMethod.GET)
|
|
||||||
@ResponseBody
|
|
||||||
public ResultLoadModel loadScriptBriefResults(
|
|
||||||
@PathVariable UUID testPlanRunId, @PathVariable int scriptId,
|
|
||||||
@PathVariable String fieldName) throws Bench4QException {
|
|
||||||
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
|
|
||||||
throw new Bench4QException(400 + "", "not permitted",
|
|
||||||
"/{testPlanRunId}/script/{scriptId}/{fieldName}");
|
|
||||||
}
|
|
||||||
ResultLoadModel ret = new ResultLoadModel();
|
|
||||||
ret.setValueTimeModels(this.getTestPlanScriptResultService()
|
|
||||||
.loadScriptBriefSpecificField(testPlanRunId, scriptId,
|
|
||||||
fieldName));
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequestMapping(value = "/{testPlanRunId}/loadBehaviorsBriefResults/{scriptId}/{fieldName}", method = RequestMethod.GET)
|
|
||||||
@ResponseBody
|
|
||||||
public ResultLoadModel loadBehaviorsBriefResults(
|
|
||||||
@PathVariable UUID testPlanRunId, @PathVariable int scriptId,
|
|
||||||
@PathVariable String fieldName) throws Bench4QException {
|
|
||||||
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
|
|
||||||
throw new Bench4QException("400", "not permitted",
|
|
||||||
"/{testPlanRunId}/loadBehaviorsBriefResults/{scriptId}/{fieldName}");
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -236,7 +236,7 @@ public class TestPlanScript implements RunningScriptInterface {
|
||||||
.getResultModelFromAgent();
|
.getResultModelFromAgent();
|
||||||
List<TestPlanScriptResult> testPlanScriptResultList = this
|
List<TestPlanScriptResult> testPlanScriptResultList = this
|
||||||
.getTestPlanFactory().createScriptResultsWithoutId(
|
.getTestPlanFactory().createScriptResultsWithoutId(
|
||||||
scriptResultModel, testPlan, this, new Date());
|
scriptResultModel, this, new Date());
|
||||||
return testPlanScriptResultList;
|
return testPlanScriptResultList;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.info(ExceptionLog.getStackTrace(e));
|
logger.info(ExceptionLog.getStackTrace(e));
|
||||||
|
|
|
@ -175,8 +175,8 @@ public class TestPlanFactory {
|
||||||
|
|
||||||
// new interface
|
// new interface
|
||||||
public List<TestPlanScriptResult> createScriptResultsWithoutId(
|
public List<TestPlanScriptResult> createScriptResultsWithoutId(
|
||||||
ScriptResultModel scriptResultModel, TestPlan testPlan,
|
ScriptResultModel scriptResultModel, TestPlanScript testPlanScript,
|
||||||
TestPlanScript testPlanScript, Date createDatetime) {
|
Date createDatetime) {
|
||||||
|
|
||||||
List<TestPlanScriptResult> testPlanScriptResults = new LinkedList<TestPlanScriptResult>();
|
List<TestPlanScriptResult> testPlanScriptResults = new LinkedList<TestPlanScriptResult>();
|
||||||
Field[] fields = scriptResultModel.getClass().getDeclaredFields();
|
Field[] fields = scriptResultModel.getClass().getDeclaredFields();
|
||||||
|
|
|
@ -73,6 +73,25 @@ public class AgentRepository extends AbstractRepositoty {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean detach(String hostName) {
|
||||||
|
Session session = this.getSessionHelper().openSession();
|
||||||
|
Transaction transaction = session.beginTransaction();
|
||||||
|
try {
|
||||||
|
Agent agent = getAgentBy(hostName, session);
|
||||||
|
if (agent == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
session.delete(agent);
|
||||||
|
transaction.commit();
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
transaction.rollback();
|
||||||
|
return false;
|
||||||
|
} finally {
|
||||||
|
releaseSession(session);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public boolean update(Agent agentForUpdate) {
|
public boolean update(Agent agentForUpdate) {
|
||||||
Session session = this.getSessionHelper().openSession();
|
Session session = this.getSessionHelper().openSession();
|
||||||
Transaction transaction = session.beginTransaction();
|
Transaction transaction = session.beginTransaction();
|
||||||
|
@ -113,8 +132,7 @@ public class AgentRepository extends AbstractRepositoty {
|
||||||
public Agent getAgentBy(String hostName) {
|
public Agent getAgentBy(String hostName) {
|
||||||
Session session = this.getSessionHelper().openSession();
|
Session session = this.getSessionHelper().openSession();
|
||||||
try {
|
try {
|
||||||
Agent agent = (Agent) session.createCriteria(Agent.class)
|
Agent agent = getAgentBy(hostName, session);
|
||||||
.add(Restrictions.eq("hostName", hostName)).uniqueResult();
|
|
||||||
return agent;
|
return agent;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -123,6 +141,11 @@ public class AgentRepository extends AbstractRepositoty {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Agent getAgentBy(String hostName, Session session) {
|
||||||
|
return (Agent) session.createCriteria(Agent.class)
|
||||||
|
.add(Restrictions.eq("hostName", hostName)).uniqueResult();
|
||||||
|
}
|
||||||
|
|
||||||
public Agent getEntity(int id) {
|
public Agent getEntity(int id) {
|
||||||
Session session = this.getSessionHelper().openSession();
|
Session session = this.getSessionHelper().openSession();
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
package org.bench4q.master.domain.service;
|
package org.bench4q.master.domain.service;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import javax.xml.bind.JAXBException;
|
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.bench4q.master.domain.entity.TestPlanScript;
|
import org.bench4q.master.domain.entity.TestPlanScript;
|
||||||
import org.bench4q.master.domain.entity.TestPlanScriptResult;
|
import org.bench4q.master.domain.entity.TestPlanScriptResult;
|
||||||
|
@ -15,7 +12,6 @@ import org.bench4q.master.domain.repository.TestPlanRepository;
|
||||||
import org.bench4q.master.exception.ExceptionLog;
|
import org.bench4q.master.exception.ExceptionLog;
|
||||||
import org.bench4q.master.helper.SessionHelper;
|
import org.bench4q.master.helper.SessionHelper;
|
||||||
import org.bench4q.share.helper.MarshalHelper;
|
import org.bench4q.share.helper.MarshalHelper;
|
||||||
import org.bench4q.share.models.master.ValueTimeModel;
|
|
||||||
import org.bench4q.share.models.master.statistics.ScriptBehaviorsBriefModel;
|
import org.bench4q.share.models.master.statistics.ScriptBehaviorsBriefModel;
|
||||||
import org.bench4q.share.models.master.statistics.ScriptBriefResultModel;
|
import org.bench4q.share.models.master.statistics.ScriptBriefResultModel;
|
||||||
import org.bench4q.share.models.master.statistics.ScriptPagesBriefModel;
|
import org.bench4q.share.models.master.statistics.ScriptPagesBriefModel;
|
||||||
|
@ -27,22 +23,11 @@ import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class TestPlanScriptResultService {
|
public class TestPlanScriptResultService {
|
||||||
private TestPlanScriptService testPlanScriptService;
|
|
||||||
private TestPlanRepository testPlanRepository;
|
private TestPlanRepository testPlanRepository;
|
||||||
private SessionHelper sessionHelper;
|
private SessionHelper sessionHelper;
|
||||||
private static Logger logger = Logger
|
private static Logger logger = Logger
|
||||||
.getLogger(TestPlanScriptResultService.class);
|
.getLogger(TestPlanScriptResultService.class);
|
||||||
|
|
||||||
private TestPlanScriptService getTestPlanScriptService() {
|
|
||||||
return testPlanScriptService;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private void setTestPlanScriptService(
|
|
||||||
TestPlanScriptService testPlanScriptService) {
|
|
||||||
this.testPlanScriptService = testPlanScriptService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SessionHelper getSessionHelper() {
|
public SessionHelper getSessionHelper() {
|
||||||
return sessionHelper;
|
return sessionHelper;
|
||||||
}
|
}
|
||||||
|
@ -61,58 +46,6 @@ public class TestPlanScriptResultService {
|
||||||
this.testPlanRepository = testPlanRepository;
|
this.testPlanRepository = testPlanRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Here I just use the Time that createDateTime in testplanscriptResult, If
|
|
||||||
* it's not accuracy, i just need to modify the way of pick createDateTime
|
|
||||||
*
|
|
||||||
* @param testPlanId
|
|
||||||
* @param scriptId
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public List<ValueTimeModel> loadScriptBriefSpecificField(UUID testPlanId,
|
|
||||||
int scriptId, String fieldName) {
|
|
||||||
List<TestPlanScriptResult> scriptBriefresults = this
|
|
||||||
.getTestPlanScriptService().queryScriptBriefResults(testPlanId,
|
|
||||||
scriptId);
|
|
||||||
List<ValueTimeModel> ret = new ArrayList<ValueTimeModel>();
|
|
||||||
for (TestPlanScriptResult result : scriptBriefresults) {
|
|
||||||
try {
|
|
||||||
ScriptBriefResultModel briefModel = (ScriptBriefResultModel) MarshalHelper
|
|
||||||
.unmarshal(ScriptBriefResultModel.class,
|
|
||||||
result.getResultContent());
|
|
||||||
ret.add(ValueTimeModel.buildValueTimeModel(
|
|
||||||
getSpecificFieldValue(briefModel, fieldName),
|
|
||||||
result.getCreateDatetime()));
|
|
||||||
} catch (JAXBException e) {
|
|
||||||
logger.info(ExceptionLog.getStackTrace(e)
|
|
||||||
+ " When unmarshal the model from ResultCOntent");
|
|
||||||
continue;
|
|
||||||
} catch (NoSuchFieldException e) {
|
|
||||||
logger.info(ExceptionLog.getStackTrace(e)
|
|
||||||
+ " When get Field from the model from ResultCOntent");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
private long getSpecificFieldValue(ScriptBriefResultModel briefModel,
|
|
||||||
String fieldName) throws NoSuchFieldException {
|
|
||||||
try {
|
|
||||||
Field field = getFieldAndSetAccessible(briefModel, fieldName);
|
|
||||||
return (Long) field.get(briefModel);
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new NoSuchFieldException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Field getFieldAndSetAccessible(ScriptBriefResultModel briefModel,
|
|
||||||
String fieldName) throws NoSuchFieldException, SecurityException {
|
|
||||||
Field field = briefModel.getClass().getDeclaredField(fieldName);
|
|
||||||
field.setAccessible(true);
|
|
||||||
return field;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ScriptBriefResultModel> loadScriptBriefWithDuation(
|
public List<ScriptBriefResultModel> loadScriptBriefWithDuation(
|
||||||
UUID testPlanId, int scriptId, long startTime) {
|
UUID testPlanId, int scriptId, long startTime) {
|
||||||
Session session = this.getSessionHelper().openSession();
|
Session session = this.getSessionHelper().openSession();
|
||||||
|
@ -136,7 +69,8 @@ public class TestPlanScriptResultService {
|
||||||
UUID testPlanId, int scriptId, long startTime, Class<?> resultType,
|
UUID testPlanId, int scriptId, long startTime, Class<?> resultType,
|
||||||
Session session) {
|
Session session) {
|
||||||
TestPlanScript testPlanScript = this.getTestPlanRepository()
|
TestPlanScript testPlanScript = this.getTestPlanRepository()
|
||||||
.getTestPlanInDomainBy(testPlanId).extracSpecifiedScript(scriptId);
|
.getTestPlanInDomainBy(testPlanId)
|
||||||
|
.extracSpecifiedScript(scriptId);
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
List<TestPlanScriptResult> results = (List<TestPlanScriptResult>) session
|
List<TestPlanScriptResult> results = (List<TestPlanScriptResult>) session
|
||||||
.createCriteria(TestPlanScriptResult.class)
|
.createCriteria(TestPlanScriptResult.class)
|
||||||
|
@ -169,7 +103,8 @@ public class TestPlanScriptResultService {
|
||||||
private TestPlanScriptResult doGetLastSampleResult(UUID testPlanId,
|
private TestPlanScriptResult doGetLastSampleResult(UUID testPlanId,
|
||||||
int scriptId, Class<?> resultType, Session session) {
|
int scriptId, Class<?> resultType, Session session) {
|
||||||
TestPlanScript testPlanScript = this.getTestPlanRepository()
|
TestPlanScript testPlanScript = this.getTestPlanRepository()
|
||||||
.getTestPlanInDomainBy(testPlanId).extracSpecifiedScript(scriptId);
|
.getTestPlanInDomainBy(testPlanId)
|
||||||
|
.extracSpecifiedScript(scriptId);
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
List<TestPlanScriptResult> results = (List<TestPlanScriptResult>) session
|
List<TestPlanScriptResult> results = (List<TestPlanScriptResult>) session
|
||||||
.createCriteria(TestPlanScriptResult.class)
|
.createCriteria(TestPlanScriptResult.class)
|
||||||
|
|
|
@ -155,6 +155,7 @@ public class HighAvailablePoolImpl extends CurrentLoadSubject implements
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
runningAgent.substituteOnBoard();
|
runningAgent.substituteOnBoard();
|
||||||
|
this.getAgentRunIdShouldBeSubstitute().remove(agentRunId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,6 @@ public class Test_HighAvailableWithActualMessenger extends
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void prepare() {
|
public void prepare() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package org.bench4q.master.unitTest.service;
|
package org.bench4q.master.integrated;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
|
@ -2,7 +2,6 @@ package org.bench4q.master.integrated;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.bench4q.master.domain.entity.RunningAgentDB;
|
import org.bench4q.master.domain.entity.RunningAgentDB;
|
||||||
|
@ -11,7 +10,6 @@ import org.bench4q.master.domain.entity.TestPlanScript;
|
||||||
import org.bench4q.master.domain.factory.TestPlanFactory;
|
import org.bench4q.master.domain.factory.TestPlanFactory;
|
||||||
import org.bench4q.master.unitTest.TestBase_MakeUpTestPlan;
|
import org.bench4q.master.unitTest.TestBase_MakeUpTestPlan;
|
||||||
import org.bench4q.share.enums.master.TestPlanStatus;
|
import org.bench4q.share.enums.master.TestPlanStatus;
|
||||||
import org.bench4q.share.models.master.ValueTimeModel;
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -77,12 +75,6 @@ public class Test_TestPlan extends TestBase_MakeUpTestPlan {
|
||||||
assertNotNull(runningAgentDB);
|
assertNotNull(runningAgentDB);
|
||||||
assertEquals(EACH_SCRIPT_LOAD_SMALLSCALE, runningAgentDB.getLoadInUse());
|
assertEquals(EACH_SCRIPT_LOAD_SMALLSCALE, runningAgentDB.getLoadInUse());
|
||||||
Thread.sleep(10000);
|
Thread.sleep(10000);
|
||||||
List<ValueTimeModel> valueTimeModels = this
|
|
||||||
.getTestPlanScriptResultService().loadScriptBriefSpecificField(
|
|
||||||
getTestPlanRunIdUuid(), getScriptId(),
|
|
||||||
"averageResponseTime");
|
|
||||||
assertNotNull(valueTimeModels);
|
|
||||||
assertTrue(valueTimeModels.size() > 0);
|
|
||||||
while (!TestPlanStatus.valueOf(
|
while (!TestPlanStatus.valueOf(
|
||||||
this.getTestPlanRepository()
|
this.getTestPlanRepository()
|
||||||
.getTestPlanInDomainBy(getTestPlanRunIdUuid())
|
.getTestPlanInDomainBy(getTestPlanRunIdUuid())
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package org.bench4q.master.unitTest.infrastructure.communication;
|
package org.bench4q.master.integrated.communication;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package org.bench4q.master.unitTest.infrastructure.communication;
|
package org.bench4q.master.integrated.communication;
|
||||||
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
|
@ -10,6 +10,7 @@ import org.bench4q.share.communication.HttpRequester.HttpResponse;
|
||||||
import org.bench4q.share.helper.MarshalHelper;
|
import org.bench4q.share.helper.MarshalHelper;
|
||||||
import org.bench4q.share.models.master.AgentModel;
|
import org.bench4q.share.models.master.AgentModel;
|
||||||
import org.bench4q.share.models.master.AgentResponseModel;
|
import org.bench4q.share.models.master.AgentResponseModel;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class AgentPoolControllerTest extends TestBase {
|
public class AgentPoolControllerTest extends TestBase {
|
||||||
|
@ -17,6 +18,11 @@ public class AgentPoolControllerTest extends TestBase {
|
||||||
private final static String HOSTNAME1 = "127.0.0.1";
|
private final static String HOSTNAME1 = "127.0.0.1";
|
||||||
private final static String HOSTNAME2 = "133.133.12.9";
|
private final static String HOSTNAME2 = "133.133.12.9";
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void prepare() {
|
||||||
|
this.setAccessTocken(this.login());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAdd() throws JAXBException, IOException {
|
public void testAdd() throws JAXBException, IOException {
|
||||||
this.setAccessTocken(this.login());
|
this.setAccessTocken(this.login());
|
||||||
|
|
|
@ -66,6 +66,7 @@ public class PluginControllerTest extends TestBase {
|
||||||
this.paramInPluginCount = 7;
|
this.paramInPluginCount = 7;
|
||||||
this.getTest_PluginHelper().addPlugin(fileName,
|
this.getTest_PluginHelper().addPlugin(fileName,
|
||||||
this.getPluginService(), pluginName);
|
this.getPluginService(), pluginName);
|
||||||
|
this.setAccessTocken(this.login());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -7,12 +7,18 @@ import java.util.Map;
|
||||||
import javax.xml.bind.JAXBException;
|
import javax.xml.bind.JAXBException;
|
||||||
|
|
||||||
import org.bench4q.share.communication.HttpRequester.HttpResponse;
|
import org.bench4q.share.communication.HttpRequester.HttpResponse;
|
||||||
|
import org.junit.Before;
|
||||||
|
|
||||||
public class RecordPortControllerTest extends TestBase {
|
public class RecordPortControllerTest extends TestBase {
|
||||||
private final String URLSTRING = BASE_URL + "/RecordPort";
|
private final String URLSTRING = BASE_URL + "/RecordPort";
|
||||||
private final String PORT = "1100";
|
private final String PORT = "1100";
|
||||||
private final String PARAM1 = "port";
|
private final String PARAM1 = "port";
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void prepare() {
|
||||||
|
this.setAccessTocken(this.login());
|
||||||
|
}
|
||||||
|
|
||||||
public void AddPortToPool() throws IOException, JAXBException {
|
public void AddPortToPool() throws IOException, JAXBException {
|
||||||
String accesTocken = this.login();
|
String accesTocken = this.login();
|
||||||
Map<String, String> params = new HashMap<String, String>();
|
Map<String, String> params = new HashMap<String, String>();
|
||||||
|
|
|
@ -13,12 +13,18 @@ import org.bench4q.share.helper.MarshalHelper;
|
||||||
import org.bench4q.share.models.agent.RunScenarioModel;
|
import org.bench4q.share.models.agent.RunScenarioModel;
|
||||||
import org.bench4q.share.models.master.OperateScriptServerResponseModel;
|
import org.bench4q.share.models.master.OperateScriptServerResponseModel;
|
||||||
import org.bench4q.share.models.master.ScriptModel;
|
import org.bench4q.share.models.master.ScriptModel;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class RecordScriptControllerTest extends TestBase {
|
public class RecordScriptControllerTest extends TestBase {
|
||||||
private static final int RECORD_TIME = 60000;
|
private static final int RECORD_TIME = 60000;
|
||||||
private final String SCRIPT_URL = TestBase.BASE_URL + "/RecordScript";
|
private final String SCRIPT_URL = TestBase.BASE_URL + "/RecordScript";
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void prepare() {
|
||||||
|
this.setAccessTocken(this.login());
|
||||||
|
}
|
||||||
|
|
||||||
public OperateScriptServerResponseModel startRecord() throws IOException,
|
public OperateScriptServerResponseModel startRecord() throws IOException,
|
||||||
JAXBException {
|
JAXBException {
|
||||||
HttpResponse httpResponse = this.httpRequester.sendPost(this.SCRIPT_URL
|
HttpResponse httpResponse = this.httpRequester.sendPost(this.SCRIPT_URL
|
||||||
|
|
|
@ -11,12 +11,18 @@ import javax.xml.bind.JAXBException;
|
||||||
import org.bench4q.share.communication.HttpRequester.HttpResponse;
|
import org.bench4q.share.communication.HttpRequester.HttpResponse;
|
||||||
import org.bench4q.share.helper.MarshalHelper;
|
import org.bench4q.share.helper.MarshalHelper;
|
||||||
import org.bench4q.share.models.master.OperateScriptServerResponseModel;
|
import org.bench4q.share.models.master.OperateScriptServerResponseModel;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class ScriptControllerTest extends TestBase {
|
public class ScriptControllerTest extends TestBase {
|
||||||
|
|
||||||
private String controllerUrl = BASE_URL + "/RecordScript";
|
private String controllerUrl = BASE_URL + "/RecordScript";
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void prepare() {
|
||||||
|
this.setAccessTocken(this.login());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void loadScriptsTest() throws IOException, JAXBException {
|
public void loadScriptsTest() throws IOException, JAXBException {
|
||||||
String url = this.controllerUrl + "/loadScriptList";
|
String url = this.controllerUrl + "/loadScriptList";
|
||||||
|
|
|
@ -28,7 +28,6 @@ public class TestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public TestBase() {
|
public TestBase() {
|
||||||
this.setAccessTocken(this.login());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String login() {
|
public String login() {
|
||||||
|
@ -39,7 +38,7 @@ public class TestBase {
|
||||||
HttpResponse httpResponse;
|
HttpResponse httpResponse;
|
||||||
try {
|
try {
|
||||||
httpResponse = this.httpRequester.sendGet(urlString, map, null);
|
httpResponse = this.httpRequester.sendGet(urlString, map, null);
|
||||||
System.out.println("http content:"+httpResponse.getContent());
|
System.out.println("http content:" + httpResponse.getContent());
|
||||||
return ((AuthorizeResponseModel) MarshalHelper.unmarshal(
|
return ((AuthorizeResponseModel) MarshalHelper.unmarshal(
|
||||||
AuthorizeResponseModel.class, httpResponse.getContent()))
|
AuthorizeResponseModel.class, httpResponse.getContent()))
|
||||||
.getAccessToken();
|
.getAccessToken();
|
||||||
|
|
|
@ -25,6 +25,11 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
public class TestPlanScriptResultControllerTest extends TestBase_MakeUpTestPlan {
|
public class TestPlanScriptResultControllerTest extends TestBase_MakeUpTestPlan {
|
||||||
private String urlString = BASE_URL + "/testPlanResult";
|
private String urlString = BASE_URL + "/testPlanResult";
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void prepare() {
|
||||||
|
this.setAccessTocken(this.login());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetScriptResults() throws IOException, JAXBException {
|
public void testGetScriptResults() throws IOException, JAXBException {
|
||||||
HttpResponse httpResponse = this.httpRequester.sendGet(urlString + "/"
|
HttpResponse httpResponse = this.httpRequester.sendGet(urlString + "/"
|
||||||
|
|
|
@ -8,14 +8,18 @@ import java.util.Map;
|
||||||
|
|
||||||
import javax.xml.bind.JAXBException;
|
import javax.xml.bind.JAXBException;
|
||||||
|
|
||||||
import org.bench4q.master.unitTest.TestBase_MakeUpTestPlan;
|
|
||||||
import org.bench4q.share.communication.HttpRequester;
|
import org.bench4q.share.communication.HttpRequester;
|
||||||
import org.bench4q.share.communication.HttpRequester.HttpResponse;
|
import org.bench4q.share.communication.HttpRequester.HttpResponse;
|
||||||
import org.bench4q.share.helper.MarshalHelper;
|
import org.bench4q.share.helper.MarshalHelper;
|
||||||
import org.bench4q.share.models.master.MonitorMemoryResponseModel;
|
import org.bench4q.share.models.master.MonitorMemoryResponseModel;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class Test_MonitorController extends TestBase_MakeUpTestPlan {
|
public class Test_MonitorController extends TestBase {
|
||||||
|
@Before
|
||||||
|
public void prepare() {
|
||||||
|
this.setAccessTocken(this.login());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMemoryInfo() throws IOException, JAXBException {
|
public void testMemoryInfo() throws IOException, JAXBException {
|
||||||
|
|
|
@ -27,6 +27,7 @@ import org.bench4q.share.models.master.TestPlanResultModel;
|
||||||
import org.bench4q.share.models.master.TestPlanScriptBriefResultModel;
|
import org.bench4q.share.models.master.TestPlanScriptBriefResultModel;
|
||||||
import org.bench4q.share.models.master.statistics.ScriptBriefResultModel;
|
import org.bench4q.share.models.master.statistics.ScriptBriefResultModel;
|
||||||
import org.bench4q.share.models.master.statistics.ScriptPagesBriefModel;
|
import org.bench4q.share.models.master.statistics.ScriptPagesBriefModel;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
@ -72,6 +73,11 @@ public class Test_TestPlanController extends TestBase_MakeUpTestPlan {
|
||||||
this.runAndGetBrief();
|
this.runAndGetBrief();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void prepare() {
|
||||||
|
this.setAccessTocken(this.login());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWithoutBrief() throws JAXBException, IOException,
|
public void testWithoutBrief() throws JAXBException, IOException,
|
||||||
InterruptedException {
|
InterruptedException {
|
||||||
|
|
|
@ -9,12 +9,18 @@ import javax.xml.bind.JAXBException;
|
||||||
import org.bench4q.share.communication.HttpRequester.HttpResponse;
|
import org.bench4q.share.communication.HttpRequester.HttpResponse;
|
||||||
import org.bench4q.share.helper.MarshalHelper;
|
import org.bench4q.share.helper.MarshalHelper;
|
||||||
import org.bench4q.share.models.master.ResultLoadModel;
|
import org.bench4q.share.models.master.ResultLoadModel;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class Test_TestPlanResultController extends TestBase {
|
public class Test_TestPlanResultController extends TestBase {
|
||||||
private static String URL = BASE_URL + "/TestPlanResult";
|
private static String URL = BASE_URL + "/TestPlanResult";
|
||||||
private static String testPlanRunId = "0cdc3398-5b61-4bff-be48-8075e5d2fa64";
|
private static String testPlanRunId = "0cdc3398-5b61-4bff-be48-8075e5d2fa64";
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void prepare() {
|
||||||
|
this.setAccessTocken(this.login());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() {
|
public void test() {
|
||||||
fail("Not yet implemented");
|
fail("Not yet implemented");
|
||||||
|
|
|
@ -10,11 +10,16 @@ import org.bench4q.share.communication.HttpRequester.HttpResponse;
|
||||||
import org.bench4q.share.helper.MarshalHelper;
|
import org.bench4q.share.helper.MarshalHelper;
|
||||||
import org.bench4q.share.models.master.AuthorizeResponseModel;
|
import org.bench4q.share.models.master.AuthorizeResponseModel;
|
||||||
import org.bench4q.share.models.master.RegisterResponseModel;
|
import org.bench4q.share.models.master.RegisterResponseModel;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
public class UserControllerTest extends TestBase {
|
public class UserControllerTest extends TestBase {
|
||||||
|
@Before
|
||||||
|
public void prepare() {
|
||||||
|
this.setAccessTocken(this.login());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNormalAuth() throws IOException, JAXBException {
|
public void testNormalAuth() throws IOException, JAXBException {
|
||||||
|
@ -45,7 +50,7 @@ public class UserControllerTest extends TestBase {
|
||||||
clearUser(userName);
|
clearUser(userName);
|
||||||
String url = BASE_URL + "/user/register";
|
String url = BASE_URL + "/user/register";
|
||||||
Map<String, String> params = new HashMap<String, String>();
|
Map<String, String> params = new HashMap<String, String>();
|
||||||
|
|
||||||
params.put("userName", userName);
|
params.put("userName", userName);
|
||||||
params.put("password", "test");
|
params.put("password", "test");
|
||||||
params.put("scope", "1");
|
params.put("scope", "1");
|
||||||
|
@ -68,7 +73,7 @@ public class UserControllerTest extends TestBase {
|
||||||
AuthorizeResponseModel authorizeResponseModel = (AuthorizeResponseModel) MarshalHelper
|
AuthorizeResponseModel authorizeResponseModel = (AuthorizeResponseModel) MarshalHelper
|
||||||
.tryUnmarshal(AuthorizeResponseModel.class,
|
.tryUnmarshal(AuthorizeResponseModel.class,
|
||||||
httpResponse.getContent());
|
httpResponse.getContent());
|
||||||
|
|
||||||
return authorizeResponseModel;
|
return authorizeResponseModel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,11 +8,10 @@ import java.util.UUID;
|
||||||
|
|
||||||
import org.bench4q.master.domain.RunningAgentInterface;
|
import org.bench4q.master.domain.RunningAgentInterface;
|
||||||
import org.bench4q.master.domain.entity.Agent;
|
import org.bench4q.master.domain.entity.Agent;
|
||||||
import org.bench4q.master.domain.factory.RunningAgentFactory;
|
import org.bench4q.master.domain.entity.TestPlan;
|
||||||
import org.bench4q.master.domain.repository.AgentRepository;
|
import org.bench4q.master.domain.entity.TestPlanScript;
|
||||||
import org.bench4q.master.helper.SessionHelper;
|
|
||||||
import org.bench4q.master.infrastructure.highavailable.impl.HighAvailablePoolImpl;
|
import org.bench4q.master.infrastructure.highavailable.impl.HighAvailablePoolImpl;
|
||||||
import org.bench4q.share.communication.HttpRequester;
|
import org.bench4q.master.unitTest.TestBase_MakeUpTestPlan;
|
||||||
import org.bench4q.share.enums.master.AgentStatus;
|
import org.bench4q.share.enums.master.AgentStatus;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
@ -20,14 +19,10 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
import stubs.Mock_AgentMessenger;
|
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(classes = { HighAvailablePoolImpl.class,
|
@ContextConfiguration(locations = { "classpath:mockHttpMesseger-context.xml" })
|
||||||
AgentRepository.class, Mock_AgentMessenger.class, HttpRequester.class,
|
public class Test_highAvailableWithMockMessenger extends
|
||||||
SessionHelper.class, RunningAgentFactory.class })
|
TestBase_MakeUpTestPlan {
|
||||||
public class Test_highAvailableWithMockMessenger {
|
|
||||||
|
|
||||||
private List<Agent> testCase1 = new ArrayList<Agent>();
|
private List<Agent> testCase1 = new ArrayList<Agent>();
|
||||||
{
|
{
|
||||||
testCase1.add(Agent.createAgentWithoutId("127.0.0.1", 6565, 500));
|
testCase1.add(Agent.createAgentWithoutId("127.0.0.1", 6565, 500));
|
||||||
|
@ -42,12 +37,40 @@ public class Test_highAvailableWithMockMessenger {
|
||||||
testCase1.add(agent2);
|
testCase1.add(agent2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<Agent> testcase2 = new ArrayList<Agent>();
|
||||||
|
{
|
||||||
|
testcase2.add(Agent.createAgentWithoutId("127.0.0.1", 6565));
|
||||||
|
testcase2.add(Agent.createAgentWithoutId("127.0.0.2", 6565));
|
||||||
|
}
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private HighAvailablePoolImpl ha;
|
private HighAvailablePoolImpl ha;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_BreakDown() {
|
public void test_BreakDown() {
|
||||||
assertNotNull(this.ha);
|
this.prepareWith(this.testcase2);
|
||||||
|
synchronized (this.ha) {
|
||||||
|
assertEquals(1000, this.ha.getCurrentAvailableLoad());
|
||||||
|
}
|
||||||
|
this.submitATestPlanWithOneScript();
|
||||||
|
TestPlan testPlan = this.getTestPlanRepository().getTestPlanInDomainBy(
|
||||||
|
getTestPlanRunIdUuid());
|
||||||
|
testPlan.run();
|
||||||
|
// Let ha get the agent's runIds
|
||||||
|
this.ha.checkAllHeartBeat();
|
||||||
|
TestPlanScript runningScript = testPlan
|
||||||
|
.extracSpecifiedScript(getScriptId());
|
||||||
|
assertEquals(1, runningScript.getRunningAgents().size());
|
||||||
|
RunningAgentInterface runningAgentInterface = (RunningAgentInterface) runningScript
|
||||||
|
.getRunningAgents().toArray()[0];
|
||||||
|
// Kill the agent In run
|
||||||
|
runningAgentInterface.getAgent().setCurrentEnumStatus(
|
||||||
|
AgentStatus.BreakDown);
|
||||||
|
// activate ha ckeckAllHeartBeats
|
||||||
|
this.ha.checkAllHeartBeat();
|
||||||
|
assertEquals(2, runningScript.getRunningAgents().size());
|
||||||
|
|
||||||
|
this.cleanUpWith(this.testcase2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -59,15 +82,22 @@ public class Test_highAvailableWithMockMessenger {
|
||||||
|
|
||||||
private void prepareWith(List<Agent> agents) {
|
private void prepareWith(List<Agent> agents) {
|
||||||
this.ha.getPool().clear();
|
this.ha.getPool().clear();
|
||||||
for (Agent agent : this.testCase1) {
|
for (Agent agent : agents) {
|
||||||
this.ha.add(agent);
|
this.ha.add(agent);
|
||||||
}
|
}
|
||||||
|
this.ha.checkAllHeartBeat();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void cleanUpWith(List<Agent> agents) {
|
||||||
|
for (Agent agent : agents) {
|
||||||
|
this.getAgentRepository().detach(agent.getId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_applyFor() {
|
public void test_applyFor() {
|
||||||
|
prepareWith(this.testcase2);
|
||||||
int loadToApply = 10;
|
int loadToApply = 10;
|
||||||
this.ha.checkAllHeartBeat();
|
|
||||||
List<RunningAgentInterface> result = null;
|
List<RunningAgentInterface> result = null;
|
||||||
synchronized (this.ha) {
|
synchronized (this.ha) {
|
||||||
assertTrue(this.ha.getCurrentAvailableLoad() > loadToApply);
|
assertTrue(this.ha.getCurrentAvailableLoad() > loadToApply);
|
||||||
|
|
|
@ -11,6 +11,7 @@ import org.bench4q.master.domain.entity.TestPlan;
|
||||||
import org.bench4q.master.domain.entity.User;
|
import org.bench4q.master.domain.entity.User;
|
||||||
import org.bench4q.master.domain.factory.TestPlanFactory;
|
import org.bench4q.master.domain.factory.TestPlanFactory;
|
||||||
import org.bench4q.master.domain.repository.TestPlanRepository;
|
import org.bench4q.master.domain.repository.TestPlanRepository;
|
||||||
|
import org.bench4q.master.domain.service.AgentService;
|
||||||
import org.bench4q.master.domain.service.MonitorResultService;
|
import org.bench4q.master.domain.service.MonitorResultService;
|
||||||
import org.bench4q.master.exception.Bench4QException;
|
import org.bench4q.master.exception.Bench4QException;
|
||||||
import org.bench4q.master.unitTest.TestBase_MakeUpTestPlan;
|
import org.bench4q.master.unitTest.TestBase_MakeUpTestPlan;
|
||||||
|
@ -28,13 +29,15 @@ import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(locations = { "classpath:service-test-context.xml" })
|
@ContextConfiguration(locations = { "classpath:mockHttpMesseger-context.xml" })
|
||||||
public class Test_MonitorResultService extends TestBase_MakeUpTestPlan {
|
public class Test_MonitorResultService extends TestBase_MakeUpTestPlan {
|
||||||
private String monitor = "133.133.12.3";
|
private String monitor = "133.133.12.3";
|
||||||
private int port = 5556;
|
private int port = 5556;
|
||||||
private MonitorResultService monitorResultService;
|
private MonitorResultService monitorResultService;
|
||||||
private TestPlanRepository testPlanRepository;
|
private TestPlanRepository testPlanRepository;
|
||||||
private TestPlanFactory testPlanFactory;
|
private TestPlanFactory testPlanFactory;
|
||||||
|
@Autowired
|
||||||
|
private AgentService agentService;
|
||||||
|
|
||||||
public TestPlanFactory getTestPlanFactory() {
|
public TestPlanFactory getTestPlanFactory() {
|
||||||
return testPlanFactory;
|
return testPlanFactory;
|
||||||
|
@ -72,12 +75,15 @@ public class Test_MonitorResultService extends TestBase_MakeUpTestPlan {
|
||||||
@Before
|
@Before
|
||||||
public void makeUpTestPlanAndTestPlanScriptAndTestPlanScriptResult()
|
public void makeUpTestPlanAndTestPlanScriptAndTestPlanScriptResult()
|
||||||
throws JAXBException {
|
throws JAXBException {
|
||||||
|
this.agentService.addAgentToPool(Agent.createAgentWithoutId(
|
||||||
|
"127.0.0.1", 6565));
|
||||||
prepareForTestPlanRunning();
|
prepareForTestPlanRunning();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void cleanUp() {
|
public void cleanUp() {
|
||||||
cleanUpForTestPlanRunning();
|
this.getAgentRepository().detach(
|
||||||
|
this.getAgentRepository().getAgentBy("127.0.0.1").getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -124,5 +130,6 @@ public class Test_MonitorResultService extends TestBase_MakeUpTestPlan {
|
||||||
|
|
||||||
assertTrue(networkInterfaceModels.size() >= 1);
|
assertTrue(networkInterfaceModels.size() >= 1);
|
||||||
|
|
||||||
|
cleanUpForTestPlanRunning();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(locations = { "classpath:service-test-context.xml" })
|
@ContextConfiguration(locations = { "classpath:mockHttpMesseger-context.xml" })
|
||||||
public class Test_PluginService extends Test_PluginHelper {
|
public class Test_PluginService extends Test_PluginHelper {
|
||||||
private PluginService pluginService;
|
private PluginService pluginService;
|
||||||
private String pluginName;
|
private String pluginName;
|
||||||
|
|
|
@ -2,8 +2,6 @@ package org.bench4q.master.unitTest.service;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import org.bench4q.master.domain.service.report.ReportService;
|
import org.bench4q.master.domain.service.report.ReportService;
|
||||||
import org.bench4q.master.unitTest.TestBase_MakeUpTestPlan;
|
import org.bench4q.master.unitTest.TestBase_MakeUpTestPlan;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -32,10 +30,4 @@ public class Test_ReportService extends TestBase_MakeUpTestPlan {
|
||||||
assertFalse(this.getReportService().isReportCreated(
|
assertFalse(this.getReportService().isReportCreated(
|
||||||
getTestPlanRunIdUuid()));
|
getTestPlanRunIdUuid()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testCreateReport() {
|
|
||||||
this.getReportService().createReport(
|
|
||||||
UUID.fromString("a75b14de-d99a-49ad-80b8-6ad6078ae726"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(locations = { "classpath:service-test-context.xml" })
|
@ContextConfiguration(locations = { "classpath:mockHttpMesseger-context.xml" })
|
||||||
public class Test_ScriptService {
|
public class Test_ScriptService {
|
||||||
private ScriptService scriptService;
|
private ScriptService scriptService;
|
||||||
private UserService userService;
|
private UserService userService;
|
||||||
|
|
|
@ -1,38 +1,54 @@
|
||||||
package org.bench4q.master.unitTest.service;
|
package org.bench4q.master.unitTest.service;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import org.bench4q.master.Main;
|
import org.bench4q.master.Main;
|
||||||
import org.bench4q.master.domain.entity.Agent;
|
import org.bench4q.master.domain.entity.Agent;
|
||||||
import org.bench4q.master.domain.entity.TestPlan;
|
import org.bench4q.master.domain.entity.TestPlan;
|
||||||
import org.bench4q.master.domain.entity.TestPlanScript;
|
import org.bench4q.master.domain.entity.TestPlanScript;
|
||||||
import org.bench4q.master.domain.entity.User;
|
import org.bench4q.master.domain.entity.User;
|
||||||
|
import org.bench4q.master.domain.service.AgentService;
|
||||||
import org.bench4q.master.unitTest.TestBase_MakeUpTestPlan;
|
import org.bench4q.master.unitTest.TestBase_MakeUpTestPlan;
|
||||||
import org.bench4q.share.enums.master.TestPlanStatus;
|
import org.bench4q.share.enums.master.TestPlanStatus;
|
||||||
import org.bench4q.share.helper.TestHelper;
|
import org.bench4q.share.helper.TestHelper;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.junit.FixMethodOrder;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.junit.runners.MethodSorters;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(locations = { "classpath:service-test-context.xml" })
|
@ContextConfiguration(locations = { "classpath:mockHttpMesseger-context.xml" })
|
||||||
|
@FixMethodOrder(MethodSorters.JVM)
|
||||||
public class Test_TestPlanEngine extends TestBase_MakeUpTestPlan {
|
public class Test_TestPlanEngine extends TestBase_MakeUpTestPlan {
|
||||||
|
@Autowired
|
||||||
|
private AgentService agentService;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void prepare() {
|
public void prepare() {
|
||||||
prepareForTestPlanRunning();
|
synchronized (Test_TestPlanEngine.class) {
|
||||||
submitATestPlanWithOneScript();
|
this.getAgentRepository().detach("147.0.0.1");
|
||||||
|
this.agentService.addAgentToPool(Agent.createAgentWithoutId(
|
||||||
|
"147.0.0.1", 6565));
|
||||||
|
prepareForTestPlanRunning();
|
||||||
|
submitATestPlanWithOneScript();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void cleanUp() {
|
public void cleanUp() {
|
||||||
cleanUpForTestPlanRunning();
|
synchronized (Test_TestPlanEngine.class) {
|
||||||
|
cleanUpForTestPlanRunning();
|
||||||
|
Agent agent = null;
|
||||||
|
if ((agent = this.getAgentRepository().getAgentBy("147.0.01")) != null) {
|
||||||
|
this.getAgentRepository().detach(agent.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -73,11 +89,8 @@ public class Test_TestPlanEngine extends TestBase_MakeUpTestPlan {
|
||||||
public void testRunWithWronglyWhenNoEnoughLoadInPool()
|
public void testRunWithWronglyWhenNoEnoughLoadInPool()
|
||||||
throws InterruptedException {
|
throws InterruptedException {
|
||||||
System.out.println("This need each agent not in running");
|
System.out.println("This need each agent not in running");
|
||||||
User user = this.getUserRepository().getUser("admin");
|
this.submitATestPlanWithOneScript();
|
||||||
int scriptId = getUserFirstScript(user);
|
|
||||||
this.getHaPool().getPool().clear();
|
this.getHaPool().getPool().clear();
|
||||||
this.setTestPlanRunIdUuid(this.getTestPlanEngine().runWith(
|
|
||||||
createATestPlanWithOneScript(scriptId), user));
|
|
||||||
Thread.sleep(10000);
|
Thread.sleep(10000);
|
||||||
TestPlan testPlan = this.getTestPlanRepository().getTestPlanInDomainBy(
|
TestPlan testPlan = this.getTestPlanRepository().getTestPlanInDomainBy(
|
||||||
getTestPlanRunIdUuid());
|
getTestPlanRunIdUuid());
|
||||||
|
@ -105,19 +118,20 @@ public class Test_TestPlanEngine extends TestBase_MakeUpTestPlan {
|
||||||
TestPlanStatus.valueOf(testPlanPicked.getCurrentStatus()));
|
TestPlanStatus.valueOf(testPlanPicked.getCurrentStatus()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
// @Test
|
||||||
public void testPickAndRunByCycle() throws InterruptedException {
|
// public void testPickAndRunByCycle() throws InterruptedException {
|
||||||
this.getHaPool().checkAllHeartBeat();
|
// this.getHaPool().checkAllHeartBeat();
|
||||||
Main.getPortToServe();
|
// assertEquals(500, this.getHaPool().getCurrentAvailableLoad());
|
||||||
UUID testPlanRunId = this.submitATestPlanWithOneScript();
|
// Main.getPortToServe();
|
||||||
Thread.sleep(71000);
|
// UUID testPlanRunId = this.submitATestPlanWithOneScript();
|
||||||
assertEquals(
|
// Thread.sleep(71000);
|
||||||
TestPlanStatus.InRunning,
|
// assertEquals(
|
||||||
TestPlanStatus.valueOf(this.getTestPlanRepository()
|
// TestPlanStatus.InRunning,
|
||||||
.getTestPlanInDomainBy(testPlanRunId)
|
// TestPlanStatus.valueOf(this.getTestPlanRepository()
|
||||||
.getCurrentStatus()));
|
// .getTestPlanInDomainBy(testPlanRunId)
|
||||||
deleteTestPlan();
|
// .getCurrentStatus()));
|
||||||
}
|
// deleteTestPlan();
|
||||||
|
// }
|
||||||
|
|
||||||
private void testForStatus(TestPlanStatus status) throws Exception {
|
private void testForStatus(TestPlanStatus status) throws Exception {
|
||||||
this.submitATestPlanWithOneScript();
|
this.submitATestPlanWithOneScript();
|
||||||
|
|
|
@ -6,10 +6,11 @@ import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bench4q.master.domain.entity.User;
|
import org.bench4q.master.domain.entity.User;
|
||||||
|
import org.bench4q.master.domain.factory.TestPlanFactory;
|
||||||
|
import org.bench4q.master.domain.repository.TestPlanRepository;
|
||||||
|
import org.bench4q.master.domain.service.TestResultSave;
|
||||||
import org.bench4q.master.unitTest.TestBase_MakeUpTestPlan;
|
import org.bench4q.master.unitTest.TestBase_MakeUpTestPlan;
|
||||||
import org.bench4q.share.helper.TestHelper;
|
|
||||||
import org.bench4q.share.models.master.TestPlanModel;
|
import org.bench4q.share.models.master.TestPlanModel;
|
||||||
import org.bench4q.share.models.master.ValueTimeModel;
|
|
||||||
import org.bench4q.share.models.master.statistics.ScriptBehaviorsBriefModel;
|
import org.bench4q.share.models.master.statistics.ScriptBehaviorsBriefModel;
|
||||||
import org.bench4q.share.models.master.statistics.ScriptBriefResultModel;
|
import org.bench4q.share.models.master.statistics.ScriptBriefResultModel;
|
||||||
import org.bench4q.share.models.master.statistics.ScriptPagesBriefModel;
|
import org.bench4q.share.models.master.statistics.ScriptPagesBriefModel;
|
||||||
|
@ -17,49 +18,21 @@ import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(locations = { "classpath:service-test-context.xml" })
|
@ContextConfiguration(locations = { "classpath:service-test-context.xml" })
|
||||||
public class Test_TestPlanScriptResultService extends TestBase_MakeUpTestPlan {
|
public class Test_TestPlanScriptResultService extends TestBase_MakeUpTestPlan {
|
||||||
@Test
|
@Autowired
|
||||||
public void testGetSpecficFieldValue() throws Exception {
|
private TestResultSave testResultSave;
|
||||||
long averageResponseTime = (Long) TestHelper.invokePrivate(
|
|
||||||
this.getTestPlanScriptResultService(), "getSpecificFieldValue",
|
|
||||||
new Class[] { ScriptBriefResultModel.class, String.class },
|
|
||||||
new Object[] { buildScriptBriefResultModel(0),
|
|
||||||
"averageResponseTime" });
|
|
||||||
assertEquals(0, averageResponseTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Autowired
|
||||||
public void testLoadAvgFromScriptBriefResultWithWrongTestPlanID()
|
private TestPlanFactory testPlanFactory;
|
||||||
throws NoSuchFieldException, SecurityException {
|
|
||||||
List<ValueTimeModel> results = this
|
|
||||||
.getTestPlanScriptResultService()
|
|
||||||
.loadScriptBriefSpecificField(
|
|
||||||
UUID.fromString("af67ccd7-ca7b-4dbf-9544-8ffe81b3af2d"),
|
|
||||||
61,
|
|
||||||
ScriptBriefResultModel.class.getDeclaredField(
|
|
||||||
"averageResponseTime").getName());
|
|
||||||
assertEquals(0, results.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Autowired
|
||||||
public void testLoadAvgFromScriptBriefResult() throws NoSuchFieldException,
|
private TestPlanRepository testPlanRepository;
|
||||||
SecurityException, InterruptedException {
|
|
||||||
Thread.sleep(5000);
|
|
||||||
List<ValueTimeModel> results = this.getTestPlanScriptResultService()
|
|
||||||
.loadScriptBriefSpecificField(
|
|
||||||
this.getTestPlanRunIdUuid(),
|
|
||||||
this.getScriptId(),
|
|
||||||
ScriptBriefResultModel.class.getDeclaredField(
|
|
||||||
"averageResponseTime").getName());
|
|
||||||
System.out.println(results.size());
|
|
||||||
assertTrue(results.size() > 0);
|
|
||||||
assertTrue(results.get(1).getValue() % 100 == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLoadScriptBriefWithWrongTestPlanId() {
|
public void testLoadScriptBriefWithWrongTestPlanId() {
|
||||||
|
@ -85,27 +58,6 @@ public class Test_TestPlanScriptResultService extends TestBase_MakeUpTestPlan {
|
||||||
assertNotNull(behavirosResults.isFinished());
|
assertNotNull(behavirosResults.isFinished());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testLoadScriptBriefWithDuation() throws InterruptedException {
|
|
||||||
Thread.sleep(5000);
|
|
||||||
List<ScriptBriefResultModel> results = this
|
|
||||||
.getTestPlanScriptResultService().loadScriptBriefWithDuation(
|
|
||||||
this.getTestPlanRunIdUuid(), this.getScriptId(), 0);
|
|
||||||
ScriptPagesBriefModel scriptPagesBriefModel = this
|
|
||||||
.getTestPlanScriptResultService().getScriptPagesBrief(
|
|
||||||
this.getTestPlanRunIdUuid(), this.getScriptId());
|
|
||||||
ScriptBehaviorsBriefModel behavirosResults = this
|
|
||||||
.getTestPlanScriptResultService().getScriptBehaviorsBrief(
|
|
||||||
this.getTestPlanRunIdUuid(), this.getScriptId());
|
|
||||||
assertEquals(3, results.size());
|
|
||||||
assertNotNull(scriptPagesBriefModel);
|
|
||||||
assertTrue(scriptPagesBriefModel.getScriptPageBriefModels().size() > 0);
|
|
||||||
assertTrue(scriptPagesBriefModel.getScriptPageBriefModels().get(0)
|
|
||||||
.getMaxResponseTimeFromBegin() >= 200);
|
|
||||||
assertNotNull(behavirosResults);
|
|
||||||
assertNotNull(behavirosResults.isFinished());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void makeUpTestPlanAndTestPlanScriptAndTestPlanScriptResult() {
|
public void makeUpTestPlanAndTestPlanScriptAndTestPlanScriptResult() {
|
||||||
UUID testPlanRunId = UUID.randomUUID();
|
UUID testPlanRunId = UUID.randomUUID();
|
||||||
|
@ -114,35 +66,14 @@ public class Test_TestPlanScriptResultService extends TestBase_MakeUpTestPlan {
|
||||||
TestPlanModel model = createATestPlanWithOneScript(this.getScriptId());
|
TestPlanModel model = createATestPlanWithOneScript(this.getScriptId());
|
||||||
this.getTestPlanEngine().submitTestPlan(model, user, testPlanRunId);
|
this.getTestPlanEngine().submitTestPlan(model, user, testPlanRunId);
|
||||||
this.setTestPlanRunIdUuid(testPlanRunId);
|
this.setTestPlanRunIdUuid(testPlanRunId);
|
||||||
/*
|
this.testPlanRepository.getTestPlanInDomainBy(getTestPlanRunIdUuid());
|
||||||
* for (int i = 0; i < 3; i++) {
|
|
||||||
* this.getTestScriptResultSave().doSaveResult(testPlanRunId,
|
|
||||||
* this.getScriptId(), buildScriptBriefResultModel(i), new Date());
|
|
||||||
*
|
|
||||||
* this.getTestScriptResultSave().doSaveResult(testPlanRunId,
|
|
||||||
* this.getScriptId(), new ScriptBehaviorsBriefModel(), new Date());
|
|
||||||
* this.getTestScriptResultSave().doSaveResult(testPlanRunId,
|
|
||||||
* this.getScriptId(), makeUpScriptPagesBriefModel(i), new Date()); }
|
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// private ScriptPagesBriefModel makeUpScriptPagesBriefModel(int i) {
|
|
||||||
// ScriptPagesBriefModel scriptPagesBriefModel = new
|
|
||||||
// ScriptPagesBriefModel();
|
|
||||||
// ScriptPageBriefModel scriptPageBriefModel = new ScriptPageBriefModel();
|
|
||||||
// scriptPageBriefModel.setMaxResponseTimeFromBegin(200 + 10 * i);
|
|
||||||
// scriptPageBriefModel.setMinResponseTimeFromBegin(200 - 10 * i);
|
|
||||||
// scriptPagesBriefModel.getScriptPageBriefModels().add(
|
|
||||||
// scriptPageBriefModel);
|
|
||||||
// return scriptPagesBriefModel;
|
|
||||||
// }
|
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void cleanUp() {
|
public void cleanUp() {
|
||||||
this.getTestPlanService().removeTestPlanInDB(
|
this.getTestPlanService().removeTestPlanInDB(
|
||||||
this.getTestPlanRepository()
|
this.testPlanRepository.getTestPlanInDomainBy(
|
||||||
.getTestPlanInDomainBy(this.getTestPlanRunIdUuid())
|
this.getTestPlanRunIdUuid()).getId());
|
||||||
.getId());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(locations = { "classpath:service-test-context.xml" })
|
@ContextConfiguration(locations = { "classpath:mockHttpMesseger-context.xml" })
|
||||||
public class Test_TestPlanScriptService extends TestBase_MakeUpTestPlan {
|
public class Test_TestPlanScriptService extends TestBase_MakeUpTestPlan {
|
||||||
private static final int WRONG_SCRIPT_ID = 99999;
|
private static final int WRONG_SCRIPT_ID = 99999;
|
||||||
private static final String WRONG_TEST_PLAN_RUN_ID = "0cdca8da-5b61-4bff-be48-8075e5d2fa64";
|
private static final String WRONG_TEST_PLAN_RUN_ID = "0cdca8da-5b61-4bff-be48-8075e5d2fa64";
|
||||||
|
@ -26,10 +26,6 @@ public class Test_TestPlanScriptService extends TestBase_MakeUpTestPlan {
|
||||||
public void prepare() {
|
public void prepare() {
|
||||||
submitATestPlanWithOneScript();
|
submitATestPlanWithOneScript();
|
||||||
System.out.println(getScriptId());
|
System.out.println(getScriptId());
|
||||||
/*
|
|
||||||
* this.getTestScriptResultSave().doSaveResult(getTestPlanRunIdUuid(),
|
|
||||||
* getScriptId(), new ScriptBriefResultModel(), new Date());
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
|
|
@ -45,24 +45,15 @@ public class Test_ScriptLoadCommand extends TestBase_MakeUpTestPlan {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void prepare() {
|
public void prepare() {
|
||||||
buildUpHaPool();
|
this.agentService.addAgentToPool(Agent.createAgentWithoutId(
|
||||||
|
"127.0.0.1", 6565));
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void cleanUp() {
|
public void cleanUp() {
|
||||||
Agent agent = this.getAgentRepository().getAgentBy(Test_AGENT_HOSTNAME);
|
Agent agent = this.getAgentRepository().getAgentBy(Test_AGENT_HOSTNAME);
|
||||||
this.getAgentMessenger().stop(agent, this.getAgentRunId());
|
this.getAgentMessenger().stop(agent, this.getAgentRunId());
|
||||||
agent.setRemainLoad(agent.getMaxLoad());
|
this.getAgentRepository().detach(agent.getId());
|
||||||
this.getAgentRepository().update(agent);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This need a agent in running
|
|
||||||
*/
|
|
||||||
|
|
||||||
private void buildUpHaPool() {
|
|
||||||
assertTrue(this.agentService.addAgentToPool(Agent.createAgentWithoutId(
|
|
||||||
"127.0.0.1", 6565)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -45,7 +45,7 @@ public class Mock_AgentMessenger implements AgentMessenger {
|
||||||
result.setScenarioBriefModel(new AgentBriefStatusModel());
|
result.setScenarioBriefModel(new AgentBriefStatusModel());
|
||||||
result.setPagesBriefModel(new AgentPagesBriefModel());
|
result.setPagesBriefModel(new AgentPagesBriefModel());
|
||||||
result.setBehaviorsBriefModel(new AgentBehaviorsBriefModel());
|
result.setBehaviorsBriefModel(new AgentBehaviorsBriefModel());
|
||||||
return null;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -64,7 +64,7 @@ public class Mock_AgentMessenger implements AgentMessenger {
|
||||||
} else if (agent.getCurrentEnumStatus() == AgentStatus.BreakDown) {
|
} else if (agent.getCurrentEnumStatus() == AgentStatus.BreakDown) {
|
||||||
return null;
|
return null;
|
||||||
} else if (agent.getCurrentEnumStatus() == AgentStatus.InRunning) {
|
} else if (agent.getCurrentEnumStatus() == AgentStatus.InRunning) {
|
||||||
result.getRunningTests().add(UUID.randomUUID());
|
result.getRunningTests().add(this.testId);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Reference in New Issue