zoukankan      html  css  js  c++  java
  • nGrinder SocketTest.groovy

    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">
    " +
                        "<body>
    " +
                        "<output>
    " +
                        "<ip>10.24.3.246</ip>
    " +
                        "<mac>00-0B-00-19-54-F7</mac>
    " +
                        "<name>71411810004070</name>
    " +
                        "<brand>实达</brand>
    " +
                        "<model>TP-200K</model>
    " +
                        "</output>
    " +
                        "</body>
    " +
                        "</packet>
    ";
    
                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

  • 相关阅读:
    20145127 《Java程序设计》第一周学习总结
    Java 问卷调查
    一个没有成就而即将退赛的OIer的告别书
    【深度优先搜索】MZOJ_1344工作依赖
    【算法随笔】最小生成树
    【数据结构】二叉树 学习笔记1
    【深度优先搜索】NOIP2017_D2T1 洛谷3958奶酪
    【树形DP】MZOJ_1063_士兵守卫
    【算法随笔】写一个自己的名词空间
    【树形DP】洛谷1122_最大子树和
  • 原文地址:https://www.cnblogs.com/lindows/p/11160729.html
Copyright © 2011-2022 走看看