Example usage for io.netty.handler.codec PrematureChannelClosureException PrematureChannelClosureException

List of usage examples for io.netty.handler.codec PrematureChannelClosureException PrematureChannelClosureException

Introduction

In this page you can find the example usage for io.netty.handler.codec PrematureChannelClosureException PrematureChannelClosureException.

Prototype

public PrematureChannelClosureException(Throwable cause) 

Source Link

Document

Creates a new instance.

Usage

From source file:com.github.spapageo.jannel.client.JannelClientTest.java

License:Open Source License

@Test(expected = PrematureChannelClosureException.class)
public void testIdentifyCloseChannelOnFailure() throws Exception {
    Channel channel = mock(Channel.class, Answers.RETURNS_SMART_NULLS.get());
    mockWriteHandler = mock(ChannelHandler.class);

    DefaultChannelPromise completedFuture = new DefaultChannelPromise(channel);
    completedFuture.setSuccess();//from w w w  . ja v  a  2  s  .  c  o  m

    DefaultChannelPromise failedFuture = new DefaultChannelPromise(channel);
    failedFuture.setFailure(new PrematureChannelClosureException("test"));

    ChannelPipeline channelPipeline = mock(ChannelPipeline.class);
    when(channelPipeline.addLast(anyString(), any(ChannelHandler.class))).thenReturn(channelPipeline);
    when(channelPipeline.addLast(any(EventExecutorGroup.class), anyString(), any(ChannelHandler.class)))
            .thenReturn(channelPipeline);
    when(channel.pipeline()).thenReturn(channelPipeline);
    when(channel.isActive()).thenReturn(true);
    when(channel.writeAndFlush(any())).thenReturn(failedFuture);
    when(channel.close()).thenReturn(completedFuture);

    when(bootstrap.connect(anyString(), anyInt())).thenReturn(completedFuture);

    ClientSessionConfiguration configuration = new ClientSessionConfiguration();

    jannelClient.identify(configuration, null);
}