use of org.apache.nifi.processors.standard.util.WrappedMessageProducer in project nifi by apache.
the class TestPutJMS method testPutSendRoutesToFailure.
@Test
public void testPutSendRoutesToFailure() throws JMSException, NoSuchFieldException, IllegalAccessException {
final PutJMS putJMS = spy(new PutJMS());
final TestRunner runnerPut = TestRunners.newTestRunner(putJMS);
runnerPut.setProperty(JmsProperties.JMS_PROVIDER, TEST_PROVIDER);
runnerPut.setProperty(JmsProperties.URL, TEST_URL);
runnerPut.setProperty(JmsProperties.DESTINATION_TYPE, TEST_DEST_TYPE);
runnerPut.setProperty(JmsProperties.DESTINATION_NAME, TEST_DEST_NAME + testQueueSuffix());
final ProcessContext context = runnerPut.getProcessContext();
final Queue<WrappedMessageProducer> wrappedMessageProducerQueue = (Queue) spy(new LinkedBlockingQueue<>());
injectFieldValue(PutJMS.class, putJMS, "producerQueue", wrappedMessageProducerQueue);
final WrappedMessageProducer wrappedMessageProducer = spy(JmsFactory.createMessageProducer(context, true));
final MessageProducer messageProducer = spy(wrappedMessageProducer.getProducer());
doAnswer(new Answer<WrappedMessageProducer>() {
@Override
public WrappedMessageProducer answer(InvocationOnMock invocationOnMock) {
return wrappedMessageProducer;
}
}).when(wrappedMessageProducerQueue).poll();
assertEquals(wrappedMessageProducer, wrappedMessageProducerQueue.poll());
doAnswer(new Answer<MessageProducer>() {
@Override
public MessageProducer answer(InvocationOnMock invocationOnMock) {
return messageProducer;
}
}).when(wrappedMessageProducer).getProducer();
doThrow(new JMSException("force send to fail")).when(messageProducer).send(any(Message.class));
final Map<String, String> attributes = new HashMap<>();
attributes.put("filename", "file1.txt");
runnerPut.enqueue("putSendRoutesToFailure".getBytes(), attributes);
runnerPut.run();
assertEquals(0, runnerPut.getFlowFilesForRelationship(PutJMS.REL_SUCCESS).size());
assertEquals(1, runnerPut.getFlowFilesForRelationship(PutJMS.REL_FAILURE).size());
final List<MockFlowFile> flowFilesFail = runnerPut.getFlowFilesForRelationship(PutJMS.REL_FAILURE);
assertEquals(1, flowFilesFail.size());
}
Aggregations