Source:
public void adminRequestResponseTest() throws IOException { for (AdminRequestOrResponseType type : AdminRequestOrResponseType.values()) { MockClusterMap clusterMap = new MockClusterMap(); PartitionId id = clusterMap.getWritablePartitionIds().get(0); AdminRequest adminRequest = new AdminRequest(type, id, 1234, "client"); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); WritableByteChannel writableByteChannel = Channels.newChannel(outputStream); do { adminRequest.writeTo(writableByteChannel); } while (!adminRequest.isSendComplete()); DataInputStream requestStream = new DataInputStream(new ByteArrayInputStream(outputStream.toByteArray())); requestStream.readLong(); requestStream.readShort(); AdminRequest deserializedDeleteRequest = AdminRequest.readFrom(requestStream, clusterMap); Assert.assertEquals(deserializedDeleteRequest.getCorrelationId(), 1234); Assert.assertEquals(deserializedDeleteRequest.getClientId(), "client"); Assert.assertEquals(deserializedDeleteRequest.getType(), type); Assert.assertTrue(deserializedDeleteRequest.getPartitionId().isEqual(id.toString())); AdminResponse response = new AdminResponse(1234, "client", ServerErrorCode.No_Error); outputStream.reset(); do { response.writeTo(writableByteChannel); } while (!response.isSendComplete()); requestStream = new DataInputStream(new ByteArrayInputStream(outputStream.toByteArray())); requestStream.readLong(); AdminResponse deserializedDeleteResponse = AdminResponse.readFrom(requestStream); Assert.assertEquals(deserializedDeleteResponse.getCorrelationId(), 1234); Assert.assertEquals(deserializedDeleteResponse.getError(), ServerErrorCode.No_Error); } }

Target:
public void adminRequestResponseTest() throws IOException { for (AdminRequestOrResponseType type : AdminRequestOrResponseType.values()) { MockClusterMap clusterMap = new MockClusterMap(); PartitionId id = clusterMap.getWritablePartitionIds().get(0); AdminRequest adminRequest = new AdminRequest(type, id, 1234, "client"); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); WritableByteChannel writableByteChannel = Channels.newChannel(outputStream); do { adminRequest.writeTo(writableByteChannel); } while (!adminRequest.isSendComplete()); DataInputStream requestStream = new DataInputStream(new ByteArrayInputStream(outputStream.toByteArray())); requestStream.readLong(); requestStream.readShort(); AdminRequest deserializedAdminRequest = AdminRequest.readFrom(requestStream, clusterMap); Assert.assertEquals(deserializedAdminRequest.getCorrelationId(), 1234); Assert.assertEquals(deserializedAdminRequest.getClientId(), "client"); Assert.assertEquals(deserializedAdminRequest.getType(), type); Assert.assertTrue(deserializedAdminRequest.getPartitionId().isEqual(id.toString())); AdminResponse response = new AdminResponse(1234, "client", ServerErrorCode.No_Error); outputStream.reset(); do { response.writeTo(writableByteChannel); } while (!response.isSendComplete()); requestStream = new DataInputStream(new ByteArrayInputStream(outputStream.toByteArray())); requestStream.readLong(); AdminResponse deserializedAdminResponse = AdminResponse.readFrom(requestStream); Assert.assertEquals(deserializedAdminResponse.getCorrelationId(), 1234); Assert.assertEquals(deserializedAdminResponse.getError(), ServerErrorCode.No_Error); } }