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

  • 相关阅读:
    移动MM首届手机软件设计及创意大赛决赛取得圆满成功
    Windows Phone 7 EKB系列文章发布
    EVC3/4项目升级到Visual Studio项目的一些建议
    Windows Phone SDK 7.1 RTM 发布
    Howto: 创建Windows Phone 7自定义控件
    风云再起,7迹由你WP7技术沙龙上海站第二次活动
    Windows Phone Dev Notes如何使用ConnectionSettingsTask 来启动连接设置页面
    【OneNote Mobile】 如何处理便签内容的格式?
    《101 Windows Phone 7 Apps》读书笔记PASSWORDS & SECRETS
    3年MVP路,一颗感恩的心
  • 原文地址:https://www.cnblogs.com/lindows/p/11160729.html
Copyright © 2011-2022 走看看