aboutsummaryrefslogtreecommitdiffstats
path: root/vespa-feed-client-cli
diff options
context:
space:
mode:
authorjonmv <venstad@gmail.com>2023-01-04 08:53:57 +0100
committerjonmv <venstad@gmail.com>2023-01-04 08:53:57 +0100
commiteb0bf8c5bb18ad89ba03d290c6cedc6773b321bc (patch)
treefb27b08113e31c46015659d89eae0d92230b5711 /vespa-feed-client-cli
parentc9746a990c0daf8103dc7a09ab0d80ee87565a3b (diff)
Use --compression gzip instead
Diffstat (limited to 'vespa-feed-client-cli')
-rw-r--r--vespa-feed-client-cli/src/main/java/ai/vespa/feed/client/impl/CliArguments.java20
-rw-r--r--vespa-feed-client-cli/src/main/java/ai/vespa/feed/client/impl/CliClient.java2
-rw-r--r--vespa-feed-client-cli/src/test/java/ai/vespa/feed/client/impl/CliArgumentsTest.java42
-rw-r--r--vespa-feed-client-cli/src/test/resources/help.txt5
4 files changed, 49 insertions, 20 deletions
diff --git a/vespa-feed-client-cli/src/main/java/ai/vespa/feed/client/impl/CliArguments.java b/vespa-feed-client-cli/src/main/java/ai/vespa/feed/client/impl/CliArguments.java
index f827c2b64ca..42f9713c54e 100644
--- a/vespa-feed-client-cli/src/main/java/ai/vespa/feed/client/impl/CliArguments.java
+++ b/vespa-feed-client-cli/src/main/java/ai/vespa/feed/client/impl/CliArguments.java
@@ -1,6 +1,7 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package ai.vespa.feed.client.impl;
+import ai.vespa.feed.client.FeedClientBuilder.Compression;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
@@ -24,6 +25,8 @@ import java.util.Optional;
import java.util.OptionalDouble;
import java.util.OptionalInt;
+import static ai.vespa.feed.client.FeedClientBuilder.Compression.none;
+
/**
* Parses command line arguments
*
@@ -58,7 +61,7 @@ class CliArguments {
private static final String STDIN_OPTION = "stdin";
private static final String DOOM_OPTION = "max-failure-seconds";
private static final String PROXY_OPTION = "proxy";
- private static final String GZIP_REQUESTS_OPTION = "gzip-requests";
+ private static final String COMPRESSION = "compression";
private final CommandLine arguments;
@@ -182,7 +185,14 @@ class CliArguments {
boolean speedTest() { return has(SPEED_TEST_OPTION); }
- boolean gzipRequests() { return has(GZIP_REQUESTS_OPTION); }
+ Compression compression() throws CliArgumentsException {
+ try {
+ return stringValue(COMPRESSION).map(Compression::valueOf).orElse(none);
+ }
+ catch (IllegalArgumentException e) {
+ throw new CliArgumentsException("Invalid " + COMPRESSION + " argument: " + e.getMessage(), e);
+ }
+ }
OptionalInt testPayloadSize() throws CliArgumentsException { return intValue(TEST_PAYLOAD_SIZE_OPTION); }
@@ -359,8 +369,10 @@ class CliArguments {
.type(URL.class)
.build())
.addOption(Option.builder()
- .longOpt(GZIP_REQUESTS_OPTION)
- .desc("Compress request bodies with gzip")
+ .longOpt(COMPRESSION)
+ .desc("Compression mode for feed requests: 'none' (default), 'gzip'")
+ .hasArg()
+ .type(Compression.class)
.build());
}
diff --git a/vespa-feed-client-cli/src/main/java/ai/vespa/feed/client/impl/CliClient.java b/vespa-feed-client-cli/src/main/java/ai/vespa/feed/client/impl/CliClient.java
index 6b5e41a6b36..39462d8ba68 100644
--- a/vespa-feed-client-cli/src/main/java/ai/vespa/feed/client/impl/CliClient.java
+++ b/vespa-feed-client-cli/src/main/java/ai/vespa/feed/client/impl/CliClient.java
@@ -159,7 +159,7 @@ public class CliClient {
cliArgs.headers().forEach(builder::addRequestHeader);
builder.setDryrun(cliArgs.dryrunEnabled());
builder.setSpeedTest(cliArgs.speedTest());
- builder.setGzipRequests(cliArgs.gzipRequests());
+ builder.setCompression(cliArgs.compression());
cliArgs.doomSeconds().ifPresent(doom -> builder.setCircuitBreaker(new GracePeriodCircuitBreaker(Duration.ofSeconds(10),
Duration.ofSeconds(doom))));
cliArgs.proxy().ifPresent(builder::setProxy);
diff --git a/vespa-feed-client-cli/src/test/java/ai/vespa/feed/client/impl/CliArgumentsTest.java b/vespa-feed-client-cli/src/test/java/ai/vespa/feed/client/impl/CliArgumentsTest.java
index dcfa96d5531..21e279b0584 100644
--- a/vespa-feed-client-cli/src/test/java/ai/vespa/feed/client/impl/CliArgumentsTest.java
+++ b/vespa-feed-client-cli/src/test/java/ai/vespa/feed/client/impl/CliArgumentsTest.java
@@ -1,6 +1,7 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package ai.vespa.feed.client.impl;
+import ai.vespa.feed.client.FeedClientBuilder.Compression;
import ai.vespa.feed.client.impl.CliArguments.CliArgumentsException;
import org.junit.jupiter.api.Test;
@@ -24,12 +25,27 @@ class CliArgumentsTest {
@Test
void parses_parameters_correctly() throws CliArguments.CliArgumentsException {
CliArguments args = CliArguments.fromRawArgs(new String[]{
- "--endpoint=https://vespa.ai:4443/", "--file=feed.json", "--connections=10",
- "--max-streams-per-connection=128", "--certificate=cert.pem", "--private-key=key.pem",
- "--ca-certificates=ca-certs.pem", "--disable-ssl-hostname-verification",
- "--header=\"My-Header: my-value\"", "--header", "Another-Header: another-value", "--benchmark",
- "--route=myroute", "--timeout=0.125", "--trace=9", "--verbose", "--silent", "--gzip-requests",
- "--show-errors", "--show-all", "--max-failure-seconds=30", "--proxy", "https://myproxy:1234"});
+ "--endpoint", "https://vespa.ai:4443/",
+ "--file", "feed.json",
+ "--connections", "10",
+ "--max-streams-per-connection", "128",
+ "--certificate", "cert.pem",
+ "--private-key", "key.pem",
+ "--ca-certificates", "ca-certs.pem",
+ "--disable-ssl-hostname-verification",
+ "--header", "\"My-Header: my-value\"",
+ "--header", "Another-Header: another-value",
+ "--benchmark",
+ "--route", "myroute",
+ "--timeout", "0.125",
+ "--trace", "9",
+ "--verbose",
+ "--silent",
+ "--compression", "gzip",
+ "--show-errors",
+ "--show-all",
+ "--max-failure-seconds", "30",
+ "--proxy", "https://myproxy:1234"});
assertEquals(URI.create("https://vespa.ai:4443/"), args.endpoint());
assertEquals(Paths.get("feed.json"), args.inputFile().get());
assertEquals(10, args.connections().getAsInt());
@@ -52,15 +68,15 @@ class CliArgumentsTest {
assertTrue(args.showErrors());
assertTrue(args.showSuccesses());
assertFalse(args.showProgress());
- assertTrue(args.gzipRequests());
+ assertEquals(Compression.gzip, args.compression());
assertEquals(URI.create("https://myproxy:1234"), args.proxy().orElse(null));
}
@Test
void fails_on_missing_parameters() {
- CliArguments.CliArgumentsException exception = assertThrows(
+ CliArguments.CliArgumentsException exception = assertThrows(
CliArguments.CliArgumentsException.class,
- () -> CliArguments.fromRawArgs(new String[] {"--file=/path/to/file", "--stdin"}));
+ () -> CliArguments.fromRawArgs(new String[] {"--file", "/path/to/file", "--stdin"}));
assertEquals("Endpoint must be specified", exception.getMessage());
}
@@ -68,20 +84,20 @@ class CliArgumentsTest {
void fails_on_conflicting_parameters() throws CliArgumentsException {
assertEquals("Exactly one of 'file' and 'stdin' must be specified",
assertThrows(CliArgumentsException.class,
- () -> CliArguments.fromRawArgs(new String[] {"--endpoint=https://endpoint", "--file=/path/to/file", "--stdin"}))
+ () -> CliArguments.fromRawArgs(new String[] {"--endpoint", "https://endpoint", "--file", "/path/to/file", "--stdin"}))
.getMessage());
assertEquals("Exactly one of 'file' and 'stdin' must be specified",
assertThrows(CliArgumentsException.class,
- () -> CliArguments.fromRawArgs(new String[] {"--endpoint=https://endpoint"}))
+ () -> CliArguments.fromRawArgs(new String[] {"--endpoint", "https://endpoint"}))
.getMessage());
assertEquals("At most one of 'file', 'stdin' and 'test-payload-size' may be specified",
assertThrows(CliArgumentsException.class,
- () -> CliArguments.fromRawArgs(new String[] {"--endpoint=https://endpoint", "--speed-test", "--test-payload-size=123", "--file=file"}))
+ () -> CliArguments.fromRawArgs(new String[] {"--endpoint", "https://endpoint", "--speed-test", "--test-payload-size", "123", "--file", "file"}))
.getMessage());
- CliArguments.fromRawArgs(new String[] {"--endpoint=foo", "--speed-test"});
+ CliArguments.fromRawArgs(new String[] {"--endpoint", "foo", "--speed-test"});
}
@Test
diff --git a/vespa-feed-client-cli/src/test/resources/help.txt b/vespa-feed-client-cli/src/test/resources/help.txt
index 63e4adf0d7d..f33dde82f7b 100644
--- a/vespa-feed-client-cli/src/test/resources/help.txt
+++ b/vespa-feed-client-cli/src/test/resources/help.txt
@@ -6,6 +6,9 @@ Vespa feed client
certificates encoded as PEM
--certificate <arg> Path to PEM encoded X.509
certificate file
+ --compression <arg> Compression mode for feed
+ requests: 'none' (default),
+ 'gzip'
--connections <arg> Number of concurrent HTTP/2
connections
--disable-ssl-hostname-verification Disable SSL hostname
@@ -15,8 +18,6 @@ Vespa feed client
across the network
--endpoint <arg> URI to feed endpoint
--file <arg> Path to feed file in JSON format
- --gzip-requests Compress request bodies with
- gzip
--header <arg> HTTP header on the form 'Name:
value'
--help