@Test public void buildHttp11Server() { XioServerBootstrap bootstrap = XioServerBootstrap.fromConfig("xio.testHttpsServer").addToPipeline(new SmartHttpPipeline()); XioServer server = bootstrap.build(); assertEquals("ssl-http/1.1", server.getInstrumentation().applicationProtocol()); } }
public ApplicationBootstrap addServer( String server, UnaryOperator<XioServerBootstrap> configure) { XioServerConfig serverConfig = new XioServerConfig(config.getServer(server)); XioServerState serverState = new XioServerState(serverConfig); XioServerBootstrap serverBootstrap = configure.apply( new XioServerBootstrap(state, serverConfig, serverState) .channelConfig(state.getChannelConfiguration())); serverBootstraps.put(server, serverBootstrap); return this; }
public XioServerBootstrap( ApplicationState appState, XioServerConfig config, XioServerState state) { serverBootstrap = new ServerBootstrap(); pipelineAssembler = new XioPipelineAssembler(appState, config, state); this.config = config; this.state = state; if (XioServiceLocator.getInstance() == null) { XioServiceLocator.buildInstance(appState.config(), appState); } bindAddress(config.getBindAddress()); channelConfig(appState.getChannelConfiguration()); }
new XioServerBootstrap(appState, serverConfig, new XioServerState(serverConfig)) .addToPipeline( new SmartHttpPipeline() { @Override XioServer xioServer = bootstrap.build(); GrpcClient client = GrpcClient.run(xioServer.getPort());
public static void main(String args[]) throws Exception { Application application = new ApplicationBootstrap("exhibitor-test") .addServer("main", bs -> bs.addToPipeline(new SmartHttpPipeline())) .build(); application .getState() .getZkClient() .getClient() .create() .creatingParentsIfNeeded() .forPath("/test/key", "value".getBytes()); } }
public static XioServerBootstrap fromConfig(String key) { return fromConfig(key, ConfigFactory.load()); }
public static XioServerBootstrap fromConfig(String key, Config config) { XioServerConfig serverConfig = XioServerConfig.fromConfig(key, config); ApplicationConfig appConfig = ApplicationConfig.fromConfig("xio.defaultApplication", ConfigFactory.load()); return new XioServerBootstrap( new ApplicationState(appConfig, new XioTracing(appConfig.getTracingConfig())), serverConfig, new XioServerState(serverConfig)); }
public Application build() { Map<String, XioServer> servers = new HashMap<>(); serverBootstraps.forEach((k, v) -> servers.put(k, v.build())); ZkClient zkClient = state.getZkClient(); zkClient.registerUpdater( new IpFilterConfig.Updater(config.getIpFilterPath(), state::setIpFilterConfig)); zkClient.registerUpdater( new Http1FilterConfig.Updater(config.getHttp1FilterPath(), state::setHttp1FilterConfig)); state.getZkClient().start(); Configurator configurator = Configurator.build(config.settings()); configurator.start(); Application application = new Application(config, servers, state, configurator); new ApplicationRunner(application).start(); return application; } }
new XioServerBootstrap(appState, serverConfig, new XioServerState(serverConfig)) .addToPipeline( new SmartHttpPipeline() { @Override XioServer xioServer = bootstrap.build(); GrpcClient client = GrpcClient.run(xioServer.getPort());
@Before public void before() { application = new ApplicationBootstrap("xio.testZipkinApplication") .addServer( "exampleServer", (bs) -> bs.addToPipeline(new SmartHttpPipeline(TestHandler::new))) .build(); MetricRegistry metricRegistry = mock(MetricRegistry.class); requestsMeter = mock(Meter.class); when(metricRegistry.meter("requests")).thenReturn(requestsMeter); successMeter = mock(Meter.class); when(metricRegistry.meter("statusClassSuccess")).thenReturn(successMeter); application.getState().setMetricRegistry(metricRegistry); }
@Test public void testEchoServer() { XioServerBootstrap bootstrap = XioServerBootstrap.fromConfig("xio.testEchoServer").addToPipeline(new XioEchoPipeline()); try (XioServer server = bootstrap.build(); EchoClient client = new EchoClient()) { client.connect(server.getInstrumentation().addressBound()); String payload = "test message"; client.send(payload); String response = client.recv(); assertEquals(payload, response); } }
public void start(Config config) { ApplicationState appState = new ApplicationState(ApplicationConfig.fromConfig(proxyConfig, config)); Stream<ProxyRouteConfig> proxyRouteConfigs = Arrays.stream(routeConfig.split(",")).map(it -> new ProxyRouteConfig(config.getConfig(it))); ProxyClientFactory clientFactory = new ProxyClientFactory(appState); RouteStates routeStates = new RouteStates(proxyRouteConfigs, appState, clientFactory); application = new ApplicationBootstrap(appState.config()) .addServer( "main", bs -> bs.addToPipeline( new SmartHttpPipeline() { @Override public ChannelHandler getApplicationRouter() { return new PipelineRouter(routeStates.routeMap()) { @Override protected void channelRead0(ChannelHandlerContext ctx, Request msg) { super.channelRead0(ctx, msg); if (msg.endOfMessage()) { requestCount.incrementAndGet(); } } }; } })) .build(); }
@Test public void testEchoServerLargePayload() { XioServerBootstrap bootstrap = XioServerBootstrap.fromConfig("xio.testEchoServer").addToPipeline(new XioEchoPipeline()); try (XioServer server = bootstrap.build(); EchoClient client = new EchoClient()) { client.connect(server.getInstrumentation().addressBound()); int n = 800; String payload = "Netty rocks!"; StringBuilder builder = new StringBuilder(n * payload.length()); for (int i = 0; i < n; i += 1) { builder.append(payload); } payload = builder.toString(); client.send(payload); String response = client.recv(); assertEquals(payload, response); } } }
public Application build() { addServer("main", bs -> bs.addToPipeline(pipelineFragment())); return super.build(); }
@Test public void testProxyServer() throws IOException { XioServerBootstrap bootstrap = XioServerBootstrap.fromConfig("xio.testHttpServer") .addToPipeline( new SmartHttpPipeline(() -> new SampleHandler()) { @Override try (XioServer server = bootstrap.build()) { InetSocketAddress address = server.getInstrumentation().addressBound(); Response response = ClientHelper.http(address);
@Before public void before() throws Exception { ApplicationConfig appConfig = ApplicationConfig.fromConfig("xio.testZipkinApplication"); application = new ApplicationBootstrap(appConfig, XioTracingDecorator::new) .addServer( "exampleServer", (bs) -> bs.addToPipeline(new SmartHttpPipeline(TestHandler::new))) .build(); }
@Test public void testServe404() { XioServerBootstrap bootstrap = XioServerBootstrap.fromConfig("xio.testHttpServer") .addToPipeline( new SmartHttpPipeline( new XioPipelineFragment() { public String applicationProtocol() { return ""; } public void buildHandlers( ApplicationState appState, XioServerConfig config, XioServerState state, ChannelPipeline pipeline) { pipeline.addLast(new XioHttp404Handler()); } })); try (XioServer server = bootstrap.build()) { Response response = ClientHelper.http(server.getInstrumentation().addressBound()); assertEquals(404, response.code()); assertEquals(server.getInstrumentation() != null, true); } } }
@Test public void testProxy() throws Exception { InetSocketAddress proxiedAddress = new InetSocketAddress("127.0.0.1", server.getPort()); Application application = new ApplicationBootstrap("xio.proxyApplication") .addServer("proxyServer", (bs) -> bs.addToPipeline(proxyFragment(proxiedAddress))) .build(); Dispatcher dispatcher = new Dispatcher() { @Override public MockResponse dispatch(RecordedRequest request) throws InterruptedException { return new MockResponse().setBody("['I am a json response']"); } }; server.setDispatcher(dispatcher); InetSocketAddress proxy = application.instrumentation("proxyServer").boundAddress(); Request request = buildRequest(proxy); Response response = get(request); RecordedRequest servedRequest = server.takeRequest(); application.close(); assertEquals("/api/v1/fives/hand/slap", servedRequest.getRequestUrl().encodedPath()); }
@Test public void testEchoServerLargePayload() { try (EchoClient client = new EchoClient(); EchoServer server = new EchoServer()) { server.bind(new InetSocketAddress("127.0.0.1", 0)); XioServerBootstrap bootstrap = XioServerBootstrap.fromConfig("xio.testTcpProxyServer") .addToPipeline(new XioTcpProxyPipeline(server.addressBound())); try (XioServer proxy = bootstrap.build()) { client.connect(proxy.getInstrumentation().addressBound()); server.accept(); int n = 800; String payload = "Netty rocks!"; StringBuilder builder = new StringBuilder(n * payload.length()); for (int i = 0; i < n; i += 1) { builder.append(payload); } payload = builder.toString(); client.send(payload); String line = server.process(); String response = client.recv(); assertEquals(payload, line); assertEquals(payload, response); } } } }
@Test public void testProxyServer() { try (EchoClient client = new EchoClient(); EchoServer server = new EchoServer()) { server.bind(new InetSocketAddress("127.0.0.1", 0)); XioServerBootstrap bootstrap = XioServerBootstrap.fromConfig("xio.testTcpProxyServer") .addToPipeline(new XioTcpProxyPipeline(server.addressBound())); try (XioServer proxy = bootstrap.build()) { client.connect(proxy.getInstrumentation().addressBound()); server.accept(); String payload = "test message"; client.send(payload); String line = server.process(); String response = client.recv(); assertEquals(payload, line); assertEquals(payload, response); } } }