Skip to content

Commit

Permalink
Fixes #18 - LoadGeneratorStarter should ignore unknown options.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbordet committed Jul 28, 2017
1 parent 6ca0e05 commit a2731cd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
public class LoadGeneratorStarter {
private static final Logger LOGGER = Log.getLogger(LoadGeneratorStarter.class);

public static void main(String[] args) throws Exception {
public static void main(String[] args) {
LoadGeneratorStarterArgs starterArgs = parse(args);
if (starterArgs == null) {
return;
Expand All @@ -49,29 +49,35 @@ public static void main(String[] args) throws Exception {

public static LoadGeneratorStarterArgs parse(String[] args) {
LoadGeneratorStarterArgs starterArgs = new LoadGeneratorStarterArgs();
JCommander jCommander = new JCommander(starterArgs, args);
JCommander jCommander = new JCommander(starterArgs);
jCommander.setAcceptUnknownOptions(true);
jCommander.parse(args);
if (starterArgs.isHelp()) {
jCommander.usage();
return null;
}
return starterArgs;
}

public static LoadGenerator.Builder prepare(LoadGeneratorStarterArgs starterArgs) throws Exception {
LoadGenerator.Builder builder = new LoadGenerator.Builder();
return builder.threads(starterArgs.getThreads())
.warmupIterationsPerThread(starterArgs.getWarmupIterations())
.iterationsPerThread(starterArgs.getIterations())
.usersPerThread(starterArgs.getUsers())
.channelsPerUser(starterArgs.getChannelsPerUser())
.resource(starterArgs.getResource(builder))
.resourceRate(starterArgs.getResourceRate())
.httpClientTransportBuilder(starterArgs.getHttpClientTransportBuilder())
.sslContextFactory(new SslContextFactory())
.scheme(starterArgs.getScheme())
.host(starterArgs.getHost())
.port(starterArgs.getPort())
.maxRequestsQueued(starterArgs.getMaxRequestsQueued());
public static LoadGenerator.Builder prepare(LoadGeneratorStarterArgs starterArgs) {
try {
LoadGenerator.Builder builder = new LoadGenerator.Builder();
return builder.threads(starterArgs.getThreads())
.warmupIterationsPerThread(starterArgs.getWarmupIterations())
.iterationsPerThread(starterArgs.getIterations())
.usersPerThread(starterArgs.getUsers())
.channelsPerUser(starterArgs.getChannelsPerUser())
.resource(starterArgs.getResource(builder))
.resourceRate(starterArgs.getResourceRate())
.httpClientTransportBuilder(starterArgs.getHttpClientTransportBuilder())
.sslContextFactory(new SslContextFactory())
.scheme(starterArgs.getScheme())
.host(starterArgs.getHost())
.port(starterArgs.getPort())
.maxRequestsQueued(starterArgs.getMaxRequestsQueued());
} catch (Exception x) {
throw new RuntimeException(x);
}
}

public static void run(LoadGenerator.Builder builder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.mortbay.jetty.load.generator.starter;

import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.nio.file.Files;
Expand Down Expand Up @@ -295,9 +296,7 @@ public Resource getResource(LoadGenerator.Builder builder) throws Exception {
String jsonPath = getResourceJSONPath();
if (jsonPath != null) {
Path path = Paths.get(jsonPath);
if (Files.exists(path)) {
return evaluateJSON(path);
}
return evaluateJSON(path);
}
String xmlPath = getResourceXMLPath();
if (xmlPath != null) {
Expand All @@ -318,13 +317,13 @@ public Resource getResource(LoadGenerator.Builder builder) throws Exception {
throw new IllegalArgumentException("resource not defined");
}

public static Resource evaluateJSON(Path profilePath) throws Exception {
public static Resource evaluateJSON(Path profilePath) throws IOException {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
return objectMapper.readValue(profilePath.toFile(), Resource.class);
}

public static Resource evaluateGroovy(Reader script, Map<String, Object> context) throws Exception {
public static Resource evaluateGroovy(Reader script, Map<String, Object> context) {
CompilerConfiguration config = new CompilerConfiguration(CompilerConfiguration.DEFAULT);
config.setDebug(true);
config.setVerbose(true);
Expand Down

0 comments on commit a2731cd

Please sign in to comment.