Skip to content

Commit

Permalink
build: add jdk 17 to java units and dependency builds (#1461)
Browse files Browse the repository at this point in the history
* chore(java): rename master branch to main

Source-Author: Neenu Shaji <Neenu1995@users.noreply.github.com>
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 <BenWhitehead@users.noreply.github.com>
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 <chanseok@google.com>
  • Loading branch information
yoshi-automation and chanseokoh committed Oct 7, 2021
1 parent 57ef11a commit 06f8845
Show file tree
Hide file tree
Showing 12 changed files with 138 additions and 65 deletions.
19 changes: 12 additions & 7 deletions .github/workflows/ci.yaml
Expand Up @@ -9,14 +9,15 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
java: [8, 11]
java: [8, 11, 17]
steps:
- uses: actions/checkout@v2
- uses: stCarolas/setup-maven@v4
with:
maven-version: 3.8.1
- uses: actions/setup-java@v1
- uses: actions/setup-java@v2
with:
distribution: zulu
java-version: ${{matrix.java}}
- run: java -version
- run: .kokoro/build.sh
Expand All @@ -29,8 +30,9 @@ jobs:
- uses: stCarolas/setup-maven@v4
with:
maven-version: 3.8.1
- uses: actions/setup-java@v1
- uses: actions/setup-java@v2
with:
distribution: zulu
java-version: 8
- run: java -version
- run: .kokoro/build.bat
Expand All @@ -40,14 +42,15 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
java: [8, 11]
java: [8, 11, 17]
steps:
- uses: actions/checkout@v2
- uses: stCarolas/setup-maven@v4
with:
maven-version: 3.8.1
- uses: actions/setup-java@v1
- uses: actions/setup-java@v2
with:
distribution: zulu
java-version: ${{matrix.java}}
- run: java -version
- run: .kokoro/dependencies.sh
Expand All @@ -58,8 +61,9 @@ jobs:
- uses: stCarolas/setup-maven@v4
with:
maven-version: 3.8.1
- uses: actions/setup-java@v1
- uses: actions/setup-java@v2
with:
distribution: zulu
java-version: 8
- run: java -version
- run: .kokoro/build.sh
Expand All @@ -72,8 +76,9 @@ jobs:
- uses: stCarolas/setup-maven@v4
with:
maven-version: 3.8.1
- uses: actions/setup-java@v1
- uses: actions/setup-java@v2
with:
distribution: zulu
java-version: 8
- run: java -version
- run: .kokoro/build.sh
Expand Down
23 changes: 22 additions & 1 deletion .kokoro/dependencies.sh
Expand Up @@ -28,7 +28,28 @@ source ${scriptDir}/common.sh
java -version
echo $JOB_TYPE

export MAVEN_OPTS="-Xmx1024m -XX:MaxPermSize=128m"
function determineMavenOpts() {
local javaVersion=$(
# filter down to the version line, then pull out the version between quotes,
# then trim the version number down to its minimal number (removing any
# update or suffix number).
java -version 2>&1 | grep "version" \
| sed -E 's/^.*"(.*?)".*$/\1/g' \
| sed -E 's/^(1\.[0-9]\.0).*$/\1/g'
)

case $javaVersion in
"17")
# MaxPermSize is no longer supported as of jdk 17
echo -n "-Xmx1024m"
;;
*)
echo -n "-Xmx1024m -XX:MaxPermSize=128m"
;;
esac
}

export MAVEN_OPTS=$(determineMavenOpts)

# this should run maven enforcer
retry_with_backoff 3 10 \
Expand Down
5 changes: 0 additions & 5 deletions google-http-client-apache-v2/pom.xml
Expand Up @@ -99,10 +99,5 @@
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Expand Up @@ -20,14 +20,13 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeFalse;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.junit.Assume.assumeTrue;

import com.google.api.client.http.GenericUrl;
import com.google.api.client.http.HttpResponseException;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.LowLevelHttpResponse;
import com.google.api.client.testing.http.apache.MockHttpClient;
import com.google.api.client.util.ByteArrayStreamingContent;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
Expand All @@ -47,7 +46,9 @@
import org.apache.http.HttpRequestInterceptor;
import org.apache.http.HttpResponse;
import org.apache.http.HttpVersion;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.conn.ConnectTimeoutException;
import org.apache.http.conn.HttpHostConnectException;
Expand All @@ -65,6 +66,15 @@
*/
public class ApacheHttpTransportTest {

private static class MockHttpResponse extends BasicHttpResponse implements CloseableHttpResponse {
public MockHttpResponse() {
super(HttpVersion.HTTP_1_1, 200, "OK");
}

@Override
public void close() throws IOException {}
}

@Test
public void testApacheHttpTransport() {
ApacheHttpTransport transport = new ApacheHttpTransport();
Expand Down Expand Up @@ -99,10 +109,14 @@ private void checkHttpClient(HttpClient client) {

@Test
public void testRequestsWithContent() throws IOException {
HttpClient mockClient = mock(HttpClient.class);
HttpResponse mockResponse = mock(HttpResponse.class);
when(mockClient.execute(any(HttpUriRequest.class))).thenReturn(mockResponse);

HttpClient mockClient =
new MockHttpClient() {
@Override
public CloseableHttpResponse execute(HttpUriRequest request)
throws IOException, ClientProtocolException {
return new MockHttpResponse();
}
};
ApacheHttpTransport transport = new ApacheHttpTransport(mockClient);

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

HttpTransport httpTransport = new ApacheHttpTransport();
GenericUrl url = new GenericUrl("http://google.com:81");
Expand All @@ -213,7 +230,7 @@ public void testConnectTimeout() {
} catch (HttpHostConnectException | ConnectTimeoutException expected) {
// expected
} catch (IOException e) {
fail("unexpected IOException: " + e.getClass().getName());
fail("unexpected IOException: " + e.getClass().getName() + ": " + e.getMessage());
}
}

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

FakeServer(HttpHandler httpHandler) throws IOException {
this.server = HttpServer.create(new InetSocketAddress(0), 0);
this.executorService = Executors.newFixedThreadPool(1);
server.setExecutor(this.executorService);
server = HttpServer.create(new InetSocketAddress(0), 0);
executorService = Executors.newFixedThreadPool(1);
server.setExecutor(executorService);
server.createContext("/", httpHandler);
server.start();
}
Expand All @@ -235,8 +252,8 @@ public int getPort() {

@Override
public void close() {
this.server.stop(0);
this.executorService.shutdownNow();
server.stop(0);
executorService.shutdownNow();
}
}

Expand Down
5 changes: 0 additions & 5 deletions google-http-client/pom.xml
Expand Up @@ -167,11 +167,6 @@
<artifactId>truth</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.opencensus</groupId>
<artifactId>opencensus-impl</artifactId>
Expand Down
Expand Up @@ -28,10 +28,12 @@
*/
public class GZipEncoding implements HttpEncoding {

@Override
public String getName() {
return "gzip";
}

@Override
public void encode(StreamingContent content, OutputStream out) throws IOException {
// must not close the underlying output stream
OutputStream out2 =
Expand Down
Expand Up @@ -38,7 +38,7 @@ public class MockJsonParser extends JsonParser {

private final JsonFactory factory;

MockJsonParser(JsonFactory factory) {
public MockJsonParser(JsonFactory factory) {
this.factory = factory;
}

Expand Down
Expand Up @@ -28,19 +28,33 @@
*/
public class GZipEncodingTest extends TestCase {

byte[] EXPECED_ZIPPED =
private static final byte[] EXPECED_ZIPPED =
new byte[] {
31, -117, 8, 0, 0, 0, 0, 0, 0, -1, -53, -49, -57, 13, 0, -30, -66, -14, 54, 28, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0
};

// TODO: remove when no longer using Java < 16: https://bugs.openjdk.java.net/browse/JDK-8244706
@Deprecated
private static final byte[] EXPECED_ZIPPED_BELOW_JAVA_16 =
new byte[] {
31, -117, 8, 0, 0, 0, 0, 0, 0, 0, -53, -49, -57, 13, 0, -30, -66, -14, 54, 28, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0
};

public void test() throws IOException {
// TODO: remove when no longer using Java < 16.
byte[] expected =
System.getProperty("java.version").compareTo("16") >= 0
? EXPECED_ZIPPED
: EXPECED_ZIPPED_BELOW_JAVA_16;

GZipEncoding encoding = new GZipEncoding();
ByteArrayStreamingContent content =
new ByteArrayStreamingContent(StringUtils.getBytesUtf8("oooooooooooooooooooooooooooo"));
TestableByteArrayOutputStream out = new TestableByteArrayOutputStream();
encoding.encode(content, out);
assertFalse(out.isClosed());
Assert.assertArrayEquals(EXPECED_ZIPPED, out.getBuffer());
Assert.assertArrayEquals(expected, out.getBuffer());
}
}
Expand Up @@ -28,13 +28,27 @@
*/
public class HttpEncodingStreamingContentTest extends TestCase {

byte[] EXPECED_ZIPPED =
private static final byte[] EXPECED_ZIPPED =
new byte[] {
31, -117, 8, 0, 0, 0, 0, 0, 0, -1, -53, -49, -57, 13, 0, -30, -66, -14, 54, 28, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0
};

// TODO: remove when no longer using Java < 16: https://bugs.openjdk.java.net/browse/JDK-8244706
@Deprecated
private static final byte[] EXPECED_ZIPPED_BELOW_JAVA_16 =
new byte[] {
31, -117, 8, 0, 0, 0, 0, 0, 0, 0, -53, -49, -57, 13, 0, -30, -66, -14, 54, 28, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0
};

public void test() throws IOException {
// TODO: remove when no longer using Java < 16.
byte[] expected =
System.getProperty("java.version").compareTo("16") >= 0
? EXPECED_ZIPPED
: EXPECED_ZIPPED_BELOW_JAVA_16;

GZipEncoding encoding = new GZipEncoding();
ByteArrayStreamingContent content =
new ByteArrayStreamingContent(StringUtils.getBytesUtf8("oooooooooooooooooooooooooooo"));
Expand All @@ -43,6 +57,6 @@ public void test() throws IOException {
new HttpEncodingStreamingContent(content, encoding);
encodingContent.writeTo(out);
assertFalse(out.isClosed());
Assert.assertArrayEquals(EXPECED_ZIPPED, out.getBuffer());
Assert.assertArrayEquals(expected, out.getBuffer());
}
}

0 comments on commit 06f8845

Please sign in to comment.