Skip to content

Instantly share code, notes, and snippets.

@minisu
Last active August 29, 2015 13:59
Show Gist options
  • Save minisu/10714626 to your computer and use it in GitHub Desktop.
Save minisu/10714626 to your computer and use it in GitHub Desktop.
/**
* Manages statistic updates for a Runner in a load test.
*/
public class WebRunnerStatsSender
{
private final Map<String, VariableGroup> resourceToVariableGroup = new HashMap<>();
private final Clock clock;
public WebRunnerStatsSender( Clock clock )
{
this.clock = clock;
}
/**
* Register a resource. This is done once per resource in the beginning of a test.
*/
public void addResource( String resource )
{
resourceToVariableGroup.put( resource, new VariableGroup( resource ) );
}
/**
* Updates the time taken statistic with a new sample.
* This is done once per response (i.e. typically several times per second throughout the test).
*/
public void updateTimeTaken( String resource, long timeTaken )
{
long timeStamp = clock.millis();
VariableGroup resorceVariables = getVariablesFor( resource );
if( resorceVariables != null )
{
resorceVariables.timeTakenVariable.update( timeStamp, timeTaken );
}
}
private VariableGroup getVariablesFor( String resource )
{
return resourceToVariableGroup.get( resource );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment