Retrieving the IP address of a virtual user

This example shows how to retrieve the local IP address of a virtual user. Retrieving IP addresses is particularly useful when virtual users are using IP aliases.

The Javadoc for the test execution services interfaces and classes can be accessed from the product by clicking Help > Help Contents > DevOps Test Performance API Reference.

The following custom code retrieves the IP address that was assigned to a virtual user:

import java.net.InetAddress;
import com.ibm.rational.test.lt.kernel.IDataArea;
import com.ibm.rational.test.lt.kernel.services.ITestLogManager;
import com.ibm.rational.test.lt.kernel.services.IVirtualUserInfo;

public String exec(ITestExecutionServices tes, String[] args) {
	IVirtualUserInfo vui = (IVirtualUserInfo) tes.findDataArea(IDataArea.VIRTUALUSER).get(IVirtualUserInfo.KEY);
	ITestLogManager tlm = tes.getTestLogManager();

	if (vui != null) {
		String localAddr = null;
		InetAddress ipAddr = vui.getIPAddress();
		if (ipAddr != null)
			localAddr = ipAddr.toString();
		tlm.reportMessage("IPAlias address is " + (localAddr != null ? localAddr : "not set"));
		return localAddr;
	}
else
		return ("Virtual User Info not found");
}