Search in sources :

Example 1 with MockChannel

use of software.amazon.awssdk.http.nio.netty.internal.MockChannel in project aws-sdk-java-v2 by aws.

the class ChannelUtilsTest method testGetAttributes.

@Test
public void testGetAttributes() throws Exception {
    MockChannel channel = null;
    try {
        channel = new MockChannel();
        channel.attr(MAX_CONCURRENT_STREAMS).set(1L);
        assertThat(ChannelUtils.getAttribute(channel, MAX_CONCURRENT_STREAMS).get()).isEqualTo(1L);
        assertThat(ChannelUtils.getAttribute(channel, HTTP2_MULTIPLEXED_CHANNEL_POOL)).isNotPresent();
    } finally {
        Optional.ofNullable(channel).ifPresent(Channel::close);
    }
}
Also used : MockChannel(software.amazon.awssdk.http.nio.netty.internal.MockChannel) Channel(io.netty.channel.Channel) MockChannel(software.amazon.awssdk.http.nio.netty.internal.MockChannel) Test(org.junit.jupiter.api.Test)

Example 2 with MockChannel

use of software.amazon.awssdk.http.nio.netty.internal.MockChannel in project aws-sdk-java-v2 by aws.

the class ChannelUtilsTest method removeIfExists.

@Test
public void removeIfExists() throws Exception {
    MockChannel channel = null;
    try {
        channel = new MockChannel();
        ChannelPipeline pipeline = channel.pipeline();
        pipeline.addLast(new ReadTimeoutHandler(1));
        pipeline.addLast(new LoggingHandler(LogLevel.DEBUG));
        ChannelUtils.removeIfExists(pipeline, ReadTimeoutHandler.class, LoggingHandler.class);
        assertThat(pipeline.get(ReadTimeoutHandler.class)).isNull();
        assertThat(pipeline.get(LoggingHandler.class)).isNull();
    } finally {
        Optional.ofNullable(channel).ifPresent(Channel::close);
    }
}
Also used : LoggingHandler(io.netty.handler.logging.LoggingHandler) MockChannel(software.amazon.awssdk.http.nio.netty.internal.MockChannel) Channel(io.netty.channel.Channel) MockChannel(software.amazon.awssdk.http.nio.netty.internal.MockChannel) ReadTimeoutHandler(io.netty.handler.timeout.ReadTimeoutHandler) ChannelPipeline(io.netty.channel.ChannelPipeline) Test(org.junit.jupiter.api.Test)

Example 3 with MockChannel

use of software.amazon.awssdk.http.nio.netty.internal.MockChannel in project aws-sdk-java-v2 by aws.

the class HttpOrHttp2ChannelPoolTest method invalidProtocolConfig_shouldFailPromise.

@Test(timeout = 5_000)
public void invalidProtocolConfig_shouldFailPromise() throws Exception {
    HttpOrHttp2ChannelPool invalidChannelPool = new HttpOrHttp2ChannelPool(mockDelegatePool, eventLoopGroup, 4, new NettyConfiguration(AttributeMap.builder().put(CONNECTION_ACQUIRE_TIMEOUT, Duration.ofSeconds(1)).put(MAX_PENDING_CONNECTION_ACQUIRES, 0).build()));
    Promise<Channel> acquirePromise = eventLoopGroup.next().newPromise();
    when(mockDelegatePool.acquire()).thenReturn(acquirePromise);
    Thread.sleep(500);
    Channel channel = new MockChannel();
    eventLoopGroup.register(channel);
    channel.attr(PROTOCOL_FUTURE).set(CompletableFuture.completedFuture(Protocol.HTTP1_1));
    acquirePromise.setSuccess(channel);
    Future<Channel> p = invalidChannelPool.acquire();
    assertThat(p.await().cause().getMessage()).contains("maxPendingAcquires: 0 (expected: >= 1)");
    verify(mockDelegatePool).release(channel);
    assertThat(channel.isOpen()).isFalse();
}
Also used : MockChannel(software.amazon.awssdk.http.nio.netty.internal.MockChannel) NettyConfiguration(software.amazon.awssdk.http.nio.netty.internal.NettyConfiguration) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) Channel(io.netty.channel.Channel) MockChannel(software.amazon.awssdk.http.nio.netty.internal.MockChannel) Test(org.junit.Test)

Example 4 with MockChannel

use of software.amazon.awssdk.http.nio.netty.internal.MockChannel in project aws-sdk-java-v2 by aws.

the class HttpOrHttp2ChannelPoolTest method protocolFutureAwaitsReleaseFuture.

@Test(timeout = 5_000)
public void protocolFutureAwaitsReleaseFuture() throws Exception {
    Promise<Channel> delegateAcquirePromise = eventLoopGroup.next().newPromise();
    Promise<Void> releasePromise = eventLoopGroup.next().newPromise();
    when(mockDelegatePool.acquire()).thenReturn(delegateAcquirePromise);
    when(mockDelegatePool.release(any(Channel.class))).thenReturn(releasePromise);
    MockChannel channel = new MockChannel();
    eventLoopGroup.register(channel);
    channel.attr(PROTOCOL_FUTURE).set(CompletableFuture.completedFuture(Protocol.HTTP1_1));
    // Acquire a new connection and save the returned future
    Future<Channel> acquireFuture = httpOrHttp2ChannelPool.acquire();
    // Return a successful connection from the delegate pool
    delegateAcquirePromise.setSuccess(channel);
    // The returned future should not complete until the release completes
    assertThat(acquireFuture.isDone()).isFalse();
    // Complete the release
    releasePromise.setSuccess(null);
    // Assert the returned future completes (within the test timeout)
    acquireFuture.await();
}
Also used : MockChannel(software.amazon.awssdk.http.nio.netty.internal.MockChannel) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) Channel(io.netty.channel.Channel) MockChannel(software.amazon.awssdk.http.nio.netty.internal.MockChannel) Test(org.junit.Test)

Example 5 with MockChannel

use of software.amazon.awssdk.http.nio.netty.internal.MockChannel in project aws-sdk-java-v2 by aws.

the class Http2StreamExceptionHandlerTest method setup.

@Before
public void setup() throws Exception {
    embeddedParentChannel = new MockChannel();
    verifyExceptionHandler = new TestVerifyExceptionHandler();
    embeddedParentChannel.pipeline().addLast(verifyExceptionHandler);
    when(context.channel()).thenReturn(streamChannel);
    handler = Http2StreamExceptionHandler.create();
    when(context.executor()).thenReturn(GROUP.next());
}
Also used : MockChannel(software.amazon.awssdk.http.nio.netty.internal.MockChannel) Before(org.junit.Before)

Aggregations

MockChannel (software.amazon.awssdk.http.nio.netty.internal.MockChannel)10 Channel (io.netty.channel.Channel)6 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)3 Test (org.junit.jupiter.api.Test)3 Before (org.junit.Before)2 Test (org.junit.Test)2 ChannelPipeline (io.netty.channel.ChannelPipeline)1 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)1 LoggingHandler (io.netty.handler.logging.LoggingHandler)1 SslContext (io.netty.handler.ssl.SslContext)1 SslHandler (io.netty.handler.ssl.SslHandler)1 ReadTimeoutHandler (io.netty.handler.timeout.ReadTimeoutHandler)1 SSLEngine (javax.net.ssl.SSLEngine)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 NettyConfiguration (software.amazon.awssdk.http.nio.netty.internal.NettyConfiguration)1 MetricCollection (software.amazon.awssdk.metrics.MetricCollection)1 MetricCollector (software.amazon.awssdk.metrics.MetricCollector)1