List of usage examples for io.netty.buffer ByteBufAllocator DEFAULT
ByteBufAllocator DEFAULT
To view the source code for io.netty.buffer ByteBufAllocator DEFAULT.
Click Source Link
From source file:com.github.milenkovicm.kafka.example.Example1.java
License:Apache License
public static void main(String[] args) throws InterruptedException { ProducerProperties properties = new ProducerProperties(); properties.override(ProducerProperties.NETTY_DEBUG_PIPELINE, true); ByteBuf key = ByteBufAllocator.DEFAULT.buffer(10); // add some key here ByteBuf value = ByteBufAllocator.DEFAULT.buffer(10); // and value here KafkaProducer producer = new KafkaProducer("localhost", 9092, "test_topic", properties); producer.connect().sync();//from ww w .java2 s . c om KafkaTopic kafkaTopic = producer.topic(); kafkaTopic.send(key, value); producer.disconnect().sync(); }
From source file:com.google.devtools.build.lib.remote.blobstore.http.HttpUploadHandlerTest.java
License:Open Source License
private void uploadsShouldWork(boolean casUpload, EmbeddedChannel ch, HttpResponseStatus status) throws Exception { ByteArrayInputStream data = new ByteArrayInputStream(new byte[] { 1, 2, 3, 4, 5 }); ChannelPromise writePromise = ch.newPromise(); ch.writeOneOutbound(new UploadCommand(CACHE_URI, casUpload, "abcdef", data, 5), writePromise); HttpRequest request = ch.readOutbound(); assertThat(request.method()).isEqualTo(HttpMethod.PUT); assertThat(request.headers().get(HttpHeaders.CONNECTION)).isEqualTo(HttpHeaderValues.KEEP_ALIVE.toString()); HttpChunkedInput content = ch.readOutbound(); assertThat(content.readChunk(ByteBufAllocator.DEFAULT).content().readableBytes()).isEqualTo(5); FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, status); response.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE); ch.writeInbound(response);//from w w w. ja v a2 s.c om assertThat(writePromise.isDone()).isTrue(); assertThat(ch.isOpen()).isTrue(); }
From source file:com.linecorp.armeria.client.http.SimpleHttpClientCodecTest.java
License:Apache License
@Before public void setUp() { codec = new SimpleHttpClientCodec("www.github.com"); when(channel.alloc()).thenReturn(ByteBufAllocator.DEFAULT); }
From source file:com.linecorp.armeria.client.Http2ClientSettingsTest.java
License:Apache License
private static ByteBuf readGoAwayFrame(InputStream in) throws IOException { // Read a GOAWAY frame. final byte[] goAwayFrameBuf = readBytes(in, 9); final int payloadLength = payloadLength(goAwayFrameBuf); final ByteBuf buffer = ByteBufAllocator.DEFAULT.buffer(9 + payloadLength); buffer.writeBytes(goAwayFrameBuf);/*from w w w. j a v a 2 s .c o m*/ buffer.writeBytes(in, payloadLength); return buffer; }
From source file:com.linecorp.armeria.internal.grpc.GrpcMessageMarshallerTest.java
License:Apache License
@Before public void setUp() { marshaller = new GrpcMessageMarshaller<>(ByteBufAllocator.DEFAULT, GrpcSerializationFormats.PROTO, TestServiceGrpc.getUnaryCallMethod(), MessageMarshaller.builder().register(SimpleRequest.getDefaultInstance()) .register(SimpleResponse.getDefaultInstance()).build(), false);/* w w w. ja v a 2 s. com*/ }
From source file:com.linecorp.armeria.internal.grpc.GrpcMessageMarshallerTest.java
License:Apache License
@Test public void deserializeRequest_byteBuf() throws Exception { ByteBuf buf = ByteBufAllocator.DEFAULT.buffer(GrpcTestUtil.REQUEST_MESSAGE.getSerializedSize()); assertThat(buf.refCnt()).isEqualTo(1); buf.writeBytes(GrpcTestUtil.REQUEST_MESSAGE.toByteArray()); SimpleRequest request = marshaller.deserializeRequest(new ByteBufOrStream(buf)); assertThat(request).isEqualTo(GrpcTestUtil.REQUEST_MESSAGE); assertThat(buf.refCnt()).isEqualTo(0); }
From source file:com.linecorp.armeria.internal.grpc.GrpcMessageMarshallerTest.java
License:Apache License
@Test public void deserializeRequest_wrappedByteBuf() throws Exception { marshaller = new GrpcMessageMarshaller<>(ByteBufAllocator.DEFAULT, GrpcSerializationFormats.PROTO, TestServiceGrpc.getUnaryCallMethod(), MessageMarshaller.builder().register(SimpleRequest.getDefaultInstance()) .register(SimpleResponse.getDefaultInstance()).build(), true);/*from w ww . j a v a2s. c o m*/ ByteBuf buf = ByteBufAllocator.DEFAULT.buffer(GrpcTestUtil.REQUEST_MESSAGE.getSerializedSize()); assertThat(buf.refCnt()).isEqualTo(1); buf.writeBytes(GrpcTestUtil.REQUEST_MESSAGE.toByteArray()); SimpleRequest request = marshaller.deserializeRequest(new ByteBufOrStream(buf)); assertThat(request).isEqualTo(GrpcTestUtil.REQUEST_MESSAGE); assertThat(buf.refCnt()).isEqualTo(1); buf.release(); }
From source file:com.linecorp.armeria.internal.grpc.GrpcMessageMarshallerTest.java
License:Apache License
@Test public void deserializeResponse_bytebuf() throws Exception { ByteBuf buf = ByteBufAllocator.DEFAULT.buffer(GrpcTestUtil.RESPONSE_MESSAGE.getSerializedSize()); assertThat(buf.refCnt()).isEqualTo(1); buf.writeBytes(GrpcTestUtil.RESPONSE_MESSAGE.toByteArray()); SimpleResponse response = marshaller.deserializeResponse(new ByteBufOrStream(buf)); assertThat(response).isEqualTo(GrpcTestUtil.RESPONSE_MESSAGE); assertThat(buf.refCnt()).isEqualTo(0); }
From source file:com.linecorp.armeria.internal.grpc.GrpcMessageMarshallerTest.java
License:Apache License
@Test public void deserializeResponse_wrappedByteBuf() throws Exception { marshaller = new GrpcMessageMarshaller<>(ByteBufAllocator.DEFAULT, GrpcSerializationFormats.PROTO, TestServiceGrpc.getUnaryCallMethod(), MessageMarshaller.builder().register(SimpleRequest.getDefaultInstance()) .register(SimpleResponse.getDefaultInstance()).build(), true);//w w w . j a v a 2s . c o m ByteBuf buf = ByteBufAllocator.DEFAULT.buffer(GrpcTestUtil.RESPONSE_MESSAGE.getSerializedSize()); assertThat(buf.refCnt()).isEqualTo(1); buf.writeBytes(GrpcTestUtil.RESPONSE_MESSAGE.toByteArray()); SimpleResponse response = marshaller.deserializeResponse(new ByteBufOrStream(buf)); assertThat(response).isEqualTo(GrpcTestUtil.RESPONSE_MESSAGE); assertThat(buf.refCnt()).isEqualTo(1); buf.release(); }
From source file:com.linecorp.armeria.server.grpc.ArmeriaServerCallTest.java
License:Apache License
@Before public void setUp() { completionFuture = new CompletableFuture<>(); when(res.completionFuture()).thenReturn(completionFuture); when(ctx.eventLoop()).thenReturn(eventLoop); when(ctx.contextAwareEventLoop()).thenReturn(eventLoop); when(ctx.alloc()).thenReturn(ByteBufAllocator.DEFAULT); call = new ArmeriaServerCall<>(HttpHeaders.of(), TestServiceGrpc.getUnaryCallMethod(), CompressorRegistry.getDefaultInstance(), DecompressorRegistry.getDefaultInstance(), res, MAX_MESSAGE_BYTES, MAX_MESSAGE_BYTES, ctx, GrpcSerializationFormats.PROTO, MessageMarshaller.builder().build(), false); call.setListener(listener);/*from w ww .ja v a 2 s .c o m*/ call.messageReader().onSubscribe(subscription); when(ctx.logBuilder()).thenReturn(new DefaultRequestLog(ctx)); when(ctx.alloc()).thenReturn(ByteBufAllocator.DEFAULT); when(ctx.attr(GrpcUnsafeBufferUtil.BUFFERS)).thenReturn(buffersAttr); }