diff options
Diffstat (limited to 'vespaclient-java')
-rw-r--r-- | vespaclient-java/src/main/java/com/yahoo/vespaget/CommandLineOptions.java | 26 | ||||
-rw-r--r-- | vespaclient-java/src/test/java/com/yahoo/vespaget/CommandLineOptionsTest.java | 12 |
2 files changed, 28 insertions, 10 deletions
diff --git a/vespaclient-java/src/main/java/com/yahoo/vespaget/CommandLineOptions.java b/vespaclient-java/src/main/java/com/yahoo/vespaget/CommandLineOptions.java index 518eddfd021..aa53bb408de 100644 --- a/vespaclient-java/src/main/java/com/yahoo/vespaget/CommandLineOptions.java +++ b/vespaclient-java/src/main/java/com/yahoo/vespaget/CommandLineOptions.java @@ -123,8 +123,7 @@ public class CommandLineOptions { .hasArg(true) .desc("Priority (default 6).") .longOpt(PRIORITY_OPTION) - .argName("priority") - .type(Number.class).build()); + .argName("priority").build()); options.addOption(Option.builder("l") .hasArg(true) @@ -257,18 +256,25 @@ public class CommandLineOptions { } private static DocumentProtocol.Priority getPriority(CommandLine cl) throws ParseException { - Number priorityObj = (Number) cl.getParsedOptionValue(PRIORITY_OPTION); - int priorityNumber = priorityObj != null ? priorityObj.intValue() : DocumentProtocol.Priority.NORMAL_2.getValue(); - return parsePriority(priorityNumber); + String priority = cl.getOptionValue(PRIORITY_OPTION, "NORMAL_2"); + return parsePriority(priority); } - private static DocumentProtocol.Priority parsePriority(int n) { - for (DocumentProtocol.Priority priority : DocumentProtocol.Priority.values()) { - if (priority.getValue() == n) { - return priority; + private static DocumentProtocol.Priority parsePriority(String name) { + try { + return DocumentProtocol.Priority.valueOf(name); + } catch (IllegalArgumentException e) { + } + try { + int n = Integer.parseInt(name); + for (DocumentProtocol.Priority priority : DocumentProtocol.Priority.values()) { + if (priority.getValue() == n) { + return priority; + } } + } catch (NumberFormatException e) { } - throw new IllegalArgumentException("Invalid priority: " + n); + throw new IllegalArgumentException("Invalid priority: " + name); } } diff --git a/vespaclient-java/src/test/java/com/yahoo/vespaget/CommandLineOptionsTest.java b/vespaclient-java/src/test/java/com/yahoo/vespaget/CommandLineOptionsTest.java index 0a0b4290cc1..05f8964e516 100644 --- a/vespaclient-java/src/test/java/com/yahoo/vespaget/CommandLineOptionsTest.java +++ b/vespaclient-java/src/test/java/com/yahoo/vespaget/CommandLineOptionsTest.java @@ -124,6 +124,18 @@ public class CommandLineOptionsTest { } @Test + public void TestHighestPriority() { + ClientParameters params = getParsedOptions("--priority", "HIGHEST"); + assertEquals(DocumentProtocol.Priority.HIGHEST, params.priority); + } + + @Test + public void TestHigh1PriorityAsNumber() { + ClientParameters params = getParsedOptions("--priority", "2"); + assertEquals(DocumentProtocol.Priority.HIGH_1, params.priority); + } + + @Test public void testInvalidTraceLevel1() { exception.expect(IllegalArgumentException.class); exception.expectMessage("Invalid tracelevel: -1"); |