Skip to content

Commit 06f8845

Browse files
build: add jdk 17 to java units and dependency builds (googleapis#1461)
* chore(java): rename master branch to main Source-Author: Neenu Shaji <[email protected]> Source-Date: Mon Sep 27 10:04:11 2021 -0400 Source-Repo: googleapis/synthtool Source-Sha: 67ab4f9f4272ad13f4b809de47fd0dec05f425ad Source-Link: googleapis/synthtool@67ab4f9 * build: add jdk 17 to java units and dependency builds * update dependencies.sh to not pass MaxPermSize when jdk 17 is used. MaxPermSize is an unrecognized flag in jdk 17. Source-Author: BenWhitehead <[email protected]> Source-Date: Mon Sep 27 11:34:46 2021 -0400 Source-Repo: googleapis/synthtool Source-Sha: a4be3384ccb92364795d981f2863f6986fcee620 Source-Link: googleapis/synthtool@a4be338 * Fix for Java 17 * Remove unused dependency * Fix for Java 17 * Fix format * Clean up Co-authored-by: Chanseok Oh <[email protected]>
1 parent 57ef11a commit 06f8845

File tree

12 files changed

+138
-65
lines changed

12 files changed

+138
-65
lines changed

.github/workflows/ci.yaml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ jobs:
99
runs-on: ubuntu-latest
1010
strategy:
1111
matrix:
12-
java: [8, 11]
12+
java: [8, 11, 17]
1313
steps:
1414
- uses: actions/checkout@v2
1515
- uses: stCarolas/setup-maven@v4
1616
with:
1717
maven-version: 3.8.1
18-
- uses: actions/setup-java@v1
18+
- uses: actions/setup-java@v2
1919
with:
20+
distribution: zulu
2021
java-version: ${{matrix.java}}
2122
- run: java -version
2223
- run: .kokoro/build.sh
@@ -29,8 +30,9 @@ jobs:
2930
- uses: stCarolas/setup-maven@v4
3031
with:
3132
maven-version: 3.8.1
32-
- uses: actions/setup-java@v1
33+
- uses: actions/setup-java@v2
3334
with:
35+
distribution: zulu
3436
java-version: 8
3537
- run: java -version
3638
- run: .kokoro/build.bat
@@ -40,14 +42,15 @@ jobs:
4042
runs-on: ubuntu-latest
4143
strategy:
4244
matrix:
43-
java: [8, 11]
45+
java: [8, 11, 17]
4446
steps:
4547
- uses: actions/checkout@v2
4648
- uses: stCarolas/setup-maven@v4
4749
with:
4850
maven-version: 3.8.1
49-
- uses: actions/setup-java@v1
51+
- uses: actions/setup-java@v2
5052
with:
53+
distribution: zulu
5154
java-version: ${{matrix.java}}
5255
- run: java -version
5356
- run: .kokoro/dependencies.sh
@@ -58,8 +61,9 @@ jobs:
5861
- uses: stCarolas/setup-maven@v4
5962
with:
6063
maven-version: 3.8.1
61-
- uses: actions/setup-java@v1
64+
- uses: actions/setup-java@v2
6265
with:
66+
distribution: zulu
6367
java-version: 8
6468
- run: java -version
6569
- run: .kokoro/build.sh
@@ -72,8 +76,9 @@ jobs:
7276
- uses: stCarolas/setup-maven@v4
7377
with:
7478
maven-version: 3.8.1
75-
- uses: actions/setup-java@v1
79+
- uses: actions/setup-java@v2
7680
with:
81+
distribution: zulu
7782
java-version: 8
7883
- run: java -version
7984
- run: .kokoro/build.sh

.kokoro/dependencies.sh

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,28 @@ source ${scriptDir}/common.sh
2828
java -version
2929
echo $JOB_TYPE
3030

31-
export MAVEN_OPTS="-Xmx1024m -XX:MaxPermSize=128m"
31+
function determineMavenOpts() {
32+
local javaVersion=$(
33+
# filter down to the version line, then pull out the version between quotes,
34+
# then trim the version number down to its minimal number (removing any
35+
# update or suffix number).
36+
java -version 2>&1 | grep "version" \
37+
| sed -E 's/^.*"(.*?)".*$/\1/g' \
38+
| sed -E 's/^(1\.[0-9]\.0).*$/\1/g'
39+
)
40+
41+
case $javaVersion in
42+
"17")
43+
# MaxPermSize is no longer supported as of jdk 17
44+
echo -n "-Xmx1024m"
45+
;;
46+
*)
47+
echo -n "-Xmx1024m -XX:MaxPermSize=128m"
48+
;;
49+
esac
50+
}
51+
52+
export MAVEN_OPTS=$(determineMavenOpts)
3253

3354
# this should run maven enforcer
3455
retry_with_backoff 3 10 \

google-http-client-apache-v2/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,5 @@
9999
<groupId>org.apache.httpcomponents</groupId>
100100
<artifactId>httpcore</artifactId>
101101
</dependency>
102-
<dependency>
103-
<groupId>org.mockito</groupId>
104-
<artifactId>mockito-all</artifactId>
105-
<scope>test</scope>
106-
</dependency>
107102
</dependencies>
108103
</project>

google-http-client-apache-v2/src/test/java/com/google/api/client/http/apache/v2/ApacheHttpTransportTest.java

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@
2020
import static org.junit.Assert.assertTrue;
2121
import static org.junit.Assert.fail;
2222
import static org.junit.Assume.assumeFalse;
23-
import static org.mockito.Matchers.any;
24-
import static org.mockito.Mockito.mock;
25-
import static org.mockito.Mockito.when;
23+
import static org.junit.Assume.assumeTrue;
2624

2725
import com.google.api.client.http.GenericUrl;
2826
import com.google.api.client.http.HttpResponseException;
2927
import com.google.api.client.http.HttpTransport;
3028
import com.google.api.client.http.LowLevelHttpResponse;
29+
import com.google.api.client.testing.http.apache.MockHttpClient;
3130
import com.google.api.client.util.ByteArrayStreamingContent;
3231
import com.sun.net.httpserver.HttpExchange;
3332
import com.sun.net.httpserver.HttpHandler;
@@ -47,7 +46,9 @@
4746
import org.apache.http.HttpRequestInterceptor;
4847
import org.apache.http.HttpResponse;
4948
import org.apache.http.HttpVersion;
49+
import org.apache.http.client.ClientProtocolException;
5050
import org.apache.http.client.HttpClient;
51+
import org.apache.http.client.methods.CloseableHttpResponse;
5152
import org.apache.http.client.methods.HttpUriRequest;
5253
import org.apache.http.conn.ConnectTimeoutException;
5354
import org.apache.http.conn.HttpHostConnectException;
@@ -65,6 +66,15 @@
6566
*/
6667
public class ApacheHttpTransportTest {
6768

69+
private static class MockHttpResponse extends BasicHttpResponse implements CloseableHttpResponse {
70+
public MockHttpResponse() {
71+
super(HttpVersion.HTTP_1_1, 200, "OK");
72+
}
73+
74+
@Override
75+
public void close() throws IOException {}
76+
}
77+
6878
@Test
6979
public void testApacheHttpTransport() {
7080
ApacheHttpTransport transport = new ApacheHttpTransport();
@@ -99,10 +109,14 @@ private void checkHttpClient(HttpClient client) {
99109

100110
@Test
101111
public void testRequestsWithContent() throws IOException {
102-
HttpClient mockClient = mock(HttpClient.class);
103-
HttpResponse mockResponse = mock(HttpResponse.class);
104-
when(mockClient.execute(any(HttpUriRequest.class))).thenReturn(mockResponse);
105-
112+
HttpClient mockClient =
113+
new MockHttpClient() {
114+
@Override
115+
public CloseableHttpResponse execute(HttpUriRequest request)
116+
throws IOException, ClientProtocolException {
117+
return new MockHttpResponse();
118+
}
119+
};
106120
ApacheHttpTransport transport = new ApacheHttpTransport(mockClient);
107121

108122
// Test GET.
@@ -204,6 +218,9 @@ public void process(HttpRequest request, HttpContext context)
204218
public void testConnectTimeout() {
205219
// Apache HttpClient doesn't appear to behave correctly on windows
206220
assumeFalse(isWindows());
221+
// TODO(chanseok): Java 17 returns an IOException (SocketException: Network is unreachable).
222+
// Figure out a way to verify connection timeout works on Java 17+.
223+
assumeTrue(System.getProperty("java.version").compareTo("17") < 0);
207224

208225
HttpTransport httpTransport = new ApacheHttpTransport();
209226
GenericUrl url = new GenericUrl("http://google.com:81");
@@ -213,7 +230,7 @@ public void testConnectTimeout() {
213230
} catch (HttpHostConnectException | ConnectTimeoutException expected) {
214231
// expected
215232
} catch (IOException e) {
216-
fail("unexpected IOException: " + e.getClass().getName());
233+
fail("unexpected IOException: " + e.getClass().getName() + ": " + e.getMessage());
217234
}
218235
}
219236

@@ -222,9 +239,9 @@ private static class FakeServer implements AutoCloseable {
222239
private final ExecutorService executorService;
223240

224241
FakeServer(HttpHandler httpHandler) throws IOException {
225-
this.server = HttpServer.create(new InetSocketAddress(0), 0);
226-
this.executorService = Executors.newFixedThreadPool(1);
227-
server.setExecutor(this.executorService);
242+
server = HttpServer.create(new InetSocketAddress(0), 0);
243+
executorService = Executors.newFixedThreadPool(1);
244+
server.setExecutor(executorService);
228245
server.createContext("/", httpHandler);
229246
server.start();
230247
}
@@ -235,8 +252,8 @@ public int getPort() {
235252

236253
@Override
237254
public void close() {
238-
this.server.stop(0);
239-
this.executorService.shutdownNow();
255+
server.stop(0);
256+
executorService.shutdownNow();
240257
}
241258
}
242259

google-http-client/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,6 @@
167167
<artifactId>truth</artifactId>
168168
<scope>test</scope>
169169
</dependency>
170-
<dependency>
171-
<groupId>org.mockito</groupId>
172-
<artifactId>mockito-all</artifactId>
173-
<scope>test</scope>
174-
</dependency>
175170
<dependency>
176171
<groupId>io.opencensus</groupId>
177172
<artifactId>opencensus-impl</artifactId>

google-http-client/src/main/java/com/google/api/client/http/GZipEncoding.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@
2828
*/
2929
public class GZipEncoding implements HttpEncoding {
3030

31+
@Override
3132
public String getName() {
3233
return "gzip";
3334
}
3435

36+
@Override
3537
public void encode(StreamingContent content, OutputStream out) throws IOException {
3638
// must not close the underlying output stream
3739
OutputStream out2 =

google-http-client/src/main/java/com/google/api/client/testing/json/MockJsonParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class MockJsonParser extends JsonParser {
3838

3939
private final JsonFactory factory;
4040

41-
MockJsonParser(JsonFactory factory) {
41+
public MockJsonParser(JsonFactory factory) {
4242
this.factory = factory;
4343
}
4444

google-http-client/src/test/java/com/google/api/client/http/GZipEncodingTest.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,33 @@
2828
*/
2929
public class GZipEncodingTest extends TestCase {
3030

31-
byte[] EXPECED_ZIPPED =
31+
private static final byte[] EXPECED_ZIPPED =
32+
new byte[] {
33+
31, -117, 8, 0, 0, 0, 0, 0, 0, -1, -53, -49, -57, 13, 0, -30, -66, -14, 54, 28, 0, 0, 0, 0,
34+
0, 0, 0, 0, 0, 0, 0, 0
35+
};
36+
37+
// TODO: remove when no longer using Java < 16: https://bugs.openjdk.java.net/browse/JDK-8244706
38+
@Deprecated
39+
private static final byte[] EXPECED_ZIPPED_BELOW_JAVA_16 =
3240
new byte[] {
3341
31, -117, 8, 0, 0, 0, 0, 0, 0, 0, -53, -49, -57, 13, 0, -30, -66, -14, 54, 28, 0, 0, 0, 0,
3442
0, 0, 0, 0, 0, 0, 0, 0
3543
};
3644

3745
public void test() throws IOException {
46+
// TODO: remove when no longer using Java < 16.
47+
byte[] expected =
48+
System.getProperty("java.version").compareTo("16") >= 0
49+
? EXPECED_ZIPPED
50+
: EXPECED_ZIPPED_BELOW_JAVA_16;
51+
3852
GZipEncoding encoding = new GZipEncoding();
3953
ByteArrayStreamingContent content =
4054
new ByteArrayStreamingContent(StringUtils.getBytesUtf8("oooooooooooooooooooooooooooo"));
4155
TestableByteArrayOutputStream out = new TestableByteArrayOutputStream();
4256
encoding.encode(content, out);
4357
assertFalse(out.isClosed());
44-
Assert.assertArrayEquals(EXPECED_ZIPPED, out.getBuffer());
58+
Assert.assertArrayEquals(expected, out.getBuffer());
4559
}
4660
}

google-http-client/src/test/java/com/google/api/client/http/HttpEncodingStreamingContentTest.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,27 @@
2828
*/
2929
public class HttpEncodingStreamingContentTest extends TestCase {
3030

31-
byte[] EXPECED_ZIPPED =
31+
private static final byte[] EXPECED_ZIPPED =
32+
new byte[] {
33+
31, -117, 8, 0, 0, 0, 0, 0, 0, -1, -53, -49, -57, 13, 0, -30, -66, -14, 54, 28, 0, 0, 0, 0,
34+
0, 0, 0, 0, 0, 0, 0, 0
35+
};
36+
37+
// TODO: remove when no longer using Java < 16: https://bugs.openjdk.java.net/browse/JDK-8244706
38+
@Deprecated
39+
private static final byte[] EXPECED_ZIPPED_BELOW_JAVA_16 =
3240
new byte[] {
3341
31, -117, 8, 0, 0, 0, 0, 0, 0, 0, -53, -49, -57, 13, 0, -30, -66, -14, 54, 28, 0, 0, 0, 0,
3442
0, 0, 0, 0, 0, 0, 0, 0
3543
};
3644

3745
public void test() throws IOException {
46+
// TODO: remove when no longer using Java < 16.
47+
byte[] expected =
48+
System.getProperty("java.version").compareTo("16") >= 0
49+
? EXPECED_ZIPPED
50+
: EXPECED_ZIPPED_BELOW_JAVA_16;
51+
3852
GZipEncoding encoding = new GZipEncoding();
3953
ByteArrayStreamingContent content =
4054
new ByteArrayStreamingContent(StringUtils.getBytesUtf8("oooooooooooooooooooooooooooo"));
@@ -43,6 +57,6 @@ public void test() throws IOException {
4357
new HttpEncodingStreamingContent(content, encoding);
4458
encodingContent.writeTo(out);
4559
assertFalse(out.isClosed());
46-
Assert.assertArrayEquals(EXPECED_ZIPPED, out.getBuffer());
60+
Assert.assertArrayEquals(expected, out.getBuffer());
4761
}
4862
}

0 commit comments

Comments
 (0)