From 0a7c0a36a0cf93c76490dc4dc3b6797c90bd3f20 Mon Sep 17 00:00:00 2001 From: Vacha Shah Date: Wed, 8 May 2024 19:17:07 +0000 Subject: [PATCH] Addressing comments Signed-off-by: Vacha Shah --- .../opensearch/transport/InboundDecoderTests.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/server/src/test/java/org/opensearch/transport/InboundDecoderTests.java b/server/src/test/java/org/opensearch/transport/InboundDecoderTests.java index 502248f978487..f2b8b317e8b44 100644 --- a/server/src/test/java/org/opensearch/transport/InboundDecoderTests.java +++ b/server/src/test/java/org/opensearch/transport/InboundDecoderTests.java @@ -51,7 +51,7 @@ public abstract class InboundDecoderTests extends OpenSearchTestCase { - public ThreadContext threadContext; + protected ThreadContext threadContext; protected abstract BytesReference serialize( boolean isRequest, @@ -75,15 +75,16 @@ public void testDecode() throws IOException { long requestId = randomNonNegativeLong(); final String headerKey = randomAlphaOfLength(10); final String headerValue = randomAlphaOfLength(20); - final BytesReference totalBytes; + TransportMessage transportMessage; if (isRequest) { threadContext.putHeader(headerKey, headerValue); - totalBytes = serialize(isRequest, Version.CURRENT, false, false, action, requestId, new TestRequest(randomAlphaOfLength(100))); + transportMessage = new TestRequest(randomAlphaOfLength(100)); } else { threadContext.addResponseHeader(headerKey, headerValue); - totalBytes = serialize(isRequest, Version.CURRENT, false, false, action, requestId, new TestResponse(randomAlphaOfLength(100))); + transportMessage = new TestResponse(randomAlphaOfLength(100)); } + final BytesReference totalBytes = serialize(isRequest, Version.CURRENT, false, false, action, requestId, transportMessage); int totalHeaderSize = TcpHeader.headerSize(Version.CURRENT) + totalBytes.getInt(TcpHeader.VARIABLE_HEADER_SIZE_POSITION); final BytesReference messageBytes = totalBytes.slice(totalHeaderSize, totalBytes.length() - totalHeaderSize); @@ -171,15 +172,13 @@ public void testCompressedDecode() throws IOException { threadContext.addResponseHeader(headerKey, headerValue); } TransportMessage transportMessage; - final BytesReference totalBytes; if (isRequest) { transportMessage = new TestRequest(randomAlphaOfLength(100)); - totalBytes = serialize(true, Version.CURRENT, false, true, action, requestId, transportMessage); } else { transportMessage = new TestResponse(randomAlphaOfLength(100)); - totalBytes = serialize(false, Version.CURRENT, false, true, action, requestId, transportMessage); } + final BytesReference totalBytes = serialize(false, Version.CURRENT, false, true, action, requestId, transportMessage); final BytesStreamOutput out = new BytesStreamOutput(); transportMessage.writeTo(out); final BytesReference uncompressedBytes = out.bytes();