@Test(expected = MessagingException.class)
  public void testProcessOneWayNoThreadingWithException() throws Exception {
    ThreadingProfile threadingProfile =
        new ChainedThreadingProfile(muleContext.getDefaultThreadingProfile());
    threadingProfile.setDoThreading(false);
    threadingProfile.setMuleContext(muleContext);

    MessageProcessor mockListener = mock(MessageProcessor.class);
    when(mockListener.process((MuleEvent) any())).thenThrow(new RuntimeException());

    SedaStageInterceptingMessageProcessor sedaStageInterceptingMessageProcessor =
        new SedaStageInterceptingMessageProcessor(
            "testProcessOneWayNoThreadingWithException",
            "testProcessOneWayNoThreadingWithException",
            queueProfile,
            queueTimeout,
            threadingProfile,
            queueStatistics,
            muleContext);
    sedaStageInterceptingMessageProcessor.setListener(mockListener);
    sedaStageInterceptingMessageProcessor.initialise();
    sedaStageInterceptingMessageProcessor.start();

    MessagingExceptionHandler exceptionHandler = mock(MessagingExceptionHandler.class);
    Flow flow = mock(Flow.class);
    when(flow.getExceptionListener()).thenReturn(exceptionHandler);
    when(flow.getProcessingStrategy()).thenReturn(new AsynchronousProcessingStrategy());
    MuleEvent event = getTestEvent(TEST_MESSAGE, flow, MessageExchangePattern.ONE_WAY);

    sedaStageInterceptingMessageProcessor.process(event);
  }
Пример #2
0
  protected <T, U> void runFlowWithPayload(String flowName, T expect, U payload) throws Exception {
    Flow flow = lookupFlowConstruct(flowName);
    MuleEvent event = AbstractMuleTestCase.getTestEvent(payload);
    MuleEvent responseEvent = flow.process(event);

    assertEquals(expect, responseEvent.getMessage().getPayload());
  }
Пример #3
0
  protected <U> MuleEvent runFlowWithPayload(String flowName, U payload) throws Exception {
    Flow flow = lookupFlowConstruct(flowName);
    MuleEvent event = AbstractMuleTestCase.getTestEvent(payload);
    MuleEvent responseEvent = flow.process(event);

    return responseEvent;
  }
  /**
   * Run the flow specified by name and assert equality on the expected output
   *
   * @param flowName The name of the flow to run
   * @param expect The expected output
   */
  protected <T> void runFlowAndExpect(String flowName, T expect) throws Exception {
    Flow flow = lookupFlowConstruct(flowName);
    MuleEvent event = AbstractMuleTestCase.getTestEvent(null);
    MuleEvent responseEvent = flow.process(event);

    if (expect != null) {
      assertEquals(expect, responseEvent.getMessage().getPayload());
    }
  }
  private void doUnresolvedMetadataTest(String flowName) {
    Flow flowConstruct = (Flow) muleContext.getRegistry().lookupFlowConstruct(flowName);

    List<MessageProcessor> messageProcessors = flowConstruct.getMessageProcessors();
    AbstractSingleQueryDbMessageProcessor queryMessageProcessor =
        (AbstractSingleQueryDbMessageProcessor) messageProcessors.get(0);
    Result<MetaData> inputMetaData = queryMessageProcessor.getInputMetaData();

    assertThat(inputMetaData, equalTo(null));
  }
  @Test
  public void testProcessOneWayThreadWaitTimeout() throws Exception {
    final int threadTimeout = 20;
    ThreadingProfile threadingProfile =
        new ChainedThreadingProfile(muleContext.getDefaultThreadingProfile());
    threadingProfile.setThreadWaitTimeout(threadTimeout);
    // Need 3 threads: 1 for polling, 2 to process work successfully without timeout
    threadingProfile.setMaxThreadsActive(3);
    threadingProfile.setPoolExhaustedAction(ThreadingProfile.WHEN_EXHAUSTED_WAIT);
    threadingProfile.setMuleContext(muleContext);

    MessageProcessor mockListener = mock(MessageProcessor.class);
    when(mockListener.process((MuleEvent) any()))
        .thenAnswer(
            new Answer<MuleEvent>() {
              public MuleEvent answer(InvocationOnMock invocation) throws Throwable {
                Thread.sleep(threadTimeout * 2);
                return (MuleEvent) invocation.getArguments()[0];
              }
            });

    SedaStageInterceptingMessageProcessor sedaStageInterceptingMessageProcessor =
        new SedaStageInterceptingMessageProcessor(
            "testProcessOneWayThreadWaitTimeout",
            "testProcessOneWayThreadWaitTimeout",
            queueProfile,
            queueTimeout,
            threadingProfile,
            queueStatistics,
            muleContext);
    sedaStageInterceptingMessageProcessor.setListener(mockListener);
    sedaStageInterceptingMessageProcessor.initialise();
    sedaStageInterceptingMessageProcessor.start();

    MessagingExceptionHandler exceptionHandler = mock(MessagingExceptionHandler.class);
    Flow flow = mock(Flow.class);
    when(flow.getExceptionListener()).thenReturn(exceptionHandler);
    when(flow.getProcessingStrategy()).thenReturn(new AsynchronousProcessingStrategy());
    final MuleEvent event = getTestEvent(TEST_MESSAGE, flow, MessageExchangePattern.ONE_WAY);

    for (int i = 0; i < 3; i++) {
      sedaStageInterceptingMessageProcessor.process(event);
    }

    ArgumentMatcher<MuleEvent> notSameEvent = createNotSameEventArgumentMatcher(event);

    // Two events are processed
    verify(mockListener, timeout(RECEIVE_TIMEOUT).times(2)).process(argThat(notSameEvent));

    // One event gets processed by the exception strategy
    verify(exceptionHandler, timeout(RECEIVE_TIMEOUT).times(1))
        .handleException((Exception) any(), argThat(notSameEvent));
  }
  private IdempotentMessageFilter idempotentMessageFilterFromFlow(final String flowName)
      throws Exception {
    final FlowConstruct flow = getFlowConstruct(flowName);
    assertTrue(flow instanceof Flow);

    final Flow simpleFlow = (Flow) flow;
    final List<MessageProcessor> processors = simpleFlow.getMessageProcessors();
    assertEquals(1, processors.size());

    final MessageProcessor firstMP = processors.get(0);
    assertEquals(IdempotentMessageFilter.class, firstMP.getClass());

    return (IdempotentMessageFilter) firstMP;
  }
  @Test
  public void testProcessOneWayWithException() throws Exception {
    final Latch latch = new Latch();
    ThreadingProfile threadingProfile =
        new ChainedThreadingProfile(muleContext.getDefaultThreadingProfile());
    threadingProfile.setMuleContext(muleContext);

    MessageProcessor mockListener = mock(MessageProcessor.class);
    when(mockListener.process((MuleEvent) any()))
        .thenAnswer(
            new Answer<MuleEvent>() {
              public MuleEvent answer(InvocationOnMock invocation) throws Throwable {
                latch.countDown();
                throw new RuntimeException();
              }
            });

    SedaStageInterceptingMessageProcessor sedaStageInterceptingMessageProcessor =
        new SedaStageInterceptingMessageProcessor(
            "testProcessOneWayWithException",
            "testProcessOneWayWithException",
            queueProfile,
            queueTimeout,
            threadingProfile,
            queueStatistics,
            muleContext);
    sedaStageInterceptingMessageProcessor.setListener(mockListener);
    sedaStageInterceptingMessageProcessor.initialise();
    sedaStageInterceptingMessageProcessor.start();

    MessagingExceptionHandler exceptionHandler = mock(MessagingExceptionHandler.class);
    Flow flow = mock(Flow.class);
    when(flow.getExceptionListener()).thenReturn(exceptionHandler);
    when(flow.getProcessingStrategy()).thenReturn(new AsynchronousProcessingStrategy());
    final MuleEvent event = getTestEvent(TEST_MESSAGE, flow, MessageExchangePattern.ONE_WAY);

    sedaStageInterceptingMessageProcessor.process(event);

    assertTrue(latch.await(RECEIVE_TIMEOUT, TimeUnit.MILLISECONDS));

    ArgumentMatcher<MuleEvent> notSameEvent = createNotSameEventArgumentMatcher(event);

    // One event get processed but then throws an exception
    verify(mockListener, timeout(RECEIVE_TIMEOUT).times(1)).process(argThat(notSameEvent));

    // One event gets processed by the exception strategy
    verify(exceptionHandler, timeout(RECEIVE_TIMEOUT).times(1))
        .handleException((Exception) any(), argThat(notSameEvent));
  }
Пример #9
0
 public void testMuleMessageAsParameter() throws Exception {
   Flow flow = lookupFlowConstruct("acceptMuleMessage");
   flow.process(AbstractMuleTestCase.getTestEvent(""));
 }
Пример #10
0
 protected <T> void runFlow(String flowName) throws Exception {
   String payload = EMPTY_PAYLOAD;
   Flow flow = lookupFlowConstruct(flowName);
   MuleEvent event = AbstractMuleTestCase.getTestEvent(payload);
   MuleEvent responseEvent = flow.process(event);
 }
 protected MessageProcessor lookupMessageProcessorFromFlow(String serviceName) throws Exception {
   Flow service = lookupFlow(serviceName);
   List<MessageProcessor> routers = service.getMessageProcessors();
   assertEquals(1, routers.size());
   return routers.get(0);
 }
 protected MessageProcessor lookupCustomRouterFromFlow(String serviceName) throws Exception {
   Flow service = lookupFlow(serviceName);
   return service.getMessageProcessors().get(0);
 }