Search in sources :

Example 1 with EnvelopeResponseData

use of org.apache.kafka.common.message.EnvelopeResponseData in project kafka by apache.

the class EnvelopeResponseTest method testToSend.

@Test
public void testToSend() {
    for (short version : ApiKeys.ENVELOPE.allVersions()) {
        ByteBuffer responseData = ByteBuffer.wrap("foobar".getBytes());
        EnvelopeResponse response = new EnvelopeResponse(responseData, Errors.NONE);
        short headerVersion = ApiKeys.ENVELOPE.responseHeaderVersion(version);
        ResponseHeader header = new ResponseHeader(15, headerVersion);
        Send send = response.toSend(header, version);
        ByteBuffer buffer = TestUtils.toBuffer(send);
        assertEquals(send.size() - 4, buffer.getInt());
        assertEquals(header, ResponseHeader.parse(buffer, headerVersion));
        EnvelopeResponseData parsedResponseData = new EnvelopeResponseData();
        parsedResponseData.read(new ByteBufferAccessor(buffer), version);
        assertEquals(response.data(), parsedResponseData);
    }
}
Also used : EnvelopeResponseData(org.apache.kafka.common.message.EnvelopeResponseData) ByteBufferAccessor(org.apache.kafka.common.protocol.ByteBufferAccessor) ByteBuffer(java.nio.ByteBuffer) Send(org.apache.kafka.common.network.Send) Test(org.junit.jupiter.api.Test)

Aggregations

ByteBuffer (java.nio.ByteBuffer)1 EnvelopeResponseData (org.apache.kafka.common.message.EnvelopeResponseData)1 Send (org.apache.kafka.common.network.Send)1 ByteBufferAccessor (org.apache.kafka.common.protocol.ByteBufferAccessor)1 Test (org.junit.jupiter.api.Test)1