@Test public void writeUncompressed() throws Exception { final ByteBuf buf = GrpcTestUtil.requestByteBuf(); final ByteBufHttpData framed = framer.writePayload(buf); assertThat(framed.array()).isEqualTo(GrpcTestUtil.uncompressedFrame(GrpcTestUtil.requestByteBuf())); assertThat(buf.refCnt()).isEqualTo(0); framed.release(); }
@Test public void emptyNotCompressed() throws Exception { framer.setCompressor(new Gzip()); framer.setMessageCompression(true); final ByteBuf buf = GrpcTestUtil.protoByteBuf(SimpleRequest.getDefaultInstance()); assertThat(buf.readableBytes()).isEqualTo(0); final ByteBufHttpData framed = framer.writePayload(buf); assertThat(framed.array()).isEqualTo(GrpcTestUtil.uncompressedFrame( GrpcTestUtil.protoByteBuf(SimpleRequest.getDefaultInstance()))); assertThat(buf.refCnt()).isEqualTo(0); framed.release(); }
@Test public void compressed() throws Exception { framer.setCompressor(new Gzip()); framer.setMessageCompression(true); final ByteBuf buf = GrpcTestUtil.requestByteBuf(); final ByteBufHttpData framed = framer.writePayload(buf); assertThat(framed.array()).isEqualTo(GrpcTestUtil.compressedFrame(GrpcTestUtil.requestByteBuf())); assertThat(buf.refCnt()).isEqualTo(0); framed.release(); }
@Test public void notTooLargeCompressed() throws Exception { framer.setCompressor(new Gzip()); framer.setMessageCompression(true); final SimpleRequest request = SimpleRequest.newBuilder() .setPayload(Payload.newBuilder() .setBody(ByteString.copyFromUtf8( Strings.repeat("a", 1024)))) .build(); final ByteBufHttpData framed = framer.writePayload(GrpcTestUtil.protoByteBuf(request)); assertThat(framed.array()).isEqualTo(GrpcTestUtil.compressedFrame(GrpcTestUtil.protoByteBuf(request))); framed.release(); }