diff --git a/Bench4Q-Agent/StorageTest/test.txt b/Bench4Q-Agent/StorageTest/test.txt new file mode 100644 index 00000000..e69de29b diff --git a/Bench4Q-Agent/StorageTest/test_0.xml b/Bench4Q-Agent/StorageTest/test_0.xml new file mode 100644 index 00000000..08e7553e --- /dev/null +++ b/Bench4Q-Agent/StorageTest/test_0.xml @@ -0,0 +1 @@ +test1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true1Get1064text/html2013-12-16T10:01:02.620+08:00httpHttp6true2013-12-16T10:01:02.614+08:00200true \ No newline at end of file diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/ParameterFileCollector.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/ParameterFileCollector.java index ee529586..b48cdda9 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/ParameterFileCollector.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/ParameterFileCollector.java @@ -5,6 +5,7 @@ import java.io.IOException; import java.util.List; import java.util.UUID; +import org.bench4q.share.helper.FileHelper; import org.springframework.stereotype.Component; import org.springframework.web.multipart.MultipartFile; @@ -24,10 +25,7 @@ public class ParameterFileCollector { private String guardDirExists(UUID runId) { String dirPath = "ScenarioParameters" + FILE_SEPARATOR + runId.toString() + FILE_SEPARATOR; - File dirFile = new File(dirPath); - if (!dirFile.exists()) { - dirFile.mkdirs(); - } + FileHelper.guardFolderExist(dirPath); return dirPath; } } diff --git a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/TestWithScriptFile.java b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/TestWithScriptFile.java index f0e802e1..9a86675d 100644 --- a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/TestWithScriptFile.java +++ b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/TestWithScriptFile.java @@ -192,7 +192,7 @@ public class TestWithScriptFile { + "forGoodRecord.xml")); files.add(new File("Scripts" + System.getProperty("file.separator") + "testJD.xml")); - HttpResponse httpResponse = this.getHttpRequester().postFiles( + HttpResponse httpResponse = this.getHttpRequester().postFiles(null, url + "/submitScenarioWithParams", "files[]", files, "scenarioModel", new LinkedList() { private static final long serialVersionUID = 1L; diff --git a/Bench4Q-Master/pom.xml b/Bench4Q-Master/pom.xml index 191b5459..0c89a780 100644 --- a/Bench4Q-Master/pom.xml +++ b/Bench4Q-Master/pom.xml @@ -136,6 +136,13 @@ httpcore-nio 4.3 + + + commons-fileupload + commons-fileupload + 1.2 + + org.bench4q bench4q-recorder diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/Main.java b/Bench4Q-Master/src/main/java/org/bench4q/master/Main.java index 7e22673a..5286f778 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/Main.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/Main.java @@ -15,6 +15,8 @@ public class Main { public static int MAX_FAIL_TIMES = 10; public static int MIN_EXECUTE_INTERVAL_IN_SECONDS = 600; public static int PICK_CYCLE_IN_SECONDS = 60; + public static String SCRIPT_PARAM_ROOT_FOLDER = "ScriptParameterization"; + public static String FILE_SEPARATOR = System.getProperty("file.separator"); public static void main(String[] args) { try { @@ -43,12 +45,15 @@ public class Main { .getProperty("pickTestPlanCycleInSeconds")); Min_Sample_Cycle_InSecond = Integer.parseInt(prop .getProperty("minSampleCycleInSeconds")); + SCRIPT_PARAM_ROOT_FOLDER = prop + .getProperty("scriptParamRootFolder"); } catch (Exception e) { portToUse = 8080; MAX_FAIL_TIMES = 10; MIN_EXECUTE_INTERVAL_IN_SECONDS = 600; PICK_CYCLE_IN_SECONDS = 60; Min_Sample_Cycle_InSecond = 10; + SCRIPT_PARAM_ROOT_FOLDER = "ScriptParameterization"; logger.error("There is no config file for port to serve! where path is " + configFile); } diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/api/ScriptController.java b/Bench4Q-Master/src/main/java/org/bench4q/master/api/ScriptController.java index 46281045..56dfe802 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/api/ScriptController.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/api/ScriptController.java @@ -34,6 +34,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.multipart.MultipartFile; @Controller @RequestMapping("/RecordScript") @@ -152,7 +153,7 @@ public class ScriptController extends BaseController { String content = FileUtils.readFileToString(file); logger.info("when saveToDB, scriptContent is " + content); boolean success = this.getScriptService().saveScript(scriptName, - this.getPrincipal().getId(), content); + this.getPrincipal().getId(), content, null); // this.getUserService().add return buildReponseModel(success, "Save to DataBase!!", "", port, null, null, null); @@ -166,7 +167,8 @@ public class ScriptController extends BaseController { @ResponseBody public OperateScriptServerResponseModel uploadScriptToDB( @PathVariable String scriptName, - @RequestBody RunScenarioModel scenarioModel) + @RequestParam RunScenarioModel scenarioModel, + @RequestParam(value = "paramFiles[]", required = false) List paramFiles) throws Bench4QException { if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) { throw new Bench4QException(HAVE_NO_POWER, HAVE_NO_POWER @@ -177,7 +179,8 @@ public class ScriptController extends BaseController { scriptName, this.getPrincipal().getId(), MarshalHelper - .marshal(RunScenarioModel.class, scenarioModel)); + .marshal(RunScenarioModel.class, scenarioModel), + paramFiles); logger.info("upload script:" + MarshalHelper.marshal(RunScenarioModel.class, scenarioModel)); diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/Script.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/Script.java index e4c84d4d..3bca4a2c 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/Script.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/Script.java @@ -1,6 +1,9 @@ package org.bench4q.master.domain.entity; +import java.io.File; +import java.io.IOException; import java.util.Date; +import java.util.List; import javax.persistence.Column; import javax.persistence.Entity; @@ -11,6 +14,10 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; +import org.bench4q.master.Main; +import org.bench4q.share.helper.FileHelper; +import org.springframework.web.multipart.MultipartFile; + @Entity @Table(name = "Script") public class Script { @@ -79,13 +86,29 @@ public class Script { } public static Script createScriptWithoutId(String name, - String scriptContent, User user) { + String scriptContent, User user, List paramFiles) { Script script = new Script(); script.setBehaviorCount(0); script.setCreateDateTime(new Date()); script.setName(name); script.setScriptContent(scriptContent); script.setUser(user); + script.saveScriptParamFiles(paramFiles); return script; } + + private void saveScriptParamFiles(List paramFiles) { + String folderPath = Main.SCRIPT_PARAM_ROOT_FOLDER + Main.FILE_SEPARATOR + + this.getId() + Main.FILE_SEPARATOR; + FileHelper.guardFolderExist(folderPath); + for (MultipartFile multipartFile : paramFiles) { + try { + multipartFile.transferTo(new File(folderPath + + Main.FILE_SEPARATOR + + multipartFile.getOriginalFilename())); + } catch (IllegalStateException | IOException e) { + throw new RuntimeException(e); + } + } + } } diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/TestPlanScript.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/TestPlanScript.java index f067538b..6b94754e 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/TestPlanScript.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/TestPlanScript.java @@ -31,10 +31,10 @@ import org.bench4q.master.domain.service.TestPlanService; import org.bench4q.master.domain.valueobject.datastatistics.RunningScriptSampler; import org.bench4q.master.domain.valueobject.schedulscript.ExecutionOverTask; import org.bench4q.master.domain.valueobject.schedulscript.WarmUpOverTask; +import org.bench4q.master.domain.valueobject.transaction.Transaction; +import org.bench4q.master.domain.valueobject.transaction.TransactionFactory; import org.bench4q.master.exception.ExceptionLog; import org.bench4q.master.infrastructure.communication.AgentMessenger; -import org.bench4q.master.infrastructure.highavailable.AgentRunBlotter; -import org.bench4q.master.infrastructure.highavailable.faultolerence.StopAgentFault; import org.bench4q.share.helper.MarshalHelper; import org.bench4q.share.models.agent.RunScenarioModel; import org.bench4q.share.models.agent.StopTestModel; @@ -235,7 +235,6 @@ public class TestPlanScript implements RunningScriptInterface { agentsAfterDistribute, this)); this.setSampler(new RunningScriptSampler(Collections .unmodifiableCollection(this.getRunningAgentsDB()))); - this.scheduleAsConfig(); } public List doAfterRun() { @@ -253,6 +252,29 @@ public class TestPlanScript implements RunningScriptInterface { } } + public boolean distributeLoad() { + return this.distributeLoad(this.getRequireLoad()); + } + + @SuppressWarnings("unchecked") + public boolean distributeLoad(int requiredLoad) { + Transaction scriptLoadCommand = TransactionFactory + .buildScriptTransaction(this, this.getRequireLoad()); + List runningAgents = null; + try { + runningAgents = (List) scriptLoadCommand + .execute(); + } catch (Exception e) { + logger.error("distribute load error, the runningAgents is null", e); + scriptLoadCommand.rollBack(); + return false; + } + this.doAfterDistributeLoad(runningAgents); + this.scheduleAsConfig(); + // this.getTestPlanRepository().updateEntity(this.getTestPlan()); + return true; + } + public TestPlanScript doForComplete() { for (RunningAgentInterface runningAgent : this.getRunningAgentsDB()) { if (runningAgent == null) { @@ -263,7 +285,6 @@ public class TestPlanScript implements RunningScriptInterface { if (resultModel == null || !resultModel.isSuccess()) { logger.error("can't stop the agent with hostName" + runningAgent.getAgent().getHostName()); - doFaultTolerance(runningAgent); continue; } backLoadAndCleanUp(runningAgent); @@ -272,28 +293,10 @@ public class TestPlanScript implements RunningScriptInterface { return this; } - private void doFaultTolerance(RunningAgentInterface runningAgent) { - logger.error("when stop agent with hostName " - + runningAgent.getAgent().getHostName() + " returns null!"); - StopAgentFault stopAgentFault = new StopAgentFault( - AgentRunBlotter.buildAgentRunBlotter(this.getTestPlanID(), - runningAgent)); - stopAgentFault.doTolerance(); - } - private void backLoadAndCleanUp(RunningAgentInterface runningAgent) { String hostName = runningAgent.getAgent().getHostName(); this.getAgentService().backLoadToAgent(hostName, runningAgent.getLoadInUse()); } - public RunningAgentDB extractSpecificRunningAgentDB(String hostName) { - for (RunningAgentDB runningAgentDB : this.getRunningAgentsDB()) { - if (runningAgentDB.getAgent().getHostName().equals(hostName)) { - return runningAgentDB; - } - } - return null; - } - } diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/ScriptService.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/ScriptService.java index 074f8529..3d0eac41 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/ScriptService.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/ScriptService.java @@ -16,6 +16,7 @@ import org.bench4q.share.models.agent.RunScenarioModel; import org.hibernate.criterion.Restrictions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.springframework.web.multipart.MultipartFile; @Component public class ScriptService { @@ -41,11 +42,20 @@ public class ScriptService { this.userRepository = userRepository; } + /** + * + * @param scriptName + * @param userId + * @param scriptContent + * @param paramFiles + * , this param may be null, and is permitted so. + * @return + */ public boolean saveScript(String scriptName, int userId, - String scriptContent) { + String scriptContent, List paramFiles) { return this.getScriptRepositoty().attach( Script.createScriptWithoutId(scriptName, scriptContent, this - .getUserRepository().getEntity(userId))); + .getUserRepository().getEntity(userId), paramFiles)); } public Script getScript(int scriptId) { diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/TestPlanEngine.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/TestPlanEngine.java index ff6cabaa..bbb52e05 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/TestPlanEngine.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/TestPlanEngine.java @@ -118,27 +118,7 @@ public class TestPlanEngine implements TaskCompleteCallback, return; } TestPlanStatus returnStatus = testPlan.run(); - commitTestPlanStaus(returnStatus, testPlan); - } - - private void commitTestPlanStaus(TestPlanStatus returnStatus, - TestPlan testPlan) { - if (returnStatus == TestPlanStatus.InRunning) { - commitInRunning(testPlan); - } else { - commitError(testPlan, returnStatus); - } - } - - private void commitError(TestPlan testPlan, TestPlanStatus errorStatus) { - testPlan.setCurrentStatus(errorStatus.name()); - getTestPlanRepository().updateEntity(testPlan); - } - - private void commitInRunning(TestPlan testPlan) { - testPlan.setCurrentStatus(TestPlanStatus.InRunning.name()); - testPlan.setLastRunningTime(new Date()); - getTestPlanRepository().attachRunningTestPlan(testPlan); + testPlan.setCurrentStatus(returnStatus.name()); getTestPlanRepository().updateEntity(testPlan); } @@ -159,11 +139,7 @@ public class TestPlanEngine implements TaskCompleteCallback, this.getTestPlanRepository().updateEntity(testPlan); } - public void executePendingTestPlan() { - - } - - public TestPlan pickATestPlan() { + public synchronized TestPlan pickATestPlan() { logger.info("enter pick"); try { List criterions = new ArrayList(); @@ -191,4 +167,9 @@ public class TestPlanEngine implements TaskCompleteCallback, return null; } } + + @Override + public void executePendingTestPlan() { + pickATestPlan(); + } } diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/valueobject/LoadDistribute.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/valueobject/LoadDistribute.java index 82068de4..eef6f84c 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/valueobject/LoadDistribute.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/valueobject/LoadDistribute.java @@ -1,15 +1,8 @@ package org.bench4q.master.domain.valueobject; -import java.util.List; - import org.apache.log4j.Logger; -import org.bench4q.master.domain.RunningAgentInterface; -import org.bench4q.master.domain.RunningScriptInterface; import org.bench4q.master.domain.entity.TestPlan; import org.bench4q.master.domain.entity.TestPlanScript; -import org.bench4q.master.domain.repository.TestPlanRepository; -import org.bench4q.master.domain.valueobject.transaction.Transaction; -import org.bench4q.master.domain.valueobject.transaction.TransactionFactory; import org.bench4q.master.infrastructure.highavailable.HighAvailablePool; import org.bench4q.share.enums.master.TestPlanStatus; import org.springframework.beans.factory.annotation.Autowired; @@ -19,7 +12,6 @@ import org.springframework.stereotype.Component; public class LoadDistribute { private HighAvailablePool highAvailableAgentPool; - private TestPlanRepository testPlanRepository; private static Logger logger = Logger.getLogger(LoadDistribute.class); public HighAvailablePool getHighAvailableAgentPool() { @@ -32,15 +24,6 @@ public class LoadDistribute { this.highAvailableAgentPool = highAvailableAgentPool; } - private TestPlanRepository getTestPlanRepository() { - return testPlanRepository; - } - - @Autowired - private void setTestPlanRepository(TestPlanRepository testPlanRepository) { - this.testPlanRepository = testPlanRepository; - } - private boolean hasEnoughCurrentLoad(int totalRequireLoad) { return this.highAvailableAgentPool.getCurrentAvailableLoad() >= totalRequireLoad; } @@ -59,9 +42,9 @@ public class LoadDistribute { logger.info("There is no enough current load in the pool!"); return TestPlanStatus.PendingNoEnoughCurrentLoad; } - for (RunningScriptInterface testPlanScript : testPlanInDomain + for (TestPlanScript testPlanScript : testPlanInDomain .getTestPlanScripts()) { - if (!distributeLoadForScript(testPlanScript)) { + if (!testPlanScript.distributeLoad()) { return TestPlanStatus.ErrorInDistributeLoadForScript; } } @@ -75,43 +58,4 @@ public class LoadDistribute { testPlanInDomain.doAfterRun(); } - private boolean distributeLoadForScript(RunningScriptInterface runningScript) { - return distributeLoadForScript(runningScript, - runningScript.getRequireLoad()); - } - - @SuppressWarnings("unchecked") - public boolean distributeLoadForScript( - RunningScriptInterface runningScript, int requireLoad) { - Transaction scriptLoadCommand = TransactionFactory - .buildScriptTransaction(runningScript, requireLoad); - - List runningAgents = null; - try { - runningAgents = (List) scriptLoadCommand - .execute(); - } catch (Exception e) { - logger.error("distribute load error, the runningAgents is null"); - scriptLoadCommand.rollBack(); - return false; - } - if (runningAgents == null) { - logger.error("distribute load error, the runningAgents is null"); - scriptLoadCommand.rollBack(); - return false; - } - doAfterDistributeLoadSuccessForScript(runningScript, runningAgents); - return true; - } - - private void doAfterDistributeLoadSuccessForScript( - RunningScriptInterface scriptInput, - List runningAgents) { - scriptInput.doAfterDistributeLoad(runningAgents); - if (!(scriptInput instanceof TestPlanScript)) { - return; - } - this.getTestPlanRepository().updateEntity( - ((TestPlanScript) scriptInput).getTestPlan()); - } } diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/valueobject/transaction/impl/ScriptLoadBase.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/valueobject/transaction/impl/ScriptLoadBase.java index a10ff6fd..a0b6309b 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/valueobject/transaction/impl/ScriptLoadBase.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/valueobject/transaction/impl/ScriptLoadBase.java @@ -105,19 +105,14 @@ public abstract class ScriptLoadBase implements Transaction { throw new IllegalArgumentException("runScenarioModel is null!"); } try { - this.runAgentsWithScenario(runScenarioModel, getRequireLoad(), this - .getRunningScript().getScriptId(), this.getTestPlanRunID()); - - if (this.getAgentListThisTime() == null) { - logger.error("runAgentsWithScenario fails where scriptId = " - + this.getRunningScript().getScriptId()); - return null; - } if (isNotValidScript(this.getRunningScript())) { logger.error("The running agents of runningScriptModel is null, whose scriptId is" + this.getRunningScript().getScriptId()); - return null; + throw new RuntimeException("Running Script not valid!"); } + this.runAgentsWithScenario(runScenarioModel, getRequireLoad(), this + .getRunningScript().getScriptId(), this.getTestPlanRunID()); + return this.getAgentListThisTime(); } catch (Exception e) { logger.error(ExceptionLog.getStackTrace(e).toString() @@ -125,7 +120,7 @@ public abstract class ScriptLoadBase implements Transaction { + this.getRunningScript().getScriptId() + " and TestPlanID is " + this.getTestPlanRunID().toString()); - return null; + throw new RuntimeException(e); } } diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/infrastructure/communication/AgentMessenger.java b/Bench4Q-Master/src/main/java/org/bench4q/master/infrastructure/communication/AgentMessenger.java index f3dd5f57..47ed70d3 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/infrastructure/communication/AgentMessenger.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/infrastructure/communication/AgentMessenger.java @@ -73,9 +73,10 @@ public class AgentMessenger { try { final String modelCOntent = MarshalHelper .tryMarshal(runScenarioModel); - httpResponse = this.httpRequester.postFiles(buildBaseUrl(agent) - + "/test/submitScenarioWithParams", "files[]", paramFiles, - "scenarioModel", new LinkedList() { + httpResponse = this.httpRequester.postFiles(null, + buildBaseUrl(agent) + "/test/submitScenarioWithParams", + "files[]", paramFiles, "scenarioModel", + new LinkedList() { private static final long serialVersionUID = 1L; { add(modelCOntent); @@ -112,7 +113,8 @@ public class AgentMessenger { return null; } } -//there is bug in here + + // there is bug in here public TestBriefStatusModel scriptBriefAll(Agent agent, UUID runId) { HttpResponse httpResponse = null; try { @@ -129,7 +131,8 @@ public class AgentMessenger { TestBriefStatusModel.class, httpResponse.getContent()); } catch (Exception e) { logIt(httpResponse, e); - logger.error(e.toString() + " When get script all brief the agent with hostName " + logger.error(e.toString() + + " When get script all brief the agent with hostName " + agent.getHostName()); FaultTolerenceFactory.getBriefFaultTolerance(agent).doTolerance(); return null; diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/infrastructure/highavailable/AgentRunBlotter.java b/Bench4Q-Master/src/main/java/org/bench4q/master/infrastructure/highavailable/AgentRunBlotter.java index e902a29f..7943b6a8 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/infrastructure/highavailable/AgentRunBlotter.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/infrastructure/highavailable/AgentRunBlotter.java @@ -7,7 +7,6 @@ import org.bench4q.master.domain.RunningAgentInterface; import org.bench4q.master.domain.entity.TestPlan; import org.bench4q.master.domain.entity.TestPlanScript; import org.bench4q.master.domain.repository.TestPlanRepository; -import org.bench4q.master.domain.valueobject.LoadDistribute; import org.bench4q.master.helper.ApplicationContextHelper; public class AgentRunBlotter { @@ -15,7 +14,6 @@ public class AgentRunBlotter { private UUID testPlanId; private boolean hasSubstitute; private TestPlanRepository testPlanRepository; - private LoadDistribute loadDistribute; public RunningAgentInterface getRunningAgent() { return runningAgent; @@ -49,20 +47,10 @@ public class AgentRunBlotter { this.testPlanRepository = testPlanRepository; } - private LoadDistribute getLoadDistribute() { - return loadDistribute; - } - - private void setLoadDistribute(LoadDistribute loadDistribute) { - this.loadDistribute = loadDistribute; - } - private AgentRunBlotter() { this.setHasSubstitute(false); this.setTestPlanRepository(ApplicationContextHelper.getContext() .getBean(TestPlanRepository.class)); - this.setLoadDistribute(ApplicationContextHelper.getContext().getBean( - LoadDistribute.class)); } private AgentRunBlotter(UUID testPlanID, RunningAgentInterface runningAgent) { @@ -92,8 +80,8 @@ public class AgentRunBlotter { } final TestPlanScript testPlanScript = testPlan .extracSpecifiedScript(getRunningAgent().getScriptId()); - this.getLoadDistribute().distributeLoadForScript(testPlanScript, - this.getRunningAgent().getLoadInUse()); + testPlanScript.distributeLoad(this.getRunningAgent().getLoadInUse()); handleAfterSubstituteOn(); } + } diff --git a/Bench4Q-Master/src/main/resources/org/bench4q/master/config/ServerPort.properties b/Bench4Q-Master/src/main/resources/org/bench4q/master/config/ServerPort.properties index c04e4a9a..0f2db80c 100644 --- a/Bench4Q-Master/src/main/resources/org/bench4q/master/config/ServerPort.properties +++ b/Bench4Q-Master/src/main/resources/org/bench4q/master/config/ServerPort.properties @@ -2,4 +2,5 @@ portToServe=7979 pickTestPlanCycleInSeconds=60 maxFailTime=10 minExcuteIntervalInSeconds=600 -minSampleCycleInSeconds=10 \ No newline at end of file +minSampleCycleInSeconds=10 +scriptParamRootFolder=ScriptParameterization \ No newline at end of file diff --git a/Bench4Q-Master/src/main/resources/org/bench4q/master/config/application-context.xml b/Bench4Q-Master/src/main/resources/org/bench4q/master/config/application-context.xml index 006d76d9..8e688743 100644 --- a/Bench4Q-Master/src/main/resources/org/bench4q/master/config/application-context.xml +++ b/Bench4Q-Master/src/main/resources/org/bench4q/master/config/application-context.xml @@ -10,4 +10,10 @@ + + + + + diff --git a/Bench4Q-Master/src/test/java/org/bench4q/master/test/TestBase_MakeUpTestPlan.java b/Bench4Q-Master/src/test/java/org/bench4q/master/test/TestBase_MakeUpTestPlan.java index 524383f2..85a1e5d7 100644 --- a/Bench4Q-Master/src/test/java/org/bench4q/master/test/TestBase_MakeUpTestPlan.java +++ b/Bench4Q-Master/src/test/java/org/bench4q/master/test/TestBase_MakeUpTestPlan.java @@ -6,6 +6,7 @@ import java.util.UUID; import org.bench4q.master.domain.entity.RunningAgentDB; import org.bench4q.master.domain.entity.TestPlan; +import org.bench4q.master.domain.entity.TestPlanScript; import org.bench4q.master.domain.entity.User; import org.bench4q.master.domain.repository.AgentRepository; import org.bench4q.master.domain.repository.TestPlanRepository; @@ -165,8 +166,6 @@ public class TestBase_MakeUpTestPlan extends TestBase { this.testPlanEngine = testPlanEngine; } - - public UUID getTestPlanRunIdUuid() { return testPlanRunIdUuid; } @@ -213,8 +212,8 @@ public class TestBase_MakeUpTestPlan extends TestBase { TestPlan testPlan = this.getTestPlanRepository().getTestPlanBy( getTestPlanRunIdUuid()); testPlan.setCurrentStatus(TestPlanStatus.Complete.name()); - RunningAgentDB runningAgent = testPlan.extracSpecifiedScript( - getScriptId()).extractSpecificRunningAgentDB( + RunningAgentDB runningAgent = extractRunningAgent( + testPlan.extracSpecifiedScript(getScriptId()), Test_AGENT_HOSTNAME); if (runningAgent == null) return; @@ -226,6 +225,17 @@ public class TestBase_MakeUpTestPlan extends TestBase { this.getTestPlanRepository().detach(testPlan.getId()); } + protected RunningAgentDB extractRunningAgent(TestPlanScript testPlanScript, + String hostName) { + for (RunningAgentDB runningAgentDB : testPlanScript + .getRunningAgentsDB()) { + if (runningAgentDB.getAgent().getHostName().equals(hostName)) { + return runningAgentDB; + } + } + return null; + } + protected UUID submitATestPlanWithOneScript() { return submitATestPlan(1); } diff --git a/Bench4Q-Master/src/test/java/org/bench4q/master/test/domain/testPlan/Test_TestPlan.java b/Bench4Q-Master/src/test/java/org/bench4q/master/test/domain/testPlan/Test_TestPlan.java index 099f02a5..0e7336a1 100644 --- a/Bench4Q-Master/src/test/java/org/bench4q/master/test/domain/testPlan/Test_TestPlan.java +++ b/Bench4Q-Master/src/test/java/org/bench4q/master/test/domain/testPlan/Test_TestPlan.java @@ -47,9 +47,9 @@ public class Test_TestPlan extends TestBase_MakeUpTestPlan { @Test public void testDoAfter() { - + } - + @Test public void testRun() throws InterruptedException { assertTrue(this.getHaPool().getCurrentAvailableLoad() >= 500); @@ -59,8 +59,7 @@ public class Test_TestPlan extends TestBase_MakeUpTestPlan { testPlanFromRepo); TestPlanStatus returnStatus = testPlanInDomain.run(); assertEquals(TestPlanStatus.InRunning, returnStatus); - - + assertTrue(this.getTestPlanRepository().updateEntity(testPlanInDomain)); TestPlan testPlanAfterRun = this.getTestPlanRepository().getTestPlanBy( getTestPlanRunIdUuid()); @@ -77,8 +76,8 @@ public class Test_TestPlan extends TestBase_MakeUpTestPlan { testPlanScript.getRequireLoad()); assertNotNull(testPlanScript.getRunningAgentsDB()); assertEquals(1, testPlanScript.getRunningAgentsDB().size()); - RunningAgentDB runningAgentDB = testPlanScript - .extractSpecificRunningAgentDB(Test_AGENT_HOSTNAME); + RunningAgentDB runningAgentDB = extractRunningAgent(testPlanScript, + Test_AGENT_HOSTNAME); assertNotNull(runningAgentDB); assertEquals(EACH_SCRIPT_LOAD_SMALLSCALE, runningAgentDB.getLoadInUse()); Thread.sleep(10000); diff --git a/Bench4Q-Master/src/test/java/org/bench4q/master/test/service/Test_ScriptService.java b/Bench4Q-Master/src/test/java/org/bench4q/master/test/service/Test_ScriptService.java index d8f953a6..6e59723c 100644 --- a/Bench4Q-Master/src/test/java/org/bench4q/master/test/service/Test_ScriptService.java +++ b/Bench4Q-Master/src/test/java/org/bench4q/master/test/service/Test_ScriptService.java @@ -85,7 +85,7 @@ public class Test_ScriptService { user.getId(), FileUtils.readFileToString(new File("Scripts" + System.getProperty("file.separator") - + "HBaseScript.xml"))); + + "HBaseScript.xml")), null); } private boolean doSaveAScript(User user) throws JAXBException { @@ -93,7 +93,7 @@ public class Test_ScriptService { "ad", user.getId(), MarshalHelper.marshal(RunScenarioModel.class, - new RunScenarioModel())); + new RunScenarioModel()), null); } @Before @@ -110,7 +110,7 @@ public class Test_ScriptService { "adef", user.getId(), MarshalHelper.marshal(RunScenarioModel.class, - new RunScenarioModel()))); + new RunScenarioModel()), null)); assertEquals(1, this.getScriptService().loadScripts(user).size()); } diff --git a/Bench4Q-Share/src/main/java/org/bench4q/share/communication/HttpRequester.java b/Bench4Q-Share/src/main/java/org/bench4q/share/communication/HttpRequester.java index 5fd1d1be..16bac3ae 100644 --- a/Bench4Q-Share/src/main/java/org/bench4q/share/communication/HttpRequester.java +++ b/Bench4Q-Share/src/main/java/org/bench4q/share/communication/HttpRequester.java @@ -13,6 +13,7 @@ import java.nio.charset.Charset; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.methods.PostMethod; @@ -110,10 +111,16 @@ public class HttpRequester { return httpResponse; } - public HttpResponse postFiles(String url, String filePartName, - List files, String stringPartName, List strings) { + public HttpResponse postFiles(Map headers, String url, + String filePartName, List files, String stringPartName, + List strings) { PostMethod postMethod = new PostMethod(url); try { + if (headers != null) { + for (Entry entry : headers.entrySet()) { + postMethod.addParameter(entry.getKey(), entry.getValue()); + } + } Part[] parts = new Part[files.size() + strings.size()]; for (int i = 0; i < files.size(); i++) { parts[i] = new FilePart(filePartName, files.get(i)); diff --git a/Bench4Q-Share/src/main/java/org/bench4q/share/helper/FileHelper.java b/Bench4Q-Share/src/main/java/org/bench4q/share/helper/FileHelper.java new file mode 100644 index 00000000..5c929902 --- /dev/null +++ b/Bench4Q-Share/src/main/java/org/bench4q/share/helper/FileHelper.java @@ -0,0 +1,15 @@ +package org.bench4q.share.helper; + +import java.io.File; + +public class FileHelper { + public static void guardFolderExist(String folderFullPath) { + guardFolderExist(new File(folderFullPath)); + } + + public static void guardFolderExist(File folder) { + if (!folder.exists()) { + folder.mkdirs(); + } + } +} diff --git a/Bench4Q-Web/ScriptParameters/param1.txt b/Bench4Q-Web/ScriptParameters/param1.txt new file mode 100644 index 00000000..8b3a483f --- /dev/null +++ b/Bench4Q-Web/ScriptParameters/param1.txt @@ -0,0 +1,2 @@ +123,234,566 +167,567,789 \ No newline at end of file diff --git a/Bench4Q-Web/src/main/java/org/bench4q/web/service/CommunicateWithMaster.java b/Bench4Q-Web/src/main/java/org/bench4q/web/service/CommunicateWithMaster.java index e52e2533..72381f5e 100644 --- a/Bench4Q-Web/src/main/java/org/bench4q/web/service/CommunicateWithMaster.java +++ b/Bench4Q-Web/src/main/java/org/bench4q/web/service/CommunicateWithMaster.java @@ -4,6 +4,8 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; import java.util.Map; import java.util.Properties; @@ -13,7 +15,9 @@ import org.apache.log4j.Logger; import org.bench4q.share.communication.HttpRequester; import org.bench4q.share.communication.HttpRequester.HttpResponse; import org.bench4q.share.helper.ExceptionLog; +import org.bench4q.share.helper.MarshalHelper; import org.bench4q.share.models.ErrorResponseModel; +import org.bench4q.share.models.agent.RunScenarioModel; import org.bench4q.web.api.BaseControllerService; import org.bench4q.web.exception.CustomGenericException; import org.bench4q.web.extractObjectFromXml.ObjectXmlExchange; @@ -70,6 +74,18 @@ public class CommunicateWithMaster { } + public HttpResponse uploadScriptWithParamFiles(String accessToken, + String scriptName, RunScenarioModel runScenarioModel, + List paramFiles) { + String url = masterAddress + "/uploadScript/" + scriptName; + List stringPart = new LinkedList(); + stringPart.add(MarshalHelper.tryMarshal(runScenarioModel)); + + return this.getHttpRequester().postFiles( + makeAccessTockenMap(accessToken), url, "paramFiles[]", + paramFiles, "", stringPart); + } + public Object getRespnseObjectByPostXml(String accessToken, String url, Class objectClass, String content, String caller) throws CustomGenericException { diff --git a/Bench4Q-Web/src/main/resources/ipConfig.properties b/Bench4Q-Web/src/main/resources/ipConfig.properties index 93407696..63e5d3c0 100644 --- a/Bench4Q-Web/src/main/resources/ipConfig.properties +++ b/Bench4Q-Web/src/main/resources/ipConfig.properties @@ -1 +1 @@ -masterAddress=133.133.12.1:7979/ \ No newline at end of file +masterAddress=127.0.0.1:7979/ \ No newline at end of file diff --git a/Bench4Q-Web/src/test/java/org/bench4q/web/tool/test/Test_CommunicateWithMaster.java b/Bench4Q-Web/src/test/java/org/bench4q/web/tool/test/Test_CommunicateWithMaster.java new file mode 100644 index 00000000..340f53bb --- /dev/null +++ b/Bench4Q-Web/src/test/java/org/bench4q/web/tool/test/Test_CommunicateWithMaster.java @@ -0,0 +1,35 @@ +package org.bench4q.web.tool.test; + +import static org.junit.Assert.*; +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import org.bench4q.share.communication.HttpRequester.HttpResponse; +import org.bench4q.share.helper.TestHelper; +import org.bench4q.share.models.agent.RunScenarioModel; +import org.bench4q.web.service.CommunicateWithMaster; +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; + +public class Test_CommunicateWithMaster { + private CommunicateWithMaster communicateWithMaster = new CommunicateWithMaster(); + private LoginHelper loginHelper = new LoginHelper(); + + @Test + public void test_uploadScriptWithParamFiles() { + String accessToken = this.loginHelper.login(); + List paramFiles = new ArrayList(); + String filePath = "ScriptParameters" + + System.getProperty("file.separator") + "param1.txt"; + TestHelper.createFileIfNotExist(new File(filePath)); + paramFiles.add(new File(filePath)); + HttpResponse httpResponse = this.communicateWithMaster + .uploadScriptWithParamFiles(accessToken, "test_chen", + new RunScenarioModel(), paramFiles); + assertEquals(200, httpResponse.getCode()); + } +}