use of loghub.Event 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.Event in project LogHub by fbacchella.
the class TestElasticSearch method testSendInQueue.
@Test
public void testSendInQueue() throws InterruptedException {
Stats.reset();
int count = 20;
ArrayBlockingQueue<Event> queue = new ArrayBlockingQueue<>(count - 1);
ElasticSearch es = new ElasticSearch(queue);
es.setDestinations(new String[] { "http://localhost:" + serverPort });
es.setTimeout(1);
es.setBuffersize(10);
Assert.assertTrue("Elastic configuration failed", es.configure(new Properties(Collections.emptyMap())));
es.start();
for (int i = 0; i < count; i++) {
Event ev = Tools.getEvent();
ev.put("type", "junit");
ev.put("value", "atest" + i);
ev.setTimestamp(new Date(0));
queue.add(ev);
Thread.sleep(1);
}
es.close();
Thread.sleep(1000);
if (failure != null) {
throw failure;
}
Assert.assertEquals(count, received.get());
Assert.assertEquals(count, Stats.sent.intValue());
Assert.assertEquals(0, Stats.failed.intValue());
Assert.assertEquals(0, Properties.metrics.counter("Allevents.inflight").getCount());
logger.debug("event received: {}", received);
}
use of loghub.Event in project LogHub by fbacchella.
the class TestElasticSearch method testSend.
@Test
public void testSend() throws InterruptedException {
int count = 20;
ElasticSearch es = new ElasticSearch(new ArrayBlockingQueue<>(count));
es.setDestinations(new String[] { "http://localhost:" + serverPort });
es.setTimeout(1);
es.setBuffersize(10);
Assert.assertTrue("Elastic configuration failed", es.configure(new Properties(Collections.emptyMap())));
es.start();
for (int i = 0; i < count; i++) {
Event ev = Tools.getEvent();
ev.put("type", "junit");
ev.put("value", "atest" + i);
ev.setTimestamp(new Date(0));
Assert.assertTrue(es.send(ev));
Thread.sleep(1);
}
es.close();
Thread.sleep(1000);
if (failure != null) {
throw failure;
}
Assert.assertEquals(count, received.get());
logger.debug("event received: {}", received);
}
use of loghub.Event 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.Event 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"));
}
Aggregations