Search in sources :

Example 51 with PooledByteBufAllocator

use of io.netty.buffer.PooledByteBufAllocator in project motan by weibocom.

the class YarMessageHandlerWarpperTest method buildHttpRequest.

private FullHttpRequest buildHttpRequest(YarRequest yarRequest, String requestPath) throws Exception {
    PooledByteBufAllocator allocator = new PooledByteBufAllocator();
    ByteBuf buf = allocator.buffer(2048, 1024 * 1024);
    if (yarRequest != null) {
        buf.writeBytes(YarProtocol.toProtocolBytes(yarRequest));
    }
    FullHttpRequest httpReqeust = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, requestPath, buf);
    return httpReqeust;
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) ByteBuf(io.netty.buffer.ByteBuf) PooledByteBufAllocator(io.netty.buffer.PooledByteBufAllocator)

Example 52 with PooledByteBufAllocator

use of io.netty.buffer.PooledByteBufAllocator in project netty by netty.

the class AbstractSslHandlerThroughputBenchmark method setup.

@Setup(Level.Iteration)
public final void setup() throws Exception {
    allocator = new PooledByteBufAllocator(true);
    initSslHandlers(allocator);
    wrapSrcBuffer = allocateBuffer(messageSize);
    byte[] bytes = new byte[messageSize];
    PlatformDependent.threadLocalRandom().nextBytes(bytes);
    wrapSrcBuffer.writeBytes(bytes);
    // Complete the initial TLS handshake.
    doHandshake();
}
Also used : PooledByteBufAllocator(io.netty.buffer.PooledByteBufAllocator) Setup(org.openjdk.jmh.annotations.Setup)

Example 53 with PooledByteBufAllocator

use of io.netty.buffer.PooledByteBufAllocator in project netty by netty.

the class SslEngineHandshakeBenchmark method setup.

@Setup(Level.Iteration)
public void setup() {
    allocator = new PooledByteBufAllocator(true);
    // Init an engine one time and create the buffers needed for an handshake so we can use them in the benchmark
    initEngines(allocator);
    initHandshakeBuffers();
    destroyEngines();
}
Also used : PooledByteBufAllocator(io.netty.buffer.PooledByteBufAllocator) Setup(org.openjdk.jmh.annotations.Setup)

Example 54 with PooledByteBufAllocator

use of io.netty.buffer.PooledByteBufAllocator in project spring-framework by spring-projects.

the class BodyExtractorsTests method unsupportedMediaTypeShouldConsumeAndCancel.

// SPR-17054
@Test
public void unsupportedMediaTypeShouldConsumeAndCancel() {
    NettyDataBufferFactory factory = new NettyDataBufferFactory(new PooledByteBufAllocator(true));
    NettyDataBuffer buffer = factory.wrap(ByteBuffer.wrap("spring".getBytes(StandardCharsets.UTF_8)));
    TestPublisher<DataBuffer> body = TestPublisher.create();
    MockClientHttpResponse response = new MockClientHttpResponse(HttpStatus.OK);
    response.getHeaders().setContentType(MediaType.APPLICATION_PDF);
    response.setBody(body.flux());
    BodyExtractor<Mono<User>, ReactiveHttpInputMessage> extractor = BodyExtractors.toMono(User.class);
    StepVerifier.create(extractor.extract(response, this.context)).then(() -> {
        body.assertWasSubscribed();
        body.emit(buffer);
    }).expectErrorSatisfies(throwable -> {
        boolean condition = throwable instanceof UnsupportedMediaTypeException;
        assertThat(condition).isTrue();
        assertThatExceptionOfType(IllegalReferenceCountException.class).isThrownBy(buffer::release);
        body.assertCancelled();
    }).verify();
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) TestPublisher(reactor.test.publisher.TestPublisher) FilePart(org.springframework.http.codec.multipart.FilePart) FormFieldPart(org.springframework.http.codec.multipart.FormFieldPart) JsonView(com.fasterxml.jackson.annotation.JsonView) StepVerifier(reactor.test.StepVerifier) NettyDataBufferFactory(org.springframework.core.io.buffer.NettyDataBufferFactory) DefaultDataBufferFactory(org.springframework.core.io.buffer.DefaultDataBufferFactory) ServerHttpResponse(org.springframework.http.server.reactive.ServerHttpResponse) IllegalReferenceCountException(io.netty.util.IllegalReferenceCountException) ParameterizedTypeReference(org.springframework.core.ParameterizedTypeReference) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DefaultDataBuffer(org.springframework.core.io.buffer.DefaultDataBuffer) FormHttpMessageReader(org.springframework.http.codec.FormHttpMessageReader) HttpMessageReader(org.springframework.http.codec.HttpMessageReader) HashMap(java.util.HashMap) JSON_VIEW_HINT(org.springframework.http.codec.json.Jackson2CodecSupport.JSON_VIEW_HINT) ByteBuffer(java.nio.ByteBuffer) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Part(org.springframework.http.codec.multipart.Part) Map(java.util.Map) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) Jaxb2XmlDecoder(org.springframework.http.codec.xml.Jaxb2XmlDecoder) NettyDataBuffer(org.springframework.core.io.buffer.NettyDataBuffer) ServerHttpRequest(org.springframework.http.server.reactive.ServerHttpRequest) Jackson2JsonDecoder(org.springframework.http.codec.json.Jackson2JsonDecoder) DefaultPartHttpMessageReader(org.springframework.http.codec.multipart.DefaultPartHttpMessageReader) MockClientHttpResponse(org.springframework.web.testfixture.http.client.reactive.MockClientHttpResponse) StringDecoder(org.springframework.core.codec.StringDecoder) MediaType(org.springframework.http.MediaType) MultiValueMap(org.springframework.util.MultiValueMap) Mono(reactor.core.publisher.Mono) PooledByteBufAllocator(io.netty.buffer.PooledByteBufAllocator) ByteBufferDecoder(org.springframework.core.codec.ByteBufferDecoder) DataBuffer(org.springframework.core.io.buffer.DataBuffer) StandardCharsets(java.nio.charset.StandardCharsets) DecoderHttpMessageReader(org.springframework.http.codec.DecoderHttpMessageReader) Test(org.junit.jupiter.api.Test) Flux(reactor.core.publisher.Flux) HttpStatus(org.springframework.http.HttpStatus) MockServerHttpRequest(org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest) List(java.util.List) ReactiveHttpInputMessage(org.springframework.http.ReactiveHttpInputMessage) MultipartHttpMessageReader(org.springframework.http.codec.multipart.MultipartHttpMessageReader) Optional(java.util.Optional) Collections(java.util.Collections) Mono(reactor.core.publisher.Mono) NettyDataBuffer(org.springframework.core.io.buffer.NettyDataBuffer) NettyDataBufferFactory(org.springframework.core.io.buffer.NettyDataBufferFactory) ReactiveHttpInputMessage(org.springframework.http.ReactiveHttpInputMessage) PooledByteBufAllocator(io.netty.buffer.PooledByteBufAllocator) DefaultDataBuffer(org.springframework.core.io.buffer.DefaultDataBuffer) NettyDataBuffer(org.springframework.core.io.buffer.NettyDataBuffer) DataBuffer(org.springframework.core.io.buffer.DataBuffer) MockClientHttpResponse(org.springframework.web.testfixture.http.client.reactive.MockClientHttpResponse) Test(org.junit.jupiter.api.Test)

Example 55 with PooledByteBufAllocator

use of io.netty.buffer.PooledByteBufAllocator in project thingsboard by thingsboard.

the class MqttTransportHandlerTest method getMqttPublishMessage.

MqttPublishMessage getMqttPublishMessage() {
    MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(MqttMessageType.PUBLISH, true, MqttQoS.AT_LEAST_ONCE, false, 123);
    MqttPublishVariableHeader variableHeader = new MqttPublishVariableHeader("v1/gateway/telemetry", packedId.incrementAndGet());
    ByteBuf payload = new EmptyByteBuf(new PooledByteBufAllocator());
    return new MqttPublishMessage(mqttFixedHeader, variableHeader, payload);
}
Also used : MqttFixedHeader(io.netty.handler.codec.mqtt.MqttFixedHeader) EmptyByteBuf(io.netty.buffer.EmptyByteBuf) MqttPublishMessage(io.netty.handler.codec.mqtt.MqttPublishMessage) MqttPublishVariableHeader(io.netty.handler.codec.mqtt.MqttPublishVariableHeader) ByteBuf(io.netty.buffer.ByteBuf) EmptyByteBuf(io.netty.buffer.EmptyByteBuf) PooledByteBufAllocator(io.netty.buffer.PooledByteBufAllocator)

Aggregations

PooledByteBufAllocator (io.netty.buffer.PooledByteBufAllocator)60 Test (org.junit.Test)37 LocalAddress (io.netty.channel.local.LocalAddress)29 ByteBuf (io.netty.buffer.ByteBuf)28 HttpInitiator (org.jocean.http.client.HttpClient.HttpInitiator)25 Subscription (rx.Subscription)25 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)24 HttpTrade (org.jocean.http.server.HttpServerBuilder.HttpTrade)24 DisposableWrapper (org.jocean.idiom.DisposableWrapper)20 IOException (java.io.IOException)18 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)17 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)17 ConnectException (java.net.ConnectException)17 CertificateException (java.security.cert.CertificateException)17 SSLException (javax.net.ssl.SSLException)17 TransportException (org.jocean.http.TransportException)17 TestSubscriber (rx.observers.TestSubscriber)16 Channel (io.netty.channel.Channel)9 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)9 DefaultHttpRequest (io.netty.handler.codec.http.DefaultHttpRequest)8