1

I am trying to test my memcached installation using jMeter (we are using jMeter for other functional tests, so using it for memcached seems like the best option). I am using the TelnetClient (org.apache.commons.net.telnet.TelnetClient) to connect to memcached and fire a get command:

get somekey

I can connect, but when I try to read the response, jMeter hangs and needs to be restarted. Here is my code (where memcached_server is the IP for my server):

try 
{
   TelnetClient telnet = new TelnetClient();
   telnet.connect("memcached_server", 11211);

   PrintWriter pw = new PrintWriter(new OutputStreamWriter(telnet.getOutputStream()), true);
   String command = "get 2f605845757870234d94ae14ca83c660";
   pw.println("get 2f605845757870234d94ae14ca83c660");

   BufferedReader br = new BufferedReader(new InputStreamReader(telnet.getInputStream()));

    Scanner scan = new Scanner(br);

    System.out.println("Hello stackoverflow!!!!");      
if(scan.hasNext())
    System.out.println("It does have a next: " + scan.toString());
else
    System.out.println("It does NOT have a next");

    String output = "";         
while (scan.hasNext()) {
    String line = scan.nextLine();
        output += line;
        if (line.matches("^END.*$")) 
       break;

    }
    System.out.println("Output: " + output);
telnet.disconnect();

} 
catch(Exception e)
{
   e.printStackTrace();
}

I can run this code in Eclipse and it works fine. In jMeter I am using a BeanShell PostProcessor (some tests run before this memcached test), every time I run it, the program gets stuck in the

scan.hasNext()

line. It just hangs forever until I kill the process. I have also tried using the utilities in org.apache.commons.io.IOUtils like the toString(input stream) methods and I get the exact same behavior.

Any ideas?

4

1 回答 1

0

为什么将此代码放在 Post Processor 而不是 Sampler 中?

这似乎很奇怪。

您也可以尝试使用 JSR223 +Groovy,这可以让您有机会调试脚本。

于 2013-05-16T19:48:36.557 回答