Search in sources :

Example 61 with Channel

use of org.jboss.netty.channel.Channel in project neo4j by neo4j.

the class IdleChannelReaperTest method shouldNotCloseAnyRecentlyActiveChannels.

@Test
public void shouldNotCloseAnyRecentlyActiveChannels() {
    // given
    FakeClock clock = Clocks.fakeClock();
    ChannelCloser channelCloser = mock(ChannelCloser.class);
    IdleChannelReaper idleChannelReaper = new IdleChannelReaper(channelCloser, NO_LOGGING, clock, THRESHOLD);
    Channel channel = mock(Channel.class);
    idleChannelReaper.add(channel, dummyRequestContext());
    // when
    idleChannelReaper.run();
    // then
    verifyNoMoreInteractions(channelCloser);
}
Also used : FakeClock(org.neo4j.time.FakeClock) Channel(org.jboss.netty.channel.Channel) Test(org.junit.Test)

Example 62 with Channel

use of org.jboss.netty.channel.Channel in project neo4j by neo4j.

the class IdleChannelReaperTest method shouldNotTryToCloseAChannelThatWasRecentlyActive.

@Test
public void shouldNotTryToCloseAChannelThatWasRecentlyActive() {
    // given
    FakeClock clock = Clocks.fakeClock();
    ChannelCloser channelCloser = mock(ChannelCloser.class);
    IdleChannelReaper idleChannelReaper = new IdleChannelReaper(channelCloser, NO_LOGGING, clock, THRESHOLD);
    Channel channel = mock(Channel.class);
    RequestContext request = dummyRequestContext();
    idleChannelReaper.add(channel, request);
    // when
    clock.forward(THRESHOLD + 100, TimeUnit.MILLISECONDS);
    idleChannelReaper.update(channel);
    idleChannelReaper.run();
    // then
    verifyNoMoreInteractions(channelCloser);
}
Also used : FakeClock(org.neo4j.time.FakeClock) Channel(org.jboss.netty.channel.Channel) Test(org.junit.Test)

Example 63 with Channel

use of org.jboss.netty.channel.Channel in project neo4j by neo4j.

the class PortRangeSocketBinderTest method shouldReturnChannelAndSocketIfPortIsFree.

@Test
public void shouldReturnChannelAndSocketIfPortIsFree() {
    // given
    HostnamePort localhost = new HostnamePort("localhost", 9000);
    ServerBootstrap bootstrap = mock(ServerBootstrap.class);
    Channel channel = mock(Channel.class);
    when(bootstrap.bind(new InetSocketAddress("localhost", 9000))).thenReturn(channel);
    // when
    Connection connection = new PortRangeSocketBinder(bootstrap).bindToFirstAvailablePortInRange(localhost);
    //then
    assertEquals(channel, connection.getChannel());
    assertEquals(new InetSocketAddress("localhost", 9000), connection.getSocketAddress());
}
Also used : InetSocketAddress(java.net.InetSocketAddress) HostnamePort(org.neo4j.helpers.HostnamePort) Channel(org.jboss.netty.channel.Channel) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap) Test(org.junit.Test)

Example 64 with Channel

use of org.jboss.netty.channel.Channel in project graylog2-server by Graylog2.

the class GELFHttpHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    ChannelBuffer channelBuffer = ChannelBuffers.copiedBuffer("{}", StandardCharsets.UTF_8);
    when(headers.get(HttpHeaders.Names.CONNECTION)).thenReturn(HttpHeaders.Values.CLOSE);
    when(request.getMethod()).thenReturn(HttpMethod.POST);
    when(request.headers()).thenReturn(headers);
    when(request.getProtocolVersion()).thenReturn(HttpVersion.HTTP_1_1);
    when(request.getContent()).thenReturn(channelBuffer);
    when(request.getUri()).thenReturn("/gelf");
    when(ctx.getChannel()).thenReturn(mock(Channel.class));
    ChannelFuture channelFuture = mock(ChannelFuture.class);
    when(channel.write(any())).thenReturn(channelFuture);
    when(evt.getMessage()).thenReturn(request);
    when(evt.getChannel()).thenReturn(channel);
}
Also used : ChannelFuture(org.jboss.netty.channel.ChannelFuture) Channel(org.jboss.netty.channel.Channel) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) Before(org.junit.Before)

Example 65 with Channel

use of org.jboss.netty.channel.Channel in project crate by crate.

the class PostgresNetty method doStop.

@Override
protected void doStop() {
    synchronized (serverChannels) {
        if (serverChannels != null) {
            for (Channel channel : serverChannels) {
                channel.close().awaitUninterruptibly();
            }
            serverChannels = null;
        }
    }
    if (bootstrap != null) {
        bootstrap.releaseExternalResources();
        bootstrap = null;
    }
}
Also used : Channel(org.jboss.netty.channel.Channel)

Aggregations

Channel (org.jboss.netty.channel.Channel)187 InetSocketAddress (java.net.InetSocketAddress)57 Test (org.junit.Test)52 HttpRequest (org.jboss.netty.handler.codec.http.HttpRequest)40 DefaultHttpRequest (org.jboss.netty.handler.codec.http.DefaultHttpRequest)37 DefaultHttpResponse (org.jboss.netty.handler.codec.http.DefaultHttpResponse)34 HttpResponse (org.jboss.netty.handler.codec.http.HttpResponse)34 SocketAddress (java.net.SocketAddress)33 ChannelFuture (org.jboss.netty.channel.ChannelFuture)33 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)30 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)27 Test (org.testng.annotations.Test)23 ConditionCheck (com.linkedin.databus2.test.ConditionCheck)22 IOException (java.io.IOException)21 SimpleObjectCaptureHandler (com.linkedin.databus2.test.container.SimpleObjectCaptureHandler)19 Logger (org.apache.log4j.Logger)19 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)17 DefaultHttpChunk (org.jboss.netty.handler.codec.http.DefaultHttpChunk)16 HttpChunk (org.jboss.netty.handler.codec.http.HttpChunk)16 ArrayList (java.util.ArrayList)14