Skip to content

Writing & executing Tests

Alexandre D'Erman edited this page Jul 16, 2014 · 8 revisions

If you need to write a unit test in RoQ, we provide simple and interesting classes to start a RoQ instance locally. Here is a template using the RoQAllLauncher:

public class TestStatMonitor {
	private RoQAllLocalLauncher launcher = null;
	private Logger logger = Logger.getLogger(TestStatMonitor.class);
	
	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
		this.launcher = new RoQAllLocalLauncher();
		this.launcher.setUp();
	}

	/**
	 * @throws java.lang.Exception
	 */
	@After
	public void tearDown() throws Exception {
		this.launcher.tearDown();
		this.kpiSubscriber.shutDown();
	}

	@Test
	public void test() {
                // Example of test
		//1. Create a Queue
		IRoQLogicalQueueFactory logicalQFactory = new LogicalQFactory(launcher.getConfigurationServer());
		logicalQFactory.createQueue("queue1", RoQUtils.getInstance().getLocalIP());
		
		//2. Init the KPI subscriber
		kpiSubscriber = new KPISubscriber(launcher.getConfigurationServer(), "queue1", false);
		new Thread(kpiSubscriber).start();
		
		//3. Create a subscriber
		IRoQConnectionFactory factory = new RoQConnectionFactory(launcher.getConfigurationServer());
		// add a subscriber
		IRoQSubscriberConnection subConnection = factory.createRoQSubscriberConnection("queue1", "key");
		...

Look at the TestStatMonitor.java in the test of the simulation module.

A RoQ Abstract Test case

In order to make test easier, we created an abstract test case in the Simulation module. This test case already provides the startup and tear down method using the RoQ All in one Launcher. In addition, we provides facility methods to register a subscriber or to send message to a queue. Then, you just need to write a test case !

public class TestMngtController extends RoQTestCase {
	private Logger logger = Logger.getLogger(TestMngtController.class);
	...

	
	/**
	 * Test the BSON interface exposed by the management controller
	 * @throws Exception
	 */
	@Test
	public void testBsonRequest() throws Exception {
		ZMQ.Context context = ZMQ.context(1);
		ZMQ.Socket mngtREQSocket = context.socket(ZMQ.REQ);
		mngtREQSocket.connect("tcp://localhost:5003");
		
		//1. define the queue
		String qName = "testQ1";
		
		//2.  Create a client management & sending command request
		MngClient client = new MngClient("localhost");
		client.testCreate(qName);
		
		//3. Test the message sending
		attachSUbscriber(qName);
		IRoQPublisher publisher = attachPublisher(qName);
		sendMsg(publisher);
		
		//4. Remove the queue
		client.testRemove(qName);
}

Test load

In order to evaluate RoQ under load for evaluating its elastic behaviour, we are currently re-factoring the load test tool developed for the EQS paper. The new architecture is shown below. High level architecture of the new test loader.

The input parameters of the test loader process are:

  1. The Spawn rate x: every x second we start a producer. This is similar as a warm-up period.
  2. Max producers y: the maximum number of producers to spawn.
  3. Rate (msg/min) r: the number of messages per minute to be sent by each spawned producer.
  4. Duration (min) d: the test duration.
  5. Payload (kb) p: the message content size, simulated by an array of px1000 size of byte.
  6. Number of subscribers s: the maximum number of producers to spawn
  7. Delay (s) de: the waiting time before starting the test.

Launching tests

We have created a test toolkit to make load test on a RoQ cluster. This section described how to launch tests from a clean RoQ installation. First of all we need to create a queue that will be used for the load test. Afterwards, we will launch the load test with a specific test configuration as defined in the previous section.

  1. Get the last RoQ build, install and start it as indicated in the README.md
  2. Create a queue that will be used for the test. For this purpose, we created an helper process to create and remove queues.
    java -Djava.library.path=/usr/local/lib -Dlog4j.configuration="file:roq/config/log4j.properties" -cp roq/lib/roq-management-1.0-SNAPSHOT-jar-with-dependencies.jar org.roqmessaging.management.launcher.QueueManagementLauncher 127.0.0.1 add testload
    where the 127.0.0.1 (just an example) is the GCM address, the second argument can be "add" or "del" it specifies whether we need to create or remove a queue, and finally the last argument, "testload" here is the queue name we want to create.
  3. Start the load test. The test description must be defined in a JSON format in a file. An example could be:
{
  "maxPub":5,
  "duration":2.5,
  "rate":3000,
  "maxSub":5,
  "payload":20,
  "delay":5,
  "spawnRate":1
}

Notice that is important for the duration to explicitly write a "X.X" value. In the case of the test description, we will launch 5 publishers that will send 3000 msg/s each. It will also launch 5 subscribers, each of them receiving 3000x5 msg/s. As a result the queue will handle a throughput of 15000x5 msg/s.

As soon as the test description is in a file we can launch the test.

java -Djava.library.path=/usr/local/lib -Dlog4j.configuration="file:roq/config/log4j.properties" -cp roq/lib/roq-simulation-1.0-SNAPSHOT-jar-with-dependencies.jar org.roqmessaging.loaders.launcher.TestLoaderLauncher test.txt testload

The first argument, "test.txt" here is the path to the file containing the test load description, while the second argument is the name of the queue on which we want to launch the test.