I'm trying to write a jmeter sampler in beanshell to execute a memcached telnet interface command, specifically flush_all. I need this to clear the cache after each test as it causes tests in quick succession to fail.
I have the following code:
import org.apache.commons.net.telnet.TelnetClient;
TelnetClient telnet = new TelnetClient();
telnet.connect( "memcachedServer.dev", 11211 );
//InputStream in = telnet.getInputStream();
PrintStream out = new PrintStream( telnet.getOutputStream() );
out.println("flush_all\r");
out.println("quit\r");
telnet.disconnect();
It seems to execute with no problems but the cache is not cleared. I have tried the code with and without the "\r" but neither way works.
Anyone know what's wrong?
Thanks, Adrian
Any reason for not using TCP Sampler?
Put the following lines into "Text to send" area:
flush_all${CR}${LF}
quit${CR}${LF}
Put the following code into the PreProcessor's "Script" area:
vars.put("LF",URLDecoder.decode("%0D", "ASCII"));
vars.put("CR",URLDecoder.decode("%0A", "ASCII"));
See How To Send Control Characters Using The JMeter TCP Sampler? guide for more detailed information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With