Bug 46030 - Extend TCP Sampler to Support Length-Prefixed Binary Data
Extend TCP Sampler to Support Length-Prefixed Binary Data
Product: JMeter
Classification: Unclassified
Component: Main
All All
: P2 enhancement (vote)
: ---
Assigned To: JMeter issues mailing list
Depends on:
  Show dependency tree
Reported: 2008-10-16 23:59 UTC by Oghie Sheehy
Modified: 2008-11-06 10:53 UTC (History)
0 users

Code to implement enhancement (7.42 KB, application/zip)
2008-10-16 23:59 UTC, Oghie Sheehy

Note You need to log in before you can comment on or make changes to this bug.
Description Oghie Sheehy 2008-10-16 23:59:25 UTC
Created attachment 22749 [details]
Code to implement enhancement

We have a requirement to test a TCP service where data is exchanged in length-prefixed binary format.

To meet this need we have implemented the attached classes which we wish to submit for a future release of JMeter.  A brief description of the classes follows:

Concrete class which implements TCPClient Interface and converts hex-encoded strings to byte array in 
write(OutputStream, String) and from byte array to hex-encoded string in read(InputStream). 
write(OutputStream, InputStream) is unsupported.
Contains utility method hexStringToByteArray(String s) which is a mirror of the JOrphanUtils.baToHexString(byte[]) method.  

Abstract class implementing TCPClient Interface. This is to allow wrapping of TCPClientImpl/BinaryTCPClientImpl above with length prefixing methods.
Contains two utility methods intToByteArray(int value, int len) and byteArrayToInt(byte[] b).  Methods support 2 and 4 and byte lengths only and throw an IllegalArgumentException in other cases.

Extends TCPClientDecorator and instantiates decorator with BinaryTCPClientImpl.
The length to use in the prefix is taken from the properties file and defaults to 2.
For write(OutputStream os, String s) the length is calculated and written to the output stream then the method delegates to the BinaryTCPClientImpl write() method.
read(InputStream is) is overridden.
write(OutputStream os, InputStream is) is not supported.

Have created JUnit tests for the three utility methods but not for the read/write implementations themselves.  These are in two test classes, BinaryTCPClientImplTest and TCPClientDecoratorTest.

Have left the utility methods bundled with the client implementations to avoid modifying existing utility classes.
Comment 1 Sebb 2008-11-06 10:53:30 UTC
Code has been added to SVN.

Thanks very much for the contribution.