From a2731cd5e3fdcd825d6334b30dc5b460c83e09b5 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Fri, 28 Jul 2017 18:34:21 +0200 Subject: [PATCH] Fixes #18 - LoadGeneratorStarter should ignore unknown options. --- .../starter/LoadGeneratorStarter.java | 40 +++++++++++-------- .../starter/LoadGeneratorStarterArgs.java | 9 ++--- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/jetty-load-generator-starter/src/main/java/org/mortbay/jetty/load/generator/starter/LoadGeneratorStarter.java b/jetty-load-generator-starter/src/main/java/org/mortbay/jetty/load/generator/starter/LoadGeneratorStarter.java index 2775bd1a..fcbb35b7 100644 --- a/jetty-load-generator-starter/src/main/java/org/mortbay/jetty/load/generator/starter/LoadGeneratorStarter.java +++ b/jetty-load-generator-starter/src/main/java/org/mortbay/jetty/load/generator/starter/LoadGeneratorStarter.java @@ -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; @@ -49,7 +49,9 @@ 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; @@ -57,21 +59,25 @@ public static LoadGeneratorStarterArgs parse(String[] args) { 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) { diff --git a/jetty-load-generator-starter/src/main/java/org/mortbay/jetty/load/generator/starter/LoadGeneratorStarterArgs.java b/jetty-load-generator-starter/src/main/java/org/mortbay/jetty/load/generator/starter/LoadGeneratorStarterArgs.java index 1971042f..5219e89e 100644 --- a/jetty-load-generator-starter/src/main/java/org/mortbay/jetty/load/generator/starter/LoadGeneratorStarterArgs.java +++ b/jetty-load-generator-starter/src/main/java/org/mortbay/jetty/load/generator/starter/LoadGeneratorStarterArgs.java @@ -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; @@ -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) { @@ -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 context) throws Exception { + public static Resource evaluateGroovy(Reader script, Map context) { CompilerConfiguration config = new CompilerConfiguration(CompilerConfiguration.DEFAULT); config.setDebug(true); config.setVerbose(true);