Example usage for io.netty.buffer UnpooledByteBufAllocator buffer

List of usage examples for io.netty.buffer UnpooledByteBufAllocator buffer

Introduction

In this page you can find the example usage for io.netty.buffer UnpooledByteBufAllocator buffer.

Prototype

@Override
    public ByteBuf buffer(int initialCapacity) 

Source Link

Usage

From source file:com.streamsets.pipeline.lib.parser.udp.netflow.TestNetflowParser.java

License:Apache License

@Test
public void testV5() throws Exception {
    UnpooledByteBufAllocator allocator = new UnpooledByteBufAllocator(false);
    NetflowParser netflowParser = makeNetflowParser();
    byte[] bytes = Resources.toByteArray(Resources.getResource(TEN_PACKETS));
    ByteBuf buf = allocator.buffer(bytes.length);
    buf.writeBytes(bytes);//from w  w w .j a va2 s .c o  m
    List<Record> records = netflowParser.parse(buf, null, null);
    NetflowTestUtil.assertRecordsForTenPackets(records);
}

From source file:com.streamsets.pipeline.lib.parser.udp.syslog.TestSyslogParser.java

License:Apache License

@Test
public void testParseFailure() throws Exception {
    SyslogParser parser = new SyslogParser(getContext(), StandardCharsets.UTF_8);
    String msg = "<123>                    ";
    byte[] bytes = msg.getBytes(StandardCharsets.UTF_8);
    UnpooledByteBufAllocator allocator = new UnpooledByteBufAllocator(false);
    ByteBuf buffer = allocator.buffer(bytes.length);
    buffer.writeBytes(bytes);/*www  . j  a  v  a 2 s .  c  o  m*/
    try {
        parser.parse(buffer, InetSocketAddress.createUnresolved("localhost", 5000),
                InetSocketAddress.createUnresolved("localhost", 50000));
        Assert.fail("Expected OnRecordErrorException");
    } catch (OnRecordErrorException ex) {
        Record record = ex.getRecord();
        Assert.assertEquals(msg, record.get().getValueAsString());
    }
}

From source file:com.streamsets.pipeline.lib.parser.udp.syslog.TestSyslogParser.java

License:Apache License

@Test
public void testMessageParsing() throws Exception {
    SyslogParser parser = new SyslogParser(getContext(), StandardCharsets.UTF_8);
    List<String> messages = getTestMessageStrings();

    UnpooledByteBufAllocator allocator = new UnpooledByteBufAllocator(false);
    // test with default keepFields = false
    for (String msg : messages) {
        byte[] bytes = msg.getBytes(StandardCharsets.UTF_8);
        ByteBuf buffer = allocator.buffer(bytes.length);
        buffer.writeBytes(bytes);//from  w  w w.  j  a v  a  2s  . c  om
        List<Record> records = parser.parse(buffer, InetSocketAddress.createUnresolved("localhost", 5000),
                InetSocketAddress.createUnresolved("localhost", 50000));
        Assert.assertEquals(1, records.size());
        Assert.assertEquals("Failure to parse known-good syslog message", msg,
                records.get(0).get("/raw").getValueAsString());
        Assert.assertEquals("Failure to parse known-good syslog message", "localhost:5000",
                records.get(0).get("/receiverAddr").getValueAsString());
        Assert.assertEquals("Failure to parse known-good syslog message", "localhost:50000",
                records.get(0).get("/senderAddr").getValueAsString());
        Assert.assertNotNull("Failure to parse known-good syslog message",
                records.get(0).get("/host").getValueAsString());
    }
}

From source file:com.streamsets.pipeline.lib.parser.udp.syslog.TestSyslogParser.java

License:Apache License

@Test
public void testMessageParsingIPv6() throws Exception {
    SyslogParser parser = new SyslogParser(getContext(), StandardCharsets.UTF_8);
    List<String> messages = getTestMessageStrings();

    UnpooledByteBufAllocator allocator = new UnpooledByteBufAllocator(false);
    // test with default keepFields = false
    for (String msg : messages) {
        byte[] bytes = msg.getBytes(StandardCharsets.UTF_8);
        ByteBuf buffer = allocator.buffer(bytes.length);
        buffer.writeBytes(bytes);/*ww  w . ja va2s  . com*/
        List<Record> records = parser.parse(buffer, InetSocketAddress.createUnresolved("::1", 5000),
                InetSocketAddress.createUnresolved("2001:db8::ff00:42:8329", 50000));
        Assert.assertEquals(1, records.size());
        Assert.assertEquals("Failure to parse known-good syslog message", msg,
                records.get(0).get("/raw").getValueAsString());
        Assert.assertEquals("Failure to parse known-good syslog message", "[::1]:5000",
                records.get(0).get("/receiverAddr").getValueAsString());
        Assert.assertEquals("Failure to parse known-good syslog message", "[2001:db8::ff00:42:8329]:50000",
                records.get(0).get("/senderAddr").getValueAsString());
        Assert.assertNotNull("Failure to parse known-good syslog message",
                records.get(0).get("/host").getValueAsString());
    }
}