Java Code Examples for org.apache.nifi.util.TestRunner#assertPenalizeCount()
The following examples show how to use
org.apache.nifi.util.TestRunner#assertPenalizeCount() .
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: DeleteGCSObjectTest.java From localization_nifi with Apache License 2.0 | 6 votes |
@Test public void testFailureOnException() throws Exception { reset(storage); final TestRunner runner = buildNewRunner(getProcessor()); addRequiredPropertiesToRunner(runner); runner.assertValid(); runner.enqueue("testdata"); when(storage.delete(any(BlobId.class))).thenThrow(new StorageException(1, "Test Exception")); runner.run(); runner.assertPenalizeCount(1); runner.assertAllFlowFilesTransferred(DeleteGCSObject.REL_FAILURE); runner.assertTransferCount(DeleteGCSObject.REL_FAILURE, 1); }
Example 2
Source File: TestInvokeGRPC.java From nifi with Apache License 2.0 | 6 votes |
@Test public void testNoInput() throws Exception { final TestGRPCServer<DummyFlowFileService> server = new TestGRPCServer<>(DummyFlowFileService.class); try { final int port = server.start(0); final TestRunner runner = TestRunners.newTestRunner(InvokeGRPC.class); runner.setProperty(InvokeGRPC.PROP_SERVICE_HOST, TestGRPCServer.HOST); runner.setProperty(InvokeGRPC.PROP_SERVICE_PORT, String.valueOf(port)); runner.run(); runner.assertTransferCount(InvokeGRPC.REL_RESPONSE, 0); runner.assertTransferCount(InvokeGRPC.REL_SUCCESS_REQ, 0); runner.assertTransferCount(InvokeGRPC.REL_RETRY, 0); runner.assertTransferCount(InvokeGRPC.REL_NO_RETRY, 0); runner.assertTransferCount(InvokeGRPC.REL_FAILURE, 0); runner.assertPenalizeCount(0); } finally { server.stop(); } }
Example 3
Source File: TestPutFile.java From nifi with Apache License 2.0 | 6 votes |
@Test public void testFailConflictResolution() throws IOException { final TestRunner runner = TestRunners.newTestRunner(new PutFile()); runner.setProperty(PutFile.DIRECTORY, targetDir.getAbsolutePath()); runner.setProperty(PutFile.CONFLICT_RESOLUTION, PutFile.FAIL_RESOLUTION); Map<String,String> attributes = new HashMap<>(); attributes.put(CoreAttributes.FILENAME.key(), "targetFile.txt"); runner.enqueue("Hello world!!".getBytes(), attributes); runner.run(); runner.assertAllFlowFilesTransferred(FetchFile.REL_SUCCESS, 1); Path targetPath = Paths.get(TARGET_DIRECTORY+"/targetFile.txt"); byte[] content = Files.readAllBytes(targetPath); assertEquals("Hello world!!", new String(content)); //Second file attributes.put(CoreAttributes.FILENAME.key(), "targetFile.txt"); runner.enqueue("Another file".getBytes(), attributes); runner.run(); runner.assertTransferCount(PutFile.REL_SUCCESS, 1); runner.assertTransferCount(PutFile.REL_FAILURE, 1); runner.assertPenalizeCount(1); }
Example 4
Source File: TestPutFile.java From nifi with Apache License 2.0 | 6 votes |
@Test public void testMaxFileLimitReach() throws IOException { final TestRunner runner = TestRunners.newTestRunner(new PutFile()); runner.setProperty(PutFile.DIRECTORY, targetDir.getAbsolutePath()); runner.setProperty(PutFile.CONFLICT_RESOLUTION, PutFile.REPLACE_RESOLUTION); runner.setProperty(PutFile.MAX_DESTINATION_FILES, "1"); Map<String,String> attributes = new HashMap<>(); attributes.put(CoreAttributes.FILENAME.key(), "targetFile.txt"); runner.enqueue("Hello world!!".getBytes(), attributes); runner.run(); runner.assertAllFlowFilesTransferred(FetchFile.REL_SUCCESS, 1); Path targetPath = Paths.get(TARGET_DIRECTORY+"/targetFile.txt"); byte[] content = Files.readAllBytes(targetPath); assertEquals("Hello world!!", new String(content)); //Second file attributes.put(CoreAttributes.FILENAME.key(), "secondFile.txt"); runner.enqueue("Hello world!!".getBytes(), attributes); runner.run(); runner.assertTransferCount(PutFile.REL_FAILURE, 1); runner.assertPenalizeCount(1); }
Example 5
Source File: DeleteGCSObjectTest.java From nifi with Apache License 2.0 | 6 votes |
@Test public void testFailureOnException() throws Exception { reset(storage); final TestRunner runner = buildNewRunner(getProcessor()); addRequiredPropertiesToRunner(runner); runner.assertValid(); runner.enqueue("testdata"); when(storage.delete(any(BlobId.class))).thenThrow(new StorageException(1, "Test Exception")); runner.run(); runner.assertPenalizeCount(1); runner.assertAllFlowFilesTransferred(DeleteGCSObject.REL_FAILURE); runner.assertTransferCount(DeleteGCSObject.REL_FAILURE, 1); }
Example 6
Source File: TestDeleteHDFS.java From localization_nifi with Apache License 2.0 | 5 votes |
@Test public void testIOException() throws Exception { Path filePath = new Path("/some/path/to/file.txt"); when(mockFileSystem.exists(any(Path.class))).thenThrow(new IOException()); DeleteHDFS deleteHDFS = new TestableDeleteHDFS(kerberosProperties, mockFileSystem); TestRunner runner = TestRunners.newTestRunner(deleteHDFS); runner.setProperty(DeleteHDFS.FILE_OR_DIRECTORY, "${hdfs.file}"); Map<String, String> attributes = Maps.newHashMap(); attributes.put("hdfs.file", filePath.toString()); runner.enqueue("foo", attributes); runner.run(); runner.assertQueueNotEmpty(); runner.assertPenalizeCount(1); assertEquals(1, runner.getQueueSize().getObjectCount()); }
Example 7
Source File: TestInvokeGRPC.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testRetry() throws Exception { final TestGRPCServer<DummyFlowFileService> server = new TestGRPCServer<>(DummyFlowFileService.class); try { final int port = server.start(0); final TestRunner runner = TestRunners.newTestRunner(InvokeGRPC.class); runner.setProperty(InvokeGRPC.PROP_SERVICE_HOST, TestGRPCServer.HOST); runner.setProperty(InvokeGRPC.PROP_SERVICE_PORT, String.valueOf(port)); final MockFlowFile mockFlowFile = new MockFlowFile(RETRY); runner.enqueue(mockFlowFile); runner.run(); runner.assertTransferCount(InvokeGRPC.REL_RESPONSE, 0); runner.assertTransferCount(InvokeGRPC.REL_SUCCESS_REQ, 0); runner.assertTransferCount(InvokeGRPC.REL_RETRY, 1); runner.assertTransferCount(InvokeGRPC.REL_NO_RETRY, 0); runner.assertTransferCount(InvokeGRPC.REL_FAILURE, 0); runner.assertPenalizeCount(1); final List<MockFlowFile> responseFiles = runner.getFlowFilesForRelationship(InvokeGRPC.REL_RETRY); assertThat(responseFiles.size(), equalTo(1)); final MockFlowFile response = responseFiles.get(0); response.assertAttributeEquals(InvokeGRPC.RESPONSE_CODE, String.valueOf(FlowFileReply.ResponseCode.RETRY)); response.assertAttributeEquals(InvokeGRPC.RESPONSE_BODY, "retry"); response.assertAttributeEquals(InvokeGRPC.SERVICE_HOST, TestGRPCServer.HOST); response.assertAttributeEquals(InvokeGRPC.SERVICE_PORT, String.valueOf(port)); } finally { server.stop(); } }
Example 8
Source File: TestInvokeGRPC.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testRetryAlwaysOutputResponse() throws Exception { final TestGRPCServer<DummyFlowFileService> server = new TestGRPCServer<>(DummyFlowFileService.class); try { final int port = server.start(0); final TestRunner runner = TestRunners.newTestRunner(InvokeGRPC.class); runner.setProperty(InvokeGRPC.PROP_SERVICE_HOST, TestGRPCServer.HOST); runner.setProperty(InvokeGRPC.PROP_SERVICE_PORT, String.valueOf(port)); runner.setProperty(InvokeGRPC.PROP_OUTPUT_RESPONSE_REGARDLESS, "true"); final MockFlowFile mockFlowFile = new MockFlowFile(RETRY); runner.enqueue(mockFlowFile); runner.run(); runner.assertTransferCount(InvokeGRPC.REL_RESPONSE, 1); runner.assertTransferCount(InvokeGRPC.REL_SUCCESS_REQ, 0); runner.assertTransferCount(InvokeGRPC.REL_RETRY, 1); runner.assertTransferCount(InvokeGRPC.REL_NO_RETRY, 0); runner.assertTransferCount(InvokeGRPC.REL_FAILURE, 0); runner.assertPenalizeCount(1); final List<MockFlowFile> retryFiles = runner.getFlowFilesForRelationship(InvokeGRPC.REL_RETRY); assertThat(retryFiles.size(), equalTo(1)); final MockFlowFile retry = retryFiles.get(0); retry.assertAttributeEquals(InvokeGRPC.RESPONSE_CODE, String.valueOf(FlowFileReply.ResponseCode.RETRY)); retry.assertAttributeEquals(InvokeGRPC.RESPONSE_BODY, "retry"); retry.assertAttributeEquals(InvokeGRPC.SERVICE_HOST, TestGRPCServer.HOST); retry.assertAttributeEquals(InvokeGRPC.SERVICE_PORT, String.valueOf(port)); final List<MockFlowFile> responseFiles = runner.getFlowFilesForRelationship(InvokeGRPC.REL_RESPONSE); assertThat(responseFiles.size(), equalTo(1)); final MockFlowFile response = responseFiles.get(0); response.assertAttributeEquals(InvokeGRPC.RESPONSE_CODE, String.valueOf(FlowFileReply.ResponseCode.RETRY)); response.assertAttributeEquals(InvokeGRPC.RESPONSE_BODY, "retry"); response.assertAttributeEquals(InvokeGRPC.SERVICE_HOST, TestGRPCServer.HOST); response.assertAttributeEquals(InvokeGRPC.SERVICE_PORT, String.valueOf(port)); } finally { server.stop(); } }
Example 9
Source File: TestInvokeGRPC.java From nifi with Apache License 2.0 | 4 votes |
@Test public void testNoRetryOnErrorAlwaysOutputResponseAndPenalize() throws Exception { final TestGRPCServer<DummyFlowFileService> server = new TestGRPCServer<>(DummyFlowFileService.class); try { final int port = server.start(0); final TestRunner runner = TestRunners.newTestRunner(InvokeGRPC.class); runner.setProperty(InvokeGRPC.PROP_SERVICE_HOST, TestGRPCServer.HOST); runner.setProperty(InvokeGRPC.PROP_SERVICE_PORT, String.valueOf(port)); runner.setProperty(InvokeGRPC.PROP_OUTPUT_RESPONSE_REGARDLESS, "true"); runner.setProperty(InvokeGRPC.PROP_PENALIZE_NO_RETRY, "true"); final MockFlowFile mockFlowFile = new MockFlowFile(ERROR); runner.enqueue(mockFlowFile); runner.run(); runner.assertTransferCount(InvokeGRPC.REL_RESPONSE, 1); runner.assertTransferCount(InvokeGRPC.REL_SUCCESS_REQ, 0); runner.assertTransferCount(InvokeGRPC.REL_RETRY, 0); runner.assertTransferCount(InvokeGRPC.REL_NO_RETRY, 1); runner.assertTransferCount(InvokeGRPC.REL_FAILURE, 0); runner.assertPenalizeCount(1); final List<MockFlowFile> noRetryFiles = runner.getFlowFilesForRelationship(InvokeGRPC.REL_NO_RETRY); assertThat(noRetryFiles.size(), equalTo(1)); final MockFlowFile noRetry = noRetryFiles.get(0); noRetry.assertAttributeEquals(InvokeGRPC.RESPONSE_CODE, String.valueOf(FlowFileReply.ResponseCode.ERROR)); noRetry.assertAttributeEquals(InvokeGRPC.RESPONSE_BODY, "error"); noRetry.assertAttributeEquals(InvokeGRPC.SERVICE_HOST, TestGRPCServer.HOST); noRetry.assertAttributeEquals(InvokeGRPC.SERVICE_PORT, String.valueOf(port)); final List<MockFlowFile> responseFiles = runner.getFlowFilesForRelationship(InvokeGRPC.REL_RESPONSE); assertThat(responseFiles.size(), equalTo(1)); final MockFlowFile response = responseFiles.get(0); response.assertAttributeEquals(InvokeGRPC.RESPONSE_CODE, String.valueOf(FlowFileReply.ResponseCode.ERROR)); response.assertAttributeEquals(InvokeGRPC.RESPONSE_BODY, "error"); response.assertAttributeEquals(InvokeGRPC.SERVICE_HOST, TestGRPCServer.HOST); response.assertAttributeEquals(InvokeGRPC.SERVICE_PORT, String.valueOf(port)); } finally { server.stop(); } }