JMeter - XMPP身份验证

时间:2014-07-04 02:54:14

标签: xmpp jmeter

我正在构建一个测试计划,用JMeter测试XMPP。但是,即使身份验证字符串正确,我也会在向服务器发送身份验证字符串时遇到错误。有没有人有同样的问题或知道如何解决这个问题?感谢。

2014/07/04 10:23:22 INFO  - jmeter.engine.StandardJMeterEngine: Running the test! 
2014/07/04 10:23:22 INFO  - jmeter.gui.util.JMeterMenuBar: setRunning(true,*local*) 
2014/07/04 10:23:22 INFO  - jmeter.engine.StandardJMeterEngine: Starting ThreadGroup: 1 : Thread Group 
2014/07/04 10:23:22 INFO  - jmeter.engine.StandardJMeterEngine: Starting 1 threads for group Thread Group. 
2014/07/04 10:23:22 INFO  - jmeter.engine.StandardJMeterEngine: Thread will continue on error 
2014/07/04 10:23:22 INFO  - jmeter.threads.ThreadGroup: Starting thread group number 1 threads 1 ramp-up 1 perThread 1000.0 delayedStart=false 
2014/07/04 10:23:22 INFO  - jmeter.threads.ThreadGroup: Started thread group number 1 
2014/07/04 10:23:22 INFO  - jmeter.engine.StandardJMeterEngine: All thread groups have been started 
2014/07/04 10:23:22 INFO  - jmeter.threads.JMeterThread: Thread started: Thread Group 1-1 
2014/07/04 10:23:22 ERROR - ru.yandex.jmeter.XMPPClientImpl: Error reading data java.lang.RuntimeException: Retries more than 1000, aborting read
at ru.yandex.jmeter.XMPPClientImpl.read(XMPPClientImpl.java:116)
at org.apache.jmeter.protocol.tcp.sampler.TCPSampler.sample(TCPSampler.java:414)
at org.apache.jmeter.threads.JMeterThread.process_sampler(JMeterThread.java:428)
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:256)
at java.lang.Thread.run(Unknown Source)

2014/07/04 10:23:22 ERROR - jmeter.protocol.tcp.sampler.TCPSampler:  java.lang.RuntimeException: Error reading data
at ru.yandex.jmeter.XMPPClientImpl.read(XMPPClientImpl.java:152)
at org.apache.jmeter.protocol.tcp.sampler.TCPSampler.sample(TCPSampler.java:414)
at org.apache.jmeter.threads.JMeterThread.process_sampler(JMeterThread.java:428)
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:256)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.RuntimeException: Retries more than 1000, aborting read
at ru.yandex.jmeter.XMPPClientImpl.read(XMPPClientImpl.java:116)
... 4 more

2014/07/04 10:23:22 INFO  - jmeter.threads.JMeterThread: Thread finished: Thread Group 1-1 
2014/07/04 10:23:22 INFO  - jmeter.engine.StandardJMeterEngine: Notifying test listeners of end of test 
2014/07/04 10:23:22 INFO  - jmeter.gui.util.JMeterMenuBar: setRunning(false,*local*) 

1 个答案:

答案 0 :(得分:0)

我曾尝试使用XMPPClientImpl插件,但总是得到相同的错误("重试超过1000,中止读取"),所以我决定离开它并编写我自己的代码。

我使用BeanShell Sampler,在其中运行以下代码(使用smack库)连接到XMPP服务器。

<?php

不要忘记将smack路径(例如C:\ JMeter \ apache-jmeter-2.13 \ lib \ ext \ smack)添加到库字段(在&#34; 添加目录或jar下)测试计划的“测试计划”节点中的classpath &#34;)。

连接 -

String CLASS_PATH = "C:/JMeter/apache-jmeter-2.13/lib/ext/smack/";

addClassPath(CLASS_PATH + "smack-android-extensions-4.1.3.jar");
addClassPath(CLASS_PATH + "smack-tcp-4.1.3.jar");
addClassPath(CLASS_PATH + "smack-android-4.1.3.jar");

// explicitly import every class you need 
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.ConnectionListener;

import org.jivesoftware.smack.tcp.XMPPTCPConnection;
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;

import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.XMPPException.XMPPErrorException;

String jabberId = "...";
String jabberPass = "...";

String SERVER_ADDRESS = "...";
int    PORT =  5222;  // or any other port

XMPPTCPConnection getConnection() {

    XMPPTCPConnectionConfiguration config  = 
        XMPPTCPConnectionConfiguration.builder()
           .setUsernameAndPassword(jabberId, jabberPass)
           .setHost(SERVER_ADDRESS)
           .setServiceName(SERVER_ADDRESS)
           .setPort(DEFAULT_PORT)
        // .setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
           .setSendPresence(true)
        // .setDebuggerEnabled(YouMe.DEBUG)
           .build();

   XMPPTCPConnection con = new XMPPTCPConnection(config);

   int REPLY_TIMEOUT = 50000;  // 50 seconds, but can be shorter
   con.setPacketReplyTimeout(REPLY_TIMEOUT);

   return con;
}

登录 -

con = getConnection();
con.connect();

您还可以添加连接侦听器 -

con.login(jabberId, jabberPass);