@Test public void testNewChannel_forwardsWrappedFactoryFailure() { final ChannelException innerException = new ChannelException(); mockContext.checking(new Expectations() { { one(realChannelFactory).newChannel( with(any(ChannelPipeline.class))); will(throwException(innerException)); } }); try { factory.newChannel(Channels.pipeline(new SimpleChannelHandler())); fail("Expected ChannelException"); } catch (ChannelException e) { assertSame(innerException, e); } }
@Override public void initialize(Map props) { super.initialize(props); // Pull the destination host and port. String host = props.get(NETTY_HOST_KEY).toString(); Object p_string = props.get(NETTY_PORT_KEY); int port = DEFAULT_PORT; if (p_string != null) { port = Integer.parseInt(p_string.toString()); } // Connect and pull the channel. ChannelFactory factory = new NioClientSocketChannelFactory( Executors.newCachedThreadPool(), Executors.newCachedThreadPool()); ClientBootstrap bootstrap = new ClientBootstrap(factory); bootstrap.setPipelineFactory(new ChannelPipelineFactory() { public ChannelPipeline getPipeline() { return Channels.pipeline( new StringEncoder(CharsetUtil.UTF_8), new SimpleChannelHandler()); } }); bootstrap.setOption("keepAlive", true); ChannelFuture f = bootstrap.connect(new InetSocketAddress(host, port)); f.awaitUninterruptibly(); if (!f.isSuccess()) { throw new RuntimeException("Initialization failed.", f.getCause()); } channel = f.getChannel(); }
@Before public void setUp() throws Exception { realChannelFactory = mockContext.mock(ServerSocketChannelFactory.class); factory = new HttpTunnelServerChannelFactory(realChannelFactory); ChannelPipeline pipeline = Channels.pipeline(new SimpleChannelHandler()); realChannel = new FakeServerSocketChannel(factory, pipeline, new FakeChannelSink()); }
/** * @see HttpTunnelClientChannelFactory#newChannel(ChannelPipeline) */ protected HttpTunnelClientChannel(ChannelFactory factory, ChannelPipeline pipeline, HttpTunnelClientChannelSink sink, ClientSocketChannelFactory outboundFactory, ChannelGroup realConnections) { super(null, factory, pipeline, sink); this.outboundFactory = outboundFactory; final WorkerCallbacks callbackProxy = new WorkerCallbacks(); incomingBuffer = new IncomingBuffer<ChannelBuffer>(this); Metrics.newGauge(HttpTunnelClientChannel.class, "incomingBuffer", new Gauge<Integer>() { @Override public Integer value() { return incomingBuffer.size(); } }); sendChannel = outboundFactory.newChannel(Channels.pipeline(new SimpleChannelHandler())); pollChannel = outboundFactory.newChannel(Channels.pipeline(new SimpleChannelHandler())); config = new HttpTunnelClientChannelConfig(sendChannel.getConfig(), pollChannel.getConfig()); saturationManager = new SaturationManager(config.getWriteBufferLowWaterMark(), config.getWriteBufferHighWaterMark()); sendHttpHandler = new HttpTunnelClientChannelProxyHandler(); sendHandler = new HttpTunnelClientChannelSendHandler(callbackProxy); pollHttpHandler = new HttpTunnelClientChannelProxyHandler(); pollHandler = new HttpTunnelClientChannelPollHandler(callbackProxy); opened = new AtomicBoolean(true); bindState = new AtomicReference<BindState>(BindState.UNBOUND); connectState = new AtomicReference<ConnectState>(ConnectState.DISCONNECTED); connectFuture = new AtomicReference<ChannelFuture>(null); tunnelId = null; remoteAddress = null; this.initSendPipeline(sendChannel.getPipeline()); this.initPollPipeline(pollChannel.getPipeline()); realConnections.add(sendChannel); realConnections.add(pollChannel); Channels.fireChannelOpen(this); }