diff --git a/.gitignore b/.gitignore index a8754446..11ba6f7b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ .project .classpath /.settings -/target \ No newline at end of file +/target +/Scripts +/report +/logs diff --git a/src/main/java/org/bench4q/master/api/TestPlanController.java b/src/main/java/org/bench4q/master/api/TestPlanController.java index aabb8db2..10ff5441 100644 --- a/src/main/java/org/bench4q/master/api/TestPlanController.java +++ b/src/main/java/org/bench4q/master/api/TestPlanController.java @@ -226,7 +226,9 @@ public class TestPlanController extends BaseController { response.setHeader("Content-disposition", "attachment; filename=\"" + testPlanRunID.toString() + ".pdf\""); response.addHeader("Content-Length", "" + pdfBuffer.length); - System.out.println(pdfBuffer.length); + // this.logger.info("report of test plan " + + // testPlanRunID.toString() + // + " length is: " + pdfBuffer.length); response.setContentType("application/pdf"); outputStream.write(pdfBuffer); outputStream.flush(); diff --git a/src/main/java/org/bench4q/master/communication/AgentStateService.java b/src/main/java/org/bench4q/master/communication/AgentStateService.java index 07f1be72..ed91c856 100644 --- a/src/main/java/org/bench4q/master/communication/AgentStateService.java +++ b/src/main/java/org/bench4q/master/communication/AgentStateService.java @@ -7,6 +7,7 @@ import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; +import org.apache.log4j.Logger; import org.bench4q.master.communication.HttpRequester.HttpResponse; import org.bench4q.master.communication.agent.ServerStatusModel; import org.springframework.beans.factory.annotation.Autowired; @@ -15,6 +16,7 @@ import org.springframework.stereotype.Component; @Component public class AgentStateService { private HttpRequester httpRequester = new HttpRequester(); + private static Logger logger = Logger.getLogger(AgentStateService.class); public HttpRequester getHttpRequester() { return httpRequester; @@ -34,10 +36,11 @@ public class AgentStateService { } return _extractServerStatusModel(httpResponse.getContent()); } catch (IOException e) { - System.out.println("agent :" + hostName + " break down!"); + logger.error("agent :" + hostName + " break down!"); return null; } catch (JAXBException e) { - System.out.println("unmarshall happen an exception!"); + logger.error("unmarshall happen an exception! whose host name is: " + + hostName); return null; } } diff --git a/src/main/java/org/bench4q/master/scriptrecord/ScriptCapturer.java b/src/main/java/org/bench4q/master/scriptrecord/ScriptCapturer.java index 2c327cc9..01195cd6 100644 --- a/src/main/java/org/bench4q/master/scriptrecord/ScriptCapturer.java +++ b/src/main/java/org/bench4q/master/scriptrecord/ScriptCapturer.java @@ -54,11 +54,6 @@ public class ScriptCapturer { private void startHttpCaptureProxyServer(int port, String filePath) { try { this.getHttpCaptureMap().get(new Integer(port)).startProxyServer(); - // httpCapture = new HttpCapture(this.getScriptPath(), port, - // HTTPCATUREGENERATOR_STRING, new JTextArea()); - // httpCapture.startProxyServer(); - // System.out.println("INFO: Proxy Server Started at Port: " - // + this.getPortForRecord()); } catch (IOException e1) { System.out.println("Error When build the proxy server!"); e1.printStackTrace(); diff --git a/src/main/java/org/bench4q/master/service/AgentService.java b/src/main/java/org/bench4q/master/service/AgentService.java index 5c86fa3b..1839843d 100644 --- a/src/main/java/org/bench4q/master/service/AgentService.java +++ b/src/main/java/org/bench4q/master/service/AgentService.java @@ -9,6 +9,7 @@ import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; +import org.apache.log4j.Logger; import org.bench4q.master.communication.HttpRequester; import org.bench4q.master.communication.HttpRequester.HttpResponse; import org.bench4q.master.communication.agent.RunScenarioResultModel; @@ -34,6 +35,7 @@ public class AgentService { private SessionHelper sessionHelper; private Object AGENT_LOCK; private HttpRequester httpRequester; + private static Logger logger = Logger.getLogger(AgentService.class); public AgentService() { this.setAgentLock(new Object()); @@ -157,7 +159,8 @@ public class AgentService { agent.setRemainLoad(agent.getRemainLoad() + backLoad); session.merge(agent); transaction.commit(); - System.out.println(agent.getRemainLoad()); + logger.info("The agent with hostname " + agent.getHostName() + + " remainload is " + agent.getRemainLoad()); return true; } catch (Exception e) { e.printStackTrace(); @@ -182,7 +185,8 @@ public class AgentService { agent.setRemainLoad(agent.getRemainLoad() - requireLoad); session.merge(agent); transaction.commit(); - System.out.println(agent.getRemainLoad()); + logger.info("agent with hostname " + agent.getHostName() + + "remain load is " + agent.getRemainLoad()); return true; } catch (Exception e) { e.printStackTrace(); @@ -208,8 +212,9 @@ public class AgentService { } agentFromDB.setRemainLoad(agentFromDB.getMaxLoad()); - Agent agent = (Agent) session.merge(agentFromDB); - System.out.println(agent.getRemainLoad()); + session.merge(agentFromDB); + logger.info("agent with hostname " + agentFromDB.getHostName() + + "remain load is " + agentFromDB.getRemainLoad()); transaction.commit(); return true; } catch (Exception e) { diff --git a/src/test/java/org/bench4q/master/test/AgentPoolControllerTest.java b/src/test/java/org/bench4q/master/test/AgentPoolControllerTest.java index 14c7a570..6dd2c43e 100644 --- a/src/test/java/org/bench4q/master/test/AgentPoolControllerTest.java +++ b/src/test/java/org/bench4q/master/test/AgentPoolControllerTest.java @@ -23,36 +23,32 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @ContextConfiguration(locations = "classpath:applicationContext.xml") public class AgentPoolControllerTest extends TestBase { private final String URLSTRING = "http://localhost:8080/agentManage"; - private final String HOSTNAME = "127.0.0.1"; + private final static String HOSTNAME1 = "127.0.0.1"; + private final static String HOSTNAME2 = "133.133.12.9"; public static void main(String[] args) throws JAXBException, IOException { AgentPoolControllerTest test = new AgentPoolControllerTest(); - test.accessTocken = test.login(); - test.addAgentToPool(); + test.setAccessTocken(test.login()); + test.addAgentToPool(HOSTNAME2); // test.removeAgentToPool(); test.loadAgentsFromPool(); } @Test - public void addAgentToPool() throws JAXBException, IOException { + public void addAgentToPool(String hostName) throws JAXBException, + IOException { String urlString = this.URLSTRING + "/addAgentToPool"; - String content; AgentResponseModel agentResponseModel = new AgentResponseModel(); Agent agent = new Agent(); - agent.setHostName(HOSTNAME); + agent.setHostName(hostName); agent.setMaxLoad(500); agent.setRemainLoad(500); agent.setPort(6565); - content = _marshalAgentToString(agent); - - Map properties = new HashMap(); - properties.put(AUTH_HEADER_PROPERTY, this.ACCES_TOCKEN_STARTER - + this.accessTocken); - HttpResponse httpResponse = this.httpRequester.sendPostXml(urlString, - content, properties); + marshalAgentToString(agent), + makeAccessTockenMap(this.getAccessTocken())); agentResponseModel = _extractAgentResponseModel(httpResponse); @@ -67,7 +63,7 @@ public class AgentPoolControllerTest extends TestBase { String urlString = this.URLSTRING + "/removeAgentFromPool"; Map map = new HashMap(); - map.put("hostName", HOSTNAME); + map.put("hostName", HOSTNAME1); HttpResponse httpResponse = this.httpRequester.sendGet(urlString, map, propertiesMap); System.out.println(httpResponse.getContent()); @@ -95,7 +91,7 @@ public class AgentPoolControllerTest extends TestBase { return agentResponseModel; } - private String _marshalAgentToString(Agent agent) throws JAXBException { + private String marshalAgentToString(Agent agent) throws JAXBException { StringWriter stringWriter = new StringWriter(); Marshaller marshaller = JAXBContext.newInstance(agent.getClass()) .createMarshaller();