Skip to content

Commit

Permalink
remove ResourceProfile class to only use Resource #9
Browse files Browse the repository at this point in the history
Signed-off-by: olivier lamy <[email protected]>
  • Loading branch information
olamy committed Feb 21, 2017
1 parent d576da7 commit bbc1579
Show file tree
Hide file tree
Showing 21 changed files with 129 additions and 225 deletions.
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,29 @@ More documentation https://jetty-project.github.io/jetty-load-generator/
## Documentation

### Profile
You can use the API to define a running profile (steps with url to hit)
You can use the API to define a running resource (steps with url to hit)

```java
ResourceProfile resourceProfile =
new ResourceProfile( //
Resource resource =
new Resource( //
new Resource( "/index.html" ) //
);
```

### Load Generator
Then you run the load generator with this profile
Then you run the load generator with this resource

```java
LoadGenerator loadGenerator = new LoadGenerator.Builder() //
.host( your host ) //
.port( the port ) //
.users( a users number ) //
.transactionRate( 1 ) // number of transaction per second. Transaction means all the request from the ResourceProfile
.transactionRate( 1 ) // number of transaction per second. Transaction means all the request from the Resource
.transport( transport ) // the type of transport.
.httpClientTransport( HttpClientTransport instance have a look at the various builder ) //
.scheduler( scheduler ) //
.sslContextFactory( sslContextFactory ) //
.loadProfile( profile ) //
.resource( resource ) //
.responseTimeListeners( some listeners you can build your own or use existing one ) // some listeners you can build your own
.requestListeners( some listeners you can build your own or use existing one ) //
.build();
Expand Down Expand Up @@ -112,9 +112,8 @@ See --help for usage

```
import org.mortbay.jetty.load.generator.profile.Resource
import org.mortbay.jetty.load.generator.profile.ResourceProfile
return new ResourceProfile(new Resource( "index.html",
return new Resource(new Resource( "index.html",
new Resource( "/css/bootstrap.css",
new Resource( "/css/bootstrap-theme.css" ),
new Resource( "/js/jquery-3.1.1.min.js"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.util.thread.Scheduler;
import org.mortbay.jetty.load.generator.latency.LatencyTimeListener;
import org.mortbay.jetty.load.generator.profile.ResourceProfile;
import org.mortbay.jetty.load.generator.profile.Resource;
import org.mortbay.jetty.load.generator.responsetime.ResponseTimeListener;

import javax.servlet.http.HttpServletResponse;
Expand Down Expand Up @@ -64,7 +64,7 @@ public class LoadGenerator
private int users;

/**
* number of transactions send per minute (transaction means the whole {@link ResourceProfile}
* number of transactions send per minute (transaction means the whole {@link Resource}
* <p>
* if < 0, the generator will not apply any regulation and send as many he can (will be resources dependant)
* </p>
Expand All @@ -88,7 +88,7 @@ public class LoadGenerator
*/
private int port;

private ResourceProfile profile;
private Resource resource;

private HttpClientTransport httpClientTransport;

Expand Down Expand Up @@ -141,14 +141,14 @@ public enum Transport
FCGI
}

LoadGenerator( int users, int transactionRate, String host, int port, ResourceProfile profile )
LoadGenerator( int users, int transactionRate, String host, int port, Resource resource )
{
this.users = users;
this.transactionRate = transactionRate;
this.host = host;
this.port = port;
this.stop = new AtomicBoolean( false );
this.profile = profile;
this.resource = resource;


}
Expand Down Expand Up @@ -213,9 +213,9 @@ public SocketAddressResolver getSocketAddressResolver()
return socketAddressResolver;
}

public ResourceProfile getProfile()
public Resource getResource()
{
return profile;
return resource;
}

public String getScheme()
Expand Down Expand Up @@ -368,7 +368,7 @@ public void interrupt()
public String toString()
{
return "LoadGenerator{" + "users=" + users + ", transactionRate=" + transactionRate + ", scheme='" + scheme
+ '\'' + ", host='" + host + '\'' + ", port=" + port + ", profile=" + profile + ", requestListeners="
+ '\'' + ", host='" + host + '\'' + ", port=" + port + ", resource=" + resource + ", requestListeners="
+ requestListeners + ", scheduler=" + scheduler + ", responseTimeListeners=" + responseTimeListeners
+ ", httpProxies=" + httpProxies + ", transport=" + transport + ", httpVersion=" + httpVersion
+ ", statisticsPath='" + statisticsPath + '\'' + '}';
Expand Down Expand Up @@ -656,7 +656,7 @@ public static class Builder

private SocketAddressResolver socketAddressResolver;

private ResourceProfile profile;
private Resource resource;

private List<ResponseTimeListener> responseTimeListeners;

Expand Down Expand Up @@ -741,9 +741,9 @@ public Builder httpClientSocketAddressResolver( SocketAddressResolver socketAddr
return this;
}

public Builder loadProfile( ResourceProfile resourceProfile )
public Builder resource( Resource resource )
{
this.profile = resourceProfile;
this.resource = resource;
return this;
}

Expand Down Expand Up @@ -795,7 +795,7 @@ public LoadGenerator build()
{
this.validate();
LoadGenerator loadGenerator =
new LoadGenerator( users, transactionRate, host, port, this.profile );
new LoadGenerator( users, transactionRate, host, port, this.resource );
loadGenerator.requestListeners = this.requestListeners == null ? new ArrayList<>() // //
: this.requestListeners;
loadGenerator.httpClientTransport = httpClientTransport;
Expand Down Expand Up @@ -831,7 +831,7 @@ public void validate()
throw new IllegalArgumentException( "port must be a positive integer" );
}

if ( this.profile == null )
if ( this.resource == null )
{
throw new IllegalArgumentException( "a profile is mandatory" );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void run()
break;
}

List<Resource> resources = loadGenerator.getProfile().getResources();
List<Resource> resources = loadGenerator.getResource().getResources();

for ( Resource resource : resources )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void onLoadGeneratorStart( LoadGenerator loadGenerator )
{
// we initialize Maps to avoid concurrent issues
recorderPerPath = new ConcurrentHashMap<>();
initializeMap( recorderPerPath, loadGenerator.getProfile().getResources() );
initializeMap( recorderPerPath, loadGenerator.getResource().getResources() );
}

private void initializeMap( Map<String, Recorder> recorderMap, List<Resource> resources )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ public Resource()
// no op
}

public Resource(Resource... resources)
{
this(null, resources);
}

public Resource(List<Resource> resources)
{
this.resources = resources;
}

public Resource( String path )
{
this.path( path );
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void onLoadGeneratorStart( LoadGenerator loadGenerator )
{
// we initialize Maps to avoid concurrent issues
recorderPerPath = new ConcurrentHashMap<>();
initializeMap( recorderPerPath, loadGenerator.getProfile().getResources() );
initializeMap( recorderPerPath, loadGenerator.getResource().getResources() );
}

private void initializeMap( Map<String, Recorder> recorderMap, List<Resource> resources )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ public void onLoadGeneratorStart( LoadGenerator loadGenerator )
{
// we initialize Maps to avoid concurrent issues
responseTimePerPath = new ConcurrentHashMap<>();
initializeMap( responseTimePerPath, loadGenerator.getProfile().getResources() );
initializeMap( responseTimePerPath, loadGenerator.getResource().getResources() );
latencyTimePerPath = new ConcurrentHashMap<>();
initializeMap( latencyTimePerPath, loadGenerator.getProfile().getResources() );
initializeMap( latencyTimePerPath, loadGenerator.getResource().getResources() );
}

private void initializeMap( Map<String, Recorder> recorderMap, List<Resource> resources )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
import org.mortbay.jetty.load.generator.latency.LatencyTimeDisplayListener;
import org.mortbay.jetty.load.generator.latency.LatencyTimeListener;
import org.mortbay.jetty.load.generator.profile.Resource;
import org.mortbay.jetty.load.generator.profile.ResourceProfile;
import org.mortbay.jetty.load.generator.responsetime.ResponseTimeDisplayListener;
import org.mortbay.jetty.load.generator.responsetime.ResponseTimeListener;
import org.mortbay.jetty.load.generator.responsetime.TimePerPathListener;
Expand Down Expand Up @@ -214,7 +213,7 @@ protected List<LatencyTimeListener> getLatencyTimeListeners()
return Arrays.asList( new LatencyTimeDisplayListener(), new TimePerPathListener() );
}

protected LoadGenerator build( ResourceProfile profile )
protected LoadGenerator build( Resource profile )
throws Exception
{

Expand All @@ -236,7 +235,7 @@ protected LoadGenerator build( ResourceProfile profile )
.transport( this.transport ) //
.httpClientTransport( this.httpClientTransport() ) //
.sslContextFactory( sslContextFactory ) //
.loadProfile( profile ) //
.resource( profile ) //
.responseTimeListeners(
responseTimeListeners.toArray( new ResponseTimeListener[responseTimeListeners.size()] ) ) //
.latencyTimeListeners(
Expand All @@ -257,7 +256,7 @@ protected void enhanceLoadGenerator( LoadGenerator loadGenerator )
// no op
}

protected void runProfile( ResourceProfile profile )
protected void runResource( Resource profile )
throws Exception
{

Expand Down Expand Up @@ -292,7 +291,7 @@ protected void runProfile( ResourceProfile profile )

}

private Collection<String> paths( ResourceProfile profile )
private Collection<String> paths( Resource profile )
{
Set<String> paths = new HashSet<>();

Expand All @@ -304,17 +303,6 @@ private Collection<String> paths( ResourceProfile profile )
return paths;
}

private Collection<String> paths( Resource resource )
{
Set<String> paths = new HashSet<>();
paths.add( resource.getPath() );
for ( Resource child : resource.getResources() )
{
paths.addAll( paths( child ) );
}
return paths;
}


public String currentTestRunInfos()
{
Expand Down
Loading

0 comments on commit bbc1579

Please sign in to comment.