Merge Bench4Q-Agent
This commit is contained in:
parent
c765b1746d
commit
16d4ec7248
|
@ -1,17 +1,17 @@
|
|||
<behaviorModel>
|
||||
<id>0</id>
|
||||
<name>Get</name>
|
||||
<parameters>
|
||||
<parameter>
|
||||
<key>url</key>
|
||||
<value>http://133.133.12.3:8080/Bench4QTestCase/testcase.html
|
||||
</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<key>parameters</key>
|
||||
<value></value>
|
||||
</parameter>
|
||||
</parameters>
|
||||
<type>USERBEHAVIOR</type>
|
||||
<use>http</use>
|
||||
<behaviorModel>
|
||||
<id>0</id>
|
||||
<name>Get</name>
|
||||
<parameters>
|
||||
<parameter>
|
||||
<key>url</key>
|
||||
<value>http://133.133.12.3:8080/Bench4QTestCase/testcase.html
|
||||
</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<key>parameters</key>
|
||||
<value></value>
|
||||
</parameter>
|
||||
</parameters>
|
||||
<type>USERBEHAVIOR</type>
|
||||
<use>http</use>
|
||||
</behaviorModel>
|
|
@ -1,146 +1,146 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<runScenario>
|
||||
<batches>
|
||||
<batch>
|
||||
<behaviors>
|
||||
<userBehavior>
|
||||
<id>1</id>
|
||||
<name>Get</name>
|
||||
<parameters>
|
||||
<parameter>
|
||||
<key>url</key>
|
||||
<value>http://133.133.12.3:8080/Bench4QTestCase/testcase.html
|
||||
</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<key>parameters</key>
|
||||
<value></value>
|
||||
</parameter>
|
||||
</parameters>
|
||||
<use>http</use>
|
||||
</userBehavior>
|
||||
</behaviors>
|
||||
<childId>2</childId>
|
||||
<id>0</id>
|
||||
<parentId>-1</parentId>
|
||||
</batch>
|
||||
<batch>
|
||||
<behaviors>
|
||||
<timerBehavior>
|
||||
<id>0</id>
|
||||
<name>Sleep</name>
|
||||
<parameters>
|
||||
<parameter>
|
||||
<key>time</key>
|
||||
<value>2500</value>
|
||||
</parameter>
|
||||
</parameters>
|
||||
<use>timer</use>
|
||||
</timerBehavior>
|
||||
</behaviors>
|
||||
<childId>-1</childId>
|
||||
<id>1</id>
|
||||
<parentId>-1</parentId>
|
||||
</batch>
|
||||
<batch>
|
||||
<behaviors>
|
||||
<userBehavior>
|
||||
<id>3</id>
|
||||
<name>Get</name>
|
||||
<parameters>
|
||||
<parameter>
|
||||
<key>url</key>
|
||||
<value>http://133.133.12.3:8080/Bench4QTestCase/images/3.jpg
|
||||
</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<key>parameters</key>
|
||||
<value></value>
|
||||
</parameter>
|
||||
</parameters>
|
||||
<use>http</use>
|
||||
</userBehavior>
|
||||
<userBehavior>
|
||||
<id>4</id>
|
||||
<name>Get</name>
|
||||
<parameters>
|
||||
<parameter>
|
||||
<key>url</key>
|
||||
<value>http://133.133.12.3:8080/Bench4QTestCase/script/agentTable.js
|
||||
</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<key>parameters</key>
|
||||
<value></value>
|
||||
</parameter>
|
||||
</parameters>
|
||||
<use>http</use>
|
||||
</userBehavior>
|
||||
<userBehavior>
|
||||
<id>5</id>
|
||||
<name>Get</name>
|
||||
<parameters>
|
||||
<parameter>
|
||||
<key>url</key>
|
||||
<value>http://133.133.12.3:8080/Bench4QTestCase/script/base.js
|
||||
</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<key>parameters</key>
|
||||
<value></value>
|
||||
</parameter>
|
||||
</parameters>
|
||||
<use>http</use>
|
||||
</userBehavior>
|
||||
<userBehavior>
|
||||
<id>6</id>
|
||||
<name>Get</name>
|
||||
<parameters>
|
||||
<parameter>
|
||||
<key>url</key>
|
||||
<value>http://133.133.12.3:8080/Bench4QTestCase/images/1.jpg
|
||||
</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<key>parameters</key>
|
||||
<value></value>
|
||||
</parameter>
|
||||
</parameters>
|
||||
<use>http</use>
|
||||
</userBehavior>
|
||||
<userBehavior>
|
||||
<id>7</id>
|
||||
<name>Get</name>
|
||||
<parameters>
|
||||
<parameter>
|
||||
<key>url</key>
|
||||
<value>http://133.133.12.3:8080/Bench4QTestCase/images/2.jpg
|
||||
</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<key>parameters</key>
|
||||
<value></value>
|
||||
</parameter>
|
||||
</parameters>
|
||||
<use>http</use>
|
||||
</userBehavior>
|
||||
</behaviors>
|
||||
<childId>-1</childId>
|
||||
<id>2</id>
|
||||
<parentId>0</parentId>
|
||||
</batch>
|
||||
</batches>
|
||||
<poolSize>0</poolSize>
|
||||
<usePlugins>
|
||||
<usePlugin>
|
||||
<id>http</id>
|
||||
<name>Http</name>
|
||||
<parameters />
|
||||
</usePlugin>
|
||||
<usePlugin>
|
||||
<id>timer</id>
|
||||
<name>ConstantTimer</name>
|
||||
<parameters />
|
||||
</usePlugin>
|
||||
</usePlugins>
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<runScenario>
|
||||
<batches>
|
||||
<batch>
|
||||
<behaviors>
|
||||
<userBehavior>
|
||||
<id>1</id>
|
||||
<name>Get</name>
|
||||
<parameters>
|
||||
<parameter>
|
||||
<key>url</key>
|
||||
<value>http://133.133.12.3:8080/Bench4QTestCase/testcase.html
|
||||
</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<key>parameters</key>
|
||||
<value></value>
|
||||
</parameter>
|
||||
</parameters>
|
||||
<use>http</use>
|
||||
</userBehavior>
|
||||
</behaviors>
|
||||
<childId>2</childId>
|
||||
<id>0</id>
|
||||
<parentId>-1</parentId>
|
||||
</batch>
|
||||
<batch>
|
||||
<behaviors>
|
||||
<timerBehavior>
|
||||
<id>0</id>
|
||||
<name>Sleep</name>
|
||||
<parameters>
|
||||
<parameter>
|
||||
<key>time</key>
|
||||
<value>2500</value>
|
||||
</parameter>
|
||||
</parameters>
|
||||
<use>timer</use>
|
||||
</timerBehavior>
|
||||
</behaviors>
|
||||
<childId>-1</childId>
|
||||
<id>1</id>
|
||||
<parentId>-1</parentId>
|
||||
</batch>
|
||||
<batch>
|
||||
<behaviors>
|
||||
<userBehavior>
|
||||
<id>3</id>
|
||||
<name>Get</name>
|
||||
<parameters>
|
||||
<parameter>
|
||||
<key>url</key>
|
||||
<value>http://133.133.12.3:8080/Bench4QTestCase/images/3.jpg
|
||||
</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<key>parameters</key>
|
||||
<value></value>
|
||||
</parameter>
|
||||
</parameters>
|
||||
<use>http</use>
|
||||
</userBehavior>
|
||||
<userBehavior>
|
||||
<id>4</id>
|
||||
<name>Get</name>
|
||||
<parameters>
|
||||
<parameter>
|
||||
<key>url</key>
|
||||
<value>http://133.133.12.3:8080/Bench4QTestCase/script/agentTable.js
|
||||
</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<key>parameters</key>
|
||||
<value></value>
|
||||
</parameter>
|
||||
</parameters>
|
||||
<use>http</use>
|
||||
</userBehavior>
|
||||
<userBehavior>
|
||||
<id>5</id>
|
||||
<name>Get</name>
|
||||
<parameters>
|
||||
<parameter>
|
||||
<key>url</key>
|
||||
<value>http://133.133.12.3:8080/Bench4QTestCase/script/base.js
|
||||
</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<key>parameters</key>
|
||||
<value></value>
|
||||
</parameter>
|
||||
</parameters>
|
||||
<use>http</use>
|
||||
</userBehavior>
|
||||
<userBehavior>
|
||||
<id>6</id>
|
||||
<name>Get</name>
|
||||
<parameters>
|
||||
<parameter>
|
||||
<key>url</key>
|
||||
<value>http://133.133.12.3:8080/Bench4QTestCase/images/1.jpg
|
||||
</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<key>parameters</key>
|
||||
<value></value>
|
||||
</parameter>
|
||||
</parameters>
|
||||
<use>http</use>
|
||||
</userBehavior>
|
||||
<userBehavior>
|
||||
<id>7</id>
|
||||
<name>Get</name>
|
||||
<parameters>
|
||||
<parameter>
|
||||
<key>url</key>
|
||||
<value>http://133.133.12.3:8080/Bench4QTestCase/images/2.jpg
|
||||
</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<key>parameters</key>
|
||||
<value></value>
|
||||
</parameter>
|
||||
</parameters>
|
||||
<use>http</use>
|
||||
</userBehavior>
|
||||
</behaviors>
|
||||
<childId>-1</childId>
|
||||
<id>2</id>
|
||||
<parentId>0</parentId>
|
||||
</batch>
|
||||
</batches>
|
||||
<poolSize>0</poolSize>
|
||||
<usePlugins>
|
||||
<usePlugin>
|
||||
<id>http</id>
|
||||
<name>Http</name>
|
||||
<parameters />
|
||||
</usePlugin>
|
||||
<usePlugin>
|
||||
<id>timer</id>
|
||||
<name>ConstantTimer</name>
|
||||
<parameters />
|
||||
</usePlugin>
|
||||
</usePlugins>
|
||||
</runScenario>
|
|
@ -1,25 +1,25 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<assembly
|
||||
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
|
||||
<id>publish</id>
|
||||
<formats>
|
||||
<format>tar.gz</format>
|
||||
</formats>
|
||||
<includeBaseDirectory>false</includeBaseDirectory>
|
||||
<dependencySets>
|
||||
<dependencySet>
|
||||
<outputDirectory>lib</outputDirectory>
|
||||
<useProjectArtifact>false</useProjectArtifact>
|
||||
<unpack>false</unpack>
|
||||
<scope>runtime</scope>
|
||||
</dependencySet>
|
||||
</dependencySets>
|
||||
<files>
|
||||
<file>
|
||||
<source>target/bench4q-agent.jar</source>
|
||||
<outputDirectory>/</outputDirectory>
|
||||
</file>
|
||||
</files>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<assembly
|
||||
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
|
||||
<id>publish</id>
|
||||
<formats>
|
||||
<format>tar.gz</format>
|
||||
</formats>
|
||||
<includeBaseDirectory>false</includeBaseDirectory>
|
||||
<dependencySets>
|
||||
<dependencySet>
|
||||
<outputDirectory>lib</outputDirectory>
|
||||
<useProjectArtifact>false</useProjectArtifact>
|
||||
<unpack>false</unpack>
|
||||
<scope>runtime</scope>
|
||||
</dependencySet>
|
||||
</dependencySets>
|
||||
<files>
|
||||
<file>
|
||||
<source>target/bench4q-agent.jar</source>
|
||||
<outputDirectory>/</outputDirectory>
|
||||
</file>
|
||||
</files>
|
||||
</assembly>
|
|
@ -1,64 +1,64 @@
|
|||
package org.bench4q.agent;
|
||||
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
import org.springframework.web.servlet.DispatcherServlet;
|
||||
|
||||
public class AgentServer {
|
||||
private Server server;
|
||||
private int port;
|
||||
|
||||
private Server getServer() {
|
||||
return server;
|
||||
}
|
||||
|
||||
private void setServer(Server server) {
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
private int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
private void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public AgentServer(int port) {
|
||||
this.setPort(port);
|
||||
}
|
||||
|
||||
public boolean start() {
|
||||
try {
|
||||
this.setServer(new Server(this.getPort()));
|
||||
ServletContextHandler servletContextHandler = new ServletContextHandler();
|
||||
ServletHolder servletHolder = servletContextHandler.addServlet(
|
||||
DispatcherServlet.class, "/");
|
||||
servletHolder
|
||||
.setInitParameter("contextConfigLocation",
|
||||
"classpath*:/org/bench4q/agent/config/application-context.xml");
|
||||
servletHolder.setInitOrder(1);
|
||||
this.getServer().setHandler(servletContextHandler);
|
||||
this.getServer().start();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean stop() {
|
||||
try {
|
||||
if (this.getServer() != null) {
|
||||
this.getServer().stop();
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
} finally {
|
||||
this.setServer(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
package org.bench4q.agent;
|
||||
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
import org.springframework.web.servlet.DispatcherServlet;
|
||||
|
||||
public class AgentServer {
|
||||
private Server server;
|
||||
private int port;
|
||||
|
||||
private Server getServer() {
|
||||
return server;
|
||||
}
|
||||
|
||||
private void setServer(Server server) {
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
private int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
private void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public AgentServer(int port) {
|
||||
this.setPort(port);
|
||||
}
|
||||
|
||||
public boolean start() {
|
||||
try {
|
||||
this.setServer(new Server(this.getPort()));
|
||||
ServletContextHandler servletContextHandler = new ServletContextHandler();
|
||||
ServletHolder servletHolder = servletContextHandler.addServlet(
|
||||
DispatcherServlet.class, "/");
|
||||
servletHolder
|
||||
.setInitParameter("contextConfigLocation",
|
||||
"classpath*:/org/bench4q/agent/config/application-context.xml");
|
||||
servletHolder.setInitOrder(1);
|
||||
this.getServer().setHandler(servletContextHandler);
|
||||
this.getServer().start();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean stop() {
|
||||
try {
|
||||
if (this.getServer() != null) {
|
||||
this.getServer().stop();
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
} finally {
|
||||
this.setServer(null);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,49 +1,49 @@
|
|||
package org.bench4q.agent.api;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bench4q.agent.scenario.ScenarioContext;
|
||||
import org.bench4q.agent.scenario.ScenarioEngine;
|
||||
import org.bench4q.share.models.agent.ServerStatusModel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/")
|
||||
public class HomeController {
|
||||
private ScenarioEngine scenarioEngine;
|
||||
|
||||
private ScenarioEngine getScenarioEngine() {
|
||||
return scenarioEngine;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setScenarioEngine(ScenarioEngine scenarioEngine) {
|
||||
this.scenarioEngine = scenarioEngine;
|
||||
}
|
||||
|
||||
@RequestMapping(method = { RequestMethod.GET, RequestMethod.POST })
|
||||
@ResponseBody
|
||||
public ServerStatusModel index() {
|
||||
ServerStatusModel serverStatusModel = new ServerStatusModel();
|
||||
serverStatusModel.setFinishedTests(new ArrayList<UUID>());
|
||||
serverStatusModel.setRunningTests(new ArrayList<UUID>());
|
||||
Map<UUID, ScenarioContext> contexts = new HashMap<UUID, ScenarioContext>(
|
||||
getScenarioEngine().getRunningTests());
|
||||
for (UUID key : contexts.keySet()) {
|
||||
ScenarioContext value = contexts.get(key);
|
||||
if (value.isFinished()) {
|
||||
serverStatusModel.getFinishedTests().add(key);
|
||||
} else {
|
||||
serverStatusModel.getRunningTests().add(key);
|
||||
}
|
||||
}
|
||||
return serverStatusModel;
|
||||
}
|
||||
}
|
||||
package org.bench4q.agent.api;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bench4q.agent.scenario.ScenarioContext;
|
||||
import org.bench4q.agent.scenario.ScenarioEngine;
|
||||
import org.bench4q.share.models.agent.ServerStatusModel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/")
|
||||
public class HomeController {
|
||||
private ScenarioEngine scenarioEngine;
|
||||
|
||||
private ScenarioEngine getScenarioEngine() {
|
||||
return scenarioEngine;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setScenarioEngine(ScenarioEngine scenarioEngine) {
|
||||
this.scenarioEngine = scenarioEngine;
|
||||
}
|
||||
|
||||
@RequestMapping(method = { RequestMethod.GET, RequestMethod.POST })
|
||||
@ResponseBody
|
||||
public ServerStatusModel index() {
|
||||
ServerStatusModel serverStatusModel = new ServerStatusModel();
|
||||
serverStatusModel.setFinishedTests(new ArrayList<UUID>());
|
||||
serverStatusModel.setRunningTests(new ArrayList<UUID>());
|
||||
Map<UUID, ScenarioContext> contexts = new HashMap<UUID, ScenarioContext>(
|
||||
getScenarioEngine().getRunningTests());
|
||||
for (UUID key : contexts.keySet()) {
|
||||
ScenarioContext value = contexts.get(key);
|
||||
if (value.isFinished()) {
|
||||
serverStatusModel.getFinishedTests().add(key);
|
||||
} else {
|
||||
serverStatusModel.getRunningTests().add(key);
|
||||
}
|
||||
}
|
||||
return serverStatusModel;
|
||||
}
|
||||
}
|
|
@ -1,81 +1,81 @@
|
|||
package org.bench4q.agent.api;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bench4q.agent.plugin.BehaviorInfo;
|
||||
import org.bench4q.agent.plugin.ParameterInfo;
|
||||
import org.bench4q.agent.plugin.PluginInfo;
|
||||
import org.bench4q.agent.plugin.PluginManager;
|
||||
import org.bench4q.share.models.agent.BehaviorInfoModel;
|
||||
import org.bench4q.share.models.agent.ParameterInfoModel;
|
||||
import org.bench4q.share.models.agent.PluginInfoListModel;
|
||||
import org.bench4q.share.models.agent.PluginInfoModel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/plugin")
|
||||
public class PluginController {
|
||||
private PluginManager pluginManager;
|
||||
|
||||
public PluginManager getPluginManager() {
|
||||
return pluginManager;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setPluginManager(PluginManager pluginManager) {
|
||||
this.pluginManager = pluginManager;
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public PluginInfoListModel list() {
|
||||
List<PluginInfo> pluginInfos = this.getPluginManager().getPluginInfo();
|
||||
PluginInfoListModel pluginInfoListModel = new PluginInfoListModel();
|
||||
pluginInfoListModel.setPlugins(new ArrayList<PluginInfoModel>());
|
||||
for (PluginInfo pluginInfo : pluginInfos) {
|
||||
PluginInfoModel pluginInfoModel = buildPluginInfoModel(pluginInfo);
|
||||
pluginInfoListModel.getPlugins().add(pluginInfoModel);
|
||||
}
|
||||
return pluginInfoListModel;
|
||||
}
|
||||
|
||||
private PluginInfoModel buildPluginInfoModel(PluginInfo pluginInfo) {
|
||||
PluginInfoModel pluginInfoModel = new PluginInfoModel();
|
||||
pluginInfoModel.setName(pluginInfo.getName());
|
||||
pluginInfoModel.setParameters(new ArrayList<ParameterInfoModel>());
|
||||
for (ParameterInfo param : pluginInfo.getParameters()) {
|
||||
ParameterInfoModel model = buildParameterInfoModel(param);
|
||||
pluginInfoModel.getParameters().add(model);
|
||||
}
|
||||
pluginInfoModel.setBehaviors(new ArrayList<BehaviorInfoModel>());
|
||||
for (BehaviorInfo behaviorInfo : pluginInfo.getBehaviors()) {
|
||||
BehaviorInfoModel behaviorInfoModel = buildBehaviorInfoModel(behaviorInfo);
|
||||
pluginInfoModel.getBehaviors().add(behaviorInfoModel);
|
||||
}
|
||||
return pluginInfoModel;
|
||||
}
|
||||
|
||||
private BehaviorInfoModel buildBehaviorInfoModel(BehaviorInfo behaviorInfo) {
|
||||
BehaviorInfoModel behaviorInfoModel = new BehaviorInfoModel();
|
||||
behaviorInfoModel.setName(behaviorInfo.getName());
|
||||
behaviorInfoModel.setParameters(new ArrayList<ParameterInfoModel>());
|
||||
for (ParameterInfo param : behaviorInfo.getParameters()) {
|
||||
ParameterInfoModel model = buildParameterInfoModel(param);
|
||||
behaviorInfoModel.getParameters().add(model);
|
||||
}
|
||||
return behaviorInfoModel;
|
||||
}
|
||||
|
||||
private ParameterInfoModel buildParameterInfoModel(ParameterInfo param) {
|
||||
ParameterInfoModel model = new ParameterInfoModel();
|
||||
model.setName(param.getName());
|
||||
model.setType(param.getType());
|
||||
return model;
|
||||
}
|
||||
|
||||
}
|
||||
package org.bench4q.agent.api;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bench4q.agent.plugin.BehaviorInfo;
|
||||
import org.bench4q.agent.plugin.ParameterInfo;
|
||||
import org.bench4q.agent.plugin.PluginInfo;
|
||||
import org.bench4q.agent.plugin.PluginManager;
|
||||
import org.bench4q.share.models.agent.BehaviorInfoModel;
|
||||
import org.bench4q.share.models.agent.ParameterInfoModel;
|
||||
import org.bench4q.share.models.agent.PluginInfoListModel;
|
||||
import org.bench4q.share.models.agent.PluginInfoModel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/plugin")
|
||||
public class PluginController {
|
||||
private PluginManager pluginManager;
|
||||
|
||||
public PluginManager getPluginManager() {
|
||||
return pluginManager;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setPluginManager(PluginManager pluginManager) {
|
||||
this.pluginManager = pluginManager;
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public PluginInfoListModel list() {
|
||||
List<PluginInfo> pluginInfos = this.getPluginManager().getPluginInfo();
|
||||
PluginInfoListModel pluginInfoListModel = new PluginInfoListModel();
|
||||
pluginInfoListModel.setPlugins(new ArrayList<PluginInfoModel>());
|
||||
for (PluginInfo pluginInfo : pluginInfos) {
|
||||
PluginInfoModel pluginInfoModel = buildPluginInfoModel(pluginInfo);
|
||||
pluginInfoListModel.getPlugins().add(pluginInfoModel);
|
||||
}
|
||||
return pluginInfoListModel;
|
||||
}
|
||||
|
||||
private PluginInfoModel buildPluginInfoModel(PluginInfo pluginInfo) {
|
||||
PluginInfoModel pluginInfoModel = new PluginInfoModel();
|
||||
pluginInfoModel.setName(pluginInfo.getName());
|
||||
pluginInfoModel.setParameters(new ArrayList<ParameterInfoModel>());
|
||||
for (ParameterInfo param : pluginInfo.getParameters()) {
|
||||
ParameterInfoModel model = buildParameterInfoModel(param);
|
||||
pluginInfoModel.getParameters().add(model);
|
||||
}
|
||||
pluginInfoModel.setBehaviors(new ArrayList<BehaviorInfoModel>());
|
||||
for (BehaviorInfo behaviorInfo : pluginInfo.getBehaviors()) {
|
||||
BehaviorInfoModel behaviorInfoModel = buildBehaviorInfoModel(behaviorInfo);
|
||||
pluginInfoModel.getBehaviors().add(behaviorInfoModel);
|
||||
}
|
||||
return pluginInfoModel;
|
||||
}
|
||||
|
||||
private BehaviorInfoModel buildBehaviorInfoModel(BehaviorInfo behaviorInfo) {
|
||||
BehaviorInfoModel behaviorInfoModel = new BehaviorInfoModel();
|
||||
behaviorInfoModel.setName(behaviorInfo.getName());
|
||||
behaviorInfoModel.setParameters(new ArrayList<ParameterInfoModel>());
|
||||
for (ParameterInfo param : behaviorInfo.getParameters()) {
|
||||
ParameterInfoModel model = buildParameterInfoModel(param);
|
||||
behaviorInfoModel.getParameters().add(model);
|
||||
}
|
||||
return behaviorInfoModel;
|
||||
}
|
||||
|
||||
private ParameterInfoModel buildParameterInfoModel(ParameterInfo param) {
|
||||
ParameterInfoModel model = new ParameterInfoModel();
|
||||
model.setName(param.getName());
|
||||
model.setType(param.getType());
|
||||
return model;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
package org.bench4q.agent.datacollector.impl;
|
||||
|
||||
public class BehaviorResultCollector {
|
||||
|
||||
}
|
||||
package org.bench4q.agent.datacollector.impl;
|
||||
|
||||
public class BehaviorResultCollector {
|
||||
|
||||
}
|
|
@ -1,52 +1,52 @@
|
|||
package org.bench4q.agent.datacollector.impl;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class BehaviorStatusCodeResult {
|
||||
public long count;
|
||||
public long contentLength;
|
||||
public long minResponseTime;
|
||||
public long maxResponseTime;
|
||||
public long totalResponseTimeThisTime;
|
||||
public String contentType;
|
||||
|
||||
public BehaviorStatusCodeResult(String contentType) {
|
||||
this.totalResponseTimeThisTime = 0;
|
||||
this.contentType = contentType;
|
||||
this.count = 0;
|
||||
this.contentLength = 0;
|
||||
this.minResponseTime = Long.MAX_VALUE;
|
||||
this.maxResponseTime = Long.MIN_VALUE;
|
||||
}
|
||||
|
||||
public static boolean isSuccess(int statusCode) {
|
||||
return statusCode == 200;
|
||||
}
|
||||
|
||||
public boolean equals(Object expectedObj) {
|
||||
Field[] fields = this.getClass().getDeclaredFields();
|
||||
boolean equal = true;
|
||||
try {
|
||||
for (Field field : fields) {
|
||||
field.setAccessible(true);
|
||||
if (field.getName().equals("contentType")) {
|
||||
field.get(expectedObj).equals(field.get(this));
|
||||
continue;
|
||||
}
|
||||
if (field.getLong(this) != field.getLong(expectedObj)) {
|
||||
System.out.println(field.getName()
|
||||
+ " is diferent, this is " + field.getLong(this)
|
||||
+ ", and the expected is "
|
||||
+ field.getLong(expectedObj));
|
||||
equal = false;
|
||||
}
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
equal = false;
|
||||
|
||||
}
|
||||
return equal;
|
||||
}
|
||||
package org.bench4q.agent.datacollector.impl;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class BehaviorStatusCodeResult {
|
||||
public long count;
|
||||
public long contentLength;
|
||||
public long minResponseTime;
|
||||
public long maxResponseTime;
|
||||
public long totalResponseTimeThisTime;
|
||||
public String contentType;
|
||||
|
||||
public BehaviorStatusCodeResult(String contentType) {
|
||||
this.totalResponseTimeThisTime = 0;
|
||||
this.contentType = contentType;
|
||||
this.count = 0;
|
||||
this.contentLength = 0;
|
||||
this.minResponseTime = Long.MAX_VALUE;
|
||||
this.maxResponseTime = Long.MIN_VALUE;
|
||||
}
|
||||
|
||||
public static boolean isSuccess(int statusCode) {
|
||||
return statusCode == 200;
|
||||
}
|
||||
|
||||
public boolean equals(Object expectedObj) {
|
||||
Field[] fields = this.getClass().getDeclaredFields();
|
||||
boolean equal = true;
|
||||
try {
|
||||
for (Field field : fields) {
|
||||
field.setAccessible(true);
|
||||
if (field.getName().equals("contentType")) {
|
||||
field.get(expectedObj).equals(field.get(this));
|
||||
continue;
|
||||
}
|
||||
if (field.getLong(this) != field.getLong(expectedObj)) {
|
||||
System.out.println(field.getName()
|
||||
+ " is diferent, this is " + field.getLong(this)
|
||||
+ ", and the expected is "
|
||||
+ field.getLong(expectedObj));
|
||||
equal = false;
|
||||
}
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
equal = false;
|
||||
|
||||
}
|
||||
return equal;
|
||||
}
|
||||
}
|
|
@ -1,110 +1,110 @@
|
|||
package org.bench4q.agent.datacollector.impl;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bench4q.agent.scenario.BehaviorResult;
|
||||
import org.bench4q.agent.scenario.PageResult;
|
||||
import org.bench4q.share.models.agent.statistics.AgentPageBriefModel;
|
||||
|
||||
public class PageResultCollector extends AbstractDataCollector {
|
||||
Map<Integer, PageBrief> pageBriefMap;
|
||||
|
||||
private Map<Integer, PageBrief> getPageBriefMap() {
|
||||
return pageBriefMap;
|
||||
}
|
||||
|
||||
private void setPageBriefMap(Map<Integer, PageBrief> pageBriefMap) {
|
||||
this.pageBriefMap = pageBriefMap;
|
||||
}
|
||||
|
||||
public PageResultCollector() {
|
||||
this.setPageBriefMap(new HashMap<Integer, PageBrief>());
|
||||
}
|
||||
|
||||
public void add(PageResult pageResult) {
|
||||
if (pageResult == null || pageResult.getPageId() < 0) {
|
||||
return;
|
||||
}
|
||||
PageBrief pageBrief = guardTheValueOfThePageIdExists(pageResult
|
||||
.getPageId());
|
||||
pageBrief.countThisTime++;
|
||||
pageBrief.countFromBegin++;
|
||||
pageBrief.totalResponseTimeThisTime += pageResult.getExecuteRange();
|
||||
pageBrief.latesTimeResponseTime = pageResult.getExecuteRange();
|
||||
if (pageResult.getExecuteRange() > pageBrief.maxResponseTimeFromBegin) {
|
||||
pageBrief.maxResponseTimeFromBegin = pageResult.getExecuteRange();
|
||||
}
|
||||
if (pageResult.getExecuteRange() < pageBrief.minResponseTimeFromBegin) {
|
||||
pageBrief.minResponseTimeFromBegin = pageResult.getExecuteRange();
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized PageBrief guardTheValueOfThePageIdExists(int pageId) {
|
||||
if (!this.getPageBriefMap().containsKey(pageId)) {
|
||||
this.getPageBriefMap().put(pageId, new PageBrief());
|
||||
}
|
||||
return this.getPageBriefMap().get(pageId);
|
||||
}
|
||||
|
||||
public Object getPageBriefStatistics(int pageId) {
|
||||
PageBrief pageBrief = guardTheValueOfThePageIdExists(pageId);
|
||||
AgentPageBriefModel result = new AgentPageBriefModel();
|
||||
result.setCountFromBegin(pageBrief.countFromBegin);
|
||||
result.setCountThisTime(pageBrief.countThisTime);
|
||||
result.setMaxResponseTimeFromBegin(pageBrief.maxResponseTimeFromBegin);
|
||||
result.setMinResponseTimeFromBegin(pageBrief.minResponseTimeFromBegin);
|
||||
result.setTotalResponseTimeThisTime(pageBrief.totalResponseTimeThisTime);
|
||||
result.setPageId(pageId);
|
||||
long nowTime = new Date().getTime();
|
||||
result.setTimeFrame(nowTime - pageBrief.lastSampleTime);
|
||||
result.setLatestResponseTime(pageBrief.latesTimeResponseTime);
|
||||
pageBrief.resetTemperatyField();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(BehaviorResult behaviorResult) {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String calculateSavePath(BehaviorResult behaviorResult) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getScenarioBriefStatistics() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, BehaviorStatusCodeResult> getBehaviorBriefStatistics(
|
||||
int id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public class PageBrief {
|
||||
public long lastSampleTime;
|
||||
public long countThisTime;
|
||||
public long totalResponseTimeThisTime;
|
||||
public long maxResponseTimeFromBegin;
|
||||
public long minResponseTimeFromBegin;
|
||||
public long countFromBegin;
|
||||
public long latesTimeResponseTime;
|
||||
|
||||
public PageBrief() {
|
||||
resetTemperatyField();
|
||||
this.maxResponseTimeFromBegin = Long.MIN_VALUE;
|
||||
this.minResponseTimeFromBegin = Long.MAX_VALUE;
|
||||
this.countFromBegin = 0;
|
||||
this.latesTimeResponseTime = 0;
|
||||
}
|
||||
|
||||
public void resetTemperatyField() {
|
||||
this.lastSampleTime = new Date().getTime();
|
||||
this.countThisTime = 0;
|
||||
this.totalResponseTimeThisTime = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
package org.bench4q.agent.datacollector.impl;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bench4q.agent.scenario.BehaviorResult;
|
||||
import org.bench4q.agent.scenario.PageResult;
|
||||
import org.bench4q.share.models.agent.statistics.AgentPageBriefModel;
|
||||
|
||||
public class PageResultCollector extends AbstractDataCollector {
|
||||
Map<Integer, PageBrief> pageBriefMap;
|
||||
|
||||
private Map<Integer, PageBrief> getPageBriefMap() {
|
||||
return pageBriefMap;
|
||||
}
|
||||
|
||||
private void setPageBriefMap(Map<Integer, PageBrief> pageBriefMap) {
|
||||
this.pageBriefMap = pageBriefMap;
|
||||
}
|
||||
|
||||
public PageResultCollector() {
|
||||
this.setPageBriefMap(new HashMap<Integer, PageBrief>());
|
||||
}
|
||||
|
||||
public void add(PageResult pageResult) {
|
||||
if (pageResult == null || pageResult.getPageId() < 0) {
|
||||
return;
|
||||
}
|
||||
PageBrief pageBrief = guardTheValueOfThePageIdExists(pageResult
|
||||
.getPageId());
|
||||
pageBrief.countThisTime++;
|
||||
pageBrief.countFromBegin++;
|
||||
pageBrief.totalResponseTimeThisTime += pageResult.getExecuteRange();
|
||||
pageBrief.latesTimeResponseTime = pageResult.getExecuteRange();
|
||||
if (pageResult.getExecuteRange() > pageBrief.maxResponseTimeFromBegin) {
|
||||
pageBrief.maxResponseTimeFromBegin = pageResult.getExecuteRange();
|
||||
}
|
||||
if (pageResult.getExecuteRange() < pageBrief.minResponseTimeFromBegin) {
|
||||
pageBrief.minResponseTimeFromBegin = pageResult.getExecuteRange();
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized PageBrief guardTheValueOfThePageIdExists(int pageId) {
|
||||
if (!this.getPageBriefMap().containsKey(pageId)) {
|
||||
this.getPageBriefMap().put(pageId, new PageBrief());
|
||||
}
|
||||
return this.getPageBriefMap().get(pageId);
|
||||
}
|
||||
|
||||
public Object getPageBriefStatistics(int pageId) {
|
||||
PageBrief pageBrief = guardTheValueOfThePageIdExists(pageId);
|
||||
AgentPageBriefModel result = new AgentPageBriefModel();
|
||||
result.setCountFromBegin(pageBrief.countFromBegin);
|
||||
result.setCountThisTime(pageBrief.countThisTime);
|
||||
result.setMaxResponseTimeFromBegin(pageBrief.maxResponseTimeFromBegin);
|
||||
result.setMinResponseTimeFromBegin(pageBrief.minResponseTimeFromBegin);
|
||||
result.setTotalResponseTimeThisTime(pageBrief.totalResponseTimeThisTime);
|
||||
result.setPageId(pageId);
|
||||
long nowTime = new Date().getTime();
|
||||
result.setTimeFrame(nowTime - pageBrief.lastSampleTime);
|
||||
result.setLatestResponseTime(pageBrief.latesTimeResponseTime);
|
||||
pageBrief.resetTemperatyField();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(BehaviorResult behaviorResult) {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String calculateSavePath(BehaviorResult behaviorResult) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getScenarioBriefStatistics() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, BehaviorStatusCodeResult> getBehaviorBriefStatistics(
|
||||
int id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public class PageBrief {
|
||||
public long lastSampleTime;
|
||||
public long countThisTime;
|
||||
public long totalResponseTimeThisTime;
|
||||
public long maxResponseTimeFromBegin;
|
||||
public long minResponseTimeFromBegin;
|
||||
public long countFromBegin;
|
||||
public long latesTimeResponseTime;
|
||||
|
||||
public PageBrief() {
|
||||
resetTemperatyField();
|
||||
this.maxResponseTimeFromBegin = Long.MIN_VALUE;
|
||||
this.minResponseTimeFromBegin = Long.MAX_VALUE;
|
||||
this.countFromBegin = 0;
|
||||
this.latesTimeResponseTime = 0;
|
||||
}
|
||||
|
||||
public void resetTemperatyField() {
|
||||
this.lastSampleTime = new Date().getTime();
|
||||
this.countThisTime = 0;
|
||||
this.totalResponseTimeThisTime = 0;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,278 +1,278 @@
|
|||
package org.bench4q.agent.datacollector.impl;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bench4q.agent.scenario.BehaviorResult;
|
||||
import org.bench4q.agent.scenario.PageResult;
|
||||
import org.bench4q.share.models.agent.statistics.AgentBriefStatusModel;
|
||||
|
||||
/**
|
||||
* This class collect the behavior result and statistic it.
|
||||
*
|
||||
* @author coderfengyun
|
||||
*
|
||||
*/
|
||||
public class ScenarioResultCollector extends AbstractDataCollector {
|
||||
private long timeOfPreviousCall;
|
||||
private long failCountOfThisCall;
|
||||
private long successCountOfThisCall;
|
||||
private long totalResponseTimeOfThisCall;
|
||||
private long maxResponseTimeOfThisCall;
|
||||
private long minResponseTimeOfThisCall;
|
||||
private long totalSqureResponseTimeOfThisCall;
|
||||
private long cumulativeSucessfulCount;
|
||||
private long cumulativeFailCount;
|
||||
private static long TIME_UNIT = 1000;
|
||||
private UUID testID;
|
||||
private PageResultCollector pageResultCollector;
|
||||
// The first integer is the behavior's id, and the second integer is
|
||||
// the StatusCode of this behaviorResult.
|
||||
private Map<Integer, Map<Integer, BehaviorStatusCodeResult>> detailMap;
|
||||
|
||||
private void setTimeOfPreviousCall(long timeOfPreviousCall) {
|
||||
this.timeOfPreviousCall = timeOfPreviousCall;
|
||||
}
|
||||
|
||||
private void setFailCountOfThisCall(long failCountOfThisCall) {
|
||||
this.failCountOfThisCall = failCountOfThisCall;
|
||||
}
|
||||
|
||||
private long getSuccessCountOfThisCall() {
|
||||
return successCountOfThisCall;
|
||||
}
|
||||
|
||||
private void setSuccessCountOfThisCall(long successCountOfThisCall) {
|
||||
this.successCountOfThisCall = successCountOfThisCall;
|
||||
}
|
||||
|
||||
private void setTotalResponseTimeOfThisCall(long totalResponseTimeOfThisCall) {
|
||||
this.totalResponseTimeOfThisCall = totalResponseTimeOfThisCall;
|
||||
}
|
||||
|
||||
private long getMaxResponseTimeOfThisCall() {
|
||||
return maxResponseTimeOfThisCall;
|
||||
}
|
||||
|
||||
private void setMaxResponseTimeOfThisCall(long maxResponseTimeOfThisCall) {
|
||||
this.maxResponseTimeOfThisCall = maxResponseTimeOfThisCall;
|
||||
}
|
||||
|
||||
private long getMinResponseTimeOfThisCall() {
|
||||
return minResponseTimeOfThisCall;
|
||||
}
|
||||
|
||||
private void setMinResponseTimeOfThisCall(long minResponseTimeOfThisCall) {
|
||||
this.minResponseTimeOfThisCall = minResponseTimeOfThisCall;
|
||||
}
|
||||
|
||||
private void setTotalSqureResponseTimeOfThisCall(
|
||||
long totalSqureResponseTimeOfThisCall) {
|
||||
this.totalSqureResponseTimeOfThisCall = totalSqureResponseTimeOfThisCall;
|
||||
}
|
||||
|
||||
private void setCumulativeSucessfulCount(long cumulativeSucessfulCount) {
|
||||
this.cumulativeSucessfulCount = cumulativeSucessfulCount;
|
||||
}
|
||||
|
||||
private void setCumulativeFailCount(long cumulativeFailCount) {
|
||||
this.cumulativeFailCount = cumulativeFailCount;
|
||||
}
|
||||
|
||||
private String getTestID() {
|
||||
return testID == null ? "default" : testID.toString();
|
||||
}
|
||||
|
||||
private void setTestID(UUID testID) {
|
||||
this.testID = testID;
|
||||
}
|
||||
|
||||
private void setDetailMap(
|
||||
Map<Integer, Map<Integer, BehaviorStatusCodeResult>> detailMap) {
|
||||
this.detailMap = detailMap;
|
||||
}
|
||||
|
||||
private PageResultCollector getPageResultCollector() {
|
||||
return pageResultCollector;
|
||||
}
|
||||
|
||||
private void setPageResultCollector(PageResultCollector pageResultCollector) {
|
||||
this.pageResultCollector = pageResultCollector;
|
||||
}
|
||||
|
||||
public ScenarioResultCollector(UUID testId) {
|
||||
this.setTestID(testId);
|
||||
this.setPageResultCollector(new PageResultCollector());
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
reset();
|
||||
this.setCumulativeFailCount(0);
|
||||
this.setCumulativeSucessfulCount(0);
|
||||
this.setDetailMap(new HashMap<Integer, Map<Integer, BehaviorStatusCodeResult>>());
|
||||
}
|
||||
|
||||
private void reset() {
|
||||
this.setTimeOfPreviousCall(System.currentTimeMillis());
|
||||
this.setFailCountOfThisCall(0);
|
||||
this.setMaxResponseTimeOfThisCall(Long.MIN_VALUE);
|
||||
this.setMinResponseTimeOfThisCall(Long.MAX_VALUE);
|
||||
this.setSuccessCountOfThisCall(0);
|
||||
this.setTotalResponseTimeOfThisCall(0);
|
||||
this.setTotalSqureResponseTimeOfThisCall(0);
|
||||
}
|
||||
|
||||
// ///////////////////////////////
|
||||
// DataStatistics Interface start
|
||||
// ///////////////////////////////
|
||||
|
||||
public AgentBriefStatusModel getScenarioBriefStatistics() {
|
||||
AgentBriefStatusModel result = new AgentBriefStatusModel();
|
||||
result.setTimeFrame(System.currentTimeMillis()
|
||||
- this.timeOfPreviousCall);
|
||||
if (this.getSuccessCountOfThisCall() == 0) {
|
||||
result.setMaxResponseTime(0);
|
||||
result.setMinResponseTime(0);
|
||||
} else {
|
||||
result.setMinResponseTime(this.minResponseTimeOfThisCall);
|
||||
result.setMaxResponseTime(this.maxResponseTimeOfThisCall);
|
||||
}
|
||||
this.cumulativeSucessfulCount += this.successCountOfThisCall;
|
||||
result.setSuccessCountFromBegin(this.cumulativeSucessfulCount);
|
||||
this.cumulativeFailCount += this.failCountOfThisCall;
|
||||
result.setFailCountFromBegin(this.cumulativeFailCount);
|
||||
if (result.getTimeFrame() == 0) {
|
||||
result.setSuccessThroughputThisTime(0);
|
||||
result.setFailThroughputThisTime(0);
|
||||
} else {
|
||||
result.setSuccessThroughputThisTime(this.successCountOfThisCall
|
||||
* TIME_UNIT / result.getTimeFrame());
|
||||
result.setFailThroughputThisTime(this.failCountOfThisCall
|
||||
* TIME_UNIT / result.getTimeFrame());
|
||||
}
|
||||
result.setTotalResponseTimeThisTime(this.totalResponseTimeOfThisCall);
|
||||
result.setSuccessCountThisTime(this.successCountOfThisCall);
|
||||
result.setFailCountThisTime(this.failCountOfThisCall);
|
||||
result.setTotalSqureResponseTimeThisTime(this.totalSqureResponseTimeOfThisCall);
|
||||
reset();
|
||||
return result;
|
||||
}
|
||||
|
||||
// ///////////////////////////////
|
||||
// DataStatistics Interface end
|
||||
// ///////////////////////////////
|
||||
/**
|
||||
* For the failed one, only the fail count statistics will be added, Others
|
||||
* of this failed one will be ignored.
|
||||
*
|
||||
* @param behaviorResult
|
||||
*/
|
||||
|
||||
private void statisticScenarioBriefResult(BehaviorResult behaviorResult) {
|
||||
if (behaviorResult.isSuccess()) {
|
||||
this.successCountOfThisCall++;
|
||||
this.totalResponseTimeOfThisCall += behaviorResult
|
||||
.getResponseTime();
|
||||
this.totalSqureResponseTimeOfThisCall += ((long) behaviorResult
|
||||
.getResponseTime()) * behaviorResult.getResponseTime();
|
||||
if (behaviorResult.getResponseTime() > this
|
||||
.getMaxResponseTimeOfThisCall()) {
|
||||
this.setMaxResponseTimeOfThisCall(behaviorResult
|
||||
.getResponseTime());
|
||||
}
|
||||
if (behaviorResult.getResponseTime() < this
|
||||
.getMinResponseTimeOfThisCall()) {
|
||||
this.setMinResponseTimeOfThisCall(behaviorResult
|
||||
.getResponseTime());
|
||||
}
|
||||
} else {
|
||||
this.failCountOfThisCall++;
|
||||
}
|
||||
}
|
||||
|
||||
private void statisticBehaviorBriefResult(BehaviorResult behaviorResult) {
|
||||
insertWhenNotExist(behaviorResult);
|
||||
Map<Integer, BehaviorStatusCodeResult> detailStatusMap = this.detailMap
|
||||
.get(behaviorResult.getBehaviorId());
|
||||
// TODO: there's a problem about concurrency
|
||||
guardStatusMapExists(behaviorResult, detailStatusMap);
|
||||
BehaviorStatusCodeResult statusCodeResult = detailStatusMap
|
||||
.get(behaviorResult.getStatusCode());
|
||||
statusCodeResult.count++;
|
||||
if (!behaviorResult.isSuccess()) {
|
||||
statusCodeResult.maxResponseTime = 0;
|
||||
statusCodeResult.minResponseTime = 0;
|
||||
statusCodeResult.contentLength = 0;
|
||||
statusCodeResult.totalResponseTimeThisTime = 0;
|
||||
return;
|
||||
}
|
||||
statusCodeResult.contentLength += behaviorResult.getContentLength();
|
||||
statusCodeResult.totalResponseTimeThisTime += behaviorResult
|
||||
.getResponseTime();
|
||||
if (behaviorResult.getResponseTime() > statusCodeResult.maxResponseTime) {
|
||||
statusCodeResult.maxResponseTime = behaviorResult.getResponseTime();
|
||||
}
|
||||
if (behaviorResult.getResponseTime() < statusCodeResult.minResponseTime) {
|
||||
statusCodeResult.minResponseTime = behaviorResult.getResponseTime();
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void guardStatusMapExists(
|
||||
BehaviorResult behaviorResult,
|
||||
Map<Integer, BehaviorStatusCodeResult> detailStatusMap) {
|
||||
if (!detailStatusMap.containsKey(behaviorResult.getStatusCode())) {
|
||||
detailStatusMap.put(
|
||||
new Integer(behaviorResult.getStatusCode()),
|
||||
new BehaviorStatusCodeResult(behaviorResult
|
||||
.getContentType()));
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void insertWhenNotExist(BehaviorResult behaviorResult) {
|
||||
if (!this.detailMap.containsKey(behaviorResult.getBehaviorId())) {
|
||||
this.detailMap.put(new Integer(behaviorResult.getBehaviorId()),
|
||||
new HashMap<Integer, BehaviorStatusCodeResult>());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String calculateSavePath(BehaviorResult behaviorResult) {
|
||||
Date now = new Date();
|
||||
|
||||
return "DetailResults" + System.getProperty("file.separator")
|
||||
+ new SimpleDateFormat("yyyyMMdd").format(now)
|
||||
+ System.getProperty("file.separator") + this.getTestID() + "_"
|
||||
+ behaviorResult.getBehaviorId() + "_"
|
||||
+ new SimpleDateFormat("hhmm") + ".txt";
|
||||
}
|
||||
|
||||
public void add(PageResult pageResult) {
|
||||
this.getPageResultCollector().add(pageResult);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(BehaviorResult behaviorResult) {
|
||||
super.add(behaviorResult);
|
||||
statisticScenarioBriefResult(behaviorResult);
|
||||
statisticBehaviorBriefResult(behaviorResult);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, BehaviorStatusCodeResult> getBehaviorBriefStatistics(
|
||||
int behaviorId) {
|
||||
if (!this.detailMap.containsKey(behaviorId)) {
|
||||
return null;
|
||||
}
|
||||
return Collections.unmodifiableMap(this.detailMap.get(behaviorId));
|
||||
}
|
||||
|
||||
public Object getPageBriefStatistics(int pageId) {
|
||||
return this.getPageResultCollector().getPageBriefStatistics(pageId);
|
||||
}
|
||||
|
||||
}
|
||||
package org.bench4q.agent.datacollector.impl;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bench4q.agent.scenario.BehaviorResult;
|
||||
import org.bench4q.agent.scenario.PageResult;
|
||||
import org.bench4q.share.models.agent.statistics.AgentBriefStatusModel;
|
||||
|
||||
/**
|
||||
* This class collect the behavior result and statistic it.
|
||||
*
|
||||
* @author coderfengyun
|
||||
*
|
||||
*/
|
||||
public class ScenarioResultCollector extends AbstractDataCollector {
|
||||
private long timeOfPreviousCall;
|
||||
private long failCountOfThisCall;
|
||||
private long successCountOfThisCall;
|
||||
private long totalResponseTimeOfThisCall;
|
||||
private long maxResponseTimeOfThisCall;
|
||||
private long minResponseTimeOfThisCall;
|
||||
private long totalSqureResponseTimeOfThisCall;
|
||||
private long cumulativeSucessfulCount;
|
||||
private long cumulativeFailCount;
|
||||
private static long TIME_UNIT = 1000;
|
||||
private UUID testID;
|
||||
private PageResultCollector pageResultCollector;
|
||||
// The first integer is the behavior's id, and the second integer is
|
||||
// the StatusCode of this behaviorResult.
|
||||
private Map<Integer, Map<Integer, BehaviorStatusCodeResult>> detailMap;
|
||||
|
||||
private void setTimeOfPreviousCall(long timeOfPreviousCall) {
|
||||
this.timeOfPreviousCall = timeOfPreviousCall;
|
||||
}
|
||||
|
||||
private void setFailCountOfThisCall(long failCountOfThisCall) {
|
||||
this.failCountOfThisCall = failCountOfThisCall;
|
||||
}
|
||||
|
||||
private long getSuccessCountOfThisCall() {
|
||||
return successCountOfThisCall;
|
||||
}
|
||||
|
||||
private void setSuccessCountOfThisCall(long successCountOfThisCall) {
|
||||
this.successCountOfThisCall = successCountOfThisCall;
|
||||
}
|
||||
|
||||
private void setTotalResponseTimeOfThisCall(long totalResponseTimeOfThisCall) {
|
||||
this.totalResponseTimeOfThisCall = totalResponseTimeOfThisCall;
|
||||
}
|
||||
|
||||
private long getMaxResponseTimeOfThisCall() {
|
||||
return maxResponseTimeOfThisCall;
|
||||
}
|
||||
|
||||
private void setMaxResponseTimeOfThisCall(long maxResponseTimeOfThisCall) {
|
||||
this.maxResponseTimeOfThisCall = maxResponseTimeOfThisCall;
|
||||
}
|
||||
|
||||
private long getMinResponseTimeOfThisCall() {
|
||||
return minResponseTimeOfThisCall;
|
||||
}
|
||||
|
||||
private void setMinResponseTimeOfThisCall(long minResponseTimeOfThisCall) {
|
||||
this.minResponseTimeOfThisCall = minResponseTimeOfThisCall;
|
||||
}
|
||||
|
||||
private void setTotalSqureResponseTimeOfThisCall(
|
||||
long totalSqureResponseTimeOfThisCall) {
|
||||
this.totalSqureResponseTimeOfThisCall = totalSqureResponseTimeOfThisCall;
|
||||
}
|
||||
|
||||
private void setCumulativeSucessfulCount(long cumulativeSucessfulCount) {
|
||||
this.cumulativeSucessfulCount = cumulativeSucessfulCount;
|
||||
}
|
||||
|
||||
private void setCumulativeFailCount(long cumulativeFailCount) {
|
||||
this.cumulativeFailCount = cumulativeFailCount;
|
||||
}
|
||||
|
||||
private String getTestID() {
|
||||
return testID == null ? "default" : testID.toString();
|
||||
}
|
||||
|
||||
private void setTestID(UUID testID) {
|
||||
this.testID = testID;
|
||||
}
|
||||
|
||||
private void setDetailMap(
|
||||
Map<Integer, Map<Integer, BehaviorStatusCodeResult>> detailMap) {
|
||||
this.detailMap = detailMap;
|
||||
}
|
||||
|
||||
private PageResultCollector getPageResultCollector() {
|
||||
return pageResultCollector;
|
||||
}
|
||||
|
||||
private void setPageResultCollector(PageResultCollector pageResultCollector) {
|
||||
this.pageResultCollector = pageResultCollector;
|
||||
}
|
||||
|
||||
public ScenarioResultCollector(UUID testId) {
|
||||
this.setTestID(testId);
|
||||
this.setPageResultCollector(new PageResultCollector());
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
reset();
|
||||
this.setCumulativeFailCount(0);
|
||||
this.setCumulativeSucessfulCount(0);
|
||||
this.setDetailMap(new HashMap<Integer, Map<Integer, BehaviorStatusCodeResult>>());
|
||||
}
|
||||
|
||||
private void reset() {
|
||||
this.setTimeOfPreviousCall(System.currentTimeMillis());
|
||||
this.setFailCountOfThisCall(0);
|
||||
this.setMaxResponseTimeOfThisCall(Long.MIN_VALUE);
|
||||
this.setMinResponseTimeOfThisCall(Long.MAX_VALUE);
|
||||
this.setSuccessCountOfThisCall(0);
|
||||
this.setTotalResponseTimeOfThisCall(0);
|
||||
this.setTotalSqureResponseTimeOfThisCall(0);
|
||||
}
|
||||
|
||||
// ///////////////////////////////
|
||||
// DataStatistics Interface start
|
||||
// ///////////////////////////////
|
||||
|
||||
public AgentBriefStatusModel getScenarioBriefStatistics() {
|
||||
AgentBriefStatusModel result = new AgentBriefStatusModel();
|
||||
result.setTimeFrame(System.currentTimeMillis()
|
||||
- this.timeOfPreviousCall);
|
||||
if (this.getSuccessCountOfThisCall() == 0) {
|
||||
result.setMaxResponseTime(0);
|
||||
result.setMinResponseTime(0);
|
||||
} else {
|
||||
result.setMinResponseTime(this.minResponseTimeOfThisCall);
|
||||
result.setMaxResponseTime(this.maxResponseTimeOfThisCall);
|
||||
}
|
||||
this.cumulativeSucessfulCount += this.successCountOfThisCall;
|
||||
result.setSuccessCountFromBegin(this.cumulativeSucessfulCount);
|
||||
this.cumulativeFailCount += this.failCountOfThisCall;
|
||||
result.setFailCountFromBegin(this.cumulativeFailCount);
|
||||
if (result.getTimeFrame() == 0) {
|
||||
result.setSuccessThroughputThisTime(0);
|
||||
result.setFailThroughputThisTime(0);
|
||||
} else {
|
||||
result.setSuccessThroughputThisTime(this.successCountOfThisCall
|
||||
* TIME_UNIT / result.getTimeFrame());
|
||||
result.setFailThroughputThisTime(this.failCountOfThisCall
|
||||
* TIME_UNIT / result.getTimeFrame());
|
||||
}
|
||||
result.setTotalResponseTimeThisTime(this.totalResponseTimeOfThisCall);
|
||||
result.setSuccessCountThisTime(this.successCountOfThisCall);
|
||||
result.setFailCountThisTime(this.failCountOfThisCall);
|
||||
result.setTotalSqureResponseTimeThisTime(this.totalSqureResponseTimeOfThisCall);
|
||||
reset();
|
||||
return result;
|
||||
}
|
||||
|
||||
// ///////////////////////////////
|
||||
// DataStatistics Interface end
|
||||
// ///////////////////////////////
|
||||
/**
|
||||
* For the failed one, only the fail count statistics will be added, Others
|
||||
* of this failed one will be ignored.
|
||||
*
|
||||
* @param behaviorResult
|
||||
*/
|
||||
|
||||
private void statisticScenarioBriefResult(BehaviorResult behaviorResult) {
|
||||
if (behaviorResult.isSuccess()) {
|
||||
this.successCountOfThisCall++;
|
||||
this.totalResponseTimeOfThisCall += behaviorResult
|
||||
.getResponseTime();
|
||||
this.totalSqureResponseTimeOfThisCall += ((long) behaviorResult
|
||||
.getResponseTime()) * behaviorResult.getResponseTime();
|
||||
if (behaviorResult.getResponseTime() > this
|
||||
.getMaxResponseTimeOfThisCall()) {
|
||||
this.setMaxResponseTimeOfThisCall(behaviorResult
|
||||
.getResponseTime());
|
||||
}
|
||||
if (behaviorResult.getResponseTime() < this
|
||||
.getMinResponseTimeOfThisCall()) {
|
||||
this.setMinResponseTimeOfThisCall(behaviorResult
|
||||
.getResponseTime());
|
||||
}
|
||||
} else {
|
||||
this.failCountOfThisCall++;
|
||||
}
|
||||
}
|
||||
|
||||
private void statisticBehaviorBriefResult(BehaviorResult behaviorResult) {
|
||||
insertWhenNotExist(behaviorResult);
|
||||
Map<Integer, BehaviorStatusCodeResult> detailStatusMap = this.detailMap
|
||||
.get(behaviorResult.getBehaviorId());
|
||||
// TODO: there's a problem about concurrency
|
||||
guardStatusMapExists(behaviorResult, detailStatusMap);
|
||||
BehaviorStatusCodeResult statusCodeResult = detailStatusMap
|
||||
.get(behaviorResult.getStatusCode());
|
||||
statusCodeResult.count++;
|
||||
if (!behaviorResult.isSuccess()) {
|
||||
statusCodeResult.maxResponseTime = 0;
|
||||
statusCodeResult.minResponseTime = 0;
|
||||
statusCodeResult.contentLength = 0;
|
||||
statusCodeResult.totalResponseTimeThisTime = 0;
|
||||
return;
|
||||
}
|
||||
statusCodeResult.contentLength += behaviorResult.getContentLength();
|
||||
statusCodeResult.totalResponseTimeThisTime += behaviorResult
|
||||
.getResponseTime();
|
||||
if (behaviorResult.getResponseTime() > statusCodeResult.maxResponseTime) {
|
||||
statusCodeResult.maxResponseTime = behaviorResult.getResponseTime();
|
||||
}
|
||||
if (behaviorResult.getResponseTime() < statusCodeResult.minResponseTime) {
|
||||
statusCodeResult.minResponseTime = behaviorResult.getResponseTime();
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void guardStatusMapExists(
|
||||
BehaviorResult behaviorResult,
|
||||
Map<Integer, BehaviorStatusCodeResult> detailStatusMap) {
|
||||
if (!detailStatusMap.containsKey(behaviorResult.getStatusCode())) {
|
||||
detailStatusMap.put(
|
||||
new Integer(behaviorResult.getStatusCode()),
|
||||
new BehaviorStatusCodeResult(behaviorResult
|
||||
.getContentType()));
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void insertWhenNotExist(BehaviorResult behaviorResult) {
|
||||
if (!this.detailMap.containsKey(behaviorResult.getBehaviorId())) {
|
||||
this.detailMap.put(new Integer(behaviorResult.getBehaviorId()),
|
||||
new HashMap<Integer, BehaviorStatusCodeResult>());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String calculateSavePath(BehaviorResult behaviorResult) {
|
||||
Date now = new Date();
|
||||
|
||||
return "DetailResults" + System.getProperty("file.separator")
|
||||
+ new SimpleDateFormat("yyyyMMdd").format(now)
|
||||
+ System.getProperty("file.separator") + this.getTestID() + "_"
|
||||
+ behaviorResult.getBehaviorId() + "_"
|
||||
+ new SimpleDateFormat("hhmm") + ".txt";
|
||||
}
|
||||
|
||||
public void add(PageResult pageResult) {
|
||||
this.getPageResultCollector().add(pageResult);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(BehaviorResult behaviorResult) {
|
||||
super.add(behaviorResult);
|
||||
statisticScenarioBriefResult(behaviorResult);
|
||||
statisticBehaviorBriefResult(behaviorResult);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, BehaviorStatusCodeResult> getBehaviorBriefStatistics(
|
||||
int behaviorId) {
|
||||
if (!this.detailMap.containsKey(behaviorId)) {
|
||||
return null;
|
||||
}
|
||||
return Collections.unmodifiableMap(this.detailMap.get(behaviorId));
|
||||
}
|
||||
|
||||
public Object getPageBriefStatistics(int pageId) {
|
||||
return this.getPageResultCollector().getPageBriefStatistics(pageId);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,26 +1,26 @@
|
|||
package org.bench4q.agent.helper;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ApplicationContextHelper implements ApplicationContextAware {
|
||||
|
||||
private static ApplicationContext context;
|
||||
|
||||
public static ApplicationContext getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
private void setContext(ApplicationContext context) {
|
||||
ApplicationContextHelper.context = context;
|
||||
}
|
||||
|
||||
public void setApplicationContext(ApplicationContext applicationContext)
|
||||
throws BeansException {
|
||||
this.setContext(applicationContext);
|
||||
}
|
||||
|
||||
}
|
||||
package org.bench4q.agent.helper;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ApplicationContextHelper implements ApplicationContextAware {
|
||||
|
||||
private static ApplicationContext context;
|
||||
|
||||
public static ApplicationContext getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
private void setContext(ApplicationContext context) {
|
||||
ApplicationContextHelper.context = context;
|
||||
}
|
||||
|
||||
public void setApplicationContext(ApplicationContext applicationContext)
|
||||
throws BeansException {
|
||||
this.setContext(applicationContext);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,12 +1,12 @@
|
|||
package org.bench4q.agent.plugin;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Behavior {
|
||||
String value();
|
||||
package org.bench4q.agent.plugin;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Behavior {
|
||||
String value();
|
||||
}
|
|
@ -1,23 +1,23 @@
|
|||
package org.bench4q.agent.plugin;
|
||||
|
||||
public class BehaviorInfo {
|
||||
private String name;
|
||||
private ParameterInfo[] parameters;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public ParameterInfo[] getParameters() {
|
||||
return parameters;
|
||||
}
|
||||
|
||||
public void setParameters(ParameterInfo[] parameters) {
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
}
|
||||
package org.bench4q.agent.plugin;
|
||||
|
||||
public class BehaviorInfo {
|
||||
private String name;
|
||||
private ParameterInfo[] parameters;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public ParameterInfo[] getParameters() {
|
||||
return parameters;
|
||||
}
|
||||
|
||||
public void setParameters(ParameterInfo[] parameters) {
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,124 +1,124 @@
|
|||
package org.bench4q.agent.plugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ClassHelper {
|
||||
|
||||
public List<String> getClassNames(String packageName,
|
||||
boolean searchInChildPackage) {
|
||||
try {
|
||||
List<String> classNames = new ArrayList<String>();
|
||||
URLClassLoader classLoader = (URLClassLoader) Thread
|
||||
.currentThread().getContextClassLoader();
|
||||
URL[] urls = classLoader.getURLs();
|
||||
for (URL url : urls) {
|
||||
if (url.getProtocol().equals("file")) {
|
||||
File file = new File(url.getFile());
|
||||
String root = file.getPath().replace("\\", "/");
|
||||
if (file.isDirectory()) {
|
||||
classNames.addAll(this.getClassNamesFromDirectory(root,
|
||||
packageName, searchInChildPackage, file, true));
|
||||
} else if (file.getName().endsWith(".jar")) {
|
||||
classNames.addAll(this.getClassNameFromJar(packageName,
|
||||
searchInChildPackage, file));
|
||||
}
|
||||
}
|
||||
}
|
||||
return classNames;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> getClassNamesFromDirectory(String root,
|
||||
String packageName, boolean searchInChildPackage, File directory,
|
||||
boolean continueSearch) {
|
||||
List<String> classNames = new ArrayList<String>();
|
||||
File[] files = directory.listFiles();
|
||||
for (File file : files) {
|
||||
String filePath = file.getPath().replace("\\", "/");
|
||||
if (file.isDirectory()) {
|
||||
if (searchInChildPackage || continueSearch) {
|
||||
boolean needToContinue = continueSearch;
|
||||
if (filePath.endsWith(packageName.replace(".", "/"))) {
|
||||
needToContinue = needToContinue & false;
|
||||
}
|
||||
classNames.addAll(this.getClassNamesFromDirectory(root,
|
||||
packageName, searchInChildPackage, file,
|
||||
needToContinue));
|
||||
}
|
||||
} else {
|
||||
if (filePath.endsWith(".class")) {
|
||||
String classFileName = filePath.replace(root + "/", "");
|
||||
if (classFileName.startsWith(packageName.replace(".", "/"))) {
|
||||
String className = classFileName.substring(0,
|
||||
classFileName.length() - ".class".length())
|
||||
.replace("/", ".");
|
||||
classNames.add(className);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return classNames;
|
||||
}
|
||||
|
||||
private List<String> getClassNameFromJar(String packageName,
|
||||
boolean searchInChildPackage, File file) {
|
||||
List<String> classNames = new ArrayList<String>();
|
||||
JarFile jarFile = null;
|
||||
try {
|
||||
jarFile = new JarFile(file);
|
||||
Enumeration<JarEntry> jarEntries = jarFile.entries();
|
||||
while (jarEntries.hasMoreElements()) {
|
||||
JarEntry jarEntry = jarEntries.nextElement();
|
||||
String entryName = jarEntry.getName();
|
||||
if (entryName.endsWith(".class")) {
|
||||
String packagePath = packageName.replace(".", "/");
|
||||
if (searchInChildPackage) {
|
||||
if (entryName.startsWith(packagePath)) {
|
||||
entryName = entryName.replace("/", ".").substring(
|
||||
0, entryName.lastIndexOf("."));
|
||||
classNames.add(entryName);
|
||||
}
|
||||
} else {
|
||||
int index = entryName.lastIndexOf("/");
|
||||
String entryPath;
|
||||
if (index != -1) {
|
||||
entryPath = entryName.substring(0, index);
|
||||
} else {
|
||||
entryPath = entryName;
|
||||
}
|
||||
if (entryPath.equals(packagePath)) {
|
||||
entryName = entryName.replace("/", ".").substring(
|
||||
0, entryName.lastIndexOf("."));
|
||||
classNames.add(entryName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (jarFile != null) {
|
||||
try {
|
||||
jarFile.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return classNames;
|
||||
}
|
||||
}
|
||||
package org.bench4q.agent.plugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ClassHelper {
|
||||
|
||||
public List<String> getClassNames(String packageName,
|
||||
boolean searchInChildPackage) {
|
||||
try {
|
||||
List<String> classNames = new ArrayList<String>();
|
||||
URLClassLoader classLoader = (URLClassLoader) Thread
|
||||
.currentThread().getContextClassLoader();
|
||||
URL[] urls = classLoader.getURLs();
|
||||
for (URL url : urls) {
|
||||
if (url.getProtocol().equals("file")) {
|
||||
File file = new File(url.getFile());
|
||||
String root = file.getPath().replace("\\", "/");
|
||||
if (file.isDirectory()) {
|
||||
classNames.addAll(this.getClassNamesFromDirectory(root,
|
||||
packageName, searchInChildPackage, file, true));
|
||||
} else if (file.getName().endsWith(".jar")) {
|
||||
classNames.addAll(this.getClassNameFromJar(packageName,
|
||||
searchInChildPackage, file));
|
||||
}
|
||||
}
|
||||
}
|
||||
return classNames;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> getClassNamesFromDirectory(String root,
|
||||
String packageName, boolean searchInChildPackage, File directory,
|
||||
boolean continueSearch) {
|
||||
List<String> classNames = new ArrayList<String>();
|
||||
File[] files = directory.listFiles();
|
||||
for (File file : files) {
|
||||
String filePath = file.getPath().replace("\\", "/");
|
||||
if (file.isDirectory()) {
|
||||
if (searchInChildPackage || continueSearch) {
|
||||
boolean needToContinue = continueSearch;
|
||||
if (filePath.endsWith(packageName.replace(".", "/"))) {
|
||||
needToContinue = needToContinue & false;
|
||||
}
|
||||
classNames.addAll(this.getClassNamesFromDirectory(root,
|
||||
packageName, searchInChildPackage, file,
|
||||
needToContinue));
|
||||
}
|
||||
} else {
|
||||
if (filePath.endsWith(".class")) {
|
||||
String classFileName = filePath.replace(root + "/", "");
|
||||
if (classFileName.startsWith(packageName.replace(".", "/"))) {
|
||||
String className = classFileName.substring(0,
|
||||
classFileName.length() - ".class".length())
|
||||
.replace("/", ".");
|
||||
classNames.add(className);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return classNames;
|
||||
}
|
||||
|
||||
private List<String> getClassNameFromJar(String packageName,
|
||||
boolean searchInChildPackage, File file) {
|
||||
List<String> classNames = new ArrayList<String>();
|
||||
JarFile jarFile = null;
|
||||
try {
|
||||
jarFile = new JarFile(file);
|
||||
Enumeration<JarEntry> jarEntries = jarFile.entries();
|
||||
while (jarEntries.hasMoreElements()) {
|
||||
JarEntry jarEntry = jarEntries.nextElement();
|
||||
String entryName = jarEntry.getName();
|
||||
if (entryName.endsWith(".class")) {
|
||||
String packagePath = packageName.replace(".", "/");
|
||||
if (searchInChildPackage) {
|
||||
if (entryName.startsWith(packagePath)) {
|
||||
entryName = entryName.replace("/", ".").substring(
|
||||
0, entryName.lastIndexOf("."));
|
||||
classNames.add(entryName);
|
||||
}
|
||||
} else {
|
||||
int index = entryName.lastIndexOf("/");
|
||||
String entryPath;
|
||||
if (index != -1) {
|
||||
entryPath = entryName.substring(0, index);
|
||||
} else {
|
||||
entryPath = entryName;
|
||||
}
|
||||
if (entryPath.equals(packagePath)) {
|
||||
entryName = entryName.replace("/", ".").substring(
|
||||
0, entryName.lastIndexOf("."));
|
||||
classNames.add(entryName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (jarFile != null) {
|
||||
try {
|
||||
jarFile.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return classNames;
|
||||
}
|
||||
}
|
|
@ -1,12 +1,12 @@
|
|||
package org.bench4q.agent.plugin;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target(ElementType.PARAMETER)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Parameter {
|
||||
String value();
|
||||
}
|
||||
package org.bench4q.agent.plugin;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target(ElementType.PARAMETER)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Parameter {
|
||||
String value();
|
||||
}
|
|
@ -1,23 +1,23 @@
|
|||
package org.bench4q.agent.plugin;
|
||||
|
||||
public class ParameterInfo {
|
||||
private String name;
|
||||
private String type;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
}
|
||||
package org.bench4q.agent.plugin;
|
||||
|
||||
public class ParameterInfo {
|
||||
private String name;
|
||||
private String type;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,12 +1,12 @@
|
|||
package org.bench4q.agent.plugin;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Plugin {
|
||||
String value();
|
||||
}
|
||||
package org.bench4q.agent.plugin;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Plugin {
|
||||
String value();
|
||||
}
|
|
@ -1,32 +1,32 @@
|
|||
package org.bench4q.agent.plugin;
|
||||
|
||||
public class PluginInfo {
|
||||
private String name;
|
||||
private ParameterInfo[] parameters;
|
||||
private BehaviorInfo[] behaviors;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public ParameterInfo[] getParameters() {
|
||||
return parameters;
|
||||
}
|
||||
|
||||
public void setParameters(ParameterInfo[] parameters) {
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
public BehaviorInfo[] getBehaviors() {
|
||||
return behaviors;
|
||||
}
|
||||
|
||||
public void setBehaviors(BehaviorInfo[] behaviors) {
|
||||
this.behaviors = behaviors;
|
||||
}
|
||||
|
||||
}
|
||||
package org.bench4q.agent.plugin;
|
||||
|
||||
public class PluginInfo {
|
||||
private String name;
|
||||
private ParameterInfo[] parameters;
|
||||
private BehaviorInfo[] behaviors;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public ParameterInfo[] getParameters() {
|
||||
return parameters;
|
||||
}
|
||||
|
||||
public void setParameters(ParameterInfo[] parameters) {
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
public BehaviorInfo[] getBehaviors() {
|
||||
return behaviors;
|
||||
}
|
||||
|
||||
public void setBehaviors(BehaviorInfo[] behaviors) {
|
||||
this.behaviors = behaviors;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,269 +1,269 @@
|
|||
package org.bench4q.agent.plugin;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.agent.share.DealWithLog;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class PluginManager {
|
||||
private ClassHelper classHelper;
|
||||
private TypeConverter typeConverter;
|
||||
private Map<String, Class<?>> plugins;
|
||||
private Logger logger = Logger.getLogger(PluginManager.class);
|
||||
|
||||
@Autowired
|
||||
public PluginManager(ClassHelper classHelper, TypeConverter typeConverter) {
|
||||
this.setClassHelper(classHelper);
|
||||
this.setTypeConverter(typeConverter);
|
||||
this.setPlugins(this.loadPlugins("org.bench4q.agent.plugin"));
|
||||
}
|
||||
|
||||
private ClassHelper getClassHelper() {
|
||||
return classHelper;
|
||||
}
|
||||
|
||||
private void setClassHelper(ClassHelper classHelper) {
|
||||
this.classHelper = classHelper;
|
||||
}
|
||||
|
||||
private TypeConverter getTypeConverter() {
|
||||
return typeConverter;
|
||||
}
|
||||
|
||||
private void setTypeConverter(TypeConverter typeConverter) {
|
||||
this.typeConverter = typeConverter;
|
||||
}
|
||||
|
||||
public Map<String, Class<?>> getPlugins() {
|
||||
return plugins;
|
||||
}
|
||||
|
||||
private void setPlugins(Map<String, Class<?>> plugins) {
|
||||
this.plugins = plugins;
|
||||
}
|
||||
|
||||
public Map<String, Class<?>> loadPlugins(String packageName) {
|
||||
try {
|
||||
List<String> classNames = this.getClassHelper().getClassNames(
|
||||
packageName, true);
|
||||
Map<String, Class<?>> ret = new HashMap<String, Class<?>>();
|
||||
for (String className : classNames) {
|
||||
Class<?> plugin = Class.forName(className);
|
||||
if (plugin.isAnnotationPresent(Plugin.class)) {
|
||||
ret.put(plugin.getAnnotation(Plugin.class).value(), plugin);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public List<PluginInfo> getPluginInfo() {
|
||||
try {
|
||||
Map<String, Class<?>> plugins = this.getPlugins();
|
||||
List<PluginInfo> ret = new ArrayList<PluginInfo>();
|
||||
for (Class<?> plugin : plugins.values()) {
|
||||
PluginInfo pluginInfo = new PluginInfo();
|
||||
pluginInfo
|
||||
.setName((plugin.getAnnotation(Plugin.class)).value());
|
||||
pluginInfo.setParameters(this.getParameters(plugin
|
||||
.getConstructors()[0]));
|
||||
Method[] behaviors = this.getBehaviors(plugin);
|
||||
pluginInfo.setBehaviors(new BehaviorInfo[behaviors.length]);
|
||||
int i = 0;
|
||||
for (i = 0; i < behaviors.length; i++) {
|
||||
Method behaviorMethod = behaviors[i];
|
||||
BehaviorInfo behaviorInfo = buildBehaviorInfo(behaviorMethod);
|
||||
pluginInfo.getBehaviors()[i] = behaviorInfo;
|
||||
}
|
||||
ret.add(pluginInfo);
|
||||
}
|
||||
return ret;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private BehaviorInfo buildBehaviorInfo(Method behaviorMethod)
|
||||
throws ClassNotFoundException {
|
||||
BehaviorInfo behaviorInfo = new BehaviorInfo();
|
||||
behaviorInfo.setName((behaviorMethod.getAnnotation(Behavior.class))
|
||||
.value());
|
||||
behaviorInfo.setParameters(this.getParameters(behaviorMethod));
|
||||
return behaviorInfo;
|
||||
}
|
||||
|
||||
private ParameterInfo[] getParameters(Method behavior) {
|
||||
try {
|
||||
int parameterCount = behavior.getParameterTypes().length;
|
||||
Annotation[][] parameterAnnotations = behavior
|
||||
.getParameterAnnotations();
|
||||
ParameterInfo[] parameterNames = new ParameterInfo[parameterCount];
|
||||
int i;
|
||||
for (i = 0; i < parameterCount; i++) {
|
||||
Annotation[] annotations = parameterAnnotations[i];
|
||||
Parameter parameter = (Parameter) annotations[0];
|
||||
Class<?> type = behavior.getParameterTypes()[i];
|
||||
ParameterInfo parameterInfo = buildParameterInfo(
|
||||
parameter.value(), type.getName());
|
||||
parameterNames[i] = parameterInfo;
|
||||
}
|
||||
return parameterNames;
|
||||
} catch (Exception e) {
|
||||
logger.error(DealWithLog.getExceptionStackTrace(e));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private ParameterInfo[] getParameters(Constructor<?> behavior) {
|
||||
try {
|
||||
int parameterCount = behavior.getParameterTypes().length;
|
||||
Annotation[][] parameterAnnotations = behavior
|
||||
.getParameterAnnotations();
|
||||
ParameterInfo[] parameterNames = new ParameterInfo[parameterCount];
|
||||
int i;
|
||||
for (i = 0; i < parameterCount; i++) {
|
||||
Annotation[] annotations = parameterAnnotations[i];
|
||||
Parameter parameter = (Parameter) annotations[0];
|
||||
Class<?> type = behavior.getParameterTypes()[i];
|
||||
ParameterInfo parameterInfo = buildParameterInfo(
|
||||
parameter.value(), type.getName());
|
||||
parameterNames[i] = parameterInfo;
|
||||
}
|
||||
return parameterNames;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private ParameterInfo buildParameterInfo(String name, String type) {
|
||||
ParameterInfo parameterInfo = new ParameterInfo();
|
||||
parameterInfo.setName(name);
|
||||
parameterInfo.setType(type);
|
||||
return parameterInfo;
|
||||
}
|
||||
|
||||
private Method[] getBehaviors(Class<?> plugin) {
|
||||
try {
|
||||
Method[] methods = plugin.getMethods();
|
||||
List<Method> ret = new ArrayList<Method>();
|
||||
int i = 0;
|
||||
for (i = 0; i < methods.length; i++) {
|
||||
if (methods[i].isAnnotationPresent(Behavior.class)) {
|
||||
ret.add(methods[i]);
|
||||
}
|
||||
}
|
||||
return ret.toArray(new Method[0]);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Object initializePlugin(Class<?> plugin,
|
||||
Map<String, String> parameters) {
|
||||
try {
|
||||
Constructor<?>[] ctConstructors = plugin.getConstructors();
|
||||
if (ctConstructors.length != 1) {
|
||||
return null;
|
||||
}
|
||||
Constructor<?> constructor = ctConstructors[0];
|
||||
Object[] params = prepareParameters(constructor, parameters);
|
||||
return plugin.getConstructors()[0].newInstance(params);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Object[] prepareParameters(Constructor<?> behavior,
|
||||
Map<String, String> parameters) {
|
||||
try {
|
||||
ParameterInfo[] parameterInfo = this.getParameters(behavior);
|
||||
Object values[] = new Object[parameterInfo.length];
|
||||
int i = 0;
|
||||
for (i = 0; i < parameterInfo.length; i++) {
|
||||
Object value = parameters.get(parameterInfo[i].getName());
|
||||
if (value == null) {
|
||||
values[i] = null;
|
||||
} else {
|
||||
values[i] = this.getTypeConverter().convert(value,
|
||||
parameterInfo[i].getType());
|
||||
}
|
||||
}
|
||||
return values;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Object[] prepareParameters(Method behavior,
|
||||
Map<String, String> parameters) {
|
||||
try {
|
||||
ParameterInfo[] parameterInfo = this.getParameters(behavior);
|
||||
Object values[] = new Object[parameterInfo.length];
|
||||
int i = 0;
|
||||
for (i = 0; i < parameterInfo.length; i++) {
|
||||
Object value = parameters.get(parameterInfo[i].getName());
|
||||
if (value == null) {
|
||||
values[i] = null;
|
||||
} else {
|
||||
values[i] = this.getTypeConverter().convert(value,
|
||||
parameterInfo[i].getType());
|
||||
}
|
||||
}
|
||||
return values;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Object doBehavior(Object plugin, String behaviorName,
|
||||
Map<String, String> parameters) {
|
||||
try {
|
||||
Method method = findMethod(plugin, behaviorName);
|
||||
if (method == null) {
|
||||
return null;
|
||||
}
|
||||
Object[] params = prepareParameters(method, parameters);
|
||||
return method.invoke(plugin, params);
|
||||
} catch (Exception e) {
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Method findMethod(Object plugin, String behaviorName) {
|
||||
try {
|
||||
Method[] methods = plugin.getClass().getMethods();
|
||||
int i = 0;
|
||||
for (i = 0; i < methods.length; i++) {
|
||||
if (methods[i].isAnnotationPresent(Behavior.class)) {
|
||||
if (((Behavior) methods[i].getAnnotation(Behavior.class))
|
||||
.value().equals(behaviorName)) {
|
||||
return methods[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
package org.bench4q.agent.plugin;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.agent.share.DealWithLog;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class PluginManager {
|
||||
private ClassHelper classHelper;
|
||||
private TypeConverter typeConverter;
|
||||
private Map<String, Class<?>> plugins;
|
||||
private Logger logger = Logger.getLogger(PluginManager.class);
|
||||
|
||||
@Autowired
|
||||
public PluginManager(ClassHelper classHelper, TypeConverter typeConverter) {
|
||||
this.setClassHelper(classHelper);
|
||||
this.setTypeConverter(typeConverter);
|
||||
this.setPlugins(this.loadPlugins("org.bench4q.agent.plugin"));
|
||||
}
|
||||
|
||||
private ClassHelper getClassHelper() {
|
||||
return classHelper;
|
||||
}
|
||||
|
||||
private void setClassHelper(ClassHelper classHelper) {
|
||||
this.classHelper = classHelper;
|
||||
}
|
||||
|
||||
private TypeConverter getTypeConverter() {
|
||||
return typeConverter;
|
||||
}
|
||||
|
||||
private void setTypeConverter(TypeConverter typeConverter) {
|
||||
this.typeConverter = typeConverter;
|
||||
}
|
||||
|
||||
public Map<String, Class<?>> getPlugins() {
|
||||
return plugins;
|
||||
}
|
||||
|
||||
private void setPlugins(Map<String, Class<?>> plugins) {
|
||||
this.plugins = plugins;
|
||||
}
|
||||
|
||||
public Map<String, Class<?>> loadPlugins(String packageName) {
|
||||
try {
|
||||
List<String> classNames = this.getClassHelper().getClassNames(
|
||||
packageName, true);
|
||||
Map<String, Class<?>> ret = new HashMap<String, Class<?>>();
|
||||
for (String className : classNames) {
|
||||
Class<?> plugin = Class.forName(className);
|
||||
if (plugin.isAnnotationPresent(Plugin.class)) {
|
||||
ret.put(plugin.getAnnotation(Plugin.class).value(), plugin);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public List<PluginInfo> getPluginInfo() {
|
||||
try {
|
||||
Map<String, Class<?>> plugins = this.getPlugins();
|
||||
List<PluginInfo> ret = new ArrayList<PluginInfo>();
|
||||
for (Class<?> plugin : plugins.values()) {
|
||||
PluginInfo pluginInfo = new PluginInfo();
|
||||
pluginInfo
|
||||
.setName((plugin.getAnnotation(Plugin.class)).value());
|
||||
pluginInfo.setParameters(this.getParameters(plugin
|
||||
.getConstructors()[0]));
|
||||
Method[] behaviors = this.getBehaviors(plugin);
|
||||
pluginInfo.setBehaviors(new BehaviorInfo[behaviors.length]);
|
||||
int i = 0;
|
||||
for (i = 0; i < behaviors.length; i++) {
|
||||
Method behaviorMethod = behaviors[i];
|
||||
BehaviorInfo behaviorInfo = buildBehaviorInfo(behaviorMethod);
|
||||
pluginInfo.getBehaviors()[i] = behaviorInfo;
|
||||
}
|
||||
ret.add(pluginInfo);
|
||||
}
|
||||
return ret;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private BehaviorInfo buildBehaviorInfo(Method behaviorMethod)
|
||||
throws ClassNotFoundException {
|
||||
BehaviorInfo behaviorInfo = new BehaviorInfo();
|
||||
behaviorInfo.setName((behaviorMethod.getAnnotation(Behavior.class))
|
||||
.value());
|
||||
behaviorInfo.setParameters(this.getParameters(behaviorMethod));
|
||||
return behaviorInfo;
|
||||
}
|
||||
|
||||
private ParameterInfo[] getParameters(Method behavior) {
|
||||
try {
|
||||
int parameterCount = behavior.getParameterTypes().length;
|
||||
Annotation[][] parameterAnnotations = behavior
|
||||
.getParameterAnnotations();
|
||||
ParameterInfo[] parameterNames = new ParameterInfo[parameterCount];
|
||||
int i;
|
||||
for (i = 0; i < parameterCount; i++) {
|
||||
Annotation[] annotations = parameterAnnotations[i];
|
||||
Parameter parameter = (Parameter) annotations[0];
|
||||
Class<?> type = behavior.getParameterTypes()[i];
|
||||
ParameterInfo parameterInfo = buildParameterInfo(
|
||||
parameter.value(), type.getName());
|
||||
parameterNames[i] = parameterInfo;
|
||||
}
|
||||
return parameterNames;
|
||||
} catch (Exception e) {
|
||||
logger.error(DealWithLog.getExceptionStackTrace(e));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private ParameterInfo[] getParameters(Constructor<?> behavior) {
|
||||
try {
|
||||
int parameterCount = behavior.getParameterTypes().length;
|
||||
Annotation[][] parameterAnnotations = behavior
|
||||
.getParameterAnnotations();
|
||||
ParameterInfo[] parameterNames = new ParameterInfo[parameterCount];
|
||||
int i;
|
||||
for (i = 0; i < parameterCount; i++) {
|
||||
Annotation[] annotations = parameterAnnotations[i];
|
||||
Parameter parameter = (Parameter) annotations[0];
|
||||
Class<?> type = behavior.getParameterTypes()[i];
|
||||
ParameterInfo parameterInfo = buildParameterInfo(
|
||||
parameter.value(), type.getName());
|
||||
parameterNames[i] = parameterInfo;
|
||||
}
|
||||
return parameterNames;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private ParameterInfo buildParameterInfo(String name, String type) {
|
||||
ParameterInfo parameterInfo = new ParameterInfo();
|
||||
parameterInfo.setName(name);
|
||||
parameterInfo.setType(type);
|
||||
return parameterInfo;
|
||||
}
|
||||
|
||||
private Method[] getBehaviors(Class<?> plugin) {
|
||||
try {
|
||||
Method[] methods = plugin.getMethods();
|
||||
List<Method> ret = new ArrayList<Method>();
|
||||
int i = 0;
|
||||
for (i = 0; i < methods.length; i++) {
|
||||
if (methods[i].isAnnotationPresent(Behavior.class)) {
|
||||
ret.add(methods[i]);
|
||||
}
|
||||
}
|
||||
return ret.toArray(new Method[0]);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Object initializePlugin(Class<?> plugin,
|
||||
Map<String, String> parameters) {
|
||||
try {
|
||||
Constructor<?>[] ctConstructors = plugin.getConstructors();
|
||||
if (ctConstructors.length != 1) {
|
||||
return null;
|
||||
}
|
||||
Constructor<?> constructor = ctConstructors[0];
|
||||
Object[] params = prepareParameters(constructor, parameters);
|
||||
return plugin.getConstructors()[0].newInstance(params);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Object[] prepareParameters(Constructor<?> behavior,
|
||||
Map<String, String> parameters) {
|
||||
try {
|
||||
ParameterInfo[] parameterInfo = this.getParameters(behavior);
|
||||
Object values[] = new Object[parameterInfo.length];
|
||||
int i = 0;
|
||||
for (i = 0; i < parameterInfo.length; i++) {
|
||||
Object value = parameters.get(parameterInfo[i].getName());
|
||||
if (value == null) {
|
||||
values[i] = null;
|
||||
} else {
|
||||
values[i] = this.getTypeConverter().convert(value,
|
||||
parameterInfo[i].getType());
|
||||
}
|
||||
}
|
||||
return values;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Object[] prepareParameters(Method behavior,
|
||||
Map<String, String> parameters) {
|
||||
try {
|
||||
ParameterInfo[] parameterInfo = this.getParameters(behavior);
|
||||
Object values[] = new Object[parameterInfo.length];
|
||||
int i = 0;
|
||||
for (i = 0; i < parameterInfo.length; i++) {
|
||||
Object value = parameters.get(parameterInfo[i].getName());
|
||||
if (value == null) {
|
||||
values[i] = null;
|
||||
} else {
|
||||
values[i] = this.getTypeConverter().convert(value,
|
||||
parameterInfo[i].getType());
|
||||
}
|
||||
}
|
||||
return values;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Object doBehavior(Object plugin, String behaviorName,
|
||||
Map<String, String> parameters) {
|
||||
try {
|
||||
Method method = findMethod(plugin, behaviorName);
|
||||
if (method == null) {
|
||||
return null;
|
||||
}
|
||||
Object[] params = prepareParameters(method, parameters);
|
||||
return method.invoke(plugin, params);
|
||||
} catch (Exception e) {
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Method findMethod(Object plugin, String behaviorName) {
|
||||
try {
|
||||
Method[] methods = plugin.getClass().getMethods();
|
||||
int i = 0;
|
||||
for (i = 0; i < methods.length; i++) {
|
||||
if (methods[i].isAnnotationPresent(Behavior.class)) {
|
||||
if (((Behavior) methods[i].getAnnotation(Behavior.class))
|
||||
.value().equals(behaviorName)) {
|
||||
return methods[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,44 +1,44 @@
|
|||
package org.bench4q.agent.plugin;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class TypeConverter {
|
||||
public Object convert(Object source, String targetClassName) {
|
||||
if (targetClassName.equals("boolean")) {
|
||||
return Boolean.parseBoolean(source.toString());
|
||||
}
|
||||
if (targetClassName.equals("char")) {
|
||||
return source.toString().toCharArray()[0];
|
||||
}
|
||||
if (targetClassName.equals("byte")) {
|
||||
return Byte.parseByte(source.toString());
|
||||
}
|
||||
if (targetClassName.equals("short")) {
|
||||
return Short.parseShort(source.toString());
|
||||
}
|
||||
if (targetClassName.equals("int")) {
|
||||
return Integer.parseInt(source.toString());
|
||||
}
|
||||
if (targetClassName.equals("long")) {
|
||||
return Long.parseLong(source.toString());
|
||||
}
|
||||
if (targetClassName.equals("float")) {
|
||||
return Float.parseFloat(source.toString());
|
||||
}
|
||||
if (targetClassName.equals("double")) {
|
||||
return Double.parseDouble(source.toString());
|
||||
}
|
||||
|
||||
try {
|
||||
Class<?> targetClass = Class.forName(targetClassName);
|
||||
if (targetClass.isAssignableFrom(String.class)) {
|
||||
return source.toString();
|
||||
}
|
||||
return targetClass.cast(source);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
package org.bench4q.agent.plugin;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class TypeConverter {
|
||||
public Object convert(Object source, String targetClassName) {
|
||||
if (targetClassName.equals("boolean")) {
|
||||
return Boolean.parseBoolean(source.toString());
|
||||
}
|
||||
if (targetClassName.equals("char")) {
|
||||
return source.toString().toCharArray()[0];
|
||||
}
|
||||
if (targetClassName.equals("byte")) {
|
||||
return Byte.parseByte(source.toString());
|
||||
}
|
||||
if (targetClassName.equals("short")) {
|
||||
return Short.parseShort(source.toString());
|
||||
}
|
||||
if (targetClassName.equals("int")) {
|
||||
return Integer.parseInt(source.toString());
|
||||
}
|
||||
if (targetClassName.equals("long")) {
|
||||
return Long.parseLong(source.toString());
|
||||
}
|
||||
if (targetClassName.equals("float")) {
|
||||
return Float.parseFloat(source.toString());
|
||||
}
|
||||
if (targetClassName.equals("double")) {
|
||||
return Double.parseDouble(source.toString());
|
||||
}
|
||||
|
||||
try {
|
||||
Class<?> targetClass = Class.forName(targetClassName);
|
||||
if (targetClass.isAssignableFrom(String.class)) {
|
||||
return source.toString();
|
||||
}
|
||||
return targetClass.cast(source);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,89 +1,89 @@
|
|||
package org.bench4q.agent.plugin.basic;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
import org.bench4q.agent.plugin.Behavior;
|
||||
import org.bench4q.agent.plugin.Parameter;
|
||||
import org.bench4q.agent.plugin.Plugin;
|
||||
import org.bench4q.agent.plugin.result.CommandLineReturn;
|
||||
|
||||
@Plugin("CommandLine")
|
||||
public class CommandLinePlugin {
|
||||
private String standardOutput;
|
||||
private String standardError;
|
||||
|
||||
public String getStandardOutput() {
|
||||
return standardOutput;
|
||||
}
|
||||
|
||||
private void setStandardOutput(String standardOutput) {
|
||||
this.standardOutput = standardOutput;
|
||||
}
|
||||
|
||||
public String getStandardError() {
|
||||
return standardError;
|
||||
}
|
||||
|
||||
private void setStandardError(String standardError) {
|
||||
this.standardError = standardError;
|
||||
}
|
||||
|
||||
public CommandLinePlugin() {
|
||||
|
||||
}
|
||||
|
||||
@Behavior("Command")
|
||||
public CommandLineReturn command(@Parameter("command") String command) {
|
||||
try {
|
||||
final Process process = Runtime.getRuntime().exec(command);
|
||||
new Thread() {
|
||||
public void run() {
|
||||
try {
|
||||
BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(process.getInputStream()));
|
||||
String streamline = "";
|
||||
try {
|
||||
setStandardOutput("");
|
||||
while ((streamline = reader.readLine()) != null) {
|
||||
setStandardOutput(getStandardOutput()
|
||||
+ streamline
|
||||
+ System.getProperty("line.separator"));
|
||||
}
|
||||
} finally {
|
||||
reader.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
new Thread() {
|
||||
public void run() {
|
||||
try {
|
||||
BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(process.getErrorStream()));
|
||||
String streamline = "";
|
||||
try {
|
||||
setStandardError("");
|
||||
while ((streamline = reader.readLine()) != null) {
|
||||
setStandardError(getStandardError()
|
||||
+ streamline
|
||||
+ System.getProperty("line.separator"));
|
||||
}
|
||||
} finally {
|
||||
reader.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
process.waitFor();
|
||||
return new CommandLineReturn(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return new CommandLineReturn(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
package org.bench4q.agent.plugin.basic;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
import org.bench4q.agent.plugin.Behavior;
|
||||
import org.bench4q.agent.plugin.Parameter;
|
||||
import org.bench4q.agent.plugin.Plugin;
|
||||
import org.bench4q.agent.plugin.result.CommandLineReturn;
|
||||
|
||||
@Plugin("CommandLine")
|
||||
public class CommandLinePlugin {
|
||||
private String standardOutput;
|
||||
private String standardError;
|
||||
|
||||
public String getStandardOutput() {
|
||||
return standardOutput;
|
||||
}
|
||||
|
||||
private void setStandardOutput(String standardOutput) {
|
||||
this.standardOutput = standardOutput;
|
||||
}
|
||||
|
||||
public String getStandardError() {
|
||||
return standardError;
|
||||
}
|
||||
|
||||
private void setStandardError(String standardError) {
|
||||
this.standardError = standardError;
|
||||
}
|
||||
|
||||
public CommandLinePlugin() {
|
||||
|
||||
}
|
||||
|
||||
@Behavior("Command")
|
||||
public CommandLineReturn command(@Parameter("command") String command) {
|
||||
try {
|
||||
final Process process = Runtime.getRuntime().exec(command);
|
||||
new Thread() {
|
||||
public void run() {
|
||||
try {
|
||||
BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(process.getInputStream()));
|
||||
String streamline = "";
|
||||
try {
|
||||
setStandardOutput("");
|
||||
while ((streamline = reader.readLine()) != null) {
|
||||
setStandardOutput(getStandardOutput()
|
||||
+ streamline
|
||||
+ System.getProperty("line.separator"));
|
||||
}
|
||||
} finally {
|
||||
reader.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
new Thread() {
|
||||
public void run() {
|
||||
try {
|
||||
BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(process.getErrorStream()));
|
||||
String streamline = "";
|
||||
try {
|
||||
setStandardError("");
|
||||
while ((streamline = reader.readLine()) != null) {
|
||||
setStandardError(getStandardError()
|
||||
+ streamline
|
||||
+ System.getProperty("line.separator"));
|
||||
}
|
||||
} finally {
|
||||
reader.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
process.waitFor();
|
||||
return new CommandLineReturn(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return new CommandLineReturn(false);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,27 +1,27 @@
|
|||
package org.bench4q.agent.plugin.basic;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.agent.plugin.Behavior;
|
||||
import org.bench4q.agent.plugin.Parameter;
|
||||
import org.bench4q.agent.plugin.Plugin;
|
||||
import org.bench4q.agent.plugin.result.TimerReturn;
|
||||
|
||||
@Plugin("ConstantTimer")
|
||||
public class ConstantTimerPlugin {
|
||||
private Logger logger = Logger.getLogger(ConstantTimerPlugin.class);
|
||||
|
||||
public ConstantTimerPlugin() {
|
||||
|
||||
}
|
||||
|
||||
@Behavior("Sleep")
|
||||
public TimerReturn sleep(@Parameter("time") int time) {
|
||||
try {
|
||||
Thread.sleep(time);
|
||||
return new TimerReturn(true);
|
||||
} catch (Exception e) {
|
||||
logger.info("sleep interrupted!");
|
||||
return new TimerReturn(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
package org.bench4q.agent.plugin.basic;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.agent.plugin.Behavior;
|
||||
import org.bench4q.agent.plugin.Parameter;
|
||||
import org.bench4q.agent.plugin.Plugin;
|
||||
import org.bench4q.agent.plugin.result.TimerReturn;
|
||||
|
||||
@Plugin("ConstantTimer")
|
||||
public class ConstantTimerPlugin {
|
||||
private Logger logger = Logger.getLogger(ConstantTimerPlugin.class);
|
||||
|
||||
public ConstantTimerPlugin() {
|
||||
|
||||
}
|
||||
|
||||
@Behavior("Sleep")
|
||||
public TimerReturn sleep(@Parameter("time") int time) {
|
||||
try {
|
||||
Thread.sleep(time);
|
||||
return new TimerReturn(true);
|
||||
} catch (Exception e) {
|
||||
logger.info("sleep interrupted!");
|
||||
return new TimerReturn(false);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,19 +1,19 @@
|
|||
package org.bench4q.agent.plugin.basic;
|
||||
|
||||
import org.bench4q.agent.plugin.Behavior;
|
||||
import org.bench4q.agent.plugin.Parameter;
|
||||
import org.bench4q.agent.plugin.Plugin;
|
||||
import org.bench4q.agent.plugin.result.LogReturn;
|
||||
|
||||
@Plugin("Log")
|
||||
public class LogPlugin {
|
||||
public LogPlugin() {
|
||||
|
||||
}
|
||||
|
||||
@Behavior("Log")
|
||||
public LogReturn log(@Parameter("message") String message) {
|
||||
System.out.println(message);
|
||||
return new LogReturn(true);
|
||||
}
|
||||
}
|
||||
package org.bench4q.agent.plugin.basic;
|
||||
|
||||
import org.bench4q.agent.plugin.Behavior;
|
||||
import org.bench4q.agent.plugin.Parameter;
|
||||
import org.bench4q.agent.plugin.Plugin;
|
||||
import org.bench4q.agent.plugin.result.LogReturn;
|
||||
|
||||
@Plugin("Log")
|
||||
public class LogPlugin {
|
||||
public LogPlugin() {
|
||||
|
||||
}
|
||||
|
||||
@Behavior("Log")
|
||||
public LogReturn log(@Parameter("message") String message) {
|
||||
System.out.println(message);
|
||||
return new LogReturn(true);
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
package org.bench4q.agent.plugin.result;
|
||||
|
||||
public class CommandLineReturn extends PluginReturn {
|
||||
public CommandLineReturn(boolean success) {
|
||||
this.setSuccess(success);
|
||||
}
|
||||
}
|
||||
package org.bench4q.agent.plugin.result;
|
||||
|
||||
public class CommandLineReturn extends PluginReturn {
|
||||
public CommandLineReturn(boolean success) {
|
||||
this.setSuccess(success);
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
package org.bench4q.agent.plugin.result;
|
||||
|
||||
public class LogReturn extends PluginReturn {
|
||||
public LogReturn(boolean success) {
|
||||
this.setSuccess(success);
|
||||
}
|
||||
}
|
||||
package org.bench4q.agent.plugin.result;
|
||||
|
||||
public class LogReturn extends PluginReturn {
|
||||
public LogReturn(boolean success) {
|
||||
this.setSuccess(success);
|
||||
}
|
||||
}
|
|
@ -1,12 +1,12 @@
|
|||
package org.bench4q.agent.plugin.result;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author coderfengyun
|
||||
*
|
||||
*/
|
||||
public class TimerReturn extends PluginReturn {
|
||||
public TimerReturn(boolean success) {
|
||||
this.setSuccess(success);
|
||||
}
|
||||
}
|
||||
package org.bench4q.agent.plugin.result;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author coderfengyun
|
||||
*
|
||||
*/
|
||||
public class TimerReturn extends PluginReturn {
|
||||
public TimerReturn(boolean success) {
|
||||
this.setSuccess(success);
|
||||
}
|
||||
}
|
|
@ -1,43 +1,43 @@
|
|||
package org.bench4q.agent.scenario;
|
||||
|
||||
import org.bench4q.agent.scenario.behavior.Behavior;
|
||||
|
||||
public class Batch {
|
||||
private int id;
|
||||
private int parentId;
|
||||
private int childId;
|
||||
private Behavior[] behaviors;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getParentId() {
|
||||
return parentId;
|
||||
}
|
||||
|
||||
public void setParentId(int parentId) {
|
||||
this.parentId = parentId;
|
||||
}
|
||||
|
||||
public int getChildId() {
|
||||
return childId;
|
||||
}
|
||||
|
||||
public void setChildId(int childId) {
|
||||
this.childId = childId;
|
||||
}
|
||||
|
||||
public Behavior[] getBehaviors() {
|
||||
return behaviors;
|
||||
}
|
||||
|
||||
public void setBehaviors(Behavior[] behaviors) {
|
||||
this.behaviors = behaviors;
|
||||
}
|
||||
|
||||
}
|
||||
package org.bench4q.agent.scenario;
|
||||
|
||||
import org.bench4q.agent.scenario.behavior.Behavior;
|
||||
|
||||
public class Batch {
|
||||
private int id;
|
||||
private int parentId;
|
||||
private int childId;
|
||||
private Behavior[] behaviors;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getParentId() {
|
||||
return parentId;
|
||||
}
|
||||
|
||||
public void setParentId(int parentId) {
|
||||
this.parentId = parentId;
|
||||
}
|
||||
|
||||
public int getChildId() {
|
||||
return childId;
|
||||
}
|
||||
|
||||
public void setChildId(int childId) {
|
||||
this.childId = childId;
|
||||
}
|
||||
|
||||
public Behavior[] getBehaviors() {
|
||||
return behaviors;
|
||||
}
|
||||
|
||||
public void setBehaviors(Behavior[] behaviors) {
|
||||
this.behaviors = behaviors;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,125 +1,125 @@
|
|||
package org.bench4q.agent.scenario;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class BehaviorResult {
|
||||
private String pluginId;
|
||||
private String pluginName;
|
||||
private String behaviorName;
|
||||
private Date startDate;
|
||||
private Date endDate;
|
||||
private long responseTime;
|
||||
private boolean success;
|
||||
|
||||
private int behaviorId;
|
||||
private String behaviorUrl;
|
||||
private long contentLength;
|
||||
private int statusCode;
|
||||
private String contentType;
|
||||
private boolean shouldBeCountResponseTime;
|
||||
|
||||
public String getPluginId() {
|
||||
return pluginId;
|
||||
}
|
||||
|
||||
public void setPluginId(String pluginId) {
|
||||
this.pluginId = pluginId;
|
||||
}
|
||||
|
||||
public String getPluginName() {
|
||||
return pluginName;
|
||||
}
|
||||
|
||||
public void setPluginName(String pluginName) {
|
||||
this.pluginName = pluginName;
|
||||
}
|
||||
|
||||
public String getBehaviorName() {
|
||||
return behaviorName;
|
||||
}
|
||||
|
||||
public void setBehaviorName(String behaviorName) {
|
||||
this.behaviorName = behaviorName;
|
||||
}
|
||||
|
||||
public Date getStartDate() {
|
||||
return startDate;
|
||||
}
|
||||
|
||||
public void setStartDate(Date startDate) {
|
||||
this.startDate = startDate;
|
||||
}
|
||||
|
||||
public Date getEndDate() {
|
||||
return endDate;
|
||||
}
|
||||
|
||||
public void setEndDate(Date endDate) {
|
||||
this.endDate = endDate;
|
||||
}
|
||||
|
||||
public long getResponseTime() {
|
||||
return responseTime;
|
||||
}
|
||||
|
||||
public void setResponseTime(long responseTime) {
|
||||
this.responseTime = responseTime;
|
||||
}
|
||||
|
||||
public boolean isSuccess() {
|
||||
return success;
|
||||
}
|
||||
|
||||
public void setSuccess(boolean success) {
|
||||
this.success = success;
|
||||
}
|
||||
|
||||
public int getBehaviorId() {
|
||||
return behaviorId;
|
||||
}
|
||||
|
||||
public void setBehaviorId(int behaviorId) {
|
||||
this.behaviorId = behaviorId;
|
||||
}
|
||||
|
||||
public String getBehaviorUrl() {
|
||||
return behaviorUrl;
|
||||
}
|
||||
|
||||
public void setBehaviorUrl(String behaviorUrl) {
|
||||
this.behaviorUrl = behaviorUrl;
|
||||
}
|
||||
|
||||
public long getContentLength() {
|
||||
return contentLength;
|
||||
}
|
||||
|
||||
public void setContentLength(long contentLength) {
|
||||
this.contentLength = contentLength;
|
||||
}
|
||||
|
||||
public int getStatusCode() {
|
||||
return statusCode;
|
||||
}
|
||||
|
||||
public void setStatusCode(int statusCode) {
|
||||
this.statusCode = statusCode;
|
||||
}
|
||||
|
||||
public String getContentType() {
|
||||
return contentType;
|
||||
}
|
||||
|
||||
public void setContentType(String contentType) {
|
||||
this.contentType = contentType;
|
||||
}
|
||||
|
||||
public boolean isShouldBeCountResponseTime() {
|
||||
return shouldBeCountResponseTime;
|
||||
}
|
||||
|
||||
public void setShouldBeCountResponseTime(boolean shouldBeCountResponseTime) {
|
||||
this.shouldBeCountResponseTime = shouldBeCountResponseTime;
|
||||
}
|
||||
|
||||
}
|
||||
package org.bench4q.agent.scenario;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class BehaviorResult {
|
||||
private String pluginId;
|
||||
private String pluginName;
|
||||
private String behaviorName;
|
||||
private Date startDate;
|
||||
private Date endDate;
|
||||
private long responseTime;
|
||||
private boolean success;
|
||||
|
||||
private int behaviorId;
|
||||
private String behaviorUrl;
|
||||
private long contentLength;
|
||||
private int statusCode;
|
||||
private String contentType;
|
||||
private boolean shouldBeCountResponseTime;
|
||||
|
||||
public String getPluginId() {
|
||||
return pluginId;
|
||||
}
|
||||
|
||||
public void setPluginId(String pluginId) {
|
||||
this.pluginId = pluginId;
|
||||
}
|
||||
|
||||
public String getPluginName() {
|
||||
return pluginName;
|
||||
}
|
||||
|
||||
public void setPluginName(String pluginName) {
|
||||
this.pluginName = pluginName;
|
||||
}
|
||||
|
||||
public String getBehaviorName() {
|
||||
return behaviorName;
|
||||
}
|
||||
|
||||
public void setBehaviorName(String behaviorName) {
|
||||
this.behaviorName = behaviorName;
|
||||
}
|
||||
|
||||
public Date getStartDate() {
|
||||
return startDate;
|
||||
}
|
||||
|
||||
public void setStartDate(Date startDate) {
|
||||
this.startDate = startDate;
|
||||
}
|
||||
|
||||
public Date getEndDate() {
|
||||
return endDate;
|
||||
}
|
||||
|
||||
public void setEndDate(Date endDate) {
|
||||
this.endDate = endDate;
|
||||
}
|
||||
|
||||
public long getResponseTime() {
|
||||
return responseTime;
|
||||
}
|
||||
|
||||
public void setResponseTime(long responseTime) {
|
||||
this.responseTime = responseTime;
|
||||
}
|
||||
|
||||
public boolean isSuccess() {
|
||||
return success;
|
||||
}
|
||||
|
||||
public void setSuccess(boolean success) {
|
||||
this.success = success;
|
||||
}
|
||||
|
||||
public int getBehaviorId() {
|
||||
return behaviorId;
|
||||
}
|
||||
|
||||
public void setBehaviorId(int behaviorId) {
|
||||
this.behaviorId = behaviorId;
|
||||
}
|
||||
|
||||
public String getBehaviorUrl() {
|
||||
return behaviorUrl;
|
||||
}
|
||||
|
||||
public void setBehaviorUrl(String behaviorUrl) {
|
||||
this.behaviorUrl = behaviorUrl;
|
||||
}
|
||||
|
||||
public long getContentLength() {
|
||||
return contentLength;
|
||||
}
|
||||
|
||||
public void setContentLength(long contentLength) {
|
||||
this.contentLength = contentLength;
|
||||
}
|
||||
|
||||
public int getStatusCode() {
|
||||
return statusCode;
|
||||
}
|
||||
|
||||
public void setStatusCode(int statusCode) {
|
||||
this.statusCode = statusCode;
|
||||
}
|
||||
|
||||
public String getContentType() {
|
||||
return contentType;
|
||||
}
|
||||
|
||||
public void setContentType(String contentType) {
|
||||
this.contentType = contentType;
|
||||
}
|
||||
|
||||
public boolean isShouldBeCountResponseTime() {
|
||||
return shouldBeCountResponseTime;
|
||||
}
|
||||
|
||||
public void setShouldBeCountResponseTime(boolean shouldBeCountResponseTime) {
|
||||
this.shouldBeCountResponseTime = shouldBeCountResponseTime;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,77 +1,77 @@
|
|||
package org.bench4q.agent.scenario;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PageResult {
|
||||
private int pageId;
|
||||
private long pageStartTime;
|
||||
private long pageEndTime;
|
||||
private long executeRange;
|
||||
|
||||
public int getPageId() {
|
||||
return pageId;
|
||||
}
|
||||
|
||||
private void setPageId(int pageId) {
|
||||
this.pageId = pageId;
|
||||
}
|
||||
|
||||
public long getPageStartTime() {
|
||||
return pageStartTime;
|
||||
}
|
||||
|
||||
private void setPageStartTime(long pageStartTime) {
|
||||
this.pageStartTime = pageStartTime;
|
||||
}
|
||||
|
||||
public long getPageEndTime() {
|
||||
return pageEndTime;
|
||||
}
|
||||
|
||||
private void setPageEndTime(long pageEndTime) {
|
||||
this.pageEndTime = pageEndTime;
|
||||
}
|
||||
|
||||
public long getExecuteRange() {
|
||||
return executeRange;
|
||||
}
|
||||
|
||||
private void setExecuteRange(long executeRange) {
|
||||
this.executeRange = executeRange;
|
||||
}
|
||||
|
||||
private PageResult() {
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
this.setPageStartTime(Long.MAX_VALUE);
|
||||
this.setPageEndTime(Long.MIN_VALUE);
|
||||
this.setExecuteRange(0);
|
||||
}
|
||||
|
||||
public static PageResult buildPageResult(int pageId,
|
||||
List<BehaviorResult> behaviorResults) {
|
||||
PageResult result = new PageResult();
|
||||
result.setPageId(pageId);
|
||||
if (behaviorResults == null) {
|
||||
behaviorResults = new ArrayList<BehaviorResult>();
|
||||
}
|
||||
for (BehaviorResult behaviorResult : behaviorResults) {
|
||||
if (behaviorResult.getStartDate().getTime() < result
|
||||
.getPageStartTime()) {
|
||||
result.setPageStartTime(behaviorResult.getStartDate().getTime());
|
||||
}
|
||||
if (behaviorResult.getEndDate().getTime() > result.getPageEndTime()) {
|
||||
result.setPageEndTime(behaviorResult.getEndDate().getTime());
|
||||
}
|
||||
// Page excuteRange rely on the behaviors' execute way, if it's
|
||||
// executed in batch, i should take the longest behavior in batch
|
||||
// to calculate this One.
|
||||
}
|
||||
result.setExecuteRange(result.getPageEndTime()
|
||||
- result.getPageStartTime());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
package org.bench4q.agent.scenario;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PageResult {
|
||||
private int pageId;
|
||||
private long pageStartTime;
|
||||
private long pageEndTime;
|
||||
private long executeRange;
|
||||
|
||||
public int getPageId() {
|
||||
return pageId;
|
||||
}
|
||||
|
||||
private void setPageId(int pageId) {
|
||||
this.pageId = pageId;
|
||||
}
|
||||
|
||||
public long getPageStartTime() {
|
||||
return pageStartTime;
|
||||
}
|
||||
|
||||
private void setPageStartTime(long pageStartTime) {
|
||||
this.pageStartTime = pageStartTime;
|
||||
}
|
||||
|
||||
public long getPageEndTime() {
|
||||
return pageEndTime;
|
||||
}
|
||||
|
||||
private void setPageEndTime(long pageEndTime) {
|
||||
this.pageEndTime = pageEndTime;
|
||||
}
|
||||
|
||||
public long getExecuteRange() {
|
||||
return executeRange;
|
||||
}
|
||||
|
||||
private void setExecuteRange(long executeRange) {
|
||||
this.executeRange = executeRange;
|
||||
}
|
||||
|
||||
private PageResult() {
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
this.setPageStartTime(Long.MAX_VALUE);
|
||||
this.setPageEndTime(Long.MIN_VALUE);
|
||||
this.setExecuteRange(0);
|
||||
}
|
||||
|
||||
public static PageResult buildPageResult(int pageId,
|
||||
List<BehaviorResult> behaviorResults) {
|
||||
PageResult result = new PageResult();
|
||||
result.setPageId(pageId);
|
||||
if (behaviorResults == null) {
|
||||
behaviorResults = new ArrayList<BehaviorResult>();
|
||||
}
|
||||
for (BehaviorResult behaviorResult : behaviorResults) {
|
||||
if (behaviorResult.getStartDate().getTime() < result
|
||||
.getPageStartTime()) {
|
||||
result.setPageStartTime(behaviorResult.getStartDate().getTime());
|
||||
}
|
||||
if (behaviorResult.getEndDate().getTime() > result.getPageEndTime()) {
|
||||
result.setPageEndTime(behaviorResult.getEndDate().getTime());
|
||||
}
|
||||
// Page excuteRange rely on the behaviors' execute way, if it's
|
||||
// executed in batch, i should take the longest behavior in batch
|
||||
// to calculate this One.
|
||||
}
|
||||
result.setExecuteRange(result.getPageEndTime()
|
||||
- result.getPageStartTime());
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -1,23 +1,23 @@
|
|||
package org.bench4q.agent.scenario;
|
||||
|
||||
public class Parameter {
|
||||
private String key;
|
||||
private String value;
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
}
|
||||
package org.bench4q.agent.scenario;
|
||||
|
||||
public class Parameter {
|
||||
private String key;
|
||||
private String value;
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,111 +1,111 @@
|
|||
package org.bench4q.agent.scenario;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement(name = "testResult")
|
||||
public class TestResult implements Serializable {
|
||||
private static final long serialVersionUID = -370091935554266546L;
|
||||
private UUID runId;
|
||||
private int poolSize;
|
||||
private int totalCount;
|
||||
private Date startDate;
|
||||
private long elapsedTime;
|
||||
private int successCount;
|
||||
private int failCount;
|
||||
private int finishedCount;
|
||||
private double averageResponseTime;
|
||||
private List<TestResultItem> results;
|
||||
|
||||
@XmlElement
|
||||
public UUID getRunId() {
|
||||
return runId;
|
||||
}
|
||||
|
||||
public void setRunId(UUID runId) {
|
||||
this.runId = runId;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public int getPoolSize() {
|
||||
return poolSize;
|
||||
}
|
||||
|
||||
public void setPoolSize(int poolSize) {
|
||||
this.poolSize = poolSize;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public int getTotalCount() {
|
||||
return totalCount;
|
||||
}
|
||||
|
||||
public void setTotalCount(int totalCount) {
|
||||
this.totalCount = totalCount;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public Date getStartDate() {
|
||||
return startDate;
|
||||
}
|
||||
|
||||
public void setStartDate(Date startDate) {
|
||||
this.startDate = startDate;
|
||||
}
|
||||
|
||||
public long getElapsedTime() {
|
||||
return elapsedTime;
|
||||
}
|
||||
|
||||
public void setElapsedTime(long elapsedTime) {
|
||||
this.elapsedTime = elapsedTime;
|
||||
}
|
||||
|
||||
public int getSuccessCount() {
|
||||
return successCount;
|
||||
}
|
||||
|
||||
public void setSuccessCount(int successCount) {
|
||||
this.successCount = successCount;
|
||||
}
|
||||
|
||||
public int getFailCount() {
|
||||
return failCount;
|
||||
}
|
||||
|
||||
public void setFailCount(int failCount) {
|
||||
this.failCount = failCount;
|
||||
}
|
||||
|
||||
public int getFinishedCount() {
|
||||
return finishedCount;
|
||||
}
|
||||
|
||||
public void setFinishedCount(int finishedCount) {
|
||||
this.finishedCount = finishedCount;
|
||||
}
|
||||
|
||||
public double getAverageResponseTime() {
|
||||
return averageResponseTime;
|
||||
}
|
||||
|
||||
public void setAverageResponseTime(double averageResponseTime) {
|
||||
this.averageResponseTime = averageResponseTime;
|
||||
}
|
||||
|
||||
@XmlElementWrapper(name = "results")
|
||||
@XmlElement(name = "result")
|
||||
public List<TestResultItem> getResults() {
|
||||
return results;
|
||||
}
|
||||
|
||||
public void setResults(List<TestResultItem> results) {
|
||||
this.results = results;
|
||||
}
|
||||
}
|
||||
package org.bench4q.agent.scenario;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement(name = "testResult")
|
||||
public class TestResult implements Serializable {
|
||||
private static final long serialVersionUID = -370091935554266546L;
|
||||
private UUID runId;
|
||||
private int poolSize;
|
||||
private int totalCount;
|
||||
private Date startDate;
|
||||
private long elapsedTime;
|
||||
private int successCount;
|
||||
private int failCount;
|
||||
private int finishedCount;
|
||||
private double averageResponseTime;
|
||||
private List<TestResultItem> results;
|
||||
|
||||
@XmlElement
|
||||
public UUID getRunId() {
|
||||
return runId;
|
||||
}
|
||||
|
||||
public void setRunId(UUID runId) {
|
||||
this.runId = runId;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public int getPoolSize() {
|
||||
return poolSize;
|
||||
}
|
||||
|
||||
public void setPoolSize(int poolSize) {
|
||||
this.poolSize = poolSize;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public int getTotalCount() {
|
||||
return totalCount;
|
||||
}
|
||||
|
||||
public void setTotalCount(int totalCount) {
|
||||
this.totalCount = totalCount;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public Date getStartDate() {
|
||||
return startDate;
|
||||
}
|
||||
|
||||
public void setStartDate(Date startDate) {
|
||||
this.startDate = startDate;
|
||||
}
|
||||
|
||||
public long getElapsedTime() {
|
||||
return elapsedTime;
|
||||
}
|
||||
|
||||
public void setElapsedTime(long elapsedTime) {
|
||||
this.elapsedTime = elapsedTime;
|
||||
}
|
||||
|
||||
public int getSuccessCount() {
|
||||
return successCount;
|
||||
}
|
||||
|
||||
public void setSuccessCount(int successCount) {
|
||||
this.successCount = successCount;
|
||||
}
|
||||
|
||||
public int getFailCount() {
|
||||
return failCount;
|
||||
}
|
||||
|
||||
public void setFailCount(int failCount) {
|
||||
this.failCount = failCount;
|
||||
}
|
||||
|
||||
public int getFinishedCount() {
|
||||
return finishedCount;
|
||||
}
|
||||
|
||||
public void setFinishedCount(int finishedCount) {
|
||||
this.finishedCount = finishedCount;
|
||||
}
|
||||
|
||||
public double getAverageResponseTime() {
|
||||
return averageResponseTime;
|
||||
}
|
||||
|
||||
public void setAverageResponseTime(double averageResponseTime) {
|
||||
this.averageResponseTime = averageResponseTime;
|
||||
}
|
||||
|
||||
@XmlElementWrapper(name = "results")
|
||||
@XmlElement(name = "result")
|
||||
public List<TestResultItem> getResults() {
|
||||
return results;
|
||||
}
|
||||
|
||||
public void setResults(List<TestResultItem> results) {
|
||||
this.results = results;
|
||||
}
|
||||
}
|
|
@ -1,93 +1,93 @@
|
|||
package org.bench4q.agent.scenario;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement(name = "testResultItem")
|
||||
public class TestResultItem implements Serializable {
|
||||
private static final long serialVersionUID = 3307951299814477213L;
|
||||
private UUID id;
|
||||
private String pluginId;
|
||||
private String pluginName;
|
||||
private String behaviorName;
|
||||
private Date startDate;
|
||||
private Date endDate;
|
||||
private long responseTime;
|
||||
private boolean success;
|
||||
|
||||
@XmlElement
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public String getPluginId() {
|
||||
return pluginId;
|
||||
}
|
||||
|
||||
public void setPluginId(String pluginId) {
|
||||
this.pluginId = pluginId;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public String getPluginName() {
|
||||
return pluginName;
|
||||
}
|
||||
|
||||
public void setPluginName(String pluginName) {
|
||||
this.pluginName = pluginName;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public String getBehaviorName() {
|
||||
return behaviorName;
|
||||
}
|
||||
|
||||
public void setBehaviorName(String behaviorName) {
|
||||
this.behaviorName = behaviorName;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public Date getStartDate() {
|
||||
return startDate;
|
||||
}
|
||||
|
||||
public void setStartDate(Date startDate) {
|
||||
this.startDate = startDate;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public Date getEndDate() {
|
||||
return endDate;
|
||||
}
|
||||
|
||||
public void setEndDate(Date endDate) {
|
||||
this.endDate = endDate;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public long getResponseTime() {
|
||||
return responseTime;
|
||||
}
|
||||
|
||||
public void setResponseTime(long responseTime) {
|
||||
this.responseTime = responseTime;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public boolean isSuccess() {
|
||||
return success;
|
||||
}
|
||||
|
||||
public void setSuccess(boolean success) {
|
||||
this.success = success;
|
||||
}
|
||||
}
|
||||
package org.bench4q.agent.scenario;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement(name = "testResultItem")
|
||||
public class TestResultItem implements Serializable {
|
||||
private static final long serialVersionUID = 3307951299814477213L;
|
||||
private UUID id;
|
||||
private String pluginId;
|
||||
private String pluginName;
|
||||
private String behaviorName;
|
||||
private Date startDate;
|
||||
private Date endDate;
|
||||
private long responseTime;
|
||||
private boolean success;
|
||||
|
||||
@XmlElement
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public String getPluginId() {
|
||||
return pluginId;
|
||||
}
|
||||
|
||||
public void setPluginId(String pluginId) {
|
||||
this.pluginId = pluginId;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public String getPluginName() {
|
||||
return pluginName;
|
||||
}
|
||||
|
||||
public void setPluginName(String pluginName) {
|
||||
this.pluginName = pluginName;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public String getBehaviorName() {
|
||||
return behaviorName;
|
||||
}
|
||||
|
||||
public void setBehaviorName(String behaviorName) {
|
||||
this.behaviorName = behaviorName;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public Date getStartDate() {
|
||||
return startDate;
|
||||
}
|
||||
|
||||
public void setStartDate(Date startDate) {
|
||||
this.startDate = startDate;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public Date getEndDate() {
|
||||
return endDate;
|
||||
}
|
||||
|
||||
public void setEndDate(Date endDate) {
|
||||
this.endDate = endDate;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public long getResponseTime() {
|
||||
return responseTime;
|
||||
}
|
||||
|
||||
public void setResponseTime(long responseTime) {
|
||||
this.responseTime = responseTime;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public boolean isSuccess() {
|
||||
return success;
|
||||
}
|
||||
|
||||
public void setSuccess(boolean success) {
|
||||
this.success = success;
|
||||
}
|
||||
}
|
|
@ -1,32 +1,32 @@
|
|||
package org.bench4q.agent.scenario;
|
||||
|
||||
public class UsePlugin {
|
||||
private String id;
|
||||
private String name;
|
||||
private Parameter[] parameters;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Parameter[] getParameters() {
|
||||
return parameters;
|
||||
}
|
||||
|
||||
public void setParameters(Parameter[] parameters) {
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
}
|
||||
package org.bench4q.agent.scenario;
|
||||
|
||||
public class UsePlugin {
|
||||
private String id;
|
||||
private String name;
|
||||
private Parameter[] parameters;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Parameter[] getParameters() {
|
||||
return parameters;
|
||||
}
|
||||
|
||||
public void setParameters(Parameter[] parameters) {
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,14 +1,14 @@
|
|||
package org.bench4q.agent.scenario.behavior;
|
||||
|
||||
import org.bench4q.share.models.agent.scriptrecord.BehaviorModel;
|
||||
|
||||
public class BehaviorFactory {
|
||||
public static Behavior getBuisinessObject(BehaviorModel modelInput) {
|
||||
if (modelInput.getType().equalsIgnoreCase("TIMERBEHAVIOR")) {
|
||||
return new TimerBehavior();
|
||||
} else if (modelInput.getType().equalsIgnoreCase("USERBEHAVIOR")) {
|
||||
return new UserBehavior();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
package org.bench4q.agent.scenario.behavior;
|
||||
|
||||
import org.bench4q.share.models.agent.scriptrecord.BehaviorModel;
|
||||
|
||||
public class BehaviorFactory {
|
||||
public static Behavior getBuisinessObject(BehaviorModel modelInput) {
|
||||
if (modelInput.getType().equalsIgnoreCase("TIMERBEHAVIOR")) {
|
||||
return new TimerBehavior();
|
||||
} else if (modelInput.getType().equalsIgnoreCase("USERBEHAVIOR")) {
|
||||
return new UserBehavior();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,13 +1,13 @@
|
|||
package org.bench4q.agent.share;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class DealWithLog {
|
||||
public static ByteArrayOutputStream getExceptionStackTrace(Exception e) {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
PrintStream printStream = new PrintStream(outputStream);
|
||||
e.printStackTrace(printStream);
|
||||
return outputStream;
|
||||
}
|
||||
}
|
||||
package org.bench4q.agent.share;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class DealWithLog {
|
||||
public static ByteArrayOutputStream getExceptionStackTrace(Exception e) {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
PrintStream printStream = new PrintStream(outputStream);
|
||||
e.printStackTrace(printStream);
|
||||
return outputStream;
|
||||
}
|
||||
}
|
|
@ -1,57 +1,57 @@
|
|||
package org.bench4q.agent.storage;
|
||||
|
||||
public class Buffer {
|
||||
private byte[] content;
|
||||
private int currentPos;
|
||||
private int totalSize;
|
||||
|
||||
public byte[] getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(byte[] content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public int getCurrentPos() {
|
||||
return currentPos;
|
||||
}
|
||||
|
||||
public void setCurrentPos(int currentPos) {
|
||||
this.currentPos = currentPos;
|
||||
}
|
||||
|
||||
public int getTotalSize() {
|
||||
return totalSize;
|
||||
}
|
||||
|
||||
public void setTotalSize(int totalSize) {
|
||||
this.totalSize = totalSize;
|
||||
}
|
||||
|
||||
public static Buffer createBuffer(int totalSize) {
|
||||
Buffer buffer = new Buffer();
|
||||
buffer.setContent(new byte[totalSize]);
|
||||
buffer.setCurrentPos(0);
|
||||
buffer.setTotalSize(totalSize);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public int getRemainSize() {
|
||||
return this.totalSize - this.currentPos;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
this.setCurrentPos(0);
|
||||
}
|
||||
|
||||
public void setFull() {
|
||||
this.setCurrentPos(this.getTotalSize());
|
||||
}
|
||||
|
||||
void writeToCurrentBuffer(int size, byte[] cache) {
|
||||
System.arraycopy(cache, 0, this.getContent(), this.getCurrentPos(),
|
||||
size);
|
||||
this.setCurrentPos(this.getCurrentPos() + size);
|
||||
}
|
||||
}
|
||||
package org.bench4q.agent.storage;
|
||||
|
||||
public class Buffer {
|
||||
private byte[] content;
|
||||
private int currentPos;
|
||||
private int totalSize;
|
||||
|
||||
public byte[] getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(byte[] content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public int getCurrentPos() {
|
||||
return currentPos;
|
||||
}
|
||||
|
||||
public void setCurrentPos(int currentPos) {
|
||||
this.currentPos = currentPos;
|
||||
}
|
||||
|
||||
public int getTotalSize() {
|
||||
return totalSize;
|
||||
}
|
||||
|
||||
public void setTotalSize(int totalSize) {
|
||||
this.totalSize = totalSize;
|
||||
}
|
||||
|
||||
public static Buffer createBuffer(int totalSize) {
|
||||
Buffer buffer = new Buffer();
|
||||
buffer.setContent(new byte[totalSize]);
|
||||
buffer.setCurrentPos(0);
|
||||
buffer.setTotalSize(totalSize);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public int getRemainSize() {
|
||||
return this.totalSize - this.currentPos;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
this.setCurrentPos(0);
|
||||
}
|
||||
|
||||
public void setFull() {
|
||||
this.setCurrentPos(this.getTotalSize());
|
||||
}
|
||||
|
||||
void writeToCurrentBuffer(int size, byte[] cache) {
|
||||
System.arraycopy(cache, 0, this.getContent(), this.getCurrentPos(),
|
||||
size);
|
||||
this.setCurrentPos(this.getCurrentPos() + size);
|
||||
}
|
||||
}
|
|
@ -1,157 +1,157 @@
|
|||
package org.bench4q.agent.storage;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.bench4q.share.models.agent.CleanTestResultModel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class DoubleBufferStorage {
|
||||
private static final int THRESHOLD = 1024;
|
||||
private static Charset charset = Charset.forName("utf-8");
|
||||
private static int BUFFER_SIZE = 48 * 1024;
|
||||
private List<Buffer> bufferList;
|
||||
private int currentBufferIndex;
|
||||
private LocalStorage localStorage;
|
||||
public CleanTestResultModel forTest = new CleanTestResultModel();
|
||||
|
||||
private int getCurrentBufferIndex() {
|
||||
return currentBufferIndex;
|
||||
}
|
||||
|
||||
private void setCurrentBufferIndex(int currentBuffer) {
|
||||
this.currentBufferIndex = currentBuffer;
|
||||
}
|
||||
|
||||
private List<Buffer> getBufferList() {
|
||||
return bufferList;
|
||||
}
|
||||
|
||||
private void setBufferList(List<Buffer> bufferList) {
|
||||
this.bufferList = bufferList;
|
||||
}
|
||||
|
||||
private LocalStorage getLocalStorage() {
|
||||
return localStorage;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setLocalStorage(LocalStorage localStorage) {
|
||||
this.localStorage = localStorage;
|
||||
}
|
||||
|
||||
public DoubleBufferStorage() {
|
||||
this.setBufferList(new ArrayList<Buffer>());
|
||||
this.getBufferList().add(Buffer.createBuffer(BUFFER_SIZE));
|
||||
this.getBufferList().add(Buffer.createBuffer(BUFFER_SIZE));
|
||||
this.setCurrentBufferIndex(0);
|
||||
}
|
||||
|
||||
public String readFiles(String pathPrefix) {
|
||||
int pos = pathPrefix.lastIndexOf(System.getProperty("file.separator"));
|
||||
String dirPath = pathPrefix.substring(0, pos);
|
||||
final String prefix = pathPrefix.substring(pos + 1);
|
||||
String result = new String();
|
||||
|
||||
File dirFile = new File(dirPath);
|
||||
if (!dirFile.exists()) {
|
||||
return "";
|
||||
}
|
||||
File[] files = dirFile.listFiles(new FilenameFilter() {
|
||||
public boolean accept(File dir, String name) {
|
||||
return name.contains(prefix);
|
||||
}
|
||||
});
|
||||
for (File file : files) {
|
||||
if (!file.exists()) {
|
||||
continue;
|
||||
}
|
||||
result += this.getLocalStorage().readFile(file.getAbsolutePath());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean writeFile(String content, String path) {
|
||||
ByteArrayInputStream inputStream = new ByteArrayInputStream(
|
||||
content.getBytes(charset));
|
||||
int size = -1;
|
||||
byte[] cache = new byte[THRESHOLD];
|
||||
while ((size = inputStream.read(cache, 0, THRESHOLD)) != -1) {
|
||||
if (isCurrentBufferFull(size)) {
|
||||
doSave(calculateSavePath(path));
|
||||
changeToTheMaxRemainBuffer();
|
||||
}
|
||||
this.getCurrentBuffer().writeToCurrentBuffer(size, cache);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isCurrentBufferFull(int size) {
|
||||
return getCurrentBuffer().getRemainSize() <= THRESHOLD + size;
|
||||
}
|
||||
|
||||
public String calculateSavePath(String path, int index) {
|
||||
return path.substring(0, path.lastIndexOf(".")) + "_" + index + ".xml";
|
||||
}
|
||||
|
||||
private String calculateSavePath(String path) {
|
||||
return calculateSavePath(path, this.getCurrentBufferIndex());
|
||||
}
|
||||
|
||||
private void doSave(final String path) {
|
||||
final Buffer bufferUnderSave = this.getCurrentBuffer();
|
||||
final String writeContent = this.getMeaningfulContent();
|
||||
Runnable runnable = new Runnable() {
|
||||
public void run() {
|
||||
getLocalStorage().writeFile(writeContent, path);
|
||||
bufferUnderSave.reset();
|
||||
forTest.setSuccess(true);
|
||||
}
|
||||
};
|
||||
ExecutorService service = Executors.newFixedThreadPool(1);
|
||||
service.execute(runnable);
|
||||
service.shutdown();
|
||||
|
||||
}
|
||||
|
||||
private String getMeaningfulContent() {
|
||||
byte[] meaningfulContent = new byte[getCurrentBuffer().getCurrentPos()];
|
||||
System.arraycopy(getCurrentBuffer().getContent(), 0, meaningfulContent,
|
||||
0, getCurrentBuffer().getCurrentPos());
|
||||
return new String(meaningfulContent);
|
||||
}
|
||||
|
||||
private void changeToTheMaxRemainBuffer() {
|
||||
int maxRemainSize = 2 * THRESHOLD;
|
||||
int maxRemainSizeBufferIndex = -1;
|
||||
for (int i = 0; i < this.getBufferList().size(); ++i) {
|
||||
System.out.println(i + " remain : "
|
||||
+ this.getBufferList().get(i).getRemainSize());
|
||||
if (this.getBufferList().get(i).getRemainSize() > maxRemainSize) {
|
||||
maxRemainSize = this.getBufferList().get(i).getRemainSize();
|
||||
maxRemainSizeBufferIndex = i;
|
||||
}
|
||||
}
|
||||
if (maxRemainSizeBufferIndex == -1) {
|
||||
this.getBufferList().add(Buffer.createBuffer(BUFFER_SIZE));
|
||||
maxRemainSizeBufferIndex = this.getBufferList().size() - 1;
|
||||
}
|
||||
this.setCurrentBufferIndex(maxRemainSizeBufferIndex);
|
||||
}
|
||||
|
||||
private Buffer getCurrentBuffer() {
|
||||
return this.getBufferList().get(this.getCurrentBufferIndex());
|
||||
}
|
||||
|
||||
public void flush() {
|
||||
|
||||
}
|
||||
}
|
||||
package org.bench4q.agent.storage;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.bench4q.share.models.agent.CleanTestResultModel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class DoubleBufferStorage {
|
||||
private static final int THRESHOLD = 1024;
|
||||
private static Charset charset = Charset.forName("utf-8");
|
||||
private static int BUFFER_SIZE = 48 * 1024;
|
||||
private List<Buffer> bufferList;
|
||||
private int currentBufferIndex;
|
||||
private LocalStorage localStorage;
|
||||
public CleanTestResultModel forTest = new CleanTestResultModel();
|
||||
|
||||
private int getCurrentBufferIndex() {
|
||||
return currentBufferIndex;
|
||||
}
|
||||
|
||||
private void setCurrentBufferIndex(int currentBuffer) {
|
||||
this.currentBufferIndex = currentBuffer;
|
||||
}
|
||||
|
||||
private List<Buffer> getBufferList() {
|
||||
return bufferList;
|
||||
}
|
||||
|
||||
private void setBufferList(List<Buffer> bufferList) {
|
||||
this.bufferList = bufferList;
|
||||
}
|
||||
|
||||
private LocalStorage getLocalStorage() {
|
||||
return localStorage;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setLocalStorage(LocalStorage localStorage) {
|
||||
this.localStorage = localStorage;
|
||||
}
|
||||
|
||||
public DoubleBufferStorage() {
|
||||
this.setBufferList(new ArrayList<Buffer>());
|
||||
this.getBufferList().add(Buffer.createBuffer(BUFFER_SIZE));
|
||||
this.getBufferList().add(Buffer.createBuffer(BUFFER_SIZE));
|
||||
this.setCurrentBufferIndex(0);
|
||||
}
|
||||
|
||||
public String readFiles(String pathPrefix) {
|
||||
int pos = pathPrefix.lastIndexOf(System.getProperty("file.separator"));
|
||||
String dirPath = pathPrefix.substring(0, pos);
|
||||
final String prefix = pathPrefix.substring(pos + 1);
|
||||
String result = new String();
|
||||
|
||||
File dirFile = new File(dirPath);
|
||||
if (!dirFile.exists()) {
|
||||
return "";
|
||||
}
|
||||
File[] files = dirFile.listFiles(new FilenameFilter() {
|
||||
public boolean accept(File dir, String name) {
|
||||
return name.contains(prefix);
|
||||
}
|
||||
});
|
||||
for (File file : files) {
|
||||
if (!file.exists()) {
|
||||
continue;
|
||||
}
|
||||
result += this.getLocalStorage().readFile(file.getAbsolutePath());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean writeFile(String content, String path) {
|
||||
ByteArrayInputStream inputStream = new ByteArrayInputStream(
|
||||
content.getBytes(charset));
|
||||
int size = -1;
|
||||
byte[] cache = new byte[THRESHOLD];
|
||||
while ((size = inputStream.read(cache, 0, THRESHOLD)) != -1) {
|
||||
if (isCurrentBufferFull(size)) {
|
||||
doSave(calculateSavePath(path));
|
||||
changeToTheMaxRemainBuffer();
|
||||
}
|
||||
this.getCurrentBuffer().writeToCurrentBuffer(size, cache);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isCurrentBufferFull(int size) {
|
||||
return getCurrentBuffer().getRemainSize() <= THRESHOLD + size;
|
||||
}
|
||||
|
||||
public String calculateSavePath(String path, int index) {
|
||||
return path.substring(0, path.lastIndexOf(".")) + "_" + index + ".xml";
|
||||
}
|
||||
|
||||
private String calculateSavePath(String path) {
|
||||
return calculateSavePath(path, this.getCurrentBufferIndex());
|
||||
}
|
||||
|
||||
private void doSave(final String path) {
|
||||
final Buffer bufferUnderSave = this.getCurrentBuffer();
|
||||
final String writeContent = this.getMeaningfulContent();
|
||||
Runnable runnable = new Runnable() {
|
||||
public void run() {
|
||||
getLocalStorage().writeFile(writeContent, path);
|
||||
bufferUnderSave.reset();
|
||||
forTest.setSuccess(true);
|
||||
}
|
||||
};
|
||||
ExecutorService service = Executors.newFixedThreadPool(1);
|
||||
service.execute(runnable);
|
||||
service.shutdown();
|
||||
|
||||
}
|
||||
|
||||
private String getMeaningfulContent() {
|
||||
byte[] meaningfulContent = new byte[getCurrentBuffer().getCurrentPos()];
|
||||
System.arraycopy(getCurrentBuffer().getContent(), 0, meaningfulContent,
|
||||
0, getCurrentBuffer().getCurrentPos());
|
||||
return new String(meaningfulContent);
|
||||
}
|
||||
|
||||
private void changeToTheMaxRemainBuffer() {
|
||||
int maxRemainSize = 2 * THRESHOLD;
|
||||
int maxRemainSizeBufferIndex = -1;
|
||||
for (int i = 0; i < this.getBufferList().size(); ++i) {
|
||||
System.out.println(i + " remain : "
|
||||
+ this.getBufferList().get(i).getRemainSize());
|
||||
if (this.getBufferList().get(i).getRemainSize() > maxRemainSize) {
|
||||
maxRemainSize = this.getBufferList().get(i).getRemainSize();
|
||||
maxRemainSizeBufferIndex = i;
|
||||
}
|
||||
}
|
||||
if (maxRemainSizeBufferIndex == -1) {
|
||||
this.getBufferList().add(Buffer.createBuffer(BUFFER_SIZE));
|
||||
maxRemainSizeBufferIndex = this.getBufferList().size() - 1;
|
||||
}
|
||||
this.setCurrentBufferIndex(maxRemainSizeBufferIndex);
|
||||
}
|
||||
|
||||
private Buffer getCurrentBuffer() {
|
||||
return this.getBufferList().get(this.getCurrentBufferIndex());
|
||||
}
|
||||
|
||||
public void flush() {
|
||||
|
||||
}
|
||||
}
|
|
@ -1,140 +1,140 @@
|
|||
package org.bench4q.agent.storage;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.fs.FSDataInputStream;
|
||||
import org.apache.hadoop.fs.FSDataOutputStream;
|
||||
import org.apache.hadoop.fs.FileStatus;
|
||||
import org.apache.hadoop.fs.FileSystem;
|
||||
import org.apache.hadoop.fs.Path;
|
||||
import org.apache.hadoop.io.IOUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class HdfsStorage implements Storage {
|
||||
private FileSystem getFileSystem() throws IOException {
|
||||
Configuration conf = new Configuration();
|
||||
conf.set("mapred.jop.tracker", "hdfs://133.133.12.21:9001");
|
||||
conf.set("fs.default.name", "hdfs://133.133.12.21:9000");
|
||||
return FileSystem.get(conf);
|
||||
}
|
||||
|
||||
public boolean uploadFile(String localPath, String remotePath) {
|
||||
try {
|
||||
FileSystem fs = this.getFileSystem();
|
||||
fs.copyFromLocalFile(new Path(localPath), new Path(remotePath));
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean writeFile(String content, String remotePath) {
|
||||
try {
|
||||
InputStream in = new ByteArrayInputStream(content.getBytes());
|
||||
FileSystem fs = this.getFileSystem();
|
||||
OutputStream out = fs.create(new Path(remotePath));
|
||||
IOUtils.copyBytes(in, out, 4096, true);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean downloadFile(String localPath, String remotePath) {
|
||||
try {
|
||||
FileSystem fs = this.getFileSystem();
|
||||
fs.copyToLocalFile(new Path(remotePath), new Path(localPath));
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public String readFile(String remotePath) {
|
||||
try {
|
||||
FileSystem fs = this.getFileSystem();
|
||||
FSDataInputStream hdfsInStream = fs.open(new Path(remotePath));
|
||||
OutputStream out = new ByteArrayOutputStream();
|
||||
byte[] ioBuffer = new byte[1024];
|
||||
int readLen = hdfsInStream.read(ioBuffer);
|
||||
while (-1 != readLen) {
|
||||
out.write(ioBuffer, 0, readLen);
|
||||
readLen = hdfsInStream.read(ioBuffer);
|
||||
}
|
||||
out.close();
|
||||
String ret = out.toString();
|
||||
hdfsInStream.close();
|
||||
return ret;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean appendFile(String content, String remotePath) {
|
||||
try {
|
||||
FileSystem fs = this.getFileSystem();
|
||||
FSDataOutputStream out = fs.append(new Path(remotePath));
|
||||
int readLen = content.getBytes().length;
|
||||
while (-1 != readLen) {
|
||||
out.write(content.getBytes(), 0, readLen);
|
||||
}
|
||||
out.close();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean deleteFile(String remotePath) {
|
||||
try {
|
||||
FileSystem fs = this.getFileSystem();
|
||||
return fs.delete(new Path(remotePath), false);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean deleteDirectory(String remotePath) {
|
||||
try {
|
||||
FileSystem fs = this.getFileSystem();
|
||||
return fs.delete(new Path(remotePath), true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean renameFile(String fromPath, String toPath) {
|
||||
try {
|
||||
FileSystem fs = this.getFileSystem();
|
||||
return fs.rename(new Path(fromPath), new Path(toPath));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public FileStatus[] listFile(String remotePath) {
|
||||
try {
|
||||
FileSystem fs = this.getFileSystem();
|
||||
FileStatus[] fileList = fs.listStatus(new Path(remotePath));
|
||||
return fileList;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
package org.bench4q.agent.storage;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.fs.FSDataInputStream;
|
||||
import org.apache.hadoop.fs.FSDataOutputStream;
|
||||
import org.apache.hadoop.fs.FileStatus;
|
||||
import org.apache.hadoop.fs.FileSystem;
|
||||
import org.apache.hadoop.fs.Path;
|
||||
import org.apache.hadoop.io.IOUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class HdfsStorage implements Storage {
|
||||
private FileSystem getFileSystem() throws IOException {
|
||||
Configuration conf = new Configuration();
|
||||
conf.set("mapred.jop.tracker", "hdfs://133.133.12.21:9001");
|
||||
conf.set("fs.default.name", "hdfs://133.133.12.21:9000");
|
||||
return FileSystem.get(conf);
|
||||
}
|
||||
|
||||
public boolean uploadFile(String localPath, String remotePath) {
|
||||
try {
|
||||
FileSystem fs = this.getFileSystem();
|
||||
fs.copyFromLocalFile(new Path(localPath), new Path(remotePath));
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean writeFile(String content, String remotePath) {
|
||||
try {
|
||||
InputStream in = new ByteArrayInputStream(content.getBytes());
|
||||
FileSystem fs = this.getFileSystem();
|
||||
OutputStream out = fs.create(new Path(remotePath));
|
||||
IOUtils.copyBytes(in, out, 4096, true);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean downloadFile(String localPath, String remotePath) {
|
||||
try {
|
||||
FileSystem fs = this.getFileSystem();
|
||||
fs.copyToLocalFile(new Path(remotePath), new Path(localPath));
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public String readFile(String remotePath) {
|
||||
try {
|
||||
FileSystem fs = this.getFileSystem();
|
||||
FSDataInputStream hdfsInStream = fs.open(new Path(remotePath));
|
||||
OutputStream out = new ByteArrayOutputStream();
|
||||
byte[] ioBuffer = new byte[1024];
|
||||
int readLen = hdfsInStream.read(ioBuffer);
|
||||
while (-1 != readLen) {
|
||||
out.write(ioBuffer, 0, readLen);
|
||||
readLen = hdfsInStream.read(ioBuffer);
|
||||
}
|
||||
out.close();
|
||||
String ret = out.toString();
|
||||
hdfsInStream.close();
|
||||
return ret;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean appendFile(String content, String remotePath) {
|
||||
try {
|
||||
FileSystem fs = this.getFileSystem();
|
||||
FSDataOutputStream out = fs.append(new Path(remotePath));
|
||||
int readLen = content.getBytes().length;
|
||||
while (-1 != readLen) {
|
||||
out.write(content.getBytes(), 0, readLen);
|
||||
}
|
||||
out.close();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean deleteFile(String remotePath) {
|
||||
try {
|
||||
FileSystem fs = this.getFileSystem();
|
||||
return fs.delete(new Path(remotePath), false);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean deleteDirectory(String remotePath) {
|
||||
try {
|
||||
FileSystem fs = this.getFileSystem();
|
||||
return fs.delete(new Path(remotePath), true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean renameFile(String fromPath, String toPath) {
|
||||
try {
|
||||
FileSystem fs = this.getFileSystem();
|
||||
return fs.rename(new Path(fromPath), new Path(toPath));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public FileStatus[] listFile(String remotePath) {
|
||||
try {
|
||||
FileSystem fs = this.getFileSystem();
|
||||
FileStatus[] fileList = fs.listStatus(new Path(remotePath));
|
||||
return fileList;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,17 +1,17 @@
|
|||
package org.bench4q.agent.storage;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class MooseStorage implements Storage {
|
||||
|
||||
public String readFile(String path) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean writeFile(String content, String path) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
package org.bench4q.agent.storage;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class MooseStorage implements Storage {
|
||||
|
||||
public String readFile(String path) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean writeFile(String content, String path) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,31 +1,31 @@
|
|||
log4j.rootLogger = INFO,WARN,ERROR,FALTAL,D
|
||||
|
||||
log4j.appender.WARN = org.apache.log4j.DailyRollingFileAppender
|
||||
log4j.appender.WARN.File = logs/log.log
|
||||
log4j.appender.WARN.Append = true
|
||||
log4j.appender.WARN.Threshold = WARN
|
||||
log4j.appender.WARN.layout = org.apache.log4j.PatternLayout
|
||||
log4j.appender.WARN.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
|
||||
|
||||
log4j.appender.ERROR = org.apache.log4j.DailyRollingFileAppender
|
||||
log4j.appender.ERROR.File = logs/log.log
|
||||
log4j.appender.ERROR.Append = true
|
||||
log4j.appender.ERROR.Threshold = ERROR
|
||||
log4j.appender.ERROR.layout = org.apache.log4j.PatternLayout
|
||||
log4j.appender.ERROR.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
|
||||
|
||||
log4j.appender.FALTAL = org.apache.log4j.DailyRollingFileAppender
|
||||
log4j.appender.FALTAL.File = logs/log.log
|
||||
log4j.appender.FALTAL.Append = true
|
||||
log4j.appender.FALTAL.Threshold = ERROR
|
||||
log4j.appender.FALTAL.layout = org.apache.log4j.PatternLayout
|
||||
log4j.appender.FALTAL.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
|
||||
|
||||
|
||||
log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
|
||||
log4j.appender.D.File = logs/log.log
|
||||
log4j.appender.D.Append = true
|
||||
log4j.appender.D.Threshold = INFO
|
||||
log4j.appender.D.layout = org.apache.log4j.PatternLayout
|
||||
log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
|
||||
|
||||
log4j.rootLogger = INFO,WARN,ERROR,FALTAL,D
|
||||
|
||||
log4j.appender.WARN = org.apache.log4j.DailyRollingFileAppender
|
||||
log4j.appender.WARN.File = logs/log.log
|
||||
log4j.appender.WARN.Append = true
|
||||
log4j.appender.WARN.Threshold = WARN
|
||||
log4j.appender.WARN.layout = org.apache.log4j.PatternLayout
|
||||
log4j.appender.WARN.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
|
||||
|
||||
log4j.appender.ERROR = org.apache.log4j.DailyRollingFileAppender
|
||||
log4j.appender.ERROR.File = logs/log.log
|
||||
log4j.appender.ERROR.Append = true
|
||||
log4j.appender.ERROR.Threshold = ERROR
|
||||
log4j.appender.ERROR.layout = org.apache.log4j.PatternLayout
|
||||
log4j.appender.ERROR.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
|
||||
|
||||
log4j.appender.FALTAL = org.apache.log4j.DailyRollingFileAppender
|
||||
log4j.appender.FALTAL.File = logs/log.log
|
||||
log4j.appender.FALTAL.Append = true
|
||||
log4j.appender.FALTAL.Threshold = ERROR
|
||||
log4j.appender.FALTAL.layout = org.apache.log4j.PatternLayout
|
||||
log4j.appender.FALTAL.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
|
||||
|
||||
|
||||
log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
|
||||
log4j.appender.D.File = logs/log.log
|
||||
log4j.appender.D.Append = true
|
||||
log4j.appender.D.Threshold = INFO
|
||||
log4j.appender.D.layout = org.apache.log4j.PatternLayout
|
||||
log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
|
||||
|
|
@ -1,27 +1,27 @@
|
|||
package org.bench4q.agent.test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bench4q.agent.scenario.Scenario;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.agent.RunScenarioModel;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ExtractScenarioTest {
|
||||
|
||||
@Test
|
||||
public void test() throws JAXBException, IOException {
|
||||
RunScenarioModel runScenarioModel = (RunScenarioModel) MarshalHelper
|
||||
.unmarshal(RunScenarioModel.class, FileUtils
|
||||
.readFileToString(new File("Scripts/goodForPage.xml")));
|
||||
Scenario scenario = Scenario.scenarioBuilder(runScenarioModel);
|
||||
|
||||
assertTrue(scenario.getPages().length > 0);
|
||||
}
|
||||
}
|
||||
package org.bench4q.agent.test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bench4q.agent.scenario.Scenario;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.agent.RunScenarioModel;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ExtractScenarioTest {
|
||||
|
||||
@Test
|
||||
public void test() throws JAXBException, IOException {
|
||||
RunScenarioModel runScenarioModel = (RunScenarioModel) MarshalHelper
|
||||
.unmarshal(RunScenarioModel.class, FileUtils
|
||||
.readFileToString(new File("Scripts/goodForPage.xml")));
|
||||
Scenario scenario = Scenario.scenarioBuilder(runScenarioModel);
|
||||
|
||||
assertTrue(scenario.getPages().length > 0);
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
package org.bench4q.agent.test;
|
||||
|
||||
public class HomeControllerTest {
|
||||
|
||||
}
|
||||
package org.bench4q.agent.test;
|
||||
|
||||
public class HomeControllerTest {
|
||||
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
package org.bench4q.agent.test;
|
||||
|
||||
public class PluginControllerTest {
|
||||
|
||||
}
|
||||
package org.bench4q.agent.test;
|
||||
|
||||
public class PluginControllerTest {
|
||||
|
||||
}
|
|
@ -1,30 +1,30 @@
|
|||
package org.bench4q.agent.test.model;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import org.bench4q.share.models.agent.scriptrecord.BehaviorModel;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@XmlRootElement(name = "modelTest")
|
||||
public class ModelTest {
|
||||
|
||||
@Test
|
||||
public void unmarshalVerify() throws IOException, JAXBException {
|
||||
Object object = JAXBContext
|
||||
.newInstance(BehaviorModel.class)
|
||||
.createUnmarshaller()
|
||||
.unmarshal(
|
||||
new File("Scripts"
|
||||
+ System.getProperty("file.separator")
|
||||
+ "behaviorModel.xml"));
|
||||
assertTrue(object instanceof BehaviorModel);
|
||||
}
|
||||
|
||||
}
|
||||
package org.bench4q.agent.test.model;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import org.bench4q.share.models.agent.scriptrecord.BehaviorModel;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@XmlRootElement(name = "modelTest")
|
||||
public class ModelTest {
|
||||
|
||||
@Test
|
||||
public void unmarshalVerify() throws IOException, JAXBException {
|
||||
Object object = JAXBContext
|
||||
.newInstance(BehaviorModel.class)
|
||||
.createUnmarshaller()
|
||||
.unmarshal(
|
||||
new File("Scripts"
|
||||
+ System.getProperty("file.separator")
|
||||
+ "behaviorModel.xml"));
|
||||
assertTrue(object instanceof BehaviorModel);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,26 +1,26 @@
|
|||
package org.bench4q.agent.test.model;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
|
||||
import org.bench4q.share.models.agent.scriptrecord.BehaviorModel;
|
||||
import org.junit.Test;
|
||||
|
||||
public class UserBehaviorModelTest {
|
||||
|
||||
@Test
|
||||
public void testUnmarshal() throws JAXBException {
|
||||
Unmarshaller unmarshaller = JAXBContext.newInstance(
|
||||
BehaviorModel.class).createUnmarshaller();
|
||||
Object object = unmarshaller.unmarshal(new File("Scripts"
|
||||
+ System.getProperty("file.separator") + "behaviorModel.xml"));
|
||||
BehaviorModel userBehaviorModel = (BehaviorModel) object;
|
||||
System.out.println(userBehaviorModel.getUse());
|
||||
assertTrue(object instanceof BehaviorModel);
|
||||
}
|
||||
}
|
||||
package org.bench4q.agent.test.model;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
|
||||
import org.bench4q.share.models.agent.scriptrecord.BehaviorModel;
|
||||
import org.junit.Test;
|
||||
|
||||
public class UserBehaviorModelTest {
|
||||
|
||||
@Test
|
||||
public void testUnmarshal() throws JAXBException {
|
||||
Unmarshaller unmarshaller = JAXBContext.newInstance(
|
||||
BehaviorModel.class).createUnmarshaller();
|
||||
Object object = unmarshaller.unmarshal(new File("Scripts"
|
||||
+ System.getProperty("file.separator") + "behaviorModel.xml"));
|
||||
BehaviorModel userBehaviorModel = (BehaviorModel) object;
|
||||
System.out.println(userBehaviorModel.getUse());
|
||||
assertTrue(object instanceof BehaviorModel);
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue