| |
|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
| Tool to dump test messages |
« View previous topic :: View next topic » |
| Author |
Message
|
| jeevan |
Posted: Tue Sep 11, 2007 12:13 pm Post subject: |
|
|
Grand Master
Joined: 12 Nov 2005 Posts: 1432
|
I am thinking like configuring the tool sucht that it:
generates a files of various size. In fact, I do not need that to send the file to message that is done by PM4DATA. So, I just need a tool which dumps files into a directory. But I like flexibility to configure to generates files with different sizes. |
|
| Back to top |
|
 |
| RogerLacroix |
Posted: Tue Sep 11, 2007 12:33 pm Post subject: |
|
|
 Jedi Knight
Joined: 15 May 2001 Posts: 3265 Location: London, ON Canada
|
| jeevan wrote: |
| generates a files of various size. In fact, I do not need that to send the file to message that is done by PM4DATA. So, I just need a tool which dumps files into a directory. But I like flexibility to configure to generates files with different sizes. |
That's not really an MQ Tool. You could do this very easily in Java with java.util.Random and java.io.RandomAccessFile.
Regards,
Roger Lacroix _________________ Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter |
|
| Back to top |
|
 |
| RogerLacroix |
Posted: Wed Sep 12, 2007 9:46 am Post subject: |
|
|
 Jedi Knight
Joined: 15 May 2001 Posts: 3265 Location: London, ON Canada
|
| jeevan wrote: |
| generates a files of various size. In fact, I do not need that to send the file to message that is done by PM4DATA. So, I just need a tool which dumps files into a directory. But I like flexibility to configure to generates files with different sizes. |
Well Jeevan, it must be your lucky day. Because I just got asked to create a few thousand files of different sizes for testing message flow.
So, I created the java program (based on my own advice) to do the work for me.
Here you go:
| Code: |
import java.io.IOException;
import java.io.RandomAccessFile;
import java.text.DecimalFormat;
import java.util.Date;
import java.util.Random;
/**
* CreateRdmFiles will generate a set of files with random amounts of data (file sizes).
* @author Roger Lacroix
* @version 1.0
*/
public class CreateRdmFiles
{
private static final String ALPHA_NUM = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
private static final int MIN_FILE_SIZE = 1000; // amount in bytes
private static final int MAX_FILE_SIZE = 20000; // amount in bytes
private static final String OUTPUT_DIR = "C:\\temp";
private static final String FILE_NAME_PREFIX = "test";
private static final String FILE_NAME_EXTENSION = ".txt";
/**
* The constructor
*/
public CreateRdmFiles()
{
super();
}
/**
* This method will write data to a file.
* @param byteData contents of the file.
* @param fileName the name of the file.
*/
private void writeFile(byte[] byteData, String fileName) throws IOException
{
RandomAccessFile in = new RandomAccessFile(fileName, "rw");
in.write(byteData);
in.setLength(byteData.length); // set new length if case it already existed.
in.close();
}
/**
* Retrieve the command line parameter
* @param args
* @return the number of files as an int
* @throws IllegalArgumentException
*/
private int getParameter(String[] args) throws IllegalArgumentException
{
int numberOfFiles = 0;
if (args.length == 1)
{
try
{
numberOfFiles = Integer.parseInt(args[0]);
if ( numberOfFiles < 1)
{
throw new IllegalArgumentException();
}
}
catch (Exception E)
{
throw new IllegalArgumentException();
}
}
else
{
throw new IllegalArgumentException();
}
return numberOfFiles;
}
/**
* Create some simple data
* @param requiredSize
* @return a byte array of random data
*/
private byte[] createData(int requiredSize)
{
int len = ALPHA_NUM.length();
int numOfBlocks = (requiredSize + (len-1)) / len;
StringBuffer sb = new StringBuffer(MAX_FILE_SIZE);
for (int i=0; i < numOfBlocks;i++)
{
sb.append(ALPHA_NUM);
}
sb.setLength(requiredSize);
return sb.toString().getBytes();
}
/**
* The mainline
* @param args command line arguments
*/
public static void main(String[] args)
{
CreateRdmFiles crf = new CreateRdmFiles();
DecimalFormat decFmt = new DecimalFormat("####000");
Date currentDate = new java.util.Date();
Random random = new Random(currentDate.getTime());
int numberOfFiles = 0;
try
{
numberOfFiles = crf.getParameter(args);
}
catch (Exception E)
{
System.err.println("Usage : java CreateRdmFiles NumberOfFiles");
return;
}
for (int i=0; i < numberOfFiles; i++)
{
String filename = OUTPUT_DIR + System.getProperty("file.separator") + FILE_NAME_PREFIX + "_" + decFmt.format(i+1) + FILE_NAME_EXTENSION;
try
{
crf.writeFile( crf.createData(MIN_FILE_SIZE + random.nextInt(MAX_FILE_SIZE-MIN_FILE_SIZE)), filename );
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
} |
Items to note:
- First off you need Java.
- To compile it do: javac CreateRdmFiles.java
- To run it do: java CreateRdmFiles ###
where ### is the number of files you want to create.
- The files will be created in the directory contained in the OUTPUT_DIR variable. On Windows, make sure use double (2) backslashes.
- The naming of the file is controlled by FILE_NAME_PREFIX and FILE_NAME_EXTENSION variables. The file names will look like test_0001.txt, test_0002.txt, etc...
- The random file size is controlled by MIN_FILE_SIZE and MAX_FILE_SIZE variables.
This program can be used on any platform that supports Java. i.e. Wndows, Unix, Linux, OS/2, Mac OSX, etc...
Enjoy.
Regards,
Roger Lacroix
Capitalware Inc. _________________ Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter |
|
| Back to top |
|
 |
| jeevan |
Posted: Wed Sep 12, 2007 12:11 pm Post subject: |
|
|
Grand Master
Joined: 12 Nov 2005 Posts: 1432
|
| Thank you very much. It is really helpful for testing transfer in PM4DATA. |
|
| Back to top |
|
 |
| timjohnarm |
Posted: Mon Sep 17, 2007 10:27 am Post subject: |
|
|
Apprentice
Joined: 28 Sep 2004 Posts: 40 Location: Melbourne Australia
|
The following sample script from MA0T will put 1 of 10 randomly selected messages on to a queue starting at 1 message/sec then ramping up by 1 message/sec every 5 seconds until it reaches 5 messages/sec at which point it will repeat the whole process. By changing the input parameters you can change the rate and duration easily. It also supports other modes of message rate specific operation, all of which take into account the actual time to do the MQPUT automatically.
With a partner script getting the responses MA0T is capable of measuring the response times to millisecond resolution.
I will admit to a degree of bias as the author of MA0T but it might just be what you are looking for. http://www-1.ibm.com/support/docview.wss?uid=swg24007048
<?xml version="1.0"?>
<MsgTest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="C:\MsgTest\Schema\MsgTest.xsd">
<Control>
<Connection>
<QMgr>MYQMGR</QMgr>
<Channel>MY.SVRCONN</Channel>
<Host>127.0.0.1</Host>
<Port>1444</Port>
</Connection>
<TestReport>
<File>%ScriptName%_%YYYY%_%MM%_%DD%.rpt</File>
<Dir>c:\MsgTest\TestScripts\Reports</Dir>
</TestReport>
</Control>
<Test Name="#1 Put Messages">
<Length Name="PgmVar4Len" Of="4"/>
<If Cond="0.GE.%PgmVar4Len%">
<StdOut>Script requires four invocation paramters. InitialMsgRate FinalMsgRate Increment Interval</StdOut>
<StdOut>Suggested invocation mt MessageRate8-1 1 5 1 5</StdOut>
<FailTest/>
</If>
<!-- Load up the ten test data files into separate buffers -->
<For Name="LoadFile" From="1" To="10" Incr="1" Format="%02d">
<GetFile>
<Buffer>Buff%LoadFile%</Buffer>
<File>FileIn%LoadFile%.txt</File>
<Dir>c:\MsgTest\TestScripts\DataIn</Dir>
</GetFile>
</For>
<!-- First put contains an implicit MQOPEN so get it done -->
<!-- for IntervalStart/IntervalEnd measurements -->
<PutMsg>
<Buffer>Buff01</Buffer>
<Q>MSGTEST.OUT</Q>
<MsgId/>
<CorrelId/>
<IntervalInMsgId Name="Put"/>
</PutMsg>
<!-- Put a series of messages using INCREMENTAL mode. Repeated twice -->
<For Name="Twice" From="1" To="2" Incr="1">
<ForEver Name="Ext">
<RandomNum Name="BuffSelect" From="1" To="10" Format="%02d"/>
<IntervalStart Name="PutMsg"/>
<PutMsg>
<!-- Use random number to select the message buffer to be sent -->
<Buffer>Buff%BuffSelect%</Buffer>
<Q>MSGTEST.OUT</Q>
<MsgId/>
<CorrelId/>
<MessageRate From="%1%" To="%2%" Incr="%3%" Interval="%4%" Mode="INCREMENTAL"/>
<IntervalInMsgId Name="Put"/>
</PutMsg>
<IntervalEnd Name="PutMsg"/>
</ForEver>
</For>
</Test>
</MsgTest> |
|
| Back to top |
|
 |
| RogerLacroix |
Posted: Tue Sep 18, 2007 8:51 am Post subject: |
|
|
 Jedi Knight
Joined: 15 May 2001 Posts: 3265 Location: London, ON Canada
|
| timjohnarm wrote: |
| The following sample script from MA0T will ... |
Hi Tim,
I think he was looking for test data for PM4Data (i.e. outside of MQ).
Does your tool / script integrate with ANT?
Regards,
Roger Lacroix
Capitalware Inc. _________________ Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter |
|
| Back to top |
|
 |
| jefflowrey |
Posted: Tue Sep 18, 2007 10:19 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
| RogerLacroix wrote: |
| Does your tool / script integrate with ANT? |
It's a C executable. Ant can run it. _________________ I am *not* the model of the modern major general. |
|
| Back to top |
|
 |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|