summaryrefslogtreecommitdiffstats
path: root/vespa-http-client/src
diff options
context:
space:
mode:
authorHarald Musum <musum@verizonmedia.com>2019-03-22 19:54:58 +0100
committerAndreas Eriksen <andreer@pvv.ntnu.no>2019-03-22 19:54:58 +0100
commit9379e425712abe71fcd2f406c139baf25a017108 (patch)
tree523592ac614c4c5ea8dfdc4abb06d07faae3f87e /vespa-http-client/src
parenta62e538f10f8d92af21de38000f97aea6ca7a500 (diff)
Revert "Bratseth/remove dependencies" (#8885)
Diffstat (limited to 'vespa-http-client/src')
-rw-r--r--vespa-http-client/src/main/java/com/yahoo/vespa/http/client/FeedClient.java3
-rw-r--r--vespa-http-client/src/main/java/com/yahoo/vespa/http/client/Result.java2
-rw-r--r--vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/Cluster.java3
-rw-r--r--vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/ConnectionParams.java2
-rw-r--r--vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/Endpoint.java3
-rw-r--r--vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/FeedParams.java2
-rw-r--r--vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/SessionParams.java3
-rw-r--r--vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/package-info.java8
-rw-r--r--vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/ApacheGatewayConnection.java5
-rw-r--r--vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/Vtag.java7
-rw-r--r--vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/package-info.java1
-rw-r--r--vespa-http-client/src/main/java/com/yahoo/vespa/http/client/package-info.java10
-rw-r--r--vespa-http-client/src/main/java/com/yahoo/vespa/http/client/runner/package-info.java1
-rw-r--r--vespa-http-client/src/test/java/com/yahoo/vespa/http/client/JsonTestHelper.java52
-rw-r--r--vespa-http-client/src/test/java/com/yahoo/vespa/http/client/core/operationProcessor/IncompleteResultsThrottlerTest.java128
-rw-r--r--vespa-http-client/src/test/java/com/yahoo/vespa/http/client/runner/JsonReaderTest.java2
16 files changed, 86 insertions, 146 deletions
diff --git a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/FeedClient.java b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/FeedClient.java
index 433fee69e4e..e800fbea584 100644
--- a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/FeedClient.java
+++ b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/FeedClient.java
@@ -14,10 +14,9 @@ import java.util.concurrent.atomic.AtomicInteger;
*
* A {@link FeedClientFactory} is provided to instantiate Sessions.
*
- * See com.yahoo.text.Text.stripInvalidCharacters(String) to remove invalid characters from string fields before feeding
- *
* @author dybis
* @see FeedClientFactory
+ * @see com.yahoo.text.Text#stripInvalidCharacters(String) to remove invalid characters from string fields before feeding
*/
public interface FeedClient extends AutoCloseable {
diff --git a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/Result.java b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/Result.java
index 821e12b4140..92dd0715f06 100644
--- a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/Result.java
+++ b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/Result.java
@@ -4,6 +4,7 @@ package com.yahoo.vespa.http.client;
import com.yahoo.vespa.http.client.config.Endpoint;
import com.yahoo.vespa.http.client.core.Document;
import com.yahoo.vespa.http.client.core.Exceptions;
+import net.jcip.annotations.Immutable;
import java.util.ArrayList;
import java.util.Collection;
@@ -82,6 +83,7 @@ public class Result {
/**
* Information in a Result for a single operation sent to a single endpoint.
*/
+ @Immutable
public static final class Detail {
private final ResultType resultType;
diff --git a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/Cluster.java b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/Cluster.java
index 4707cdb705c..557aeedb4c1 100644
--- a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/Cluster.java
+++ b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/Cluster.java
@@ -1,6 +1,8 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.http.client.config;
+import net.jcip.annotations.Immutable;
+
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
@@ -11,6 +13,7 @@ import java.util.List;
*
* @author Einar M R Rosenvinge
*/
+@Immutable
public final class Cluster {
/**
diff --git a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/ConnectionParams.java b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/ConnectionParams.java
index 3296cf13875..3747f37eb00 100644
--- a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/ConnectionParams.java
+++ b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/ConnectionParams.java
@@ -4,6 +4,7 @@ package com.yahoo.vespa.http.client.config;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
+import net.jcip.annotations.Immutable;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import javax.net.ssl.HostnameVerifier;
@@ -25,6 +26,7 @@ import java.util.concurrent.TimeUnit;
*
* @author Einar M R Rosenvinge
*/
+@Immutable
public final class ConnectionParams {
/**
diff --git a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/Endpoint.java b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/Endpoint.java
index 7ba6dd04a80..de7bfb5bb19 100644
--- a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/Endpoint.java
+++ b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/Endpoint.java
@@ -1,6 +1,8 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.http.client.config;
+import net.jcip.annotations.Immutable;
+
import java.io.Serializable;
/**
@@ -9,6 +11,7 @@ import java.io.Serializable;
*
* @author Einar M R Rosenvinge
*/
+@Immutable
public final class Endpoint implements Serializable {
/**
diff --git a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/FeedParams.java b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/FeedParams.java
index 30f1ad11d3a..4adf3912dbd 100644
--- a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/FeedParams.java
+++ b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/FeedParams.java
@@ -2,6 +2,7 @@
package com.yahoo.vespa.http.client.config;
import com.google.common.annotations.Beta;
+import net.jcip.annotations.Immutable;
import java.util.concurrent.TimeUnit;
@@ -12,6 +13,7 @@ import java.util.concurrent.TimeUnit;
* @author Einar M R Rosenvinge
*/
+@Immutable
public final class FeedParams {
public boolean getDenyIfBusyV3() {
diff --git a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/SessionParams.java b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/SessionParams.java
index daa6eecb823..eb3e8ec982b 100644
--- a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/SessionParams.java
+++ b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/SessionParams.java
@@ -1,6 +1,8 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.http.client.config;
+import net.jcip.annotations.Immutable;
+
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -16,6 +18,7 @@ import java.util.List;
* @see com.yahoo.vespa.http.client.SessionFactory
* @see Builder
*/
+@Immutable
public final class SessionParams {
/**
diff --git a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/package-info.java b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/package-info.java
index 8300720e3ea..17789e890d6 100644
--- a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/package-info.java
+++ b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/package-info.java
@@ -1,8 +1,10 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
/**
* Settings for creating clients/sessions.
- *
- * NOTE: This is a PUBLIC API, but not annotated as such because this is not a bundle and
- * we don't want to introduce Vespa dependencies.
*/
+@ExportPackage
+@PublicApi
package com.yahoo.vespa.http.client.config;
+
+import com.yahoo.api.annotations.PublicApi;
+import com.yahoo.osgi.annotation.ExportPackage;
diff --git a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/ApacheGatewayConnection.java b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/ApacheGatewayConnection.java
index 4468355698f..fd228fb99c5 100644
--- a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/ApacheGatewayConnection.java
+++ b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/ApacheGatewayConnection.java
@@ -3,6 +3,7 @@ package com.yahoo.vespa.http.client.core.communication;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.yahoo.component.Vtag;
import com.yahoo.vespa.http.client.config.ConnectionParams;
import com.yahoo.vespa.http.client.config.Endpoint;
import com.yahoo.vespa.http.client.config.FeedParams;
@@ -411,8 +412,8 @@ class ApacheGatewayConnection implements GatewayConnection {
clientBuilder.setConnectionManager(connMgr);
}
- clientBuilder.setUserAgent(String.format("vespa-http-client (%s)", Vtag.currentVersion));
- clientBuilder.setDefaultHeaders(List.of(new BasicHeader(Headers.CLIENT_VERSION, Vtag.currentVersion)));
+ clientBuilder.setUserAgent(String.format("vespa-http-client (%s)", Vtag.currentVersion.toFullString()));
+ clientBuilder.setDefaultHeaders(List.of(new BasicHeader(Headers.CLIENT_VERSION, Vtag.currentVersion.toFullString())));
clientBuilder.setMaxConnPerRoute(1);
clientBuilder.setMaxConnTotal(1);
clientBuilder.disableContentCompression();
diff --git a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/Vtag.java b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/Vtag.java
deleted file mode 100644
index f21a86dfc1b..00000000000
--- a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/Vtag.java
+++ /dev/null
@@ -1,7 +0,0 @@
-// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-package com.yahoo.vespa.http.client.core.communication;
-
-class Vtag {
- static final String currentVersion = "7.0.0";
-}
diff --git a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/package-info.java b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/package-info.java
index 211397476bd..56bd3e5cf99 100644
--- a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/package-info.java
+++ b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/package-info.java
@@ -1,2 +1,3 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+@com.yahoo.api.annotations.PackageMarker
package com.yahoo.vespa.http.client.core;
diff --git a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/package-info.java b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/package-info.java
index b14c2ffa4cc..bd828363702 100644
--- a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/package-info.java
+++ b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/package-info.java
@@ -5,8 +5,10 @@
* is the central interface which is used to interact with a cluster.
* Use {@link com.yahoo.vespa.http.client.SessionFactory} to
* instantiate a {@link com.yahoo.vespa.http.client.Session}.
- *
- * NOTE: This is a PUBLIC API, but not annotated as such because this is not a bundle and
- * we don't want to introduce Vespa dependencies.
- */
+ **/
+@ExportPackage
+@PublicApi
package com.yahoo.vespa.http.client;
+
+import com.yahoo.api.annotations.PublicApi;
+import com.yahoo.osgi.annotation.ExportPackage;
diff --git a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/runner/package-info.java b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/runner/package-info.java
index 00012f0f52f..506273cc6cd 100644
--- a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/runner/package-info.java
+++ b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/runner/package-info.java
@@ -1,2 +1,3 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+@com.yahoo.api.annotations.PackageMarker
package com.yahoo.vespa.http.client.runner;
diff --git a/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/JsonTestHelper.java b/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/JsonTestHelper.java
deleted file mode 100644
index 0081497fb20..00000000000
--- a/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/JsonTestHelper.java
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.vespa.http.client;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.google.common.base.Joiner;
-import org.hamcrest.MatcherAssert;
-
-import static uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs;
-
-import java.io.UncheckedIOException;
-
-public class JsonTestHelper {
-
- private static final ObjectMapper mapper = new ObjectMapper();
-
- /**
- * Convenience method to input JSON without escaping double quotes and newlines
- * Each parameter represents a line of JSON encoded data
- * The lines are joined with newline and single quotes are replaced with double quotes
- */
- public static String inputJson(String... lines) {
- return Joiner.on("\n").join(lines).replaceAll("'", "\"");
- }
-
- /** Structurally compare two JSON encoded strings */
- public static void assertJsonEquals(String inputJson, String expectedJson) {
- MatcherAssert.assertThat(inputJson, sameJSONAs(expectedJson));
- }
-
- /** Structurally compare a {@link JsonNode} and a JSON string. */
- public static void assertJsonEquals(JsonNode left, String rightJson) {
- try {
- String leftJson = mapper.writeValueAsString(left);
- assertJsonEquals(leftJson, rightJson);
- } catch (JsonProcessingException e) {
- throw new UncheckedIOException(e);
- }
- }
-
- /** Structurally compare two {@link JsonNode}s. */
- public static void assertJsonEquals(JsonNode left, JsonNode right) {
- try {
- String leftJson = mapper.writeValueAsString(left);
- String rightJson = mapper.writeValueAsString(right);
- assertJsonEquals(leftJson, rightJson);
- } catch (JsonProcessingException e) {
- throw new UncheckedIOException(e);
- }
- }
-}
diff --git a/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/core/operationProcessor/IncompleteResultsThrottlerTest.java b/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/core/operationProcessor/IncompleteResultsThrottlerTest.java
index 1267514b0d8..47aeb4d3b0f 100644
--- a/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/core/operationProcessor/IncompleteResultsThrottlerTest.java
+++ b/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/core/operationProcessor/IncompleteResultsThrottlerTest.java
@@ -1,7 +1,9 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.http.client.core.operationProcessor;
+import com.yahoo.collections.Tuple2;
import com.yahoo.vespa.http.client.core.ThrottlePolicy;
+import com.yahoo.vespa.http.client.core.operationProcessor.IncompleteResultsThrottler;
import org.junit.Test;
import java.util.ArrayList;
@@ -33,6 +35,57 @@ public class IncompleteResultsThrottlerTest {
}
/**
+ * A mock 'gateway' this is slower with more requests in-flight. It starts to become really much slower at
+ * 'breakPoint' number of parallel requests.
+ */
+ class MockServer {
+ final LinkedList<Tuple2<Long, IncompleteResultsThrottler> > messageDoneByTime = new LinkedList<>();
+ final int breakPoint;
+ final Random random = new Random();
+ long time = 0;
+
+ MockServer(int breakPoint) {
+ this.breakPoint = breakPoint;
+ }
+
+ /**
+ * Figures out when next processed data will be ready.
+ * @return time in ms for next request to be finished.
+ */
+ long nextRequestFinished() {
+ if (messageDoneByTime.isEmpty()) {
+ return Integer.MAX_VALUE;
+ }
+ return messageDoneByTime.peek().first;
+ }
+
+ /**
+ * Advance simulation time and call finished on any requests.
+ * @param time to move to
+ */
+ void moveTime(long time) {
+ this.time = time;
+ while (!messageDoneByTime.isEmpty() && messageDoneByTime.peek().first <= time) {
+ messageDoneByTime.pop().second.resultReady(true);
+ }
+ }
+
+ /**
+ * New request.
+ * @param blocker do callback on blocker when request is done.
+ */
+ void newRequest(IncompleteResultsThrottler blocker) {
+ long nextTime = (long)(20 + 0.1 * messageDoneByTime.size());
+
+ if (messageDoneByTime.size() > breakPoint) {
+ nextTime += (long) (40 + (random.nextDouble()) * 0.01 * messageDoneByTime.size()* messageDoneByTime.size());
+ }
+ nextTime += time + random.nextInt()%4;
+ messageDoneByTime.push(new Tuple2<>(nextTime, blocker));
+ }
+ }
+
+ /**
* Simulate running requests.
* @param clientCount number of parallel clients.
* @param breakPoint how many requests the server should handle in parallel before it gets slower.
@@ -214,79 +267,4 @@ public class IncompleteResultsThrottlerTest {
int distance = Math.abs(sweetSpot - size);
return 1 + 20 * distance;
}
-
- /**
- * A mock 'gateway' this is slower with more requests in-flight. It starts to become really much slower at
- * 'breakPoint' number of parallel requests.
- */
- class MockServer {
- final LinkedList<Tuple2<Long, IncompleteResultsThrottler> > messageDoneByTime = new LinkedList<>();
- final int breakPoint;
- final Random random = new Random();
- long time = 0;
-
- MockServer(int breakPoint) {
- this.breakPoint = breakPoint;
- }
-
- /**
- * Figures out when next processed data will be ready.
- * @return time in ms for next request to be finished.
- */
- long nextRequestFinished() {
- if (messageDoneByTime.isEmpty()) {
- return Integer.MAX_VALUE;
- }
- return messageDoneByTime.peek().first;
- }
-
- /**
- * Advance simulation time and call finished on any requests.
- * @param time to move to
- */
- void moveTime(long time) {
- this.time = time;
- while (!messageDoneByTime.isEmpty() && messageDoneByTime.peek().first <= time) {
- messageDoneByTime.pop().second.resultReady(true);
- }
- }
-
- /**
- * New request.
- * @param blocker do callback on blocker when request is done.
- */
- void newRequest(IncompleteResultsThrottler blocker) {
- long nextTime = (long)(20 + 0.1 * messageDoneByTime.size());
-
- if (messageDoneByTime.size() > breakPoint) {
- nextTime += (long) (40 + (random.nextDouble()) * 0.01 * messageDoneByTime.size()* messageDoneByTime.size());
- }
- nextTime += time + random.nextInt()%4;
- messageDoneByTime.push(new Tuple2<>(nextTime, blocker));
- }
- }
-
- private static class Tuple2<T1, T2> {
-
- public final T1 first;
- public final T2 second;
-
- public Tuple2(final T1 first, final T2 second) {
- this.first = first;
- this.second = second;
- }
-
- @Override
- public int hashCode() { throw new UnsupportedOperationException(); }
-
- @Override
- public boolean equals(final Object obj) { throw new UnsupportedOperationException(); }
-
- @Override
- public String toString() {
- return "Tuple2(" + first + ", " + second + ")";
- }
-
- }
-
}
diff --git a/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/runner/JsonReaderTest.java b/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/runner/JsonReaderTest.java
index e2046fe17a6..134274ff869 100644
--- a/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/runner/JsonReaderTest.java
+++ b/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/runner/JsonReaderTest.java
@@ -12,7 +12,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
-import static com.yahoo.vespa.http.client.JsonTestHelper.inputJson;
+import static com.yahoo.test.json.JsonTestHelper.inputJson;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.*;