Search in sources :

Example 1 with EnvelopeRequestData

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

the class EnvelopeRequestTest method testToSend.

@Test
public void testToSend() throws IOException {
    for (short version : ApiKeys.ENVELOPE.allVersions()) {
        ByteBuffer requestData = ByteBuffer.wrap("foobar".getBytes());
        RequestHeader header = new RequestHeader(ApiKeys.ENVELOPE, version, "clientId", 15);
        EnvelopeRequest request = new EnvelopeRequest.Builder(requestData, "principal".getBytes(), InetAddress.getLocalHost().getAddress()).build(version);
        Send send = request.toSend(header);
        ByteBuffer buffer = TestUtils.toBuffer(send);
        assertEquals(send.size() - 4, buffer.getInt());
        assertEquals(header, RequestHeader.parse(buffer));
        EnvelopeRequestData parsedRequestData = new EnvelopeRequestData();
        parsedRequestData.read(new ByteBufferAccessor(buffer), version);
        assertEquals(request.data(), parsedRequestData);
    }
}
Also used : ByteBufferAccessor(org.apache.kafka.common.protocol.ByteBufferAccessor) ByteBuffer(java.nio.ByteBuffer) EnvelopeRequestData(org.apache.kafka.common.message.EnvelopeRequestData) Send(org.apache.kafka.common.network.Send) Test(org.junit.jupiter.api.Test)

Aggregations

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