Constant timer and Http plugin added.
This commit is contained in:
parent
96be2104c6
commit
d0a14e6ea4
|
@ -9,7 +9,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
|||
@RequestMapping("/")
|
||||
public class HomeController {
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
@RequestMapping(method = { RequestMethod.GET, RequestMethod.POST })
|
||||
@ResponseBody
|
||||
public String index() {
|
||||
|
||||
|
|
|
@ -6,9 +6,9 @@ import java.util.List;
|
|||
import org.bench4q.agent.api.model.BehaviorInfoModel;
|
||||
import org.bench4q.agent.api.model.PluginInfoListModel;
|
||||
import org.bench4q.agent.api.model.PluginInfoModel;
|
||||
import org.bench4q.agent.plugin.BehaviorInfo;
|
||||
import org.bench4q.agent.plugin.PluginInfo;
|
||||
import org.bench4q.agent.plugin.PluginManager;
|
||||
import org.bench4q.agent.plugin.metadata.BehaviorInfo;
|
||||
import org.bench4q.agent.plugin.metadata.PluginInfo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
|
|
@ -49,29 +49,24 @@ public class TestController {
|
|||
scenario.getUserBehaviors()[0] = new UserBehavior();
|
||||
scenario.getUserBehaviors()[0].setUse("http");
|
||||
scenario.getUserBehaviors()[0].setName("Get");
|
||||
scenario.getUserBehaviors()[0].setParameters(new Parameter[2]);
|
||||
scenario.getUserBehaviors()[0].setParameters(new Parameter[1]);
|
||||
scenario.getUserBehaviors()[0].getParameters()[0] = new Parameter();
|
||||
scenario.getUserBehaviors()[0].getParameters()[0].setKey("url");
|
||||
scenario.getUserBehaviors()[0].getParameters()[0].setValue("localhost");
|
||||
scenario.getUserBehaviors()[0].getParameters()[1] = new Parameter();
|
||||
scenario.getUserBehaviors()[0].getParameters()[1].setKey("content");
|
||||
scenario.getUserBehaviors()[0].getParameters()[1]
|
||||
.setValue("Hello,world!");
|
||||
scenario.getUserBehaviors()[0].getParameters()[0]
|
||||
.setValue("http://www.baidu.com");
|
||||
|
||||
scenario.getUserBehaviors()[1] = new UserBehavior();
|
||||
scenario.getUserBehaviors()[1].setUse("http");
|
||||
scenario.getUserBehaviors()[1].setName("Post");
|
||||
scenario.getUserBehaviors()[1].setParameters(new Parameter[3]);
|
||||
scenario.getUserBehaviors()[1].setParameters(new Parameter[2]);
|
||||
scenario.getUserBehaviors()[1].getParameters()[0] = new Parameter();
|
||||
scenario.getUserBehaviors()[1].getParameters()[0].setKey("url");
|
||||
scenario.getUserBehaviors()[1].getParameters()[0].setValue("localhost");
|
||||
scenario.getUserBehaviors()[1].getParameters()[0]
|
||||
.setValue("http://localhost:6565");
|
||||
scenario.getUserBehaviors()[1].getParameters()[1] = new Parameter();
|
||||
scenario.getUserBehaviors()[1].getParameters()[1].setKey("content");
|
||||
scenario.getUserBehaviors()[1].getParameters()[1]
|
||||
.setValue("Hello,world!");
|
||||
scenario.getUserBehaviors()[1].getParameters()[2] = new Parameter();
|
||||
scenario.getUserBehaviors()[1].getParameters()[2].setKey("code");
|
||||
scenario.getUserBehaviors()[1].getParameters()[2].setValue("404");
|
||||
|
||||
scenario.getUserBehaviors()[2] = new UserBehavior();
|
||||
scenario.getUserBehaviors()[2].setUse("timer");
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package org.bench4q.agent.plugin.annotation;
|
||||
package org.bench4q.agent.plugin;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
|
@ -1,4 +1,4 @@
|
|||
package org.bench4q.agent.plugin.metadata;
|
||||
package org.bench4q.agent.plugin;
|
||||
|
||||
public class BehaviorInfo {
|
||||
private String name;
|
|
@ -1,4 +1,4 @@
|
|||
package org.bench4q.agent.plugin.annotation;
|
||||
package org.bench4q.agent.plugin;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
|
@ -1,4 +1,4 @@
|
|||
package org.bench4q.agent.plugin.metadata;
|
||||
package org.bench4q.agent.plugin;
|
||||
|
||||
public class PluginInfo {
|
||||
private String name;
|
|
@ -16,10 +16,6 @@ import javassist.bytecode.CodeAttribute;
|
|||
import javassist.bytecode.LocalVariableAttribute;
|
||||
import javassist.bytecode.MethodInfo;
|
||||
|
||||
import org.bench4q.agent.plugin.annotation.Behavior;
|
||||
import org.bench4q.agent.plugin.annotation.Plugin;
|
||||
import org.bench4q.agent.plugin.metadata.BehaviorInfo;
|
||||
import org.bench4q.agent.plugin.metadata.PluginInfo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
|
|
@ -1,45 +1,84 @@
|
|||
package org.bench4q.agent.plugin.http;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.Date;
|
||||
|
||||
import org.bench4q.agent.plugin.Behavior;
|
||||
import org.bench4q.agent.plugin.BehaviorResult;
|
||||
import org.bench4q.agent.plugin.annotation.Behavior;
|
||||
import org.bench4q.agent.plugin.annotation.Plugin;
|
||||
import org.bench4q.agent.plugin.Plugin;
|
||||
|
||||
@Plugin("Http")
|
||||
public class HttpPlugin {
|
||||
public HttpPlugin() {
|
||||
System.out.println("init http plugin");
|
||||
|
||||
}
|
||||
|
||||
@Behavior("Get")
|
||||
public BehaviorResult get(String url, String content) {
|
||||
public BehaviorResult get(String url) {
|
||||
BehaviorResult behaviorResult = new BehaviorResult();
|
||||
behaviorResult.setStartDate(new Date(System.currentTimeMillis()));
|
||||
try {
|
||||
System.out.println("get");
|
||||
System.out.println("url:" + url);
|
||||
System.out.println("content:" + content);
|
||||
behaviorResult.setEndDate(new Date(System.currentTimeMillis()));
|
||||
URL target = new URL(url);
|
||||
HttpURLConnection httpURLConnection = (HttpURLConnection) target
|
||||
.openConnection();
|
||||
httpURLConnection.setDoOutput(false);
|
||||
httpURLConnection.setDoInput(true);
|
||||
httpURLConnection.setUseCaches(false);
|
||||
httpURLConnection.setRequestMethod("GET");
|
||||
BufferedReader bufferedReader = new BufferedReader(
|
||||
new InputStreamReader(httpURLConnection.getInputStream()));
|
||||
int temp = -1;
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
while ((temp = bufferedReader.read()) != -1) {
|
||||
stringBuffer.append((char) temp);
|
||||
}
|
||||
bufferedReader.close();
|
||||
behaviorResult.setSuccess(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
behaviorResult.setSuccess(false);
|
||||
} finally {
|
||||
behaviorResult.setEndDate(new Date(System.currentTimeMillis()));
|
||||
behaviorResult.setSuccess(true);
|
||||
}
|
||||
return behaviorResult;
|
||||
}
|
||||
|
||||
@Behavior("Post")
|
||||
public BehaviorResult post(String url, String content, int code) {
|
||||
public BehaviorResult post(String url, String content) {
|
||||
BehaviorResult behaviorResult = new BehaviorResult();
|
||||
behaviorResult.setStartDate(new Date(System.currentTimeMillis()));
|
||||
System.out.println("get");
|
||||
System.out.println("url:" + url);
|
||||
System.out.println("content:" + content);
|
||||
System.out.println("code:" + code);
|
||||
behaviorResult.setEndDate(new Date(System.currentTimeMillis()));
|
||||
behaviorResult.setSuccess(true);
|
||||
try {
|
||||
URL target = new URL(url);
|
||||
HttpURLConnection httpURLConnection = (HttpURLConnection) target
|
||||
.openConnection();
|
||||
httpURLConnection.setDoOutput(true);
|
||||
httpURLConnection.setDoInput(true);
|
||||
httpURLConnection.setUseCaches(false);
|
||||
httpURLConnection.setRequestMethod("POST");
|
||||
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(
|
||||
httpURLConnection.getOutputStream());
|
||||
outputStreamWriter.write(content);
|
||||
outputStreamWriter.flush();
|
||||
outputStreamWriter.close();
|
||||
BufferedReader bufferedReader = new BufferedReader(
|
||||
new InputStreamReader(httpURLConnection.getInputStream()));
|
||||
int temp = -1;
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
while ((temp = bufferedReader.read()) != -1) {
|
||||
stringBuffer.append((char) temp);
|
||||
}
|
||||
bufferedReader.close();
|
||||
behaviorResult.setSuccess(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
behaviorResult.setSuccess(false);
|
||||
} finally {
|
||||
behaviorResult.setEndDate(new Date(System.currentTimeMillis()));
|
||||
}
|
||||
return behaviorResult;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,9 +2,9 @@ package org.bench4q.agent.plugin.timer;
|
|||
|
||||
import java.util.Date;
|
||||
|
||||
import org.bench4q.agent.plugin.Behavior;
|
||||
import org.bench4q.agent.plugin.BehaviorResult;
|
||||
import org.bench4q.agent.plugin.annotation.Behavior;
|
||||
import org.bench4q.agent.plugin.annotation.Plugin;
|
||||
import org.bench4q.agent.plugin.Plugin;
|
||||
|
||||
@Plugin("ConstantTimer")
|
||||
public class ConstantTimerPlugin {
|
||||
|
@ -17,14 +17,13 @@ public class ConstantTimerPlugin {
|
|||
BehaviorResult behaviorResult = new BehaviorResult();
|
||||
behaviorResult.setStartDate(new Date(System.currentTimeMillis()));
|
||||
try {
|
||||
System.out.println("sleep:" + time);
|
||||
Thread.sleep(time);
|
||||
behaviorResult.setEndDate(new Date(System.currentTimeMillis()));
|
||||
behaviorResult.setSuccess(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
behaviorResult.setEndDate(new Date(System.currentTimeMillis()));
|
||||
behaviorResult.setSuccess(false);
|
||||
} finally {
|
||||
behaviorResult.setEndDate(new Date(System.currentTimeMillis()));
|
||||
}
|
||||
return behaviorResult;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue