LoadGen is my favorite tool to perform automatic testing in BizTalk. It is easy to configure and extensible.
When I want to mimic the characteristics of the BizTalk production environment in a test lab as close as possible, LoadGen is the way to go. The load, in terms of number of messages per time unit, can be easily set and tuned by changing values in the LoadGen configuration file.
As said before I want to get as close as possible to the production environment. This also means that I want to use messages that are close to (or better equal to) the production environment.
LoadGen comes with template functionality that you can use to change the message content before passing the message on to BizTalk. This functionality is a bit limited to my opinion.
What I wanted to do is copy a batch of messages from production and use them in my test. To be able to do this I had to write a simple ‘MessageCreator’ component for LoadGen.
A ‘MessageCreator’ is a component that implements the ‘IMessageCreator’ interface found in LoadGen.dll. The ‘MessageCreator’ is called whenever the LoadGen run-time needs a new message. Its task is to create the message and pass it back to the run-time. After that the run-time passes the message to the configured transport components. (Actually the ‘MessageCreator’ fills an internal queue from which other threads dequeue messages).
The default ‘MessageCreator’ that comes with LoadGen is only capable of using a single file for input so I created a new one that:
- - builds a list of files in a specific folder
- - random picks a file from the list
- - uses this file to create the new message
The code is straightforward. The ‘CreateNewMessage’ is the main method responsible for creating the message:
It calls two helper methods ‘CreateFileList’ and ‘GetFileFromList’:
I used the following LoadGen configuration file for my test:
The ‘MessageCreator’ is put in synchronous mode to make sure it create unique messages for all the client threads.
The ‘SrcFilePath’ path contains a pointer to a file where I actually only need the folder. Unfortunately LoadGen fails when there is no file at the end of the path. Internally I only use the path. The same applies to ‘TemplateFilePath’. I don’t need that here but the run-time for this setting.
In this sample I skipped the implementation of the ‘OptimizeFileSizeLimit’ property to keep things simple. I also did not need in in my test. The ‘OptimizeFileSizeLimit’ can be configured in the configuration file and basically tells the LoadGen run-time whether or not it is dealing with a large messages. If this is the case the creation of the message might be performed in another, more optimized way. The samples provided with LoadGen use this to skip file transport component and directly stream from the message component.