VirtualUser Class

VirtualUser represents a Virtual User instance.

Typically, you have several instances of a Virtual User running at the same time.

Usually, for debugging purpose, you can get the id of the current Virtual User (e.g. "UserA#3") with context.currentVU.id

Synopsis

 public class VirtualUser {
  // Public Fields
  public String id ;
  public String name ;
  // Public Methods
  public void clearCookies();
  public void clearRuntimeVariables();
  public Object get(Object key);
  public int getCurrentIteration();
  public String getCurrentStep();
  public long getElapsedTime();
  public String getPopulationName();
  public void goToNextIteration();
  public void put(Object key,
                  Object value);
  public Object remove(Object key);
  public void setCookieForServer(String serverName,
                                 String cookie);
  @Deprecated public void stop();
}

id

public String id ;

The id of the Virtual User (e.g. "User1#3"). This id is only valid if the Virtual User is context.currentVU. In all other cases, this id will be null

name

public String name ;

The Virtual User name (e.g. "User1")

clearCache()

public void clearCache();

Deletes all cache information for the Virtual User instance.

clearCookies()

public void clearCookies();

Deletes all cookies for the Virtual User instance.

clearRuntimeVariables()

public void clearRuntimeVariables();

Deletes all runtime variables for the Virtual User instance.

closeConnections()

public void closeConnections();

Closes all the open connections to servers for the Virtual User instance (HTTP, HTTPS, websockets, RTMP).

get(Object)

public Object get(Object key);

Parameters

Returns the value to which the specified key is mapped, or null if there is no mapping for the key.

getCurrentIteration()

public int getCurrentIteration();

Parameters

Returns the current instance number of a Virtual User runtime loop.

getCurrentStep()

public String getCurrentStep();

Parameters

Returns the current runtime step label for the Virtual User instance.

getElapsedTime()

public long getElapsedTime();

Parameters

Returns the elapsed time in milliseconds since this Virtual User started.

getPopulationName()

public String getPopulationName();

Parameters

Returns the name of the Population containing this Virtual User.

goToNextIteration()

public void goToNextIteration();

Switches to the next iteration of the current runtime for the Virtual User instance.

put(Object, Object)

public void put(Object key,
                Object value);

Parameters

Stores a user-defined object in the Virtual User instance. It associates the specified value with the specified key.

remove(Object)

public Object remove(Object key);

Parameters

Removes the mapping for a key if it is present.

Returns the value previously associated with the key, or null if there is no mapping for the key.

setCookieForServer(String, String)

public void setCookieForServer(String serverName,
                               String cookie);

Parameters

Sets a cookie for the Virtual User instance. The cookie is associated with the specified server so that the cookie will be sent in all following requests to the specified server according to the cookies settings: the cookie will be sent if the cookie path matches the request path and if the expiration date is not reached.

The cookie must have the standard format: e.g. "name=value; expires=Thu, 2 Aug 2007 20:47:11 UTC; path=/".

Example:

Sets a cookie that expires in 7 days, and that will be sent in requests which paths are under /app on the server jack_80

      var today = new Date();
      var oneDay = 1000 * 60 * 60 * 24; // 24H in ms
      var expires = 7 * oneDay;  
      var expires_date = new Date(today.getTime()+expires);
      var cookie = "username=John; expires=" + expires_date.toGMTString() +"; \
path=/app";
      context.currentVU.setCookieForServer("jack_80",cookie);

To clear a cookie

Set a cookie with an expired date to remove the cookie for the Virtual User instance. Note that the cookie header should be removed from the request headers of the appropriate requests in the repository: the requests that come after the Javascript and which URL match the server and path of the cookie.

Example:

      var expires_date = new Date(0);
      var cookie = "username=John; expires=" + expires_date.toGMTString() +"; \
path=/app";
      context.currentVU.setCookieForServer("jack_80",cookie);

stop()

@Deprecated public void stop();