Skip to content

Commit 32e506f

Browse files
committed
NO-JIRA: Upgraded as far as possible until new ADM release. Still pending is fixing the resource exhaustion in RosetteAPITest.
1 parent 55f861f commit 32e506f

File tree

9 files changed

+165
-47
lines changed

9 files changed

+165
-47
lines changed

api/pom.xml

Lines changed: 86 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
3-
Copyright 2018 Basis Technology Corp.
3+
Copyright 2018-2022 Basis Technology Corp.
44
55
Licensed under the Apache License, Version 2.0 (the "License");
66
you may not use this file except in compliance with the License.
@@ -51,15 +51,42 @@
5151
<groupId>com.fasterxml.jackson.core</groupId>
5252
<artifactId>jackson-databind</artifactId>
5353
</dependency>
54+
<!-- Declaring explicitly as 4.5.x httpclient brings in an old version. And we don't want mockserver
55+
dictating the version. -->
56+
<dependency>
57+
<groupId>commons-codec</groupId>
58+
<artifactId>commons-codec</artifactId>
59+
<version>${commons-codec.version}</version>
60+
</dependency>
5461
<dependency>
5562
<groupId>org.apache.httpcomponents</groupId>
5663
<artifactId>httpclient</artifactId>
5764
<version>${http-components.version}</version>
65+
<exclusions>
66+
<exclusion>
67+
<groupId>commons-codec</groupId>
68+
<artifactId>commons-codec</artifactId>
69+
</exclusion>
70+
</exclusions>
5871
</dependency>
5972
<dependency>
6073
<groupId>org.apache.httpcomponents</groupId>
6174
<artifactId>httpclient-osgi</artifactId>
6275
<version>${http-components.version}</version>
76+
<exclusions>
77+
<exclusion>
78+
<groupId>org.apache.httpcomponents</groupId>
79+
<artifactId>httpclient</artifactId>
80+
</exclusion>
81+
<exclusion>
82+
<groupId>org.apache.httpcomponents</groupId>
83+
<artifactId>httpmime</artifactId>
84+
</exclusion>
85+
<exclusion>
86+
<groupId>commons-codec</groupId>
87+
<artifactId>commons-codec</artifactId>
88+
</exclusion>
89+
</exclusions>
6390
</dependency>
6491
<dependency>
6592
<groupId>org.apache.httpcomponents</groupId>
@@ -70,6 +97,12 @@
7097
<groupId>org.apache.httpcomponents</groupId>
7198
<artifactId>httpmime</artifactId>
7299
<version>${http-components.version}</version>
100+
<exclusions>
101+
<exclusion>
102+
<groupId>org.apache.httpcomponents</groupId>
103+
<artifactId>httpclient</artifactId>
104+
</exclusion>
105+
</exclusions>
73106
</dependency>
74107
<dependency>
75108
<groupId>org.slf4j</groupId>
@@ -78,6 +111,7 @@
78111
<dependency>
79112
<groupId>junit</groupId>
80113
<artifactId>junit</artifactId>
114+
<!-- <version>5.9.1</version> -->
81115
</dependency>
82116
<dependency>
83117
<groupId>org.mock-server</groupId>
@@ -90,10 +124,60 @@
90124
<artifactId>mockserver-core</artifactId>
91125
<version>${mockserver.version}</version>
92126
<scope>test</scope>
127+
<exclusions>
128+
<exclusion>
129+
<groupId>com.google.code.findbugs</groupId>
130+
<artifactId>jsr305</artifactId>
131+
</exclusion>
132+
<exclusion>
133+
<groupId>commons-beanutils</groupId>
134+
<artifactId>commons-beanutils</artifactId>
135+
</exclusion>
136+
<exclusion>
137+
<groupId>org.apache.httpcomponents</groupId>
138+
<artifactId>httpclient</artifactId>
139+
</exclusion>
140+
<exclusion>
141+
<groupId>org.apache.commons</groupId>
142+
<artifactId>commons-lang3</artifactId>
143+
</exclusion>
144+
<exclusion>
145+
<groupId>commons-codec</groupId>
146+
<artifactId>commons-codec</artifactId>
147+
</exclusion>
148+
<exclusion>
149+
<groupId>commons-logging</groupId>
150+
<artifactId>commons-logging</artifactId>
151+
</exclusion>
152+
<exclusion>
153+
<groupId>jakarta.xml.bind</groupId>
154+
<artifactId>jakarta.xml.bind-api</artifactId>
155+
</exclusion>
156+
</exclusions>
157+
</dependency>
158+
<!-- Start: Specifically declared due to dependency convergence errors in mockserver-core. -->
159+
<dependency>
160+
<groupId>jakarta.xml.bind</groupId>
161+
<artifactId>jakarta.xml.bind-api</artifactId>
162+
<version>4.0.0</version>
163+
<scope>test</scope>
164+
</dependency>
165+
<dependency>
166+
<groupId>com.google.code.findbugs</groupId>
167+
<artifactId>jsr305</artifactId>
168+
<version>${findbugs-jsr305.version}</version>
169+
<scope>test</scope>
170+
</dependency>
171+
<dependency>
172+
<groupId>commons-beanutils</groupId>
173+
<artifactId>commons-beanutils</artifactId>
174+
<version>${commons-beanutils.version}</version>
175+
<scope>test</scope>
93176
</dependency>
177+
<!-- End: Specifically declared due to dependency convergence errors in mockserver-core. -->
94178
<dependency>
95179
<groupId>org.mock-server</groupId>
96-
<artifactId>mockserver-netty</artifactId>
180+
<artifactId>mockserver-junit-rule</artifactId>
97181
<version>${mockserver.version}</version>
98182
<scope>test</scope>
99183
</dependency>

api/src/test/java/com/basistech/rosette/api/AbstractTest.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014 Basis Technology Corp.
2+
* Copyright 2014-2022 Basis Technology Corp.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,15 +19,18 @@
1919
import com.basistech.rosette.apimodel.jackson.ApiModelMixinModule;
2020
import com.fasterxml.jackson.databind.DeserializationFeature;
2121
import com.fasterxml.jackson.databind.ObjectMapper;
22-
import com.google.common.base.Charsets;
2322
import com.google.common.io.Resources;
2423
import org.junit.Assert;
2524
import org.junit.BeforeClass;
2625

2726
import java.io.ByteArrayOutputStream;
2827
import java.io.IOException;
28+
import java.net.URISyntaxException;
2929
import java.net.URL;
3030
import java.nio.charset.StandardCharsets;
31+
import java.nio.file.Files;
32+
import java.nio.file.Path;
33+
import java.nio.file.Paths;
3134
import java.util.zip.GZIPOutputStream;
3235

3336
public abstract class AbstractTest extends Assert {
@@ -37,9 +40,9 @@ public abstract class AbstractTest extends Assert {
3740
protected static ObjectMapper mapper;
3841

3942
@BeforeClass
40-
public static void before() throws IOException {
43+
public static void before() throws IOException, URISyntaxException {
4144
URL url = Resources.getResource("MockServerClientPort.property");
42-
String clientPort = Resources.toString(url, Charsets.UTF_8);
45+
String clientPort = Resources.toString(url, StandardCharsets.UTF_8);
4346
serverPort = Integer.parseInt(clientPort);
4447
mapper = ApiModelMixinModule.setupObjectMapper(new ObjectMapper());
4548
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
@@ -53,5 +56,14 @@ protected static byte[] gzip(String text) throws IOException {
5356
return baos.toByteArray();
5457
}
5558

56-
59+
/*
60+
private static int getMockServerPort() throws IOException, URISyntaxException {
61+
String filename = "MockServerClientPort.property";
62+
URL u = Thread.currentThread().getContextClassLoader().getResource(filename);
63+
assertNotNull(u);
64+
Path p = Paths.get(u.toURI());
65+
String port = Files.readAllLines(p, StandardCharsets.UTF_8).get(0);
66+
return Integer.parseInt(port);
67+
}
68+
*/
5769
}

api/src/test/java/com/basistech/rosette/api/BasicTest.java

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@
3232

3333
import org.apache.commons.io.IOUtils;
3434
import org.apache.http.HttpHeaders;
35-
import org.junit.Before;
3635
import org.junit.Rule;
3736
import org.junit.Test;
38-
import org.mockserver.client.server.MockServerClient;
37+
import org.mockserver.client.MockServerClient;
3938
import org.mockserver.junit.MockServerRule;
4039
import org.mockserver.model.Delay;
4140
import org.mockserver.model.HttpRequest;
@@ -60,7 +59,7 @@
6059
public class BasicTest extends AbstractTest {
6160

6261
@Rule
63-
public MockServerRule mockServerRule = new MockServerRule(this, getFreePort());
62+
public MockServerRule mockServerRule = new MockServerRule(this, false, getFreePort());
6463
private MockServerClient mockServer;
6564
private HttpRosetteAPI api;
6665

@@ -75,19 +74,13 @@ private static int getFreePort() throws IOException {
7574
return serverPort;
7675
}
7776

78-
@Before
79-
public void setup() {
80-
mockServer.reset();
81-
// for version check call
82-
}
83-
8477
// an indirect way to show that connection pooling works
8578
// with concurrent connections = 1, the time to complete requests becomes serial
8679
// so: run several requests in threads, assert that they're executed serially
8780
// then set concurrent connections = 5,
8881
// run several requests again, showing they're executed in parallel
8982
@Test
90-
public void testMultipleConnections() throws IOException, InterruptedException {
83+
public void testMultipleConnections() throws InterruptedException {
9184
int delayTime = 3;
9285
int numConnections = 5;
9386

@@ -141,7 +134,6 @@ public void testMultipleConnections() throws IOException, InterruptedException {
141134
assertTrue(d2.getTime() - d1.getTime() < delayTime * numConnections * 1000); // less than (numConnections) serial requests
142135
assertTrue(d2.getTime() - d1.getTime() > delayTime * 1000); // but at least as long as one
143136
}
144-
145137
@Test
146138
public void testHeaders() throws Exception {
147139
mockServer.when(HttpRequest.request()
@@ -168,13 +160,14 @@ public void testHeaders() throws Exception {
168160
public void testAdm() throws Exception {
169161
try (InputStream reqIns = getClass().getResourceAsStream("/adm-req.json");
170162
InputStream respIns = getClass().getResourceAsStream("/adm-resp.json")) {
163+
assertNotNull(respIns);
171164
mockServer.when(HttpRequest.request()
172165
.withMethod("POST")
173166
.withPath("/rest/v1/entities"))
174167
.respond(HttpResponse.response()
175168
.withStatusCode(200)
176169
.withHeader("Content-Type", "application/json")
177-
.withBody(IOUtils.toString(respIns, "UTF-8")));
170+
.withBody(IOUtils.toString(respIns, StandardCharsets.UTF_8)));
178171
api = new HttpRosetteAPI.Builder()
179172
.key("foo-key")
180173
.url(String.format("http://localhost:%d/rest/v1", serverPort))
@@ -210,10 +203,10 @@ public void testExtendedInfo() throws Exception {
210203
assertTrue(foos.contains("Bar2"));
211204
}
212205

213-
private class ApiPinger extends Thread {
206+
private static class ApiPinger extends Thread {
214207
HttpRosetteAPI api1;
215208

216-
ApiPinger(HttpRosetteAPI api) throws IOException {
209+
ApiPinger(HttpRosetteAPI api) {
217210
this.api1 = api;
218211
}
219212

@@ -230,13 +223,14 @@ public void run() {
230223
@Test
231224
public void testLanguageSupport() throws Exception {
232225
try (InputStream respIns = getClass().getResourceAsStream("/supported-languages.json")) {
226+
assertNotNull(respIns);
233227
mockServer.when(HttpRequest.request()
234228
.withMethod("GET")
235229
.withPath("/rest/v1/entities/supported-languages"))
236230
.respond(HttpResponse.response()
237231
.withStatusCode(200)
238232
.withHeader("Content-Type", "application/json")
239-
.withBody(IOUtils.toString(respIns, "UTF-8")));
233+
.withBody(IOUtils.toString(respIns, StandardCharsets.UTF_8)));
240234
api = new HttpRosetteAPI.Builder()
241235
.key("foo-key")
242236
.url(String.format("http://localhost:%d/rest/v1", serverPort))
@@ -259,13 +253,14 @@ public void testLanguageSupport() throws Exception {
259253
@Test
260254
public void testNameSimilarityLanguageSupport() throws Exception {
261255
try (InputStream respIns = getClass().getResourceAsStream("/name-similarity-supported-languages.json")) {
256+
assertNotNull(respIns);
262257
mockServer.when(HttpRequest.request()
263258
.withMethod("GET")
264259
.withPath("/rest/v1/name-similarity/supported-languages"))
265260
.respond(HttpResponse.response()
266261
.withStatusCode(200)
267262
.withHeader("Content-Type", "application/json")
268-
.withBody(IOUtils.toString(respIns, "UTF-8")));
263+
.withBody(IOUtils.toString(respIns, StandardCharsets.UTF_8)));
269264
api = new HttpRosetteAPI.Builder()
270265
.key("foo-key")
271266
.url(String.format("http://localhost:%d/rest/v1", serverPort))
@@ -289,13 +284,14 @@ public void testNameSimilarityLanguageSupport() throws Exception {
289284
@Test
290285
public void testNameTranslationLanguageSupport() throws Exception {
291286
try (InputStream respIns = getClass().getResourceAsStream("/name-translation-supported-languages.json")) {
287+
assertNotNull(respIns);
292288
mockServer.when(HttpRequest.request()
293289
.withMethod("GET")
294290
.withPath("/rest/v1/name-translation/supported-languages"))
295291
.respond(HttpResponse.response()
296292
.withStatusCode(200)
297293
.withHeader("Content-Type", "application/json")
298-
.withBody(IOUtils.toString(respIns, "UTF-8")));
294+
.withBody(IOUtils.toString(respIns, StandardCharsets.UTF_8)));
299295
api = new HttpRosetteAPI.Builder()
300296
.key("foo-key")
301297
.url(String.format("http://localhost:%d/rest/v1", serverPort))

api/src/test/java/com/basistech/rosette/api/DevRosetteAPITest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 Basis Technology Corp.
2+
* Copyright 2017-2022 Basis Technology Corp.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,12 +23,12 @@
2323
import com.basistech.rosette.apimodel.TokensResponse;
2424
import com.basistech.util.LanguageCode;
2525
import com.basistech.util.PartOfSpeechTagSet;
26-
import com.google.common.base.Charsets;
2726
import org.junit.After;
2827
import org.junit.Before;
2928
import org.junit.Test;
3029

3130
import java.io.IOException;
31+
import java.nio.charset.StandardCharsets;
3232

3333
import static org.junit.Assert.assertEquals;
3434

@@ -58,7 +58,7 @@ public void multipart() throws Exception {
5858
// this assumes that the server has the mock version of the components.
5959
Request morphologyRequest = DocumentRequest.builder().language(LanguageCode.ENGLISH)
6060
.options(MorphologyOptions.builder().partOfSpeechTagSet(PartOfSpeechTagSet.upt16).build())
61-
.content("This is the cereal shot from 1 gun .".getBytes(Charsets.UTF_8), "text/plain;charset=utf-8")
61+
.content("This is the cereal shot from 1 gun .".getBytes(StandardCharsets.UTF_8), "text/plain;charset=utf-8")
6262
.build();
6363
TokensResponse response = api.perform(AbstractRosetteAPI.TOKENS_SERVICE_PATH, morphologyRequest, TokensResponse.class);
6464
assertEquals(9, response.getTokens().size());

api/src/test/java/com/basistech/rosette/api/InvalidErrorTest.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@
2121
import com.basistech.rosette.apimodel.LanguageResponse;
2222
import org.apache.http.HttpHeaders;
2323
import org.junit.Test;
24-
import org.mockserver.client.server.MockServerClient;
24+
import org.mockserver.client.MockServerClient;
2525
import org.mockserver.model.HttpRequest;
2626
import org.mockserver.model.HttpResponse;
2727

2828
import java.nio.charset.StandardCharsets;
2929

30+
import static java.net.HttpURLConnection.HTTP_NOT_FOUND;
31+
import static java.net.HttpURLConnection.HTTP_OK;
32+
3033

3134
public class InvalidErrorTest extends AbstractTest {
3235

@@ -38,26 +41,28 @@ public void notJsonError() throws Exception {
3841
.respond(HttpResponse.response()
3942
.withBody("Invalid path; '//'")
4043
.withHeader("X-RosetteAPI-Concurrency", "5")
41-
.withStatusCode(404));
44+
.withStatusCode(HTTP_NOT_FOUND));
4245
mockServer.when(HttpRequest.request()
4346
.withMethod("GET")
4447
.withPath("/rest/v1/ping")
4548
.withHeader(HttpHeaders.USER_AGENT, HttpRosetteAPI.USER_AGENT_STR))
4649
.respond(HttpResponse.response()
4750
.withBody("{\"message\":\"Rosette API at your service\",\"time\":1461788498633}", StandardCharsets.UTF_8)
48-
.withStatusCode(200)
51+
.withStatusCode(HTTP_OK)
4952
.withHeader("X-RosetteAPI-Concurrency", "5"));
5053
String mockServiceUrl = "http://localhost:" + Integer.toString(serverPort) + "/rest//v1";
5154
boolean exceptional = false;
5255
try {
5356
HttpRosetteAPI api = new HttpRosetteAPI.Builder().key("my-key-123").url(mockServiceUrl).build();
5457
api.perform(AbstractRosetteAPI.LANGUAGE_SERVICE_PATH, DocumentRequest.builder().content("sample text").build(), LanguageResponse.class);
58+
api.close();
5559
} catch (HttpRosetteAPIException e) {
5660
exceptional = true;
5761
assertEquals("invalidErrorResponse", e.getErrorResponse().getCode());
5862
assertEquals(Integer.valueOf(404), e.getHttpStatusCode());
5963
assertNotNull(e.getErrorResponse().getMessage());
6064
}
6165
assertTrue(exceptional);
66+
mockServer.close();
6267
}
6368
}

0 commit comments

Comments
 (0)