use of loghub.Decoder in project LogHub by fbacchella.
the class TestMsgpack method testmapsimple.
@Test
public void testmapsimple() throws IOException, DecodeException {
Decoder d = new Msgpack();
Map<Value, Value> destination = new HashMap<>();
destination.put(ValueFactory.newString("a"), ValueFactory.newString("0"));
destination.put(ValueFactory.newString("b"), ValueFactory.newInteger(1));
destination.put(ValueFactory.newString("c"), ValueFactory.newBoolean(false));
Value[] subdestination = new Value[4];
subdestination[0] = ValueFactory.newString("0");
subdestination[1] = ValueFactory.newInteger(1);
subdestination[2] = ValueFactory.newFloat(2.0);
subdestination[3] = ValueFactory.newNil();
destination.put(ValueFactory.newString("d"), ValueFactory.newArray(subdestination));
Value v = ValueFactory.newMap(destination);
ByteArrayOutputStream out = new ByteArrayOutputStream();
MessagePacker packer = MessagePack.newDefaultPacker(out);
packer.packValue(v);
packer.close();
byte[] packed = out.toByteArray();
Map<String, Object> e = d.decode(ConnectionContext.EMPTY, packed);
testContent(e);
}
use of loghub.Decoder in project LogHub by fbacchella.
the class PacketsTest method testDecode.
@SuppressWarnings("unchecked")
@Test
public void testDecode() {
Decoder nfd = new NetflowDecoder();
IpConnectionContext dummyctx = new IpConnectionContext(new InetSocketAddress(0), new InetSocketAddress(0), null);
Arrays.stream(captures).map(i -> {
logger.debug(i + ": ");
return i;
}).map(i -> "/netflow/packets/" + i).map(i -> getClass().getResourceAsStream(i)).filter(i -> i != null).map(i -> {
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buffer = new byte[8 * 1024];
for (int length; (length = i.read(buffer)) != -1; ) {
out.write(buffer, 0, length);
}
return out;
} catch (Exception e) {
Assert.fail(e.getMessage());
return null;
}
}).filter(i -> i != null).map(i -> Unpooled.wrappedBuffer(i.toByteArray())).forEach(i -> {
try {
while (i.isReadable()) {
Map<String, Object> content = nfd.decode(dummyctx, i);
Assert.assertTrue(content.containsKey("version"));
Assert.assertTrue(content.containsKey("sequenceNumber"));
Assert.assertTrue(content.containsKey("records"));
((List<Map<String, Object>>) content.get("records")).forEach(j -> Assert.assertTrue(j.containsKey("_type")));
if (((Integer) content.get("version")) < 10) {
Assert.assertTrue(content.containsKey("SysUptime"));
}
logger.debug(content);
}
} catch (Exception e) {
Assert.fail(e.getMessage());
}
});
}
use of loghub.Decoder in project LogHub by fbacchella.
the class ProcessorTest method test.
@Test
public void test() throws IOException, DecodeException, ProcessorException, InterruptedException {
Processor p = new Processor();
InputStream is = getClass().getResourceAsStream("/netflow/packets/ipfix.dat");
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buffer = new byte[8 * 1024];
for (int length; (length = is.read(buffer)) != -1; ) {
out.write(buffer, 0, length);
}
ByteBuf bbuffer = Unpooled.wrappedBuffer(out.toByteArray());
Decoder nfd = new NetflowDecoder();
IpConnectionContext dummyctx = new IpConnectionContext(new InetSocketAddress(0), new InetSocketAddress(0), null);
Map<String, Object> content = nfd.decode(dummyctx, bbuffer);
Event e = Tools.getEvent();
e.setTimestamp((Date) content.remove(Event.TIMESTAMPKEY));
e.putAll(content);
ProcessingStatus ps = Tools.runProcessing(e, "main", Collections.singletonList(p));
logger.debug(ps.mainQueue.remove());
logger.debug(ps.mainQueue.remove());
logger.debug(ps.mainQueue.remove());
logger.debug(ps.mainQueue.remove());
logger.debug(ps.mainQueue.remove());
logger.debug(ps.mainQueue.remove());
logger.debug(ps.mainQueue.remove());
logger.debug(ps.mainQueue.remove());
Assert.assertTrue(ps.mainQueue.isEmpty());
}
use of loghub.Decoder in project LogHub by fbacchella.
the class TestMsgpack method testmap.
@Test
public void testmap() throws IOException, DecodeException {
Decoder d = new Msgpack();
Map<String, Object> e = d.decode(ConnectionContext.EMPTY, objectMapper.writeValueAsBytes(obj));
testContent(e);
}
Aggregations