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);
}
}
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);
}
}
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();
}
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();
}
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());
}
Aggregations