Example usage for io.netty.channel.embedded EmbeddedChannel EmbeddedChannel

List of usage examples for io.netty.channel.embedded EmbeddedChannel EmbeddedChannel

Introduction

In this page you can find the example usage for io.netty.channel.embedded EmbeddedChannel EmbeddedChannel.

Prototype

public EmbeddedChannel() 

Source Link

Document

Create a new instance with an EmbeddedChannelId and an empty pipeline.

Usage

From source file:alluxio.client.block.stream.UfsFallbackLocalFilePacketWriterTest.java

License:Apache License

@Before
public void before() throws Exception {
    mContext = PowerMockito.mock(FileSystemContext.class);
    mAddress = Mockito.mock(WorkerNetAddress.class);

    mChannel = new EmbeddedChannel();
    PowerMockito.when(mContext.acquireNettyChannel(mAddress)).thenReturn(mChannel);
    PowerMockito.doNothing().when(mContext).releaseNettyChannel(mAddress, mChannel);
}

From source file:com.linecorp.armeria.client.thrift.ThriftClientCodecTest.java

License:Apache License

public ThriftClientCodecTest() throws Exception {
    uri = new URI("tbinary+http://localhost/hello");
    scheme = Scheme.parse(uri.getScheme());
    syncClient = new ThriftClientCodec(uri, HelloService.Iface.class, ThriftProtocolFactories.BINARY);
    asyncClient = new ThriftClientCodec(uri, HelloService.AsyncIface.class, ThriftProtocolFactories.BINARY);
    channel = new EmbeddedChannel();
    helloMethod = HelloService.Iface.class.getMethod("hello", String.class);
    asyncHelloMethod = HelloService.AsyncIface.class.getMethod("hello", String.class,
            AsyncMethodCallback.class);
}

From source file:io.crate.mqtt.protocol.MqttProcessorTest.java

@Test
public void testConnectWithWrongMqttVersion() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel();

    MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.CONNECT, false, MqttQoS.AT_LEAST_ONCE,
            false, 0);//from   w  w  w  .  java 2  s .c  om
    MqttConnectVariableHeader variableHeader = new MqttConnectVariableHeader("connect", (byte) 1, false, false,
            false, (byte) 1, false, false, 60);
    MqttConnectPayload payload = new MqttConnectPayload("mqttClient", "someTopic", new byte[0], null, null);
    processor.handleConnect(ch, (MqttConnectMessage) io.netty.handler.codec.mqtt.MqttMessageFactory
            .newMessage(fixedHeader, variableHeader, payload));

    MqttConnAckMessage response = ch.readOutbound();
    assertThat(response.variableHeader().connectReturnCode(),
            is(MqttConnectReturnCode.CONNECTION_REFUSED_UNACCEPTABLE_PROTOCOL_VERSION));
    assertFalse(response.variableHeader().isSessionPresent());
}

From source file:io.crate.mqtt.protocol.MqttProcessorTest.java

@Test
public void testConnectWithoutClientId() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel();

    // clientId may be null if the session is clean
    MqttMessage msg = connectMessage(null, true);
    processor.handleConnect(ch, (MqttConnectMessage) msg);

    MqttConnAckMessage response = ch.readOutbound();
    assertThat(response.variableHeader().connectReturnCode(), is(MqttConnectReturnCode.CONNECTION_ACCEPTED));
    assertTrue(response.variableHeader().isSessionPresent());

    // clientID must not be null if the session is not clean
    msg = connectMessage(null, false);//from  ww w . j  ava  2  s  .co m
    processor.handleConnect(ch, (MqttConnectMessage) msg);

    response = ch.readOutbound();
    assertThat(response.variableHeader().connectReturnCode(),
            is(MqttConnectReturnCode.CONNECTION_REFUSED_IDENTIFIER_REJECTED));
    assertFalse(response.variableHeader().isSessionPresent());
}

From source file:io.crate.mqtt.protocol.MqttProcessorTest.java

@Test
public void testConnectAck() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel();

    MqttMessage msg = connectMessage("client", true);
    processor.handleConnect(ch, (MqttConnectMessage) msg);

    MqttConnAckMessage response = ch.readOutbound();
    assertThat(response.variableHeader().connectReturnCode(), is(MqttConnectReturnCode.CONNECTION_ACCEPTED));
    assertTrue(response.variableHeader().isSessionPresent());
}

From source file:io.crate.protocols.http.CrateHttpsTransportTest.java

@Test
public void testPipelineConfiguration() throws Exception {
    Settings settings = Settings.builder().put(SharedSettings.ENTERPRISE_LICENSE_SETTING.getKey(), true)
            .put(PATH_HOME_SETTING.getKey(), "/tmp").put(SslConfigSettings.SSL_HTTP_ENABLED.getKey(), true)
            .put(SslConfigSettings.SSL_TRUSTSTORE_FILEPATH.getKey(), trustStoreFile.getAbsolutePath())
            .put(SslConfigSettings.SSL_TRUSTSTORE_PASSWORD.getKey(), "truststorePassword")
            .put(SslConfigSettings.SSL_KEYSTORE_FILEPATH.getKey(), keyStoreFile.getAbsolutePath())
            .put(SslConfigSettings.SSL_KEYSTORE_PASSWORD.getKey(), "keystorePassword")
            .put(SslConfigSettings.SSL_KEYSTORE_KEY_PASSWORD.getKey(), "serverKeyPassword").build();

    NetworkService networkService = new NetworkService(
            Collections.singletonList(new NetworkService.CustomNameResolver() {
                @Override/*from  w ww. j ava2 s. c  o m*/
                public InetAddress[] resolveDefault() {
                    return new InetAddress[] { InetAddresses.forString("127.0.0.1") };
                }

                @Override
                public InetAddress[] resolveIfPossible(String value) throws IOException {
                    return new InetAddress[] { InetAddresses.forString("127.0.0.1") };
                }
            }));

    PipelineRegistry pipelineRegistry = new PipelineRegistry();
    new SslContextProvider(settings, pipelineRegistry);

    CrateNettyHttpServerTransport transport = new CrateNettyHttpServerTransport(settings, networkService,
            BigArrays.NON_RECYCLING_INSTANCE, Mockito.mock(ThreadPool.class), NamedXContentRegistry.EMPTY,
            Mockito.mock(HttpServerTransport.Dispatcher.class), pipelineRegistry);

    Channel channel = new EmbeddedChannel();
    try {
        transport.start();

        CrateNettyHttpServerTransport.CrateHttpChannelHandler httpChannelHandler = (CrateNettyHttpServerTransport.CrateHttpChannelHandler) transport
                .configureServerChannelHandler();

        httpChannelHandler.initChannel(channel);

        assertThat(channel.pipeline().first(), instanceOf(SslHandler.class));

    } finally {
        transport.stop();
        transport.close();
        channel.close().awaitUninterruptibly();
    }
}

From source file:io.crate.protocols.http.HttpAuthUpstreamHandlerTest.java

@Test
public void testChannelClosedWhenUnauthorized() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel();
    HttpAuthUpstreamHandler.sendUnauthorized(ch, null);

    HttpResponse resp = ch.readOutbound();
    assertThat(resp.status(), is(HttpResponseStatus.UNAUTHORIZED));
    assertThat(ch.isOpen(), is(false));/*from www.java2s .c om*/
}

From source file:io.crate.protocols.http.HttpAuthUpstreamHandlerTest.java

@Test
public void testSendUnauthorizedWithoutBody() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel();
    HttpAuthUpstreamHandler.sendUnauthorized(ch, null);

    DefaultFullHttpResponse resp = ch.readOutbound();
    assertThat(resp.content(), is(Unpooled.EMPTY_BUFFER));
}

From source file:io.crate.protocols.http.HttpAuthUpstreamHandlerTest.java

@Test
public void testSendUnauthorizedWithBody() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel();
    HttpAuthUpstreamHandler.sendUnauthorized(ch, "not allowed\n");

    DefaultFullHttpResponse resp = ch.readOutbound();
    assertThat(resp.content().toString(StandardCharsets.UTF_8), is("not allowed\n"));
}

From source file:io.crate.protocols.http.HttpAuthUpstreamHandlerTest.java

@Test
public void testSendUnauthorizedWithBodyNoNewline() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel();
    HttpAuthUpstreamHandler.sendUnauthorized(ch, "not allowed");

    DefaultFullHttpResponse resp = ch.readOutbound();
    assertThat(resp.content().toString(StandardCharsets.UTF_8), is("not allowed\n"));
}