* Basic test to exercise multiple-port parsing.
*/
@Test
public void testMultiplePorts() throws IOException, ParseException {
MultiportSyslogTCPSource source = new MultiportSyslogTCPSource();
Channel channel = new MemoryChannel();
Context channelContext = new Context();
channelContext.put("capacity", String.valueOf(2000));
channelContext.put("transactionCapacity", String.valueOf(2000));
Configurables.configure(channel, channelContext);
List<Channel> channels = Lists.newArrayList();
channels.add(channel);
ChannelSelector rcs = new ReplicatingChannelSelector();
rcs.setChannels(channels);
source.setChannelProcessor(new ChannelProcessor(rcs));
Context context = new Context();
StringBuilder ports = new StringBuilder();
for (int i = 0; i < 1000; i++) {
ports.append(String.valueOf(BASE_TEST_SYSLOG_PORT + i)).append(" ");
}
context.put(SyslogSourceConfigurationConstants.CONFIG_PORTS,
ports.toString().trim());
source.configure(context);
source.start();
Socket syslogSocket;
for (int i = 0; i < 1000 ; i++) {
syslogSocket = new Socket(
InetAddress.getLocalHost(), BASE_TEST_SYSLOG_PORT + i);
syslogSocket.getOutputStream().write(getEvent(i));
syslogSocket.close();
}
List<Event> channelEvents = new ArrayList<Event>();
Transaction txn = channel.getTransaction();
txn.begin();
for (int i = 0; i < 1000; i++) {
Event e = channel.take();
if (e == null) {
throw new NullPointerException("Event is null");
}
channelEvents.add(e);
}