List of usage examples for io.netty.buffer UnpooledByteBufAllocator buffer
@Override public ByteBuf buffer(int initialCapacity)
From source file:com.streamsets.pipeline.lib.parser.syslog.TestSyslogParser.java
License:Apache License
@Test public void testMessageParsing() throws Exception { SyslogParser parser = new SyslogParser(getContext(), StandardCharsets.UTF_8); Charset charset = Charsets.UTF_8; List<String> messages = Lists.newArrayList(); // supported examples from RFC 3164 messages.add("<34>Oct 11 22:14:15 mymachine su: 'su root' failed for " + "lonvick on /dev/pts/8"); messages.add("<13>Feb 5 17:32:18 10.0.0.99 Use the BFG!"); messages.add("<165>Aug 24 05:34:00 CST 1987 mymachine myproc[10]: %% " + "It's time to make the do-nuts. %% Ingredients: Mix=OK, Jelly=OK # " + "Devices: Mixer=OK, Jelly_Injector=OK, Frier=OK # Transport: " + "Conveyer1=OK, Conveyer2=OK # %%"); messages.add("<0>Oct 22 10:52:12 scapegoat 1990 Oct 22 10:52:01 TZ-6 " + "scapegoat.dmz.example.org 10.1.2.3 sched[0]: That's All Folks!"); // supported examples from RFC 5424 messages.add("<34>1 2003-10-11T22:14:15.003Z mymachine.example.com su - " + "ID47 - BOM'su root' failed for lonvick on /dev/pts/8"); messages.add("<165>1 2003-08-24T05:14:15.000003-07:00 192.0.2.1 myproc " + "8710 - - %% It's time to make the do-nuts."); // non-standard (but common) messages (RFC3339 dates, no version digit) messages.add("<13>2003-08-24T05:14:15Z localhost snarf?"); messages.add("<13>2012-08-16T14:34:03-08:00 127.0.0.1 test shnap!"); 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 va 2 s.co m*/ 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.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 ww . j av a2 s. c o m List<Record> records = parser.parse(buf, null, null); Assert.assertEquals(23, records.size()); // 23 Value parts Record record0 = records.get(0); UDPTestUtil.verifyCollectdRecord(UDPTestUtil.expectedRecord0, record0); Record record2 = records.get(2); UDPTestUtil.verifyCollectdRecord(UDPTestUtil.expectedRecord2, record2); }
From source file:com.streamsets.pipeline.lib.parser.udp.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 a v a 2s.c o m List<Record> records = parser.parse(buf, null, null); Assert.assertEquals(23, records.size()); // 23 Value parts Record record0 = records.get(0); UDPTestUtil.verifyCollectdRecord(UDPTestUtil.expectedRecordNoInterval0, record0); Record record2 = records.get(2); UDPTestUtil.verifyCollectdRecord(UDPTestUtil.expectedRecordNoInterval2, record2); }
From source file:com.streamsets.pipeline.lib.parser.udp.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);/*from w ww.ja v a2s. c o m*/ List<Record> records = parser.parse(buf, null, null); Assert.assertEquals(24, records.size()); // 24 value parts Record record14 = records.get(14); UDPTestUtil.verifyCollectdRecord(UDPTestUtil.encryptedRecord14, record14); LOG.info("Num records: {}", records.size()); }
From source file:com.streamsets.pipeline.lib.parser.udp.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 ww w . j a va 2s . c om*/ List<Record> records = parser.parse(buf, null, null); Assert.assertEquals(22, records.size()); // 22 value parts Record record15 = records.get(15); UDPTestUtil.verifyCollectdRecord(UDPTestUtil.signedRecord15, record15); LOG.info("Num records: {}", records.size()); }
From source file:com.streamsets.pipeline.lib.parser.udp.netflow.TestNetflowParser.java
License:Apache License
@Test(expected = OnRecordErrorException.class) public void testInvalidVersion() throws Exception { UnpooledByteBufAllocator allocator = new UnpooledByteBufAllocator(false); NetflowParser netflowParser = makeNetflowParser(); ByteBuf buf = allocator.buffer(4); buf.writeShort(0);/*from w w w . java2 s .c om*/ buf.writeShort(0); netflowParser.parse(buf, null, null); }
From source file:com.streamsets.pipeline.lib.parser.udp.netflow.TestNetflowParser.java
License:Apache License
@Test(expected = OnRecordErrorException.class) public void testInvalidCountInvalidLength() throws Exception { UnpooledByteBufAllocator allocator = new UnpooledByteBufAllocator(false); NetflowParser netflowParser = makeNetflowParser(); ByteBuf buf = allocator.buffer(4); buf.writeShort(5);//w w w.ja v a 2s . com buf.writeShort(1); netflowParser.parse(buf, null, null); }
From source file:com.streamsets.pipeline.lib.parser.udp.netflow.TestNetflowParser.java
License:Apache License
@Test(expected = OnRecordErrorException.class) public void testInvalidCountZero() throws Exception { UnpooledByteBufAllocator allocator = new UnpooledByteBufAllocator(false); NetflowParser netflowParser = makeNetflowParser(); ByteBuf buf = allocator.buffer(4); buf.writeShort(5);//from w ww . j a va 2s.c o m buf.writeShort(0); netflowParser.parse(buf, null, null); }
From source file:com.streamsets.pipeline.lib.parser.udp.netflow.TestNetflowParser.java
License:Apache License
@Test(expected = OnRecordErrorException.class) public void testInvalidPacketTooShort1() throws Exception { UnpooledByteBufAllocator allocator = new UnpooledByteBufAllocator(false); NetflowParser netflowParser = makeNetflowParser(); ByteBuf buf = allocator.buffer(0); netflowParser.parse(buf, null, null); }
From source file:com.streamsets.pipeline.lib.parser.udp.netflow.TestNetflowParser.java
License:Apache License
@Test(expected = OnRecordErrorException.class) public void testInvalidPacketTooShort2() throws Exception { UnpooledByteBufAllocator allocator = new UnpooledByteBufAllocator(false); NetflowParser netflowParser = makeNetflowParser(); ByteBuf buf = allocator.buffer(2); buf.writeShort(5);// w w w .j a v a 2 s . c o m netflowParser.parse(buf, null, null); }