use of loghub.Pipeline in project LogHub by fbacchella.
the class TestTrap method testtrapv1Generic.
@Ignore
@Test
public void testtrapv1Generic() throws InterruptedException, IOException {
BlockingQueue<Event> receiver = new ArrayBlockingQueue<>(2);
SnmpTrap r = new SnmpTrap(receiver, new Pipeline(Collections.emptyList(), "testbig", null));
r.setPort(0);
Map<String, Object> props = new HashMap<>();
props.put("mibdirs", new String[] { "/usr/share/snmp/mibs", "/tmp/mibs" });
Assert.assertTrue(r.configure(new Properties(props)));
r.start();
CommandResponderEvent trapEvent = new CommandResponderEvent(new MessageDispatcherImpl(), new DefaultUdpTransportMapping(), TransportIpAddress.parse("127.0.0.1/162"), 0, 0, null, 0, null, null, 0, null);
PDUv1 pdu = new PDUv1();
pdu.setEnterprise(new OID("1.3.6.1.4.1.232"));
pdu.setAgentAddress(new IpAddress());
pdu.setGenericTrap(1);
pdu.setTimestamp(10);
pdu.add(new VariableBinding(new OID("1.3.6.1.6.3.1.1.4.1"), new OctetString("lldpRemTablesChange")));
trapEvent.setPDU(pdu);
r.processPdu(trapEvent);
Event e = receiver.poll();
Assert.assertEquals(0.1, (Double) e.get("time_stamp"), 1e-10);
Assert.assertEquals("warmStart", e.get("generic_trap"));
Assert.assertEquals("compaq", e.get("enterprise"));
Assert.assertEquals(null, e.get("specific_trap"));
Assert.assertEquals("lldpRemTablesChange", e.get("snmpTrapOID"));
Assert.assertEquals(InetAddress.getByName("0.0.0.0"), e.get("agent_addr"));
r.interrupt();
}
use of loghub.Pipeline in project LogHub by fbacchella.
the class TestUdp method testsend.
private void testsend(int size) throws IOException, InterruptedException {
// Generate a locally binded random socket
DatagramSocket socket = new DatagramSocket(0, InetAddress.getLoopbackAddress());
String hostname = socket.getLocalAddress().getHostAddress();
int port = socket.getLocalPort();
socket.close();
InetSocketAddress destaddr = new InetSocketAddress(hostname, port);
BlockingQueue<Event> receiver = new ArrayBlockingQueue<>(10);
Udp r = new Udp(receiver, new Pipeline(Collections.emptyList(), "testone", null));
r.setBufferSize(size + 10);
r.setHost(hostname);
r.setPort(port);
r.setDecoder(new StringCodec());
Assert.assertTrue(r.configure(new Properties(Collections.emptyMap())));
r.start();
int originalMessageSize = 0;
try (DatagramSocket send = new DatagramSocket()) {
StringBuilder buffer = new StringBuilder();
while (buffer.length() <= size) {
buffer.append("message");
}
byte[] buf = buffer.toString().getBytes();
originalMessageSize = buffer.length();
DatagramPacket packet = new DatagramPacket(buf, buf.length, destaddr);
try {
logger.debug("Listening on {}", r.getListenAddress());
send.send(packet);
logger.debug("One message sent to {}", packet.getAddress());
} catch (IOException e1) {
logger.error("IO exception on port {}", r.getPort());
throw e1;
}
}
Event e = receiver.take();
r.interrupt();
Assert.assertTrue("Invalid message content", e.get("message").toString().startsWith("message"));
Assert.assertEquals("Invalid message size", originalMessageSize, e.get("message").toString().length());
Assert.assertTrue("didn't find valid hosts informations", e.get("host") instanceof InetAddress);
}
use of loghub.Pipeline in project LogHub by fbacchella.
the class TestTest method testSub.
@Test(timeout = 2000)
public void testSub() throws InterruptedException, ProcessorException, ConfigException, IOException {
Properties conf = Tools.loadConf("testclause.conf");
for (Pipeline pipe : conf.pipelines) {
Assert.assertTrue("configuration failed", pipe.configure(conf));
}
Event sent = Tools.getEvent();
sent.put("a", 2);
conf.mainQueue.add(sent);
EventsProcessor ep = new EventsProcessor(conf.mainQueue, conf.outputQueues, conf.namedPipeLine, conf.maxSteps, conf.repository);
sent.inject(conf.namedPipeLine.get("subpipe"), conf.mainQueue);
ep.start();
Event received = conf.outputQueues.get("subpipe").take();
Assert.assertEquals("conversion not expected", 2, received.get("d"));
ep.interrupt();
}
use of loghub.Pipeline in project LogHub by fbacchella.
the class TestTest method testOK.
@Test
public void testOK() throws InterruptedException, ProcessorException, ConfigException, IOException {
Properties conf = Tools.loadConf("testclause.conf");
for (Pipeline pipe : conf.pipelines) {
Assert.assertTrue("configuration failed", pipe.configure(conf));
}
Event sent = Tools.getEvent();
sent.put("a", 1);
Tools.runProcessing(sent, conf.namedPipeLine.get("main"), conf);
Assert.assertEquals("conversion not expected", 1, sent.get("b"));
}
use of loghub.Pipeline in project LogHub by fbacchella.
the class TestTest method testKO.
@Test
public void testKO() throws ProcessorException, InterruptedException, ConfigException, IOException {
Properties conf = Tools.loadConf("testclause.conf");
for (Pipeline pipe : conf.pipelines) {
Assert.assertTrue("configuration failed", pipe.configure(conf));
}
Event sent = Tools.getEvent();
sent.put("a", 2);
Tools.runProcessing(sent, conf.namedPipeLine.get("main"), conf);
Assert.assertEquals("conversion not expected", 2, sent.get("c"));
}
Aggregations