MultiportSyslogTCPSource extends SslContextAwareAbstractSource implements
        EventDrivenSource, Configurable, BatchSizeSupported { @Override public void stop() { logger.info("Stopping {}...", this); acceptor.unbind(); acceptor.dispose(); sourceCounter.stop(); super.stop(); logger.info("{} stopped. Metrics: {}", this, sourceCounter); } MultiportSyslogTCPSource(); @Override void configure(Context context); @Override void start(); @Override void stop(); @Override String toString(); @Override long getBatchSize(); static final Logger logger; }
@Test public void testMultiplePorts() throws IOException, ParseException { MultiportSyslogTCPSource source = new MultiportSyslogTCPSource(); Channel channel = new MemoryChannel(); List<Event> channelEvents = new ArrayList<>(); int numPorts = 1000; List<Integer> portList = testNPorts(source, channel, channelEvents, numPorts, null, getSimpleEventSender(), new Context()); processEvents(channelEvents, numPorts, portList); source.stop(); }
@Test public void testMultiplePortsSSL() throws Exception { SSLContext sslContext = SSLContext.getInstance("TLS"); sslContext.init(null, new TrustManager[]{new X509TrustManager() { @Override public void checkClientTrusted(X509Certificate[] certs, String s) { } @Override public void checkServerTrusted(X509Certificate[] certs, String s) { } @Override public X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; } } }, null); SocketFactory socketFactory = sslContext.getSocketFactory(); Context context = new Context(); context.put("ssl", "true"); context.put("keystore", "src/test/resources/server.p12"); context.put("keystore-password", "password"); context.put("keystore-type", "PKCS12"); MultiportSyslogTCPSource source = new MultiportSyslogTCPSource(); Channel channel = new MemoryChannel(); List<Event> channelEvents = new ArrayList<>(); int numPorts = 10; List<Integer> portList = testNPorts(source, channel, channelEvents, numPorts, null, getSSLEventSender(socketFactory), context); processEvents(channelEvents, numPorts, portList); source.stop(); }
@Test public void testErrorCounterChannelWriteFail() throws Exception { MultiportSyslogTCPSource source = new MultiportSyslogTCPSource(); Channel channel = new MemoryChannel(); List<Event> channelEvents = new ArrayList<>(); ChannelProcessor cp = Mockito.mock(ChannelProcessor.class); doThrow(new ChannelException("dummy")).doNothing().when(cp) .processEventBatch(anyListOf(Event.class)); try { testNPorts(source, channel, channelEvents, 1, cp, getSimpleEventSender(), new Context()); } catch (Exception e) { } SourceCounter sc = (SourceCounter) Whitebox.getInternalState(source, "sourceCounter"); Assert.assertEquals(1, sc.getChannelWriteFail()); source.stop(); }