Example usage for io.netty.buffer UnpooledByteBufAllocator UnpooledByteBufAllocator

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

Introduction

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

Prototype

public UnpooledByteBufAllocator(boolean preferDirect) 

Source Link

Document

Create a new instance which uses leak-detection for direct buffers.

Usage

From source file:com.streamsets.pipeline.lib.parser.collectd.TestCollectdParser.java

License:Apache License

@Test
public void testParser() throws Exception {
    UnpooledByteBufAllocator allocator = new UnpooledByteBufAllocator(false);
    CollectdParser parser = new CollectdParser(getContext(), false, null, false, null, CHARSET);
    byte[] bytes = Files.readAllBytes(SINGLE_PACKET.toPath());
    ByteBuf buf = allocator.buffer(bytes.length);
    buf.writeBytes(bytes);//from  w w w .ja  va2 s.co  m
    List<Record> records = parser.parse(buf, null, null);

    Assert.assertEquals(23, records.size()); // 23 Value parts

    Record record0 = records.get(0);
    verifyRecord(expectedRecord0, record0);

    Record record2 = records.get(2);
    verifyRecord(expectedRecord2, record2);

}

From source file:com.streamsets.pipeline.lib.parser.collectd.TestCollectdParser.java

License:Apache License

@Test
public void testParserExcludeInterval() throws Exception {
    UnpooledByteBufAllocator allocator = new UnpooledByteBufAllocator(false);
    CollectdParser parser = new CollectdParser(getContext(), false, null, true, null, CHARSET);
    byte[] bytes = Files.readAllBytes(SINGLE_PACKET.toPath());
    ByteBuf buf = allocator.buffer(bytes.length);
    buf.writeBytes(bytes);/*from  w w  w .j av a2s.co  m*/
    List<Record> records = parser.parse(buf, null, null);

    Assert.assertEquals(23, records.size()); // 23 Value parts

    Record record0 = records.get(0);
    verifyRecord(expectedRecordNoInterval0, record0);

    Record record2 = records.get(2);
    verifyRecord(expectedRecordNoInterval2, record2);

}

From source file:com.streamsets.pipeline.lib.parser.collectd.TestCollectdParser.java

License:Apache License

@Test
public void testEncryptedRecord() throws Exception {
    // If unlimited strength encryption is not available, we cant run this test.
    Assume.assumeFalse(Cipher.getMaxAllowedKeyLength("AES") < 256);

    UnpooledByteBufAllocator allocator = new UnpooledByteBufAllocator(false);
    CollectdParser parser = new CollectdParser(getContext(), false, null, false, AUTH_FILE_PATH, CHARSET);
    byte[] bytes = Files.readAllBytes(SINGLE_ENCRYPTED_PACKET.toPath());
    ByteBuf buf = allocator.buffer(bytes.length);
    buf.writeBytes(bytes);/*ww w .  j a v  a2 s  .co m*/
    List<Record> records = parser.parse(buf, null, null);

    Assert.assertEquals(24, records.size()); // 24 value parts
    Record record14 = records.get(14);
    verifyRecord(encryptedRecord14, record14);
    LOG.info("Num records: {}", records.size());
}

From source file:com.streamsets.pipeline.lib.parser.collectd.TestCollectdParser.java

License:Apache License

@Test
public void testSignedRecord() throws Exception {
    UnpooledByteBufAllocator allocator = new UnpooledByteBufAllocator(false);
    CollectdParser parser = new CollectdParser(getContext(), false, null, false, AUTH_FILE_PATH, CHARSET);
    byte[] bytes = Files.readAllBytes(SINGLE_SIGNED_PACKET.toPath());
    ByteBuf buf = allocator.buffer(bytes.length);
    buf.writeBytes(bytes);/*from  w ww. j av  a 2 s . c o  m*/
    List<Record> records = parser.parse(buf, null, null);

    Assert.assertEquals(22, records.size()); // 22 value parts
    Record record15 = records.get(15);
    verifyRecord(signedRecord15, record15);
    LOG.info("Num records: {}", records.size());
}

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

License:Apache License

@Test(expected = OnRecordErrorException.class)
public void testInvalidVersion() throws Exception {
    UnpooledByteBufAllocator allocator = new UnpooledByteBufAllocator(false);
    NetflowParser netflowParser = new NetflowParser(getContext());
    ByteBuf buf = allocator.buffer(4);// w w w .  ja  v a 2s. c  om
    buf.writeShort(0);
    buf.writeShort(0);
    netflowParser.parse(buf, null, null);
}

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

License:Apache License

@Test(expected = OnRecordErrorException.class)
public void testInvalidCountInvalidLength() throws Exception {
    UnpooledByteBufAllocator allocator = new UnpooledByteBufAllocator(false);
    NetflowParser netflowParser = new NetflowParser(getContext());
    ByteBuf buf = allocator.buffer(4);/*from w w w.j  a  v a2  s .  co m*/
    buf.writeShort(5);
    buf.writeShort(1);
    netflowParser.parse(buf, null, null);
}

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

License:Apache License

@Test(expected = OnRecordErrorException.class)
public void testInvalidCountZero() throws Exception {
    UnpooledByteBufAllocator allocator = new UnpooledByteBufAllocator(false);
    NetflowParser netflowParser = new NetflowParser(getContext());
    ByteBuf buf = allocator.buffer(4);/*  ww w. ja  v a 2 s .  c  o m*/
    buf.writeShort(5);
    buf.writeShort(0);
    netflowParser.parse(buf, null, null);
}

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

License:Apache License

@Test(expected = OnRecordErrorException.class)
public void testInvalidPacketTooShort1() throws Exception {
    UnpooledByteBufAllocator allocator = new UnpooledByteBufAllocator(false);
    NetflowParser netflowParser = new NetflowParser(getContext());
    ByteBuf buf = allocator.buffer(0);/*from   w  w w  .j  a  v  a2s. c  o  m*/
    netflowParser.parse(buf, null, null);
}

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

License:Apache License

@Test(expected = OnRecordErrorException.class)
public void testInvalidPacketTooShort2() throws Exception {
    UnpooledByteBufAllocator allocator = new UnpooledByteBufAllocator(false);
    NetflowParser netflowParser = new NetflowParser(getContext());
    ByteBuf buf = allocator.buffer(2);/*from   w  w  w .  ja  v  a  2 s .c o m*/
    buf.writeShort(5);
    netflowParser.parse(buf, null, null);
}

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

License:Apache License

@Test
public void testV5() throws Exception {
    UnpooledByteBufAllocator allocator = new UnpooledByteBufAllocator(false);
    NetflowParser netflowParser = new NetflowParser(getContext());
    byte[] bytes = Files.readAllBytes(TEN_PACKETS.toPath());
    ByteBuf buf = allocator.buffer(bytes.length);
    buf.writeBytes(bytes);/*  w w w. j a  v a 2 s .c o  m*/
    List<Record> records = netflowParser.parse(buf, null, null);
    //  seq:1 [227.213.154.241]:9231 <> [247.193.164.155]:53 proto:17 octets>:0 packets>:0 octets<:89 packets<:1 start:2013-08-14T22:56:40.140733193388244 finish:2013-08-14T22:56:40.140733193388244 tcp>:00 tcp<:00 flowlabel>:00000000 flowlabel<:00000000  (0x7fe073801a70)
    //  seq:2 [227.213.154.241]:64042 <> [247.193.164.155]:53 proto:17 octets>:0 packets>:0 octets<:89 packets<:1 start:2013-08-14T22:56:40.140733193388244 finish:2013-08-14T22:56:40.140733193388244 tcp>:00 tcp<:00 flowlabel>:00000000 flowlabel<:00000000  (0x7fe0738019e0)
    //  seq:3 [227.213.154.241]:18784 <> [247.193.164.155]:53 proto:17 octets>:0 packets>:0 octets<:89 packets<:1 start:2013-08-14T22:56:40.140733193388244 finish:2013-08-14T22:56:40.140733193388244 tcp>:00 tcp<:00 flowlabel>:00000000 flowlabel<:00000000  (0x7fe073801950)
    //  seq:4 [227.213.154.241]:43998 <> [249.229.186.21]:53 proto:17 octets>:0 packets>:0 octets<:89 packets<:1 start:2013-08-14T22:56:40.140733193388246 finish:2013-08-14T22:56:40.140733193388246 tcp>:00 tcp<:00 flowlabel>:00000000 flowlabel<:00000000  (0x7fe0738018c0)
    //  seq:5 [127.227.189.185]:53 <> [227.213.154.241]:8790 proto:17 octets>:89 packets>:1 octets<:0 packets<:0 start:2013-08-14T22:56:40.140733193388246 finish:2013-08-14T22:56:40.140733193388246 tcp>:00 tcp<:00 flowlabel>:00000000 flowlabel<:00000000  (0x7fe073801830)
    //  seq:6 [127.227.189.185]:53 <> [227.213.154.241]:38811 proto:17 octets>:89 packets>:1 octets<:0 packets<:0 start:2013-08-14T22:56:40.140733193388246 finish:2013-08-14T22:56:40.140733193388246 tcp>:00 tcp<:00 flowlabel>:00000000 flowlabel<:00000000  (0x7fe0738017a0)
    //  seq:7 [127.227.189.185]:53 <> [227.213.154.241]:48001 proto:17 octets>:89 packets>:1 octets<:0 packets<:0 start:2013-08-14T22:56:40.140733193388246 finish:2013-08-14T22:56:40.140733193388246 tcp>:00 tcp<:00 flowlabel>:00000000 flowlabel<:00000000  (0x7fe073801710)
    //  seq:8 [227.213.154.241]:57572 <> [249.229.186.21]:53 proto:17 octets>:0 packets>:0 octets<:89 packets<:1 start:2013-08-14T22:56:40.140733193388246 finish:2013-08-14T22:56:40.140733193388246 tcp>:00 tcp<:00 flowlabel>:00000000 flowlabel<:00000000  (0x7fe073801680)
    //  seq:9 [45.103.41.119]:53 <> [227.213.154.241]:54356 proto:17 octets>:696 packets>:1 octets<:0 packets<:0 start:2013-08-14T22:56:40.140733193388248 finish:2013-08-14T22:56:40.140733193388248 tcp>:00 tcp<:00 flowlabel>:00000000 flowlabel<:00000000  (0x7fe0738015f0)
    //  seq:10 [121.75.53.47]:53 <> [227.213.154.241]:5557 proto:17 octets>:504 packets>:1 octets<:0 packets<:0 start:2013-08-14T22:56:40.140733193388249 finish:2013-08-14T22:56:40.140733193388249 tcp>:00 tcp<:00 flowlabel>:00000000 flowlabel<:00000000  (0x7fe073801560)
    Assert.assertEquals(10, records.size());
    assertRecord(records.get(0), 5, "2b750f7c-7c25-1000-8080-808080808080", 53, 9231, "247.193.164.155",
            "227.213.154.241", 17, "2015-04-12T21:32:19.0577", "2015-04-12T21:32:19.0577", 504, 1, 0, 89);
    assertRecord(records.get(1), 5, "2b750f7c-7c25-1000-8080-808080808080", 53, 64042, "247.193.164.155",
            "227.213.154.241", 17, "2015-04-12T21:32:19.0577", "2015-04-12T21:32:19.0577", 504, 1, 0, 89);
    assertRecord(records.get(2), 5, "2b750f7c-7c25-1000-8080-808080808080", 53, 18784, "247.193.164.155",
            "227.213.154.241", 17, "2015-04-12T21:32:19.0577", "2015-04-12T21:32:19.0577", 504, 1, 0, 89);
    assertRecord(records.get(3), 5, "2b750f7c-7c25-1000-8080-808080808080", 53, 43998, "249.229.186.21",
            "227.213.154.241", 17, "2015-04-12T21:32:19.0575", "2015-04-12T21:32:19.0575", 504, 1, 0, 89);
    assertRecord(records.get(4), 5, "2b750f7c-7c25-1000-8080-808080808080", 53, 8790, "127.227.189.185",
            "227.213.154.241", 17, "2015-04-12T21:32:19.0575", "2015-04-12T21:32:19.0575", 504, 1, 0, 89);
    assertRecord(records.get(5), 5, "2b750f7c-7c25-1000-8080-808080808080", 53, 38811, "127.227.189.185",
            "227.213.154.241", 17, "2015-04-12T21:32:19.0575", "2015-04-12T21:32:19.0575", 504, 1, 0, 89);
    assertRecord(records.get(6), 5, "2b750f7c-7c25-1000-8080-808080808080", 53, 48001, "127.227.189.185",
            "227.213.154.241", 17, "2015-04-12T21:32:19.0575", "2015-04-12T21:32:19.0575", 504, 1, 0, 89);
    assertRecord(records.get(7), 5, "2b750f7c-7c25-1000-8080-808080808080", 53, 57572, "249.229.186.21",
            "227.213.154.241", 17, "2015-04-12T21:32:19.0575", "2015-04-12T21:32:19.0575", 504, 1, 0, 89);
    assertRecord(records.get(8), 5, "2b750f7c-7c25-1000-8080-808080808080", 53, 54356, "45.103.41.119",
            "227.213.154.241", 17, "2015-04-12T21:32:19.0573", "2015-04-12T21:32:19.0573", 504, 1, 0, 696);
    assertRecord(records.get(9), 5, "2b750f7c-7c25-1000-8080-808080808080", 53, 5557, "121.75.53.47",
            "227.213.154.241", 17, "2015-04-12T21:32:19.0572", "2015-04-12T21:32:19.0572", 504, 1, 0, 504);
}