refactor
This commit is contained in:
coderfengyun 2014-05-13 08:48:11 +08:00
parent c5f537ee40
commit 78c568a884
11 changed files with 108 additions and 33 deletions

View File

@ -1,7 +1,6 @@
package org.bench4q.master.domain.valueobject.datastatistics;
import org.bench4q.master.infrastructure.communication.impl.MonitorMessenger;
import org.bench4q.master.infrastructure.communication.MonitorMessenger;
import org.bench4q.share.models.monitor.MonitorMain;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@ -16,10 +15,8 @@ public class TestMonitorSampler {
this.monitorMessenger = monitorMessenger;
}
public MonitorMain getMonitorResult( String hostName,
int port) {
return this.monitorMessenger
.monitorModel(hostName, port);
public MonitorMain getMonitorResult(String hostName, int port) {
return this.monitorMessenger.monitorModel(hostName, port);
}
}

View File

@ -0,0 +1,23 @@
package org.bench4q.master.infrastructure.communication;
import org.bench4q.share.models.monitor.MemoryModel;
import org.bench4q.share.models.monitor.MonitorMain;
import org.bench4q.share.models.monitor.NetworkInterfaceModel;
import org.bench4q.share.models.monitor.PhysicalDiskModel;
import org.bench4q.share.models.monitor.ProcessModel;
import org.bench4q.share.models.monitor.ProcessorModel;
public interface MonitorMessenger {
public MonitorMain monitorModel(String hostName, int port);
public PhysicalDiskModel physicalDisk(String hostName, int port);
public MemoryModel memory(String hostName, int port);
public ProcessorModel processor(String hostName, int port);
public NetworkInterfaceModel networkInterface(String hostName, int port);
public ProcessModel process(String hostName, int port);
}

View File

@ -7,6 +7,7 @@ import javax.xml.bind.JAXBException;
import org.apache.log4j.Logger;
import org.bench4q.master.exception.ExceptionLog;
import org.bench4q.master.infrastructure.communication.MonitorMessenger;
import org.bench4q.share.communication.HttpRequester;
import org.bench4q.share.communication.HttpRequester.HttpResponse;
import org.bench4q.share.helper.MarshalHelper;
@ -21,16 +22,16 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class MonitorMessenger {
public class MonitorMessengerImpl implements MonitorMessenger {
private HttpRequester httpRequester;
private Logger logger = Logger.getLogger(MonitorMessenger.class);
private Logger logger = Logger.getLogger(MonitorMessengerImpl.class);
public HttpRequester getHttpRequester() {
private HttpRequester getHttpRequester() {
return httpRequester;
}
@Autowired
public void setHttpRequester(HttpRequester httpRequester) {
private void setHttpRequester(HttpRequester httpRequester) {
this.httpRequester = httpRequester;
}

View File

@ -1,7 +1,7 @@
package MonitorModelTest;
import static org.junit.Assert.*;
import org.bench4q.master.infrastructure.communication.impl.MonitorMessenger;
import org.bench4q.master.infrastructure.communication.impl.MonitorMessengerImpl;
import org.bench4q.share.models.master.MonitorModel;
import org.junit.Assert;
import org.junit.Before;
@ -15,14 +15,14 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@ContextConfiguration(locations = { "classpath:service-test-context.xml" })
public class MonitorModelTest {
private MonitorModel monitor;
private MonitorMessenger monitorMessenger;
private MonitorMessengerImpl monitorMessenger;
public MonitorMessenger getMonitorMessenger() {
public MonitorMessengerImpl getMonitorMessenger() {
return monitorMessenger;
}
@Autowired
public void setMonitorMessenger(MonitorMessenger monitorMessenger) {
public void setMonitorMessenger(MonitorMessengerImpl monitorMessenger) {
this.monitorMessenger = monitorMessenger;
}

View File

@ -3,7 +3,7 @@ package org.bench4q.master.unitTest.infrastructure.communication;
import static org.junit.Assert.assertNotNull;
import org.bench4q.master.domain.entity.Monitor;
import org.bench4q.master.infrastructure.communication.impl.MonitorMessenger;
import org.bench4q.master.infrastructure.communication.impl.MonitorMessengerImpl;
import org.bench4q.share.communication.HttpRequester;
import org.bench4q.share.models.monitor.MemoryModel;
import org.bench4q.share.models.monitor.MonitorMain;
@ -20,20 +20,20 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { MonitorMessenger.class, HttpRequester.class })
@ContextConfiguration(classes = { MonitorMessengerImpl.class, HttpRequester.class })
public class Test_MonitorMessenger {
private Monitor monitor = new Monitor();
private static final int PORT = 5556;
private static final String SUT_HOST_NAME = "133.133.12.3";
private MonitorMessenger monitorService;
private MonitorMessengerImpl monitorService;
private MonitorMessenger getMonitorService() {
private MonitorMessengerImpl getMonitorService() {
return monitorService;
}
@Autowired
private void setMonitorService(MonitorMessenger monitorService) {
private void setMonitorService(MonitorMessengerImpl monitorService) {
this.monitorService = monitorService;
}

View File

@ -2,7 +2,7 @@ package org.bench4q.master.unitTest.service;
import static org.junit.Assert.*;
import org.bench4q.master.infrastructure.communication.impl.MonitorMessenger;
import org.bench4q.master.infrastructure.communication.impl.MonitorMessengerImpl;
import org.bench4q.share.models.monitor.MemoryModel;
import org.bench4q.share.models.monitor.MonitorMain;
import org.bench4q.share.models.monitor.NetworkInterfaceModel;
@ -20,14 +20,14 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
public class Test_MonitorMessenger {
private static final int PORT = 5556;
private static final String SUT_HOST_NAME = "133.133.12.3";
private MonitorMessenger monitorService;
private MonitorMessengerImpl monitorService;
private MonitorMessenger getMonitorService() {
private MonitorMessengerImpl getMonitorService() {
return monitorService;
}
@Autowired
private void setMonitorService(MonitorMessenger monitorService) {
private void setMonitorService(MonitorMessengerImpl monitorService) {
this.monitorService = monitorService;
}

View File

@ -20,10 +20,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import stubs.Mock_AgentMessenger;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:mockHttpMesseger-context.xml" }, classes = { Mock_AgentMessenger.class })
@ContextConfiguration(locations = { "classpath:mockHttpMesseger-context.xml" })
public class Test_ScriptLoadCommand extends TestBase_MakeUpTestPlan {
private static final String Test_AGENT_HOSTNAME = "127.0.0.1";
private AgentService agentService;
@ -47,6 +45,7 @@ public class Test_ScriptLoadCommand extends TestBase_MakeUpTestPlan {
@Before
public void prepare() {
buildUpHaPool();
}
@After

View File

@ -0,0 +1,55 @@
package stubs;
import java.util.Date;
import org.bench4q.master.infrastructure.communication.MonitorMessenger;
import org.bench4q.share.models.monitor.MemoryModel;
import org.bench4q.share.models.monitor.MonitorMain;
import org.bench4q.share.models.monitor.NetworkInterfaceModel;
import org.bench4q.share.models.monitor.PhysicalDiskModel;
import org.bench4q.share.models.monitor.ProcessModel;
import org.bench4q.share.models.monitor.ProcessorModel;
import org.springframework.stereotype.Component;
@Component
public class Mock_MonitorMessenger implements MonitorMessenger {
@Override
public MonitorMain monitorModel(String hostName, int port) {
MonitorMain result = new MonitorMain();
result.setFinished(false);
result.setMemoryModel(new MemoryModel());
result.setNetworkInterfaceModel(new NetworkInterfaceModel());
result.setPhysicalDiskModel(new PhysicalDiskModel());
result.setProcessModel(new ProcessModel());
result.setProcessorModel(new ProcessorModel());
result.setSamplingTime(new Date());
return result;
}
@Override
public PhysicalDiskModel physicalDisk(String hostName, int port) {
return monitorModel(hostName, port).getPhysicalDiskModel();
}
@Override
public MemoryModel memory(String hostName, int port) {
return monitorModel(hostName, port).getMemoryModel();
}
@Override
public ProcessorModel processor(String hostName, int port) {
return monitorModel(hostName, port).getProcessorModel();
}
@Override
public NetworkInterfaceModel networkInterface(String hostName, int port) {
return monitorModel(hostName, port).getNetworkInterfaceModel();
}
@Override
public ProcessModel process(String hostName, int port) {
return monitorModel(hostName, port).getProcessModel();
}
}

View File

@ -8,7 +8,7 @@
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd">
<context:component-scan
base-package="org.bench4q.master.test.testHelper,org.bench4q.master.domain,org.bench4q.master.infrastructure.highavailable,org.bench4q.master.report, org.bench4q.master.helper, org.bench4q.master.testplan, org.bench4q.share, org.bench4q.master.domain.factory, org.bench4q.master.domain.repository" />
base-package="org.bench4q.master.test.testHelper,org.bench4q.master.domain,org.bench4q.master.infrastructure.highavailable,org.bench4q.master.report, org.bench4q.master.helper, org.bench4q.master.testplan, org.bench4q.share, org.bench4q.master.domain.factory, org.bench4q.master.domain.repository, stubs" />
<mvc:annotation-driven />
<task:annotation-driven />
</beans>

View File

@ -67,11 +67,11 @@
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
</dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>

View File

@ -1 +1 @@
masterAddress=127.0.0.1:7979/
masterAddress=127.0.0.1:10086/