nGrinder SocketTest.groovy
发布时间:2020-12-14 16:21:47 所属栏目:大数据 来源:网络整理
导读:s import net.grinder.plugin.http.HTTPRequest import net.grinder.script.GTest import net.grinder.scriptengine.groovy.junit.GrinderRunner import net.grinder.scriptengine.groovy.junit.annotation.BeforeProcess import net.grinder.scriptengine.g
s import net.grinder.plugin.http.HTTPRequest import net.grinder.script.GTest import net.grinder.scriptengine.groovy.junit.GrinderRunner import net.grinder.scriptengine.groovy.junit.annotation.BeforeProcess import net.grinder.scriptengine.groovy.junit.annotation.BeforeThread import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import com.s*****.testwa.taskserver.echo.EchoClient import static net.grinder.script.Grinder.grinder // import static net.grinder.util.GrinderUtils.* // You can use this if you‘re using nGrinder after 3.2.3 /** * A simple example using the HTTP plugin that shows the retrieval of a * single page via HTTP. * * This script is automatically generated by ngrinder. * * @author papapa */ @RunWith(GrinderRunner) class SocketTest { public static BufferedReader br public static InputStream is public static PrintWriter pw public static OutputStream os public static BufferedWriter bw GTest test1 = new GTest(1,"事务1") HTTPRequest request @BeforeProcess public static void beforeProcess() { //进程初始化 grinder.logger.info("beforeProcess.") } @BeforeThread public void beforeThread() { test1.record(this,"action") grinder.threadNumber grinder.logger.info("beforeThread.") } @Before public void before() { grinder.logger.info("before.") } @Test public void test1() { Socket socket = new Socket("talk8xgc.cns*****.com",6700); socket.setSoLinger(true,0) while(true){ sleep(10000) } } public void action() { Socket socket = new Socket("10.243.248.185",9100); socket.setSoLinger() try { is = socket.getInputStream(); os = socket.getOutputStream(); String s1 = "<packet id="Heartbeat">n" + "<body>n" + "<output>n" + "<ip>10.24.3.246</ip>n" + "<mac>00-0B-00-19-54-F7</mac>n" + "<name>71411810004070</name>n" + "<brand>实达</brand>n" + "<model>TP-200K</model>n" + "</output>n" + "</body>n" + "</packet>n"; bw = new BufferedWriter(new OutputStreamWriter(os,"GBK")); //鍚戞湇鍔″櫒绔?彂閫佷竴鏉℃秷鎭? bw.write(s1); bw.flush(); //璇诲彇鏈嶅姟鍣ㄨ繑鍥炵殑娑堟伅 BufferedReader br = new BufferedReader(new InputStreamReader(is)); String mess = br.readLine(); grinder.logger.info("---------mess={}",mess) } catch (IOException e) { e.printStackTrace(); } socket.setSoLinger(true,0) } } ? ? end (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |