@Test(timeout = 60000) public void testAddChannelHandlerFirst() throws Exception { String handlerName = "test_handler"; Func0<ChannelHandler> handlerFactory = clientStateRule.newHandler(); ClientState<String, String> newState = clientStateRule.clientState .addChannelHandlerFirst(handlerName, handlerFactory); clientStateRule.verifyMockPipelineAccessPostCopy(); assertThat("Client state not copied.", clientStateRule.clientState, is(not(newState))); assertThat("Options copied.", clientStateRule.clientState.unsafeChannelOptions(), is(newState.unsafeChannelOptions())); assertThat("Detached pipeline not copied.", clientStateRule.clientState.unsafeDetachedPipeline(), is(not(newState.unsafeDetachedPipeline()))); Mockito.verify(newState.unsafeDetachedPipeline()).addFirst(handlerName, handlerFactory); Mockito.verifyNoMoreInteractions(newState.unsafeDetachedPipeline()); Mockito.verifyNoMoreInteractions(clientStateRule.mockPipeline); }
public static <WW, RR> ClientState<WW, RR> create(DetachedChannelPipeline detachedPipeline, ConnectionProviderFactory<WW, RR> factory, Observable<Host> hostStream, EventLoopGroup eventLoopGroup, Class<? extends Channel> channelClass) { return new ClientState<>(hostStream, factory, detachedPipeline, eventLoopGroup, channelClass); }
@Test(timeout = 60000) public void testEnableWireLogging() throws Exception { ClientState<String, String> newState = clientStateRule.clientState.enableWireLogging("", LogLevel.ERROR); clientStateRule.verifyMockPipelineAccessPostCopy(); assertThat("Client state not copied.", clientStateRule.clientState, is(not(newState))); assertThat("Options copied.", clientStateRule.clientState.unsafeChannelOptions(), is(newState.unsafeChannelOptions())); assertThat("Detached pipeline not copied.", clientStateRule.clientState.unsafeDetachedPipeline(), is(not(newState.unsafeDetachedPipeline()))); Mockito.verify(newState.unsafeDetachedPipeline()) .addFirst(HandlerNames.WireLogging.getName(), LoggingHandlerFactory.getFactory("", LogLevel.ERROR)); Mockito.verifyNoMoreInteractions(newState.unsafeDetachedPipeline()); Mockito.verifyNoMoreInteractions(clientStateRule.mockPipeline); }
public static <WW, RR> ClientState<WW, RR> create(ConnectionProviderFactory<WW, RR> factory, Observable<Host> hostStream, EventLoopGroup eventLoopGroup, Class<? extends Channel> channelClass) { return new ClientState<>(hostStream, factory, newChannelPipeline(new TailHandlerFactory(false)), eventLoopGroup, channelClass); }
@Test(timeout = 60000) public void testAddChannelHandlerBefore() throws Exception { String handlerName = "test_handler"; String baseHandlerName = "test_handler_base"; Func0<ChannelHandler> handlerFactory = clientStateRule.newHandler(); ClientState<String, String> newState = clientStateRule.clientState .addChannelHandlerBefore(baseHandlerName, handlerName, handlerFactory); clientStateRule.verifyMockPipelineAccessPostCopy(); assertThat("Client state not copied.", clientStateRule.clientState, is(not(newState))); assertThat("Options copied.", clientStateRule.clientState.unsafeChannelOptions(), is(newState.unsafeChannelOptions())); assertThat("Detached pipeline not copied.", clientStateRule.clientState.unsafeDetachedPipeline(), is(not(newState.unsafeDetachedPipeline()))); Mockito.verify(newState.unsafeDetachedPipeline()).addBefore(baseHandlerName, handlerName, handlerFactory); Mockito.verifyNoMoreInteractions(newState.unsafeDetachedPipeline()); Mockito.verifyNoMoreInteractions(clientStateRule.mockPipeline); }
@Test(timeout = 60000) public void testAddChannelHandlerLast() throws Exception { String handlerName = "test_handler"; Func0<ChannelHandler> handlerFactory = clientStateRule.newHandler(); ClientState<String, String> newState = clientStateRule.clientState .addChannelHandlerLast(handlerName, handlerFactory); clientStateRule.verifyMockPipelineAccessPostCopy(); assertThat("Client state not copied.", clientStateRule.clientState, is(not(newState))); assertThat("Options copied.", clientStateRule.clientState.unsafeChannelOptions(), is(newState.unsafeChannelOptions())); assertThat("Detached pipeline not copied.", clientStateRule.clientState.unsafeDetachedPipeline(), is(not(newState.unsafeDetachedPipeline()))); Mockito.verify(newState.unsafeDetachedPipeline()).addLast(handlerName, handlerFactory); Mockito.verifyNoMoreInteractions(newState.unsafeDetachedPipeline()); Mockito.verifyNoMoreInteractions(clientStateRule.mockPipeline); }
@Test(timeout = 60000) public void testAddChannelHandlerAfter() throws Exception { String handlerName = "test_handler"; String baseHandlerName = "test_handler_base"; Func0<ChannelHandler> handlerFactory = clientStateRule.newHandler(); ClientState<String, String> newState = clientStateRule.clientState .addChannelHandlerAfter(baseHandlerName, handlerName, handlerFactory); clientStateRule.verifyMockPipelineAccessPostCopy(); assertThat("Client state not copied.", clientStateRule.clientState, is(not(newState))); assertThat("Options copied.", clientStateRule.clientState.unsafeChannelOptions(), is(newState.unsafeChannelOptions())); assertThat("Detached pipeline not copied.", clientStateRule.clientState.unsafeDetachedPipeline(), is(not(newState.unsafeDetachedPipeline()))); Mockito.verify(newState.unsafeDetachedPipeline()).addAfter(baseHandlerName, handlerName, handlerFactory); Mockito.verifyNoMoreInteractions(newState.unsafeDetachedPipeline()); Mockito.verifyNoMoreInteractions(clientStateRule.mockPipeline); }
@Override public void evaluate() throws Throwable { mockPipeline = Mockito.mock(DetachedChannelPipeline.class, Mockito.RETURNS_MOCKS); EmbeddedConnectionProvider<String, String> ecp = new EmbeddedConnectionProvider<>(); clientState = ClientState.create(mockPipeline, ecp.asFactory(), Observable.<Host>empty()) .enableWireLogging(LogLevel.ERROR); base.evaluate(); } };
@Test(timeout = 60000) public void testPipelineConfigurator() throws Exception { final Action1<ChannelPipeline> pipelineConfigurator = new Action1<ChannelPipeline>() { @Override public void call(ChannelPipeline pipeline) { } }; ClientState<String, String> newState = clientStateRule.clientState.pipelineConfigurator(pipelineConfigurator); clientStateRule.verifyMockPipelineAccessPostCopy(); assertThat("Client state not copied.", clientStateRule.clientState, is(not(newState))); assertThat("Options copied.", clientStateRule.clientState.unsafeChannelOptions(), is(newState.unsafeChannelOptions())); assertThat("Detached pipeline not copied.", clientStateRule.clientState.unsafeDetachedPipeline(), is(not(newState.unsafeDetachedPipeline()))); Mockito.verify(newState.unsafeDetachedPipeline()).configure(pipelineConfigurator); Mockito.verifyNoMoreInteractions(newState.unsafeDetachedPipeline()); Mockito.verifyNoMoreInteractions(clientStateRule.mockPipeline); }
public ClientState<W, R> enableWireLogging(String name, final LogLevel wireLoggingLevel) { return addChannelHandlerFirst(WireLogging.getName(), LoggingHandlerFactory.getFactory(name, wireLoggingLevel)); }
public ClientState<W, R> enableWireLogging(final LogLevel wireLoggingLevel) { return enableWireLogging(LoggingHandler.class.getName(), wireLoggingLevel); }
public ClientState<W, R> secure(Func1<ByteBufAllocator, SSLEngine> sslEngineFactory) { return secure(new DefaultSslCodec(sslEngineFactory)); }
public static <W, R> TcpClientImpl<W, R> create(ConnectionProviderFactory<W, R> factory, Observable<Host> hostStream) { ClientState<W, R> state = ClientState.create(factory, hostStream); final TcpClientEventPublisher eventPublisher = new TcpClientEventPublisher(); return _create(state, eventPublisher); }
public static <W, R> TcpClientImpl<W, R> create(SocketAddress socketAddress) { return create(socketAddress, ClientState.defaultEventloopGroup(), ClientState.defaultSocketChannelClass()); }
@Override public <WW, RR> TcpClient<WW, RR> addChannelHandlerBefore(String baseName, String name, Func0<ChannelHandler> handlerFactory) { return copy(state.<WW, RR>addChannelHandlerBefore(baseName, name, handlerFactory), eventPublisher); }
@Override public <WW, RR> TcpClient<WW, RR> addChannelHandlerAfter(String baseName, String name, Func0<ChannelHandler> handlerFactory) { return copy(state.<WW, RR>addChannelHandlerAfter(baseName, name, handlerFactory), eventPublisher); }
@Override public <WW, RR> TcpClient<WW, RR> addChannelHandlerLast(EventExecutorGroup group, String name, Func0<ChannelHandler> handlerFactory) { return copy(state.<WW, RR>addChannelHandlerLast(group, name, handlerFactory), eventPublisher); }
@Override public <WW, RR> TcpClient<WW, RR> pipelineConfigurator(Action1<ChannelPipeline> pipelineConfigurator) { return copy(state.<WW, RR>pipelineConfigurator(pipelineConfigurator), eventPublisher); }
@Test(timeout = 60000) public void testAddChannelHandlerBeforeWithEventExecGroup() throws Exception { String handlerName = "test_handler"; String baseHandlerName = "test_handler_base"; Func0<ChannelHandler> handlerFactory = clientStateRule.newHandler(); NioEventLoopGroup executor = new NioEventLoopGroup(); ClientState<String, String> newState = clientStateRule.clientState .addChannelHandlerBefore(executor, baseHandlerName, handlerName, handlerFactory); clientStateRule.verifyMockPipelineAccessPostCopy(); assertThat("Client state not copied.", clientStateRule.clientState, is(not(newState))); assertThat("Options copied.", clientStateRule.clientState.unsafeChannelOptions(), is(newState.unsafeChannelOptions())); assertThat("Detached pipeline not copied.", clientStateRule.clientState.unsafeDetachedPipeline(), is(not(newState.unsafeDetachedPipeline()))); Mockito.verify(newState.unsafeDetachedPipeline()).addBefore(executor, baseHandlerName, handlerName, handlerFactory); Mockito.verifyNoMoreInteractions(newState.unsafeDetachedPipeline()); Mockito.verifyNoMoreInteractions(clientStateRule.mockPipeline); }
@Test(timeout = 60000) public void testAddChannelHandlerLastWithEventExecGroup() throws Exception { String handlerName = "test_handler"; Func0<ChannelHandler> handlerFactory = clientStateRule.newHandler(); NioEventLoopGroup executor = new NioEventLoopGroup(); ClientState<String, String> newState = clientStateRule.clientState .addChannelHandlerLast(executor, handlerName, handlerFactory); clientStateRule.verifyMockPipelineAccessPostCopy(); assertThat("Client state not copied.", clientStateRule.clientState, is(not(newState))); assertThat("Options copied.", clientStateRule.clientState.unsafeChannelOptions(), is(newState.unsafeChannelOptions())); assertThat("Detached pipeline not copied.", clientStateRule.clientState.unsafeDetachedPipeline(), is(not(newState.unsafeDetachedPipeline()))); Mockito.verify(newState.unsafeDetachedPipeline()).addLast(executor, handlerName, handlerFactory); Mockito.verifyNoMoreInteractions(newState.unsafeDetachedPipeline()); Mockito.verifyNoMoreInteractions(clientStateRule.mockPipeline); }