List of usage examples for io.netty.buffer ByteBuf writeBytes
public abstract ByteBuf writeBytes(ByteBuffer src);
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); List<Record> records = parser.parse(buf, null, null); Assert.assertEquals(22, records.size()); // 22 value parts Record record15 = records.get(15);//from w w w . j a v a 2 s .c o m verifyRecord(signedRecord15, record15); LOG.info("Num records: {}", records.size()); }
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); 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); }
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); 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()); }/* w w w . ja v a 2s .c o m*/ }
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); List<Record> records = parser.parse(buf, null, null); Assert.assertEquals(23, records.size()); // 23 Value parts Record record0 = records.get(0);/* ww w . j a v a2 s . c o m*/ 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); List<Record> records = parser.parse(buf, null, null); Assert.assertEquals(23, records.size()); // 23 Value parts Record record0 = records.get(0);/*from w ww . j ava 2s.com*/ 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); List<Record> records = parser.parse(buf, null, null); Assert.assertEquals(24, records.size()); // 24 value parts Record record14 = records.get(14);/*from w ww . j a v a2s . c om*/ 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); List<Record> records = parser.parse(buf, null, null); Assert.assertEquals(22, records.size()); // 22 value parts Record record15 = records.get(15);//from www. ja v a2s. com 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 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); 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); try {//from ww w. j a v a2s .com 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); 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 w ww. j a v a 2s .c o m }