Skip to content

Commit

Permalink
Addressing comments
Browse files Browse the repository at this point in the history
Signed-off-by: Vacha Shah <[email protected]>
  • Loading branch information
VachaShah committed May 8, 2024
1 parent c904eda commit 0a7c0a3
Showing 1 changed file with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

public abstract class InboundDecoderTests extends OpenSearchTestCase {

public ThreadContext threadContext;
protected ThreadContext threadContext;

protected abstract BytesReference serialize(
boolean isRequest,
Expand All @@ -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);

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 0a7c0a3

Please sign in to comment.