Skip to content

build: add jdk 17 to java units and dependency builds #1461

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/blunderbuss.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Configuration for the Blunderbuss GitHub app. For more info see
# https://github.com/googleapis/repo-automation-bots/tree/master/packages/blunderbuss
# https://github.com/googleapis/repo-automation-bots/tree/main/packages/blunderbuss
assign_prs_by:
- labels:
- samples
Expand Down
21 changes: 13 additions & 8 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
on:
push:
branches:
- master
- main
pull_request:
name: ci
jobs:
units:
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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>
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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());
}
}
Original file line number Diff line number Diff line change
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());
}
}
Loading