Issue Details (XML | Word | Printable)

Key: SFTP-17
Type: Improvement Improvement
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Magnus Larsson
Reporter: Magnus Larsson
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
SFTP Transport Project

Simplify writing tests that need to know when a file is processed

Created: 06/Dec/09 02:39 PM   Updated: 19/Dec/09 05:41 PM
Component/s: Test
Affects Version/s: 2.2.1-RC1
Fix Version/s: 2.2.1-RC2

Time Tracking:
Not Specified

Labels:
User impact: Medium
Similar Issues:


 Description  « Hide
Currently when writing tests where we need to be sure that a file is fully processed we force the test to "sleep" for a time period sufficient for the background processing. This leads to both non robust test code and/or tests that take unnecessary long time to be executed.

Instead of forcing the test code to "sleep" a helper method that uses Mule ESB internal notification mechanism could listen for internal delivery notifications to detect when the background processing is complete and allow the test code to continue immediately after the background processing is complete.

Example of current test code:

// Send an file to the SFTP server, which the inbound-endpoint then can pick up
muleClient.dispatch(getAddressByEndpoint(muleClient, INBOUND_ENDPOINT_NAME) + "?connector=sftpCustomConnector", TEST_MESSAGE, fileNameProperties);

// TODO dont know any better way to wait for the above to finish? We cant use the same as SftpFileAgeFunctionalTestCase
//   for example since we dont have the TestComp
Thread.sleep(10000);

...continue tests here...

Sample code using new helper method:

dispatchAndWaitForDelivery("sftpCustomConnector", INBOUND_ENDPOINT_NAME, OUTBOUND_ENDPOINT_NAME);

...continue tests here...


 All   Comments   Work Log   Change History   Transitions   FishEye      Sort Order: Ascending order - Click to sort in descending order
Magnus Larsson added a comment - 10/Dec/09 03:31 AM
To simplify usage of the helper method dispatchAndWaitForDelivery() but still allow for some flexibility I added a parameter-object, DispatchParameters where most parameters are optional.

Simples possible call looks like:

dispatchAndWaitForDelivery(new DispatchParameters(INBOUND_ENDPOINT_NAME, OUTBOUND_ENDPOINT_NAME));

...and usage of some optional parameter looks like:

DispatchParameters p = new DispatchParameters(INBOUND_ENDPOINT_NAME, OUTBOUND_ENDPOINT_NAME);
p.setSftpConnector("sftpCustomConnector");
dispatchAndWaitForDelivery(p);

Open issue:

The helper method dispatchAndWaitForDelivery() uses programmatic registration of message-event listeners.
To make programmatic registration of message-event listeners to work we have to add a declaration in the mule config file like:

<spring:bean name="endpointMessageNotificationLogger" class="org.mule.transport.sftp.notification.EndpointMessageNotificationTestListener"/>
<notifications>
	<notification event="ENDPOINT-MESSAGE"/>
	<notification-listener ref="endpointMessageNotificationLogger"/>
</notifications>

To me registration of the bean (endpointMessageNotificationLogger) should not be required by I can't get the notification to work unless I regiter the bean...


Magnus Larsson added a comment - 19/Dec/09 05:41 PM
  1. added dispatchAndWaitForException() in AbstractSftpTestCase to be able to wait for exceptions as well
  2. replaced all calls to Thread.sleep() in test cases with calls to dispatchAndWaitForException() or dispatchAndWaitForDelivery().