You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jmeter.apache.org by GitBox <gi...@apache.org> on 2020/12/10 03:25:08 UTC

[GitHub] [jmeter] DDDHuang opened a new pull request #637: add: tcp record proxy

DDDHuang opened a new pull request #637:
URL: https://github.com/apache/jmeter/pull/637


   ## Description
   <!--- Provide a general summary of your changes in the Title above -->
   <!--- Describe your changes in detail here -->
   
   ## Motivation and Context
   <!--- Why is this change required? What problem does it solve? -->
   <!--- If it fixes an open issue, please link to the issue here. -->
   
   ## How Has This Been Tested?
   <!--- Please describe in detail how you tested your changes. -->
   <!--- Include details of your testing environment, tests ran to see how -->
   <!--- your change affects other areas of the code, etc. -->
   
   ## Screenshots (if appropriate):
   
   ## Types of changes
   <!--- What types of changes does your code introduce? Delete as appropriate -->
   - Bug fix (non-breaking change which fixes an issue)
   - New feature (non-breaking change which adds functionality)
   - Breaking change (fix or feature that would cause existing functionality to not work as expected)
   
   ## Checklist:
   <!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
   <!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->
   - [ ] My code follows the [code style][style-guide] of this project.
   - [ ] I have updated the documentation accordingly.
   
   [style-guide]: https://wiki.apache.org/jmeter/CodeStyleGuidelines
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [jmeter] DDDHuang commented on pull request #637: add: tcp record proxy

Posted by GitBox <gi...@apache.org>.
DDDHuang commented on pull request #637:
URL: https://github.com/apache/jmeter/pull/637#issuecomment-748715121


    I have updated saveservice.properties in new commit. Thank you for your suggestion.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [jmeter] DDDHuang commented on a change in pull request #637: add: tcp record proxy

Posted by GitBox <gi...@apache.org>.
DDDHuang commented on a change in pull request #637:
URL: https://github.com/apache/jmeter/pull/637#discussion_r544078310



##########
File path: src/protocol/tcp/src/main/java/org/apache/jmeter/protocol/tcp/proxy/TCPSamplerManager.java
##########
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jmeter.protocol.tcp.proxy;
+
+import java.util.ArrayDeque;
+import java.util.Queue;
+
+import org.apache.jmeter.exceptions.IllegalUserActionException;
+import org.apache.jmeter.gui.GuiPackage;
+import org.apache.jmeter.gui.tree.JMeterTreeNode;
+import org.apache.jmeter.protocol.tcp.control.gui.TCPSamplerGui;
+import org.apache.jmeter.protocol.tcp.proxy.gui.TCPProxyDef;
+import org.apache.jmeter.protocol.tcp.sampler.BinaryTCPClientImpl;
+import org.apache.jmeter.protocol.tcp.sampler.TCPSampler;
+import org.apache.jmeter.samplers.SampleResult;
+import org.apache.jmeter.testelement.TestElement;
+import org.apache.jorphan.util.JOrphanUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TCPSamplerManager extends Thread {

Review comment:
       Thank you for your suggestion. I have added some java doc in new commit.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [jmeter] DDDHuang commented on a change in pull request #637: add: tcp record proxy

Posted by GitBox <gi...@apache.org>.
DDDHuang commented on a change in pull request #637:
URL: https://github.com/apache/jmeter/pull/637#discussion_r544075044



##########
File path: src/protocol/tcp/src/main/java/org/apache/jmeter/protocol/tcp/proxy/TCPSamplerManager.java
##########
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jmeter.protocol.tcp.proxy;
+
+import java.util.ArrayDeque;
+import java.util.Queue;
+
+import org.apache.jmeter.exceptions.IllegalUserActionException;
+import org.apache.jmeter.gui.GuiPackage;
+import org.apache.jmeter.gui.tree.JMeterTreeNode;
+import org.apache.jmeter.protocol.tcp.control.gui.TCPSamplerGui;
+import org.apache.jmeter.protocol.tcp.proxy.gui.TCPProxyDef;
+import org.apache.jmeter.protocol.tcp.sampler.BinaryTCPClientImpl;
+import org.apache.jmeter.protocol.tcp.sampler.TCPSampler;
+import org.apache.jmeter.samplers.SampleResult;
+import org.apache.jmeter.testelement.TestElement;
+import org.apache.jorphan.util.JOrphanUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TCPSamplerManager extends Thread {
+    private static final Logger log = LoggerFactory.getLogger(TCPSamplerManager.class);
+
+    private final JMeterTreeNode targetNode;
+    private final TestElement tcpSamplerElement;
+    private boolean workStatus = false;
+
+    private final Queue<TCPSampler> tcpSamplerInfoQueue = new ArrayDeque<>();
+
+    public TCPSamplerManager(TestElement tcpSamplerElement, JMeterTreeNode targetNode) {
+        this.tcpSamplerElement = tcpSamplerElement;
+        this.targetNode = targetNode;
+    }
+
+    /**
+     * create a new TCPSampler and put into TCPSampler queue.
+     * manager will store all TCPSampler to target JmeterTreeNode.
+     *
+     * @param data tcp payload
+     * @return target server response payload
+     */
+    public byte[] newTCPSampler(String data) {
+        log.debug("new sampler , payload " + data);
+        TCPSampler tcpSampler = new TCPSampler();
+        TestElement element = (TestElement) tcpSamplerElement.clone();
+        element.removeProperty(TCPSampler.PROXY_SERVER_PORT);
+        if (useHexPayload(element)) {
+            data = JOrphanUtils.baToHexString(data.getBytes());
+        }
+        element.setProperty(TCPSampler.REQUEST, data);
+        element.setProperty(TestElement.GUI_CLASS, TCPSamplerGui.class.getName());
+        element.setName("TCP Sampler");
+        tcpSampler.addTestElement(element);
+        tcpSamplerInfoQueue.add(tcpSampler);
+        SampleResult tcpSampleResult = tcpSampler.sample();
+        if (useHexPayload(element)) {
+            return BinaryTCPClientImpl.hexStringToByteArray(new String(tcpSampleResult.getResponseData()));
+        }
+        return tcpSampleResult.getResponseData();
+    }
+
+    private boolean useHexPayload(TestElement element) {
+        String tcpSamplerClassPath = element.getPropertyAsString(TCPSampler.CLASSNAME);
+        TCPProxyDef samplerClass = TCPProxyDef.findByClassPath(tcpSamplerClassPath);
+        if (samplerClass != null) {
+            switch (samplerClass) {
+                case BinaryTCPClientImpl_class:
+                case LengthPrefixedBinaryTCPClientImpl_class:
+                    return true;
+                case TCPClientImpl_class:
+                default:
+                    return false;
+            }
+        }
+        return false;
+    }
+
+    public synchronized void managerStart() {
+        log.debug("start");
+        workStatus = true;
+        start();
+    }
+
+    /**
+     * manager will stop after samplerQueue is empty
+     */
+    public void managerStop() {
+        workStatus = false;
+    }
+
+    @Override
+    public void run() {
+        while (workStatus) {
+            try {
+                Thread.sleep(500);
+            } catch (InterruptedException e) {
+                e.printStackTrace();

Review comment:
       I have added the " Exception Log" in new commit. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [jmeter] DDDHuang commented on a change in pull request #637: add: tcp record proxy

Posted by GitBox <gi...@apache.org>.
DDDHuang commented on a change in pull request #637:
URL: https://github.com/apache/jmeter/pull/637#discussion_r544077588



##########
File path: src/protocol/tcp/src/main/java/org/apache/jmeter/protocol/tcp/proxy/TCPSamplerManager.java
##########
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jmeter.protocol.tcp.proxy;
+
+import java.util.ArrayDeque;
+import java.util.Queue;
+
+import org.apache.jmeter.exceptions.IllegalUserActionException;
+import org.apache.jmeter.gui.GuiPackage;
+import org.apache.jmeter.gui.tree.JMeterTreeNode;
+import org.apache.jmeter.protocol.tcp.control.gui.TCPSamplerGui;
+import org.apache.jmeter.protocol.tcp.proxy.gui.TCPProxyDef;
+import org.apache.jmeter.protocol.tcp.sampler.BinaryTCPClientImpl;
+import org.apache.jmeter.protocol.tcp.sampler.TCPSampler;
+import org.apache.jmeter.samplers.SampleResult;
+import org.apache.jmeter.testelement.TestElement;
+import org.apache.jorphan.util.JOrphanUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TCPSamplerManager extends Thread {
+    private static final Logger log = LoggerFactory.getLogger(TCPSamplerManager.class);
+
+    private final JMeterTreeNode targetNode;
+    private final TestElement tcpSamplerElement;
+    private boolean workStatus = false;
+
+    private final Queue<TCPSampler> tcpSamplerInfoQueue = new ArrayDeque<>();
+
+    public TCPSamplerManager(TestElement tcpSamplerElement, JMeterTreeNode targetNode) {
+        this.tcpSamplerElement = tcpSamplerElement;
+        this.targetNode = targetNode;
+    }
+
+    /**
+     * create a new TCPSampler and put into TCPSampler queue.
+     * manager will store all TCPSampler to target JmeterTreeNode.
+     *
+     * @param data tcp payload
+     * @return target server response payload
+     */
+    public byte[] newTCPSampler(String data) {
+        log.debug("new sampler , payload " + data);
+        TCPSampler tcpSampler = new TCPSampler();
+        TestElement element = (TestElement) tcpSamplerElement.clone();
+        element.removeProperty(TCPSampler.PROXY_SERVER_PORT);
+        if (useHexPayload(element)) {
+            data = JOrphanUtils.baToHexString(data.getBytes());
+        }
+        element.setProperty(TCPSampler.REQUEST, data);
+        element.setProperty(TestElement.GUI_CLASS, TCPSamplerGui.class.getName());
+        element.setName("TCP Sampler");
+        tcpSampler.addTestElement(element);
+        tcpSamplerInfoQueue.add(tcpSampler);
+        SampleResult tcpSampleResult = tcpSampler.sample();
+        if (useHexPayload(element)) {
+            return BinaryTCPClientImpl.hexStringToByteArray(new String(tcpSampleResult.getResponseData()));
+        }
+        return tcpSampleResult.getResponseData();
+    }
+
+    private boolean useHexPayload(TestElement element) {
+        String tcpSamplerClassPath = element.getPropertyAsString(TCPSampler.CLASSNAME);
+        TCPProxyDef samplerClass = TCPProxyDef.findByClassPath(tcpSamplerClassPath);
+        if (samplerClass != null) {
+            switch (samplerClass) {
+                case BinaryTCPClientImpl_class:
+                case LengthPrefixedBinaryTCPClientImpl_class:
+                    return true;
+                case TCPClientImpl_class:
+                default:
+                    return false;
+            }
+        }
+        return false;
+    }
+
+    public synchronized void managerStart() {
+        log.debug("start");

Review comment:
       This TCPSamplerManager is start by TCPProxyServer, it don't need port.
   Considered your suggestion,  i have added some server parameter in log.Thank you for your suggestion.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [jmeter] DDDHuang commented on a change in pull request #637: add: tcp record proxy

Posted by GitBox <gi...@apache.org>.
DDDHuang commented on a change in pull request #637:
URL: https://github.com/apache/jmeter/pull/637#discussion_r544079673



##########
File path: src/protocol/tcp/src/main/java/org/apache/jmeter/protocol/tcp/proxy/TCPProxyServer.java
##########
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jmeter.protocol.tcp.proxy;
+
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.SocketException;
+import java.util.Arrays;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TCPProxyServer extends Thread {

Review comment:
       Thank you for your suggestion. I have added some java doc in new commit.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [jmeter] DDDHuang commented on a change in pull request #637: add: tcp record proxy

Posted by GitBox <gi...@apache.org>.
DDDHuang commented on a change in pull request #637:
URL: https://github.com/apache/jmeter/pull/637#discussion_r544079509



##########
File path: src/protocol/tcp/src/main/java/org/apache/jmeter/protocol/tcp/proxy/TCPProxyServer.java
##########
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jmeter.protocol.tcp.proxy;
+
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.SocketException;
+import java.util.Arrays;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TCPProxyServer extends Thread {
+    private static final Logger log = LoggerFactory.getLogger(TCPProxyServer.class);
+
+    ServerSocket serverSocket;
+    public static final int DEFAULT_PORT = 8899;
+    int proxyPort = DEFAULT_PORT;
+    int bufferSize = 4096;
+    boolean runningFlag = true;
+
+    private TCPSamplerManager samplerManager;
+
+    public TCPProxyServer(int proxyPort, TCPSamplerManager samplerManager) {
+        this.proxyPort = proxyPort;
+        this.samplerManager = samplerManager;
+    }
+
+    public void serverStart() throws IOException {
+        log.debug("proxy start");
+        runningFlag = true;
+        serverSocket = new ServerSocket(proxyPort);
+        log.debug("proxy server socket open success");
+        this.samplerManager.managerStart();
+        start();
+        log.debug("proxy start success");
+    }
+
+    public void serverStop() throws IOException {
+        runningFlag = false;
+        serverSocket.close();
+        this.samplerManager.managerStop();
+    }
+
+    @Override
+    public void run() {
+        if (serverSocket == null || serverSocket.isClosed()) {
+            try {
+                serverSocket = new ServerSocket(proxyPort);
+            } catch (IOException ioException) {
+                log.error("start proxy fail " + ioException.getMessage());
+            }
+        }
+        try {
+            while (runningFlag) {
+                Socket socket = serverSocket.accept();
+                log.debug("new client connection " + socket.getInetAddress().getHostName() + ":" + socket.getPort());
+                new Thread(new Runnable() {
+                    @Override
+                    public void run() {
+                        try {
+                            byte[] buffer = new byte[bufferSize];
+                            int readFlag = socket.getInputStream().read(buffer);
+                            if (readFlag != -1) {
+                                byte[] dataRead = Arrays.copyOf(buffer, readFlag);
+                                byte[] responseData = samplerManager.newTCPSampler(new String(dataRead));
+                                socket.getOutputStream().write(responseData);
+                            }
+                        } catch (IOException e) {
+                            log.debug("proxy socket exception " + e.getMessage());
+                        } finally {
+                            try {
+                                socket.close();
+                            } catch (IOException ignore) {
+                            }
+                        }
+                    }
+                }).start();
+            }
+        } catch (SocketException socketException) {
+            log.debug("proxy closed ");

Review comment:
       Thank you for your suggestion. I have changed the log style in new commit.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [jmeter] pmouawad commented on pull request #637: add: tcp record proxy

Posted by GitBox <gi...@apache.org>.
pmouawad commented on pull request #637:
URL: https://github.com/apache/jmeter/pull/637#issuecomment-748462622


   Thank you for taking into account the review.
   The tests are still failing.
   One of the issues I see is that you have not updated saveservice.properties (and SaveService.FILEVERSION once you'll get the id).
   Could you fix it ?
   Thank you


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [jmeter] DDDHuang commented on a change in pull request #637: add: tcp record proxy

Posted by GitBox <gi...@apache.org>.
DDDHuang commented on a change in pull request #637:
URL: https://github.com/apache/jmeter/pull/637#discussion_r544074431



##########
File path: src/protocol/tcp/src/main/java/org/apache/jmeter/protocol/tcp/sampler/TCPSampler.java
##########
@@ -348,8 +350,17 @@ private TCPClient getProtocol() {
         return tcpClient;
     }
 
+    public SampleResult sample(){
+        return sample(null, true);
+    }
+
     @Override
     public SampleResult sample(Entry e)// Entry tends to be ignored ...
+    {
+        return sample(e, firstSample);
+    }
+
+    public SampleResult sample(Entry e, boolean firstSampleFlag)// Entry tends to be ignored ...

Review comment:
       I have added the java document at this function in new commit.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [jmeter] DDDHuang commented on a change in pull request #637: add: tcp record proxy

Posted by GitBox <gi...@apache.org>.
DDDHuang commented on a change in pull request #637:
URL: https://github.com/apache/jmeter/pull/637#discussion_r544082739



##########
File path: src/protocol/tcp/src/main/java/org/apache/jmeter/protocol/tcp/proxy/TCPProxyServer.java
##########
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jmeter.protocol.tcp.proxy;
+
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.SocketException;
+import java.util.Arrays;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TCPProxyServer extends Thread {
+    private static final Logger log = LoggerFactory.getLogger(TCPProxyServer.class);
+
+    ServerSocket serverSocket;
+    public static final int DEFAULT_PORT = 8899;
+    int proxyPort = DEFAULT_PORT;
+    int bufferSize = 4096;
+    boolean runningFlag = true;
+
+    private TCPSamplerManager samplerManager;
+
+    public TCPProxyServer(int proxyPort, TCPSamplerManager samplerManager) {
+        this.proxyPort = proxyPort;
+        this.samplerManager = samplerManager;
+    }
+
+    public void serverStart() throws IOException {
+        log.debug("proxy start");
+        runningFlag = true;
+        serverSocket = new ServerSocket(proxyPort);
+        log.debug("proxy server socket open success");
+        this.samplerManager.managerStart();
+        start();
+        log.debug("proxy start success");
+    }
+
+    public void serverStop() throws IOException {
+        runningFlag = false;
+        serverSocket.close();
+        this.samplerManager.managerStop();
+    }
+
+    @Override
+    public void run() {
+        if (serverSocket == null || serverSocket.isClosed()) {
+            try {
+                serverSocket = new ServerSocket(proxyPort);
+            } catch (IOException ioException) {
+                log.error("start proxy fail " + ioException.getMessage());
+            }
+        }
+        try {
+            while (runningFlag) {
+                Socket socket = serverSocket.accept();
+                log.debug("new client connection " + socket.getInetAddress().getHostName() + ":" + socket.getPort());
+                new Thread(new Runnable() {
+                    @Override
+                    public void run() {
+                        try {
+                            byte[] buffer = new byte[bufferSize];
+                            int readFlag = socket.getInputStream().read(buffer);
+                            if (readFlag != -1) {
+                                byte[] dataRead = Arrays.copyOf(buffer, readFlag);
+                                byte[] responseData = samplerManager.newTCPSampler(new String(dataRead));
+                                socket.getOutputStream().write(responseData);
+                            }
+                        } catch (IOException e) {
+                            log.debug("proxy socket exception " + e.getMessage());
+                        } finally {
+                            try {
+                                socket.close();
+                            } catch (IOException ignore) {
+                            }
+                        }
+                    }
+                }).start();
+            }
+        } catch (SocketException socketException) {
+            log.debug("proxy closed ");
+        } catch (IOException ioException) {
+            ioException.printStackTrace();

Review comment:
       I have add the "IOException log" in new commit.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [jmeter] pmouawad commented on a change in pull request #637: add: tcp record proxy

Posted by GitBox <gi...@apache.org>.
pmouawad commented on a change in pull request #637:
URL: https://github.com/apache/jmeter/pull/637#discussion_r542162475



##########
File path: src/protocol/tcp/src/main/java/org/apache/jmeter/protocol/tcp/sampler/TCPSampler.java
##########
@@ -348,8 +350,17 @@ private TCPClient getProtocol() {
         return tcpClient;
     }
 
+    public SampleResult sample(){
+        return sample(null, true);
+    }
+
     @Override
     public SampleResult sample(Entry e)// Entry tends to be ignored ...
+    {
+        return sample(e, firstSample);
+    }
+
+    public SampleResult sample(Entry e, boolean firstSampleFlag)// Entry tends to be ignored ...

Review comment:
       Could you add javadoc explaining firstSampleFlag

##########
File path: src/protocol/tcp/src/main/java/org/apache/jmeter/protocol/tcp/proxy/TCPSamplerManager.java
##########
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jmeter.protocol.tcp.proxy;
+
+import java.util.ArrayDeque;
+import java.util.Queue;
+
+import org.apache.jmeter.exceptions.IllegalUserActionException;
+import org.apache.jmeter.gui.GuiPackage;
+import org.apache.jmeter.gui.tree.JMeterTreeNode;
+import org.apache.jmeter.protocol.tcp.control.gui.TCPSamplerGui;
+import org.apache.jmeter.protocol.tcp.proxy.gui.TCPProxyDef;
+import org.apache.jmeter.protocol.tcp.sampler.BinaryTCPClientImpl;
+import org.apache.jmeter.protocol.tcp.sampler.TCPSampler;
+import org.apache.jmeter.samplers.SampleResult;
+import org.apache.jmeter.testelement.TestElement;
+import org.apache.jorphan.util.JOrphanUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TCPSamplerManager extends Thread {
+    private static final Logger log = LoggerFactory.getLogger(TCPSamplerManager.class);
+
+    private final JMeterTreeNode targetNode;
+    private final TestElement tcpSamplerElement;
+    private boolean workStatus = false;
+
+    private final Queue<TCPSampler> tcpSamplerInfoQueue = new ArrayDeque<>();
+
+    public TCPSamplerManager(TestElement tcpSamplerElement, JMeterTreeNode targetNode) {
+        this.tcpSamplerElement = tcpSamplerElement;
+        this.targetNode = targetNode;
+    }
+
+    /**
+     * create a new TCPSampler and put into TCPSampler queue.
+     * manager will store all TCPSampler to target JmeterTreeNode.
+     *
+     * @param data tcp payload
+     * @return target server response payload
+     */
+    public byte[] newTCPSampler(String data) {
+        log.debug("new sampler , payload " + data);
+        TCPSampler tcpSampler = new TCPSampler();
+        TestElement element = (TestElement) tcpSamplerElement.clone();
+        element.removeProperty(TCPSampler.PROXY_SERVER_PORT);
+        if (useHexPayload(element)) {
+            data = JOrphanUtils.baToHexString(data.getBytes());
+        }
+        element.setProperty(TCPSampler.REQUEST, data);
+        element.setProperty(TestElement.GUI_CLASS, TCPSamplerGui.class.getName());
+        element.setName("TCP Sampler");
+        tcpSampler.addTestElement(element);
+        tcpSamplerInfoQueue.add(tcpSampler);
+        SampleResult tcpSampleResult = tcpSampler.sample();
+        if (useHexPayload(element)) {
+            return BinaryTCPClientImpl.hexStringToByteArray(new String(tcpSampleResult.getResponseData()));
+        }
+        return tcpSampleResult.getResponseData();
+    }
+
+    private boolean useHexPayload(TestElement element) {
+        String tcpSamplerClassPath = element.getPropertyAsString(TCPSampler.CLASSNAME);
+        TCPProxyDef samplerClass = TCPProxyDef.findByClassPath(tcpSamplerClassPath);
+        if (samplerClass != null) {
+            switch (samplerClass) {
+                case BinaryTCPClientImpl_class:
+                case LengthPrefixedBinaryTCPClientImpl_class:
+                    return true;
+                case TCPClientImpl_class:
+                default:
+                    return false;
+            }
+        }
+        return false;
+    }
+
+    public synchronized void managerStart() {
+        log.debug("start");
+        workStatus = true;
+        start();
+    }
+
+    /**
+     * manager will stop after samplerQueue is empty
+     */
+    public void managerStop() {
+        workStatus = false;
+    }
+
+    @Override
+    public void run() {
+        while (workStatus) {
+            try {
+                Thread.sleep(500);
+            } catch (InterruptedException e) {
+                e.printStackTrace();

Review comment:
       prefer logging

##########
File path: src/protocol/tcp/src/main/java/org/apache/jmeter/protocol/tcp/proxy/TCPProxyServer.java
##########
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jmeter.protocol.tcp.proxy;
+
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.SocketException;
+import java.util.Arrays;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TCPProxyServer extends Thread {
+    private static final Logger log = LoggerFactory.getLogger(TCPProxyServer.class);
+
+    ServerSocket serverSocket;
+    public static final int DEFAULT_PORT = 8899;
+    int proxyPort = DEFAULT_PORT;
+    int bufferSize = 4096;
+    boolean runningFlag = true;
+
+    private TCPSamplerManager samplerManager;
+
+    public TCPProxyServer(int proxyPort, TCPSamplerManager samplerManager) {
+        this.proxyPort = proxyPort;
+        this.samplerManager = samplerManager;
+    }
+
+    public void serverStart() throws IOException {
+        log.debug("proxy start");
+        runningFlag = true;
+        serverSocket = new ServerSocket(proxyPort);
+        log.debug("proxy server socket open success");
+        this.samplerManager.managerStart();
+        start();
+        log.debug("proxy start success");
+    }
+
+    public void serverStop() throws IOException {
+        runningFlag = false;
+        serverSocket.close();
+        this.samplerManager.managerStop();
+    }
+
+    @Override
+    public void run() {
+        if (serverSocket == null || serverSocket.isClosed()) {
+            try {
+                serverSocket = new ServerSocket(proxyPort);
+            } catch (IOException ioException) {
+                log.error("start proxy fail " + ioException.getMessage());
+            }
+        }
+        try {
+            while (runningFlag) {
+                Socket socket = serverSocket.accept();
+                log.debug("new client connection " + socket.getInetAddress().getHostName() + ":" + socket.getPort());
+                new Thread(new Runnable() {
+                    @Override
+                    public void run() {
+                        try {
+                            byte[] buffer = new byte[bufferSize];
+                            int readFlag = socket.getInputStream().read(buffer);
+                            if (readFlag != -1) {
+                                byte[] dataRead = Arrays.copyOf(buffer, readFlag);
+                                byte[] responseData = samplerManager.newTCPSampler(new String(dataRead));
+                                socket.getOutputStream().write(responseData);
+                            }
+                        } catch (IOException e) {
+                            log.debug("proxy socket exception " + e.getMessage());
+                        } finally {
+                            try {
+                                socket.close();
+                            } catch (IOException ignore) {
+                            }
+                        }
+                    }
+                }).start();
+            }
+        } catch (SocketException socketException) {
+            log.debug("proxy closed ");
+        } catch (IOException ioException) {
+            ioException.printStackTrace();

Review comment:
       Use logging

##########
File path: src/protocol/tcp/src/main/java/org/apache/jmeter/protocol/tcp/proxy/TCPProxyServer.java
##########
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jmeter.protocol.tcp.proxy;
+
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.SocketException;
+import java.util.Arrays;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TCPProxyServer extends Thread {

Review comment:
       Javadocs missing

##########
File path: src/protocol/tcp/src/main/java/org/apache/jmeter/protocol/tcp/proxy/TCPSamplerManager.java
##########
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jmeter.protocol.tcp.proxy;
+
+import java.util.ArrayDeque;
+import java.util.Queue;
+
+import org.apache.jmeter.exceptions.IllegalUserActionException;
+import org.apache.jmeter.gui.GuiPackage;
+import org.apache.jmeter.gui.tree.JMeterTreeNode;
+import org.apache.jmeter.protocol.tcp.control.gui.TCPSamplerGui;
+import org.apache.jmeter.protocol.tcp.proxy.gui.TCPProxyDef;
+import org.apache.jmeter.protocol.tcp.sampler.BinaryTCPClientImpl;
+import org.apache.jmeter.protocol.tcp.sampler.TCPSampler;
+import org.apache.jmeter.samplers.SampleResult;
+import org.apache.jmeter.testelement.TestElement;
+import org.apache.jorphan.util.JOrphanUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TCPSamplerManager extends Thread {
+    private static final Logger log = LoggerFactory.getLogger(TCPSamplerManager.class);
+
+    private final JMeterTreeNode targetNode;
+    private final TestElement tcpSamplerElement;
+    private boolean workStatus = false;
+
+    private final Queue<TCPSampler> tcpSamplerInfoQueue = new ArrayDeque<>();
+
+    public TCPSamplerManager(TestElement tcpSamplerElement, JMeterTreeNode targetNode) {
+        this.tcpSamplerElement = tcpSamplerElement;
+        this.targetNode = targetNode;
+    }
+
+    /**
+     * create a new TCPSampler and put into TCPSampler queue.
+     * manager will store all TCPSampler to target JmeterTreeNode.
+     *
+     * @param data tcp payload
+     * @return target server response payload
+     */
+    public byte[] newTCPSampler(String data) {
+        log.debug("new sampler , payload " + data);
+        TCPSampler tcpSampler = new TCPSampler();
+        TestElement element = (TestElement) tcpSamplerElement.clone();
+        element.removeProperty(TCPSampler.PROXY_SERVER_PORT);
+        if (useHexPayload(element)) {
+            data = JOrphanUtils.baToHexString(data.getBytes());
+        }
+        element.setProperty(TCPSampler.REQUEST, data);
+        element.setProperty(TestElement.GUI_CLASS, TCPSamplerGui.class.getName());
+        element.setName("TCP Sampler");
+        tcpSampler.addTestElement(element);
+        tcpSamplerInfoQueue.add(tcpSampler);
+        SampleResult tcpSampleResult = tcpSampler.sample();
+        if (useHexPayload(element)) {
+            return BinaryTCPClientImpl.hexStringToByteArray(new String(tcpSampleResult.getResponseData()));
+        }
+        return tcpSampleResult.getResponseData();
+    }
+
+    private boolean useHexPayload(TestElement element) {
+        String tcpSamplerClassPath = element.getPropertyAsString(TCPSampler.CLASSNAME);
+        TCPProxyDef samplerClass = TCPProxyDef.findByClassPath(tcpSamplerClassPath);
+        if (samplerClass != null) {
+            switch (samplerClass) {
+                case BinaryTCPClientImpl_class:
+                case LengthPrefixedBinaryTCPClientImpl_class:
+                    return true;
+                case TCPClientImpl_class:
+                default:
+                    return false;
+            }
+        }
+        return false;
+    }
+
+    public synchronized void managerStart() {
+        log.debug("start");

Review comment:
       Maybe add some contextual (port ...) data to log message

##########
File path: src/protocol/tcp/src/main/java/org/apache/jmeter/protocol/tcp/proxy/TCPSamplerManager.java
##########
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jmeter.protocol.tcp.proxy;
+
+import java.util.ArrayDeque;
+import java.util.Queue;
+
+import org.apache.jmeter.exceptions.IllegalUserActionException;
+import org.apache.jmeter.gui.GuiPackage;
+import org.apache.jmeter.gui.tree.JMeterTreeNode;
+import org.apache.jmeter.protocol.tcp.control.gui.TCPSamplerGui;
+import org.apache.jmeter.protocol.tcp.proxy.gui.TCPProxyDef;
+import org.apache.jmeter.protocol.tcp.sampler.BinaryTCPClientImpl;
+import org.apache.jmeter.protocol.tcp.sampler.TCPSampler;
+import org.apache.jmeter.samplers.SampleResult;
+import org.apache.jmeter.testelement.TestElement;
+import org.apache.jorphan.util.JOrphanUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TCPSamplerManager extends Thread {
+    private static final Logger log = LoggerFactory.getLogger(TCPSamplerManager.class);
+
+    private final JMeterTreeNode targetNode;
+    private final TestElement tcpSamplerElement;
+    private boolean workStatus = false;
+
+    private final Queue<TCPSampler> tcpSamplerInfoQueue = new ArrayDeque<>();
+
+    public TCPSamplerManager(TestElement tcpSamplerElement, JMeterTreeNode targetNode) {
+        this.tcpSamplerElement = tcpSamplerElement;
+        this.targetNode = targetNode;
+    }
+
+    /**
+     * create a new TCPSampler and put into TCPSampler queue.
+     * manager will store all TCPSampler to target JmeterTreeNode.
+     *
+     * @param data tcp payload
+     * @return target server response payload
+     */
+    public byte[] newTCPSampler(String data) {
+        log.debug("new sampler , payload " + data);

Review comment:
       use log.debug("New sampler with payload{}", data)

##########
File path: src/protocol/tcp/src/main/java/org/apache/jmeter/protocol/tcp/proxy/TCPProxyServer.java
##########
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jmeter.protocol.tcp.proxy;
+
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.SocketException;
+import java.util.Arrays;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TCPProxyServer extends Thread {
+    private static final Logger log = LoggerFactory.getLogger(TCPProxyServer.class);
+
+    ServerSocket serverSocket;
+    public static final int DEFAULT_PORT = 8899;
+    int proxyPort = DEFAULT_PORT;
+    int bufferSize = 4096;
+    boolean runningFlag = true;
+
+    private TCPSamplerManager samplerManager;
+
+    public TCPProxyServer(int proxyPort, TCPSamplerManager samplerManager) {
+        this.proxyPort = proxyPort;
+        this.samplerManager = samplerManager;
+    }
+
+    public void serverStart() throws IOException {
+        log.debug("proxy start");
+        runningFlag = true;
+        serverSocket = new ServerSocket(proxyPort);
+        log.debug("proxy server socket open success");
+        this.samplerManager.managerStart();
+        start();
+        log.debug("proxy start success");
+    }
+
+    public void serverStop() throws IOException {
+        runningFlag = false;
+        serverSocket.close();
+        this.samplerManager.managerStop();
+    }
+
+    @Override
+    public void run() {
+        if (serverSocket == null || serverSocket.isClosed()) {
+            try {
+                serverSocket = new ServerSocket(proxyPort);
+            } catch (IOException ioException) {
+                log.error("start proxy fail " + ioException.getMessage());
+            }
+        }
+        try {
+            while (runningFlag) {
+                Socket socket = serverSocket.accept();
+                log.debug("new client connection " + socket.getInetAddress().getHostName() + ":" + socket.getPort());
+                new Thread(new Runnable() {
+                    @Override
+                    public void run() {
+                        try {
+                            byte[] buffer = new byte[bufferSize];
+                            int readFlag = socket.getInputStream().read(buffer);
+                            if (readFlag != -1) {
+                                byte[] dataRead = Arrays.copyOf(buffer, readFlag);
+                                byte[] responseData = samplerManager.newTCPSampler(new String(dataRead));
+                                socket.getOutputStream().write(responseData);
+                            }
+                        } catch (IOException e) {
+                            log.debug("proxy socket exception " + e.getMessage());
+                        } finally {
+                            try {
+                                socket.close();
+                            } catch (IOException ignore) {
+                            }
+                        }
+                    }
+                }).start();
+            }
+        } catch (SocketException socketException) {
+            log.debug("proxy closed ");

Review comment:
       Add contextual data and exception
   log.debug("Proxy closed", socketException)

##########
File path: src/protocol/tcp/src/main/java/org/apache/jmeter/protocol/tcp/proxy/TCPSamplerManager.java
##########
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jmeter.protocol.tcp.proxy;
+
+import java.util.ArrayDeque;
+import java.util.Queue;
+
+import org.apache.jmeter.exceptions.IllegalUserActionException;
+import org.apache.jmeter.gui.GuiPackage;
+import org.apache.jmeter.gui.tree.JMeterTreeNode;
+import org.apache.jmeter.protocol.tcp.control.gui.TCPSamplerGui;
+import org.apache.jmeter.protocol.tcp.proxy.gui.TCPProxyDef;
+import org.apache.jmeter.protocol.tcp.sampler.BinaryTCPClientImpl;
+import org.apache.jmeter.protocol.tcp.sampler.TCPSampler;
+import org.apache.jmeter.samplers.SampleResult;
+import org.apache.jmeter.testelement.TestElement;
+import org.apache.jorphan.util.JOrphanUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TCPSamplerManager extends Thread {

Review comment:
       Add some javadoc explaining class purpose




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [jmeter] DDDHuang commented on a change in pull request #637: add: tcp record proxy

Posted by GitBox <gi...@apache.org>.
DDDHuang commented on a change in pull request #637:
URL: https://github.com/apache/jmeter/pull/637#discussion_r544077899



##########
File path: src/protocol/tcp/src/main/java/org/apache/jmeter/protocol/tcp/proxy/TCPSamplerManager.java
##########
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jmeter.protocol.tcp.proxy;
+
+import java.util.ArrayDeque;
+import java.util.Queue;
+
+import org.apache.jmeter.exceptions.IllegalUserActionException;
+import org.apache.jmeter.gui.GuiPackage;
+import org.apache.jmeter.gui.tree.JMeterTreeNode;
+import org.apache.jmeter.protocol.tcp.control.gui.TCPSamplerGui;
+import org.apache.jmeter.protocol.tcp.proxy.gui.TCPProxyDef;
+import org.apache.jmeter.protocol.tcp.sampler.BinaryTCPClientImpl;
+import org.apache.jmeter.protocol.tcp.sampler.TCPSampler;
+import org.apache.jmeter.samplers.SampleResult;
+import org.apache.jmeter.testelement.TestElement;
+import org.apache.jorphan.util.JOrphanUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TCPSamplerManager extends Thread {
+    private static final Logger log = LoggerFactory.getLogger(TCPSamplerManager.class);
+
+    private final JMeterTreeNode targetNode;
+    private final TestElement tcpSamplerElement;
+    private boolean workStatus = false;
+
+    private final Queue<TCPSampler> tcpSamplerInfoQueue = new ArrayDeque<>();
+
+    public TCPSamplerManager(TestElement tcpSamplerElement, JMeterTreeNode targetNode) {
+        this.tcpSamplerElement = tcpSamplerElement;
+        this.targetNode = targetNode;
+    }
+
+    /**
+     * create a new TCPSampler and put into TCPSampler queue.
+     * manager will store all TCPSampler to target JmeterTreeNode.
+     *
+     * @param data tcp payload
+     * @return target server response payload
+     */
+    public byte[] newTCPSampler(String data) {
+        log.debug("new sampler , payload " + data);

Review comment:
       Thank you for your suggestion. I have changed the log style in new commit.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org