@@ -56,32 +56,17 @@ public void testDecode() throws IOException {
5656        }
5757
5858        try  (RecyclerBytesStreamOutput  os  = new  RecyclerBytesStreamOutput (recycler )) {
59-             final  BytesReference  totalBytes ;
60-             if  (isRequest ) {
61-                 totalBytes  = OutboundHandler .serialize (
62-                     action ,
63-                     requestId ,
64-                     false ,
65-                     TransportVersion .current (),
66-                     false ,
67-                     null ,
68-                     new  TestRequest (randomAlphaOfLength (100 )),
69-                     threadContext ,
70-                     os 
71-                 );
72-             } else  {
73-                 totalBytes  = OutboundHandler .serialize (
74-                     null ,
75-                     requestId ,
76-                     false ,
77-                     TransportVersion .current (),
78-                     false ,
79-                     null ,
80-                     new  TestResponse (randomAlphaOfLength (100 )),
81-                     threadContext ,
82-                     os 
83-                 );
84-             }
59+             final  BytesReference  totalBytes  = OutboundHandler .serialize (
60+                 isRequest  ? OutboundHandler .MessageDirection .REQUEST  : OutboundHandler .MessageDirection .RESPONSE ,
61+                 action ,
62+                 requestId ,
63+                 false ,
64+                 TransportVersion .current (),
65+                 null ,
66+                 isRequest  ? new  TestRequest (randomAlphaOfLength (100 )) : new  TestResponse (randomAlphaOfLength (100 )),
67+                 threadContext ,
68+                 os 
69+             );
8570            int  totalHeaderSize  = TcpHeader .headerSize (TransportVersion .current ()) + totalBytes .getInt (
8671                TcpHeader .VARIABLE_HEADER_SIZE_POSITION 
8772            );
@@ -138,11 +123,11 @@ public void testDecodePreHeaderSizeVariableInt() throws IOException {
138123        // 8.0 is only compatible with handshakes on a pre-variable int version 
139124        try  (RecyclerBytesStreamOutput  os  = new  RecyclerBytesStreamOutput (recycler )) {
140125            final  BytesReference  totalBytes  = OutboundHandler .serialize (
126+                 OutboundHandler .MessageDirection .REQUEST ,
141127                action ,
142128                requestId ,
143129                true ,
144130                preHeaderVariableInt ,
145-                 false ,
146131                compressionScheme ,
147132                new  TestRequest (contentValue ),
148133                threadContext ,
@@ -195,11 +180,11 @@ public void testDecodeHandshakeV7Compatibility() throws IOException {
195180        TransportVersion  handshakeCompat  = TransportHandshaker .V7_HANDSHAKE_VERSION ;
196181        try  (RecyclerBytesStreamOutput  os  = new  RecyclerBytesStreamOutput (recycler )) {
197182            BytesReference  bytes  = OutboundHandler .serialize (
183+                 OutboundHandler .MessageDirection .REQUEST ,
198184                action ,
199185                requestId ,
200186                true ,
201187                handshakeCompat ,
202-                 false ,
203188                null ,
204189                new  TestRequest (randomAlphaOfLength (100 )),
205190                threadContext ,
@@ -247,11 +232,11 @@ private void doHandshakeCompatibilityTest(TransportVersion transportVersion, Com
247232        int  totalHeaderSize  = TcpHeader .headerSize (transportVersion );
248233        try  (RecyclerBytesStreamOutput  os  = new  RecyclerBytesStreamOutput (recycler )) {
249234            final  BytesReference  bytes  = OutboundHandler .serialize (
235+                 OutboundHandler .MessageDirection .REQUEST ,
250236                action ,
251237                requestId ,
252238                true ,
253239                transportVersion ,
254-                 false ,
255240                compressionScheme ,
256241                new  TestRequest (randomAlphaOfLength (100 )),
257242                threadContext ,
@@ -298,11 +283,11 @@ public void testClientChannelTypeFailsDecodingRequests() throws Exception {
298283
299284        try  (RecyclerBytesStreamOutput  os  = new  RecyclerBytesStreamOutput (recycler )) {
300285            final  BytesReference  bytes  = OutboundHandler .serialize (
286+                 OutboundHandler .MessageDirection .REQUEST ,
301287                action ,
302288                requestId ,
303289                isHandshake ,
304290                version ,
305-                 false ,
306291                randomFrom (Compression .Scheme .DEFLATE , Compression .Scheme .LZ4 , null ),
307292                new  TestRequest (randomAlphaOfLength (100 )),
308293                threadContext ,
@@ -348,11 +333,11 @@ public void testServerChannelTypeFailsDecodingResponses() throws Exception {
348333
349334        try  (RecyclerBytesStreamOutput  os  = new  RecyclerBytesStreamOutput (recycler )) {
350335            final  BytesReference  bytes  = OutboundHandler .serialize (
351-                 null ,
336+                 OutboundHandler .MessageDirection .RESPONSE ,
337+                 "test:action" ,
352338                requestId ,
353339                isHandshake ,
354340                version ,
355-                 false ,
356341                randomFrom (Compression .Scheme .DEFLATE , Compression .Scheme .LZ4 , null ),
357342                new  TestRequest (randomAlphaOfLength (100 )),
358343                threadContext ,
@@ -388,38 +373,23 @@ public void testCompressedDecode() throws IOException {
388373        } else  {
389374            threadContext .addResponseHeader (headerKey , headerValue );
390375        }
391-         final  BytesReference  totalBytes ;
392-         TransportMessage  transportMessage ;
393376        Compression .Scheme  scheme  = randomFrom (Compression .Scheme .DEFLATE , Compression .Scheme .LZ4 );
394377
395378        try  (RecyclerBytesStreamOutput  os  = new  RecyclerBytesStreamOutput (recycler )) {
396-             if  (isRequest ) {
397-                 transportMessage  = new  TestRequest (randomAlphaOfLength (100 ));
398-                 totalBytes  = OutboundHandler .serialize (
399-                     action ,
400-                     requestId ,
401-                     false ,
402-                     TransportVersion .current (),
403-                     false ,
404-                     scheme ,
405-                     transportMessage ,
406-                     threadContext ,
407-                     os 
408-                 );
409-             } else  {
410-                 transportMessage  = new  TestResponse (randomAlphaOfLength (100 ));
411-                 totalBytes  = OutboundHandler .serialize (
412-                     null ,
413-                     requestId ,
414-                     false ,
415-                     TransportVersion .current (),
416-                     false ,
417-                     scheme ,
418-                     transportMessage ,
419-                     threadContext ,
420-                     os 
421-                 );
422-             }
379+             final  TransportMessage  transportMessage  = isRequest 
380+                 ? new  TestRequest (randomAlphaOfLength (100 ))
381+                 : new  TestResponse (randomAlphaOfLength (100 ));
382+             final  BytesReference  totalBytes  = OutboundHandler .serialize (
383+                 isRequest  ? OutboundHandler .MessageDirection .REQUEST  : OutboundHandler .MessageDirection .RESPONSE ,
384+                 action ,
385+                 requestId ,
386+                 false ,
387+                 TransportVersion .current (),
388+                 scheme ,
389+                 transportMessage ,
390+                 threadContext ,
391+                 os 
392+             );
423393            final  BytesStreamOutput  out  = new  BytesStreamOutput ();
424394            transportMessage .writeTo (out );
425395            final  BytesReference  uncompressedBytes  = out .bytes ();
@@ -479,11 +449,11 @@ public void testCompressedDecodeHandshakeCompatibility() throws IOException {
479449        TransportVersion  handshakeCompat  = TransportHandshaker .V7_HANDSHAKE_VERSION ;
480450        try  (RecyclerBytesStreamOutput  os  = new  RecyclerBytesStreamOutput (recycler )) {
481451            final  BytesReference  bytes  = OutboundHandler .serialize (
452+                 OutboundHandler .MessageDirection .REQUEST ,
482453                action ,
483454                requestId ,
484455                true ,
485456                handshakeCompat ,
486-                 false ,
487457                Compression .Scheme .DEFLATE ,
488458                new  TestRequest (randomAlphaOfLength (100 )),
489459                threadContext ,
@@ -517,11 +487,11 @@ public void testVersionIncompatibilityDecodeException() throws IOException {
517487        final  ReleasableBytesReference  releasable1 ;
518488        try  (RecyclerBytesStreamOutput  os  = new  RecyclerBytesStreamOutput (recycler )) {
519489            final  BytesReference  bytes  = OutboundHandler .serialize (
490+                 OutboundHandler .MessageDirection .REQUEST ,
520491                action ,
521492                requestId ,
522493                false ,
523494                incompatibleVersion ,
524-                 false ,
525495                Compression .Scheme .DEFLATE ,
526496                new  TestRequest (randomAlphaOfLength (100 )),
527497                threadContext ,
0 commit comments