@Test public void canDealRequestWithSeveralReactor() throws IOException { int availablePort = NetUtils.getAvailablePort(); MultiReactor reactor = MultiReactor.newBuilder() .setPort(availablePort) .setHandlerClass(InsureReactorHandler.class) .setMainReactorName("MainReactor") .setSubReactorCount(3) .build(); Thread reactorT = new Thread(reactor); reactorT.start(); String first = NetWorkClient.doRequest("localhost", availablePort, "test\n"); String second = NetWorkClient.doRequest("localhost", availablePort, "test\n"); String third = NetWorkClient.doRequest("localhost", availablePort, "test\n"); String nextRoundFirst = NetWorkClient.doRequest("localhost", availablePort, "test\n"); List<String> responses = new ArrayList<>(); responses.add(first); responses.add(second); responses.add(third); responses.add(nextRoundFirst); Map<String, Long> result = responses.stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting())); Map<String, Long> expect = new HashMap<>(); expect.put("subReactor-0", 1L); expect.put("subReactor-1", 1L); expect.put("subReactor-2", 2L); assertEquals(expect, result); }
public static Builder newBuilder() { return new Builder(); }
MultiReactor implements Runnable { public static Builder newBuilder() { return new Builder(); } }
MultiReactor implements Runnable { public static Builder newBuilder() { return new Builder(); } private  MultiReactor(String mainReactorName, int port, Class<? extends BaseHandler> handlerClass, int subReactorCount, ServletContext context); }
MultiReactor implements Runnable { public static Builder newBuilder() { return new Builder(); } private  MultiReactor(String mainReactorName, int port, Class<? extends BaseHandler> handlerClass, int subReactorCount, ServletContext context); static Builder newBuilder(); @Override void run(); void stop(); }
MultiReactor implements Runnable { public static Builder newBuilder() { return new Builder(); } private  MultiReactor(String mainReactorName, int port, Class<? extends BaseHandler> handlerClass, int subReactorCount, ServletContext context); static Builder newBuilder(); @Override void run(); void stop();  }