本文整理汇总了Java中org.apache.jmeter.JMeter类的典型用法代码示例。如果您正苦于以下问题:Java JMeter类的具体用法?Java JMeter怎么用?Java JMeter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JMeter类属于org.apache.jmeter包,在下文中一共展示了JMeter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import org.apache.jmeter.JMeter; //导入依赖的package包/类
public void start() {
log.debug("Start debugging");
frontend.started();
HashTree hashTree = getSelectedTree();
StandardJMeterEngine.register(new StateListener()); // oh, dear, they use static field then clean it...
engine = new DebuggerEngine(JMeterContextService.getContext());
engine.setStepper(this);
JMeter.convertSubTree(hashTree);
engine.configure(hashTree);
try {
engine.runTest();
} catch (JMeterEngineException e) {
log.error("Failed to pauseContinue debug", e);
stop();
}
}
示例2: runRealEngine
import org.apache.jmeter.JMeter; //导入依赖的package包/类
@Test
public void runRealEngine() throws Exception {
TestTreeProvider prov = new TestProvider();
HashTree hashTree = prov.getTestTree();
JMeter.convertSubTree(hashTree);
StandardJMeterEngine engine = new StandardJMeterEngine();
engine.configure(hashTree);
engine.runTest();
while (engine.isActive()) {
Thread.sleep(1000);
}
}
示例3: startEngine
import org.apache.jmeter.JMeter; //导入依赖的package包/类
/**
* Start JMeter engine
* @param noTimer ignore timers
*/
private void startEngine(boolean ignoreTimer) {
GuiPackage gui = GuiPackage.getInstance();
HashTree testTree = gui.getTreeModel().getTestPlan();
JMeter.convertSubTree(testTree);
testTree.add(testTree.getArray()[0], gui.getMainFrame());
log.debug("test plan before cloning is running version: "
+ ((TestPlan) testTree.getArray()[0]).isRunningVersion());
TreeCloner cloner = cloneTree(testTree, ignoreTimer);
engine = new StandardJMeterEngine();
engine.configure(cloner.getClonedTree());
try {
engine.runTest();
} catch (JMeterEngineException e) {
JOptionPane.showMessageDialog(gui.getMainFrame(), e.getMessage(),
JMeterUtils.getResString("error_occurred"), JOptionPane.ERROR_MESSAGE); //$NON-NLS-1$
}
log.debug("test plan after cloning and running test is running version: "
+ ((TestPlan) testTree.getArray()[0]).isRunningVersion());
}
示例4: runDebugEngine
import org.apache.jmeter.JMeter; //导入依赖的package包/类
@Test
public void runDebugEngine() throws Exception {
TestProvider prov = new TestProvider();
Debugger sel = new Debugger(prov, new FrontendMock());
AbstractThreadGroup tg = prov.getTG(0);
sel.selectThreadGroup(tg);
HashTree testTree = sel.getSelectedTree();
DebuggingThreadGroup tg2 = (DebuggingThreadGroup) getFirstTG(testTree);
LoopController samplerController = (LoopController) tg2.getSamplerController();
samplerController.setLoops(1);
samplerController.setContinueForever(false);
JMeter.convertSubTree(testTree);
DebuggerEngine engine = new DebuggerEngine(JMeterContextService.getContext());
StepTriggerCounter hook = new StepTriggerCounter();
engine.setStepper(hook);
engine.configure(testTree);
engine.runTest();
while (engine.isActive()) {
Thread.sleep(1000);
}
assertEquals(88, hook.cnt);
}
示例5: checkProxy
import org.apache.jmeter.JMeter; //导入依赖的package包/类
private void checkProxy() {
if (JMeter.isNonGUI()) {
this.setUseProxy(true);
// we check to see if the proxy host and port are set
String port = this.getPropertyAsString(PROXY_PORT);
String host = this.getPropertyAsString(PROXY_HOST);
if (host == null || host.length() == 0) {
// it's not set, lets check if the user passed
// proxy host and port from command line
host = System.getProperty("http.proxyHost");
if (host != null) {
this.setProxyHost(host);
}
}
if (port == null || port.length() == 0) {
// it's not set, lets check if the user passed
// proxy host and port from command line
port = System.getProperty("http.proxyPort");
if (port != null) {
this.setProxyPort(port);
}
}
}
}
示例6: main
import org.apache.jmeter.JMeter; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
int port = JMeter.UDP_PORT_DEFAULT;
if (args.length > 1){
port = Integer.parseInt(args[1]);
} else if (args.length == 0) {
throw new RuntimeException("Usage: command [port]");
}
String command = args[0];
System.out.println("Sending "+command+" request to port "+port);
DatagramSocket socket = new DatagramSocket();
byte[] buf = command.getBytes("ASCII");
InetAddress address = InetAddress.getByName("localhost");
DatagramPacket packet = new DatagramPacket(buf, buf.length, address, port);
socket.send(packet);
socket.close();
}
示例7: createHTTPClient
import org.apache.jmeter.JMeter; //导入依赖的package包/类
private static AbstractHttpClient createHTTPClient() {
AbstractHttpClient client = new DefaultHttpClient();
String proxyHost = System.getProperty("https.proxyHost", "");
if (!proxyHost.isEmpty()) {
int proxyPort = Integer.parseInt(System.getProperty("https.proxyPort", "-1"));
log.info("Using proxy " + proxyHost + ":" + proxyPort);
HttpParams params = client.getParams();
HttpHost proxy = new HttpHost(proxyHost, proxyPort);
params.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
String proxyUser = System.getProperty(JMeter.HTTP_PROXY_USER, JMeterUtils.getProperty(JMeter.HTTP_PROXY_USER));
if (proxyUser != null) {
log.info("Using authenticated proxy with username: " + proxyUser);
String proxyPass = System.getProperty(JMeter.HTTP_PROXY_PASS, JMeterUtils.getProperty(JMeter.HTTP_PROXY_PASS));
String localHost;
try {
localHost = InetAddress.getLocalHost().getCanonicalHostName();
} catch (Throwable e) {
log.error("Failed to get local host name, defaulting to 'localhost'", e);
localHost = "localhost";
}
AuthScope authscope = new AuthScope(proxyHost, proxyPort);
String proxyDomain = JMeterUtils.getPropDefault("http.proxyDomain", "");
NTCredentials credentials = new NTCredentials(proxyUser, proxyPass, localHost, proxyDomain);
client.getCredentialsProvider().setCredentials(authscope, credentials);
}
}
return client;
}
示例8: testEnded
import org.apache.jmeter.JMeter; //导入依赖的package包/类
@Override
public void testEnded(String arg0) {
logger.info("in testEnded, isNonGUI=" + JMeter.isNonGUI() + ", sleepFlag=" + sleepFlag.get());
this.interrupt = true;
try {
if (JMeter.isNonGUI()) {
if(!sleepFlag.get()) {
//The keepTime is saved as static variable, because keepTime variable in testEnded()
//returns with initial value.
logger.info("The work has been done, will keep connection for " + keepTime + " sceconds.");
TimeUnit.SECONDS.sleep(keepTime);
sleepFlag.set(true);
}
//The following code does not make sense, because the connection variable was already reset.
//But it makes sense in threadFinished method.
//The reason for not sleeping and then disconnecting in threadFinished is to avoid maintain too much of threads.
//Otherwise each thread (for a thread-group) will be kept open before sleeping.
/*if(this.connection != null) {
this.connection.disconnect();
logger.info(MessageFormat.format("The connection {0} disconneted successfully.", connection));
}*/
}
} catch(Exception ex) {
logger.error(ex.getMessage(), ex);
}
}
示例9: interrupt
import org.apache.jmeter.JMeter; //导入依赖的package包/类
@Override
public boolean interrupt() {
this.interrupt = true;
if (!JMeter.isNonGUI()) {
logger.info("In GUI mode, received the interrupt request from user.");
}
return true;
}
示例10: sampleOccurred
import org.apache.jmeter.JMeter; //导入依赖的package包/类
/**
* In this listener, it can receive the interrupt event trigger by user.
*/
@Override
public void sampleOccurred(SampleEvent event) {
if (!JMeter.isNonGUI() && "MQTT Connection Sampler".equals(event.getResult().getSampleLabel() )) {
logger.info("Created the sampler results, will sleep current thread for " + getConnKeepTime() + " sceconds");
sleepCurrentThreadAndDisconnect();
}
}
示例11: initProxyConfiguration
import org.apache.jmeter.JMeter; //导入依赖的package包/类
static void initProxyConfiguration() {
proxyHost = System.getProperty("http.proxyHost",null);
proxyPort = Integer.parseInt(System.getProperty("http.proxyPort","0"));
List<String> nonProxyHostList = Arrays.asList(System.getProperty("http.nonProxyHosts","").split("\\|"));
nonProxyHosts = nonProxyHostList.stream().filter(h -> !h.startsWith("*")).collect(Collectors.toList());
nonProxyWildcards = nonProxyHostList.stream().filter(h -> h.startsWith("*")).map(w -> w.substring(1)).collect(Collectors.toList());
proxyUsername = JMeterUtils.getPropDefault(JMeter.HTTP_PROXY_USER,null);
proxyPassword = JMeterUtils.getPropDefault(JMeter.HTTP_PROXY_PASS,null);
}
示例12: selectThreadGroup
import org.apache.jmeter.JMeter; //导入依赖的package包/类
private void selectThreadGroup(AbstractThreadGroup tg) {
debugger.selectThreadGroup(tg);
treeModel.clearTestPlan();
HashTree origTree = debugger.getSelectedTree();
TreeCloner cloner = new TreeCloner();
origTree.traverse(cloner);
HashTree selectedTree = cloner.getClonedTree();
// Hack to resolve ModuleControllers from JMeter.java
SearchClass<ReplaceableController> replaceableControllers = new SearchClass<>(ReplaceableController.class);
selectedTree.traverse(replaceableControllers);
Collection<ReplaceableController> replaceableControllersRes = replaceableControllers.getSearchResults();
for (ReplaceableController replaceableController : replaceableControllersRes) {
replaceableController.resolveReplacementSubTree((JMeterTreeNode) treeModel.getRoot());
}
JMeter.convertSubTree(selectedTree);
try {
treeModel.addSubTree(selectedTree, (JMeterTreeNode) treeModel.getRoot());
} catch (IllegalUserActionException e) {
throw new RuntimeException(e);
}
// select TG for visual convenience
SearchByClass<DebuggingThreadGroup> tgs = new SearchByClass<>(DebuggingThreadGroup.class);
selectedTree.traverse(tgs);
for (DebuggingThreadGroup forSel : tgs.getSearchResults()) {
Wrapper<AbstractThreadGroup> wtg = new ThreadGroupWrapper();
wtg.setWrappedElement(forSel);
selectTargetInTree(wtg);
}
}
示例13: runVariablesDebugEngine
import org.apache.jmeter.JMeter; //导入依赖的package包/类
@Test
public void runVariablesDebugEngine() throws Exception {
TestProvider prov = new TestProvider("/com/blazemeter/jmeter/debugger/vars.jmx", "vars.jmx");
Debugger sel = new Debugger(prov, new FrontendMock());
AbstractThreadGroup tg = prov.getTG(0);
sel.selectThreadGroup(tg);
HashTree testTree = sel.getSelectedTree();
TestSampleListener listener = new TestSampleListener();
testTree.add(testTree.getArray()[0], listener);
DebuggingThreadGroup tg2 = (DebuggingThreadGroup) getFirstTG(testTree);
LoopController samplerController = (LoopController) tg2.getSamplerController();
samplerController.setLoops(1);
samplerController.setContinueForever(false);
JMeter.convertSubTree(testTree);
DebuggerEngine engine = new DebuggerEngine(JMeterContextService.getContext());
StepTriggerCounter hook = new StepTriggerCounter();
engine.setStepper(hook);
engine.configure(testTree);
engine.runTest();
while (engine.isActive()) {
Thread.sleep(1000);
}
assertEquals(8, hook.cnt);
assertEquals(3, listener.events.size());
for (SampleEvent event : listener.events) {
SampleResult res = event.getResult();
String label = res.getSampleLabel();
assertTrue("Label: " + label + " must end with '123'", label.endsWith("123"));
assertFalse("Variable ${VAR} must be changed to '123' value. label: " + label, label.contains("${VAR}"));
assertTrue("label: '" + label + "' response: '" + res.getResponseMessage() +"'", res.isSuccessful());
}
}
示例14: runVariablesInAssertions
import org.apache.jmeter.JMeter; //导入依赖的package包/类
@Test
public void runVariablesInAssertions() throws Exception {
TestProvider prov = new TestProvider("/com/blazemeter/jmeter/debugger/debug.jmx", "debug.jmx");
Debugger sel = new Debugger(prov, new FrontendMock());
AbstractThreadGroup tg = prov.getTG(0);
sel.selectThreadGroup(tg);
HashTree testTree = sel.getSelectedTree();
TestSampleListener listener = new TestSampleListener();
testTree.add(testTree.getArray()[0], listener);
DebuggingThreadGroup tg2 = (DebuggingThreadGroup) getFirstTG(testTree);
LoopController samplerController = (LoopController) tg2.getSamplerController();
samplerController.setLoops(1);
samplerController.setContinueForever(false);
JMeter.convertSubTree(testTree);
DebuggerEngine engine = new DebuggerEngine(JMeterContextService.getContext());
StepTriggerCounter hook = new StepTriggerCounter();
engine.setStepper(hook);
engine.configure(testTree);
engine.runTest();
while (engine.isActive()) {
Thread.sleep(1000);
}
assertEquals(4, hook.cnt);
assertEquals(1, listener.events.size());
SampleEvent event = listener.events.get(0);
SampleResult result = event.getResult();
AssertionResult[] assertionResults = result.getAssertionResults();
assertEquals(1, assertionResults.length);
AssertionResult assertionRes = assertionResults[0];
assertNull(assertionRes.getFailureMessage());
}
示例15: runVariablesInControllers
import org.apache.jmeter.JMeter; //导入依赖的package包/类
@Test
public void runVariablesInControllers() throws Exception {
TestProvider prov = new TestProvider("/com/blazemeter/jmeter/debugger/loops.jmx", "loops.jmx");
Debugger sel = new Debugger(prov, new FrontendMock());
AbstractThreadGroup tg = prov.getTG(0);
sel.selectThreadGroup(tg);
HashTree testTree = sel.getSelectedTree();
TestSampleListener listener = new TestSampleListener();
testTree.add(testTree.getArray()[0], listener);
DebuggingThreadGroup tg2 = (DebuggingThreadGroup) getFirstTG(testTree);
LoopController samplerController = (LoopController) tg2.getSamplerController();
samplerController.setLoops(1);
samplerController.setContinueForever(false);
JMeter.convertSubTree(testTree);
DebuggerEngine engine = new DebuggerEngine(JMeterContextService.getContext());
StepTriggerCounter hook = new StepTriggerCounter();
engine.setStepper(hook);
engine.configure(testTree);
engine.runTest();
while (engine.isActive()) {
Thread.sleep(1000);
}
assertEquals(12, hook.cnt);
assertEquals(3, listener.events.size());
}