Example usage for io.netty.channel DefaultChannelProgressivePromise DefaultChannelProgressivePromise

List of usage examples for io.netty.channel DefaultChannelProgressivePromise DefaultChannelProgressivePromise

Introduction

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

Prototype

public DefaultChannelProgressivePromise(Channel channel, EventExecutor executor) 

Source Link

Document

Creates a new instance.

Usage

From source file:org.restcomm.media.network.netty.NettyNetworkManagerTest.java

License:Open Source License

@SuppressWarnings("unchecked")
@Test/*from   w  w w.ja  va2  s  . c  om*/
public void testOpenChannelAsyncFailure() throws Exception {
    // given
    this.eventLoopGroup = new NioEventLoopGroup(1);
    final Bootstrap bootstrap = PowerMockito.mock(Bootstrap.class);
    PowerMockito.when(bootstrap.group()).thenReturn(eventLoopGroup);
    this.eventExecutor = new DefaultEventExecutor();
    final FutureCallback<Channel> callback = mock(FutureCallback.class);
    final Channel channel = mock(Channel.class);
    final ChannelPromise promise = new DefaultChannelProgressivePromise(channel, eventExecutor);
    final Exception exception = new RuntimeException("Testing purposes!");

    try (final NettyNetworkManager networkManager = new NettyNetworkManager(bootstrap)) {
        // when
        when(bootstrap.clone()).thenReturn(bootstrap);
        when(bootstrap.register()).thenReturn(promise);
        promise.setFailure(exception);

        networkManager.openChannel(callback);

        // then
        verify(callback, timeout(100)).onFailure(exception);
    }
}