Java Code Examples for org.apache.nifi.util.file.FileUtils#computeMd5Digest()
The following examples show how to use
org.apache.nifi.util.file.FileUtils#computeMd5Digest() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExecuteFlumeSinkTest.java From localization_nifi with Apache License 2.0 | 5 votes |
@Test @Ignore("Does not work on Windows") public void testHdfsSink() throws IOException { File destDir = temp.newFolder("hdfs"); TestRunner runner = TestRunners.newTestRunner(ExecuteFlumeSink.class); runner.setProperty(ExecuteFlumeSink.SINK_TYPE, "hdfs"); runner.setProperty(ExecuteFlumeSink.FLUME_CONFIG, "tier1.sinks.sink-1.hdfs.path = " + destDir.toURI().toString() + "\n" + "tier1.sinks.sink-1.hdfs.fileType = DataStream\n" + "tier1.sinks.sink-1.hdfs.serializer = TEXT\n" + "tier1.sinks.sink-1.serializer.appendNewline = false" ); try (InputStream inputStream = getClass().getResourceAsStream("/testdata/records.txt")) { Map<String, String> attributes = new HashMap<>(); attributes.put(CoreAttributes.FILENAME.key(), "records.txt"); runner.enqueue(inputStream, attributes); runner.run(); } File[] files = destDir.listFiles((FilenameFilter)HiddenFileFilter.VISIBLE); assertEquals("Unexpected number of destination files.", 1, files.length); File dst = files[0]; byte[] expectedMd5; try (InputStream md5Stream = getClass().getResourceAsStream("/testdata/records.txt")) { expectedMd5 = FileUtils.computeMd5Digest(md5Stream); } byte[] actualMd5 = FileUtils.computeMd5Digest(dst); Assert.assertArrayEquals("Destination file doesn't match source data", expectedMd5, actualMd5); }
Example 2
Source File: ExecuteFlumeSinkTest.java From nifi with Apache License 2.0 | 5 votes |
@Test @Ignore("Does not work on Windows") public void testHdfsSink() throws IOException { File destDir = temp.newFolder("hdfs"); TestRunner runner = TestRunners.newTestRunner(ExecuteFlumeSink.class); runner.setProperty(ExecuteFlumeSink.SINK_TYPE, "hdfs"); runner.setProperty(ExecuteFlumeSink.FLUME_CONFIG, "tier1.sinks.sink-1.hdfs.path = " + destDir.toURI().toString() + "\n" + "tier1.sinks.sink-1.hdfs.fileType = DataStream\n" + "tier1.sinks.sink-1.hdfs.serializer = TEXT\n" + "tier1.sinks.sink-1.serializer.appendNewline = false" ); try (InputStream inputStream = getClass().getResourceAsStream("/testdata/records.txt")) { Map<String, String> attributes = new HashMap<>(); attributes.put(CoreAttributes.FILENAME.key(), "records.txt"); runner.enqueue(inputStream, attributes); runner.run(); } File[] files = destDir.listFiles((FilenameFilter)HiddenFileFilter.VISIBLE); assertEquals("Unexpected number of destination files.", 1, files.length); File dst = files[0]; byte[] expectedMd5; try (InputStream md5Stream = getClass().getResourceAsStream("/testdata/records.txt")) { expectedMd5 = FileUtils.computeMd5Digest(md5Stream); } byte[] actualMd5 = FileUtils.computeMd5Digest(dst); Assert.assertArrayEquals("Destination file doesn't match source data", expectedMd5, actualMd5); }