@Test public void testPingStatsResponser() throws TimeoutException { PingStats pingStats = mock(PingStats.class); when(pingStats.getPingStatsResult()).thenReturn(new PingStatsResult(System.currentTimeMillis() - 2, System.currentTimeMillis(), localHostport(randomPort()), localHostport(randomPort()))); when(pingStatsManager.getAllPingStats()).thenReturn(Lists.newArrayList(pingStats)); AtomicReference<ByteBuf> result = new AtomicReference<>(); Channel channel = getWriteBackChannel(result); handler.doHandle(channel, new String[]{"PingStats"}); waitConditionUntilTimeOut(()->result.get() != null, 1000); ArrayParser parser = (ArrayParser) new ArrayParser().read(result.get()); Object[] objects = parser.getPayload(); for(Object object : objects) { PingStatsResult pingStatsResult = PingStatsResult.parse(object); logger.info("{}", pingStatsResult.getDirect()); logger.info("{}", pingStatsResult.getReal()); logger.info("{}", pingStatsResult.getStart()); logger.info("{}", pingStatsResult.getEnd()); } }
@Override protected void doHandle(Channel channel, String[] content) { if(content == null || content.length < 1) { throw new IllegalArgumentException("monitor option is needed"); } ProxyMonitorParser.Type type = ProxyMonitorParser.Type.parse(content[0]); if(type == null) { logger.warn("[doHandle] unknown type: {}", content[0]); return; } switch (type) { case SocketStats: new SocketStatsResponser().response(channel); break; case PingStats: new PingStatsResponser().response(channel); break; case TunnelStats: new TunnelStatsResponser().response(channel); break; case TrafficStats: new TunnelTrafficResponser().response(channel); break; default: break; } }
ProxyMonitorHandler extends AbstractProxyProtocolOptionHandler { @Override protected void doHandle(Channel channel, String[] content) { if(content == null || content.length < 1) { throw new IllegalArgumentException("monitor option is needed"); } ProxyMonitorParser.Type type = ProxyMonitorParser.Type.parse(content[0]); if(type == null) { logger.warn("[doHandle] unknown type: {}", content[0]); return; } switch (type) { case SocketStats: new SocketStatsResponser().response(channel); break; case PingStats: new PingStatsResponser().response(channel); break; case TunnelStats: new TunnelStatsResponser().response(channel); break; case TrafficStats: new TunnelTrafficResponser().response(channel); break; default: break; } } }
ProxyMonitorHandler extends AbstractProxyProtocolOptionHandler { @Override protected void doHandle(Channel channel, String[] content) { if(content == null || content.length < 1) { throw new IllegalArgumentException("monitor option is needed"); } ProxyMonitorParser.Type type = ProxyMonitorParser.Type.parse(content[0]); if(type == null) { logger.warn("[doHandle] unknown type: {}", content[0]); return; } switch (type) { case SocketStats: new SocketStatsResponser().response(channel); break; case PingStats: new PingStatsResponser().response(channel); break; case TunnelStats: new TunnelStatsResponser().response(channel); break; case TrafficStats: new TunnelTrafficResponser().response(channel); break; default: break; } } ProxyMonitorHandler(TunnelManager tunnelManager, PingStatsManager pingStatsManager, ProxyConfig proxyConfig); }
ProxyMonitorHandler extends AbstractProxyProtocolOptionHandler { @Override protected void doHandle(Channel channel, String[] content) { if(content == null || content.length < 1) { throw new IllegalArgumentException("monitor option is needed"); } ProxyMonitorParser.Type type = ProxyMonitorParser.Type.parse(content[0]); if(type == null) { logger.warn("[doHandle] unknown type: {}", content[0]); return; } switch (type) { case SocketStats: new SocketStatsResponser().response(channel); break; case PingStats: new PingStatsResponser().response(channel); break; case TunnelStats: new TunnelStatsResponser().response(channel); break; case TrafficStats: new TunnelTrafficResponser().response(channel); break; default: break; } } ProxyMonitorHandler(TunnelManager tunnelManager, PingStatsManager pingStatsManager, ProxyConfig proxyConfig); @Override PROXY_OPTION getOption(); }
ProxyMonitorHandler extends AbstractProxyProtocolOptionHandler { @Override protected void doHandle(Channel channel, String[] content) { if(content == null || content.length < 1) { throw new IllegalArgumentException("monitor option is needed"); } ProxyMonitorParser.Type type = ProxyMonitorParser.Type.parse(content[0]); if(type == null) { logger.warn("[doHandle] unknown type: {}", content[0]); return; } switch (type) { case SocketStats: new SocketStatsResponser().response(channel); break; case PingStats: new PingStatsResponser().response(channel); break; case TunnelStats: new TunnelStatsResponser().response(channel); break; case TrafficStats: new TunnelTrafficResponser().response(channel); break; default: break; } } ProxyMonitorHandler(TunnelManager tunnelManager, PingStatsManager pingStatsManager, ProxyConfig proxyConfig); @Override PROXY_OPTION getOption();  }