Skip to content

Commit 94e762c

Browse files
committed
Merge branch 'main' into googleapisgh-1375/custom-write-timeout-executor
2 parents e622b5e + 198e0d5 commit 94e762c

File tree

17 files changed

+136
-133
lines changed

17 files changed

+136
-133
lines changed

.github/.OwlBot.lock.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
docker:
22
image: gcr.io/repo-automation-bots/owlbot-java:latest
3-
digest: sha256:a3ac08d167454718ff057b97a1950d3cb5e16fc39fb3f355d90276285a6cac75
3+
digest: sha256:a4d7b2cfc6a9d6b378a6b2458740eae15fcab28854bd23dad3a15102d2e47c87

.github/workflows/ci.yaml

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@ jobs:
88
units:
99
runs-on: ubuntu-latest
1010
strategy:
11+
fail-fast: false
1112
matrix:
1213
java: [8, 11, 17]
1314
steps:
1415
- uses: actions/checkout@v2
15-
- uses: stCarolas/setup-maven@v4
16-
with:
17-
maven-version: 3.8.1
1816
- uses: actions/setup-java@v2
1917
with:
2018
distribution: zulu
@@ -27,9 +25,6 @@ jobs:
2725
runs-on: windows-latest
2826
steps:
2927
- uses: actions/checkout@v2
30-
- uses: stCarolas/setup-maven@v4
31-
with:
32-
maven-version: 3.8.1
3328
- uses: actions/setup-java@v2
3429
with:
3530
distribution: zulu
@@ -45,9 +40,6 @@ jobs:
4540
java: [8, 11, 17]
4641
steps:
4742
- uses: actions/checkout@v2
48-
- uses: stCarolas/setup-maven@v4
49-
with:
50-
maven-version: 3.8.1
5143
- uses: actions/setup-java@v2
5244
with:
5345
distribution: zulu
@@ -58,13 +50,10 @@ jobs:
5850
runs-on: ubuntu-latest
5951
steps:
6052
- uses: actions/checkout@v2
61-
- uses: stCarolas/setup-maven@v4
62-
with:
63-
maven-version: 3.8.1
6453
- uses: actions/setup-java@v2
6554
with:
6655
distribution: zulu
67-
java-version: 8
56+
java-version: 11
6857
- run: java -version
6958
- run: .kokoro/build.sh
7059
env:
@@ -73,9 +62,6 @@ jobs:
7362
runs-on: ubuntu-latest
7463
steps:
7564
- uses: actions/checkout@v2
76-
- uses: stCarolas/setup-maven@v4
77-
with:
78-
maven-version: 3.8.1
7965
- uses: actions/setup-java@v2
8066
with:
8167
distribution: zulu

.kokoro/build.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ integration)
7171
;;
7272
graalvm)
7373
# Run Unit and Integration Tests with Native Image
74-
mvn test -Pnative -Penable-integration-tests
74+
mvn -ntp -Pnative -Penable-integration-tests test
7575
RETURN_CODE=$?
7676
;;
7777
samples)
@@ -91,7 +91,6 @@ samples)
9191

9292
pushd ${SAMPLES_DIR}
9393
mvn -B \
94-
-Penable-samples \
9594
-ntp \
9695
-DtrimStackTrace=false \
9796
-Dclirr.skip=true \

.kokoro/release/publish_javadoc11.sh

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,9 @@ mvn clean install -B -q -DskipTests=true
3636
export NAME=google-http-client
3737
export VERSION=$(grep ${NAME}: versions.txt | cut -d: -f3)
3838

39-
# V3 generates docfx yml from javadoc
40-
# generate yml
41-
mvn clean site -B -q -P docFX
42-
43-
# copy README to docfx-yml dir and rename index.md
44-
cp README.md target/docfx-yml/index.md
45-
# copy CHANGELOG to docfx-yml dir and rename history.md
39+
# cloud RAD generation
40+
mvn clean javadoc:aggregate -B -q -P docFX
41+
# include CHANGELOG
4642
cp CHANGELOG.md target/docfx-yml/history.md
4743

4844
pushd target/docfx-yml

CONTRIBUTING.md

Lines changed: 7 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ mvn -Penable-integration-tests clean verify
5353

5454
## Code Samples
5555

56-
Code Samples must be bundled in separate Maven modules, and guarded by a
57-
Maven profile with the name `enable-samples`.
56+
All code samples must be in compliance with the [java sample formatting guide][3].
57+
Code Samples must be bundled in separate Maven modules.
5858

5959
The samples must be separate from the primary project for a few reasons:
60-
1. Primary projects have a minimum Java version of Java 7 whereas samples have
61-
a minimum Java version of Java 8. Due to this we need the ability to
60+
1. Primary projects have a minimum Java version of Java 8 whereas samples can have
61+
Java version of Java 11. Due to this we need the ability to
6262
selectively exclude samples from a build run.
6363
2. Many code samples depend on external GCP services and need
6464
credentials to access the service.
@@ -68,39 +68,16 @@ The samples must be separate from the primary project for a few reasons:
6868
### Building
6969

7070
```bash
71-
mvn -Penable-samples clean verify
71+
mvn clean verify
7272
```
7373

7474
Some samples require access to GCP services and require a service account:
7575

7676
```bash
7777
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service/account.json
78-
mvn -Penable-samples clean verify
78+
mvn clean verify
7979
```
8080

81-
### Profile Config
82-
83-
1. To add samples in a profile to your Maven project, add the following to your
84-
`pom.xml`
85-
86-
```xml
87-
<project>
88-
[...]
89-
<profiles>
90-
<profile>
91-
<id>enable-samples</id>
92-
<modules>
93-
<module>sample</module>
94-
</modules>
95-
</profile>
96-
</profiles>
97-
[...]
98-
</project>
99-
```
100-
101-
2. [Activate](#profile-activation) the profile.
102-
3. Define your samples in a normal Maven project in the `samples/` directory.
103-
10481
### Code Formatting
10582

10683
Code in this repo is formatted with
@@ -110,30 +87,6 @@ To run formatting on your project, you can run:
11087
mvn com.coveo:fmt-maven-plugin:format
11188
```
11289

113-
### Profile Activation
114-
115-
To include code samples when building and testing the project, enable the
116-
`enable-samples` Maven profile.
117-
118-
#### Command line
119-
120-
To activate the Maven profile on the command line add `-Penable-samples` to your
121-
Maven command.
122-
123-
#### Maven `settings.xml`
124-
125-
To activate the Maven profile in your `~/.m2/settings.xml` add an entry of
126-
`enable-samples` following the instructions in [Active Profiles][2].
127-
128-
This method has the benefit of applying to all projects you build (and is
129-
respected by IntelliJ IDEA) and is recommended if you are going to be
130-
contributing samples to several projects.
131-
132-
#### IntelliJ IDEA
133-
134-
To activate the Maven Profile inside IntelliJ IDEA, follow the instructions in
135-
[Activate Maven profiles][3] to activate `enable-samples`.
136-
13790
[1]: https://cloud.google.com/docs/authentication/getting-started#creating_a_service_account
13891
[2]: https://maven.apache.org/settings.html#Active_Profiles
139-
[3]: https://www.jetbrains.com/help/idea/work-with-maven-profiles.html#activate_maven_profiles
92+
[3]: https://github.com/GoogleCloudPlatform/java-docs-samples/blob/main/SAMPLE_FORMAT.md

docs/setup.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ the `dependencyManagement` section of your `pom.xml`:
2323
<dependency>
2424
<groupId>com.google.cloud</groupId>
2525
<artifactId>libraries-bom</artifactId>
26-
<version>23.1.0</version>
26+
<version>24.1.0</version>
2727
<type>pom</type>
2828
<scope>import</scope>
2929
</dependency>

google-http-client-bom/pom.xml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,18 +144,10 @@
144144
<plugin>
145145
<groupId>com.coveo</groupId>
146146
<artifactId>fmt-maven-plugin</artifactId>
147-
<version>2.9</version>
147+
<version>2.13</version>
148148
<configuration>
149-
<style>google</style>
150149
<verbose>true</verbose>
151150
</configuration>
152-
<dependencies>
153-
<dependency>
154-
<groupId>com.google.googlejavaformat</groupId>
155-
<artifactId>google-java-format</artifactId>
156-
<version>1.7</version>
157-
</dependency>
158-
</dependencies>
159151
</plugin>
160152
</plugins>
161153
</build>

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,9 @@ public HttpResponse execute() throws IOException {
11321132
// throw an exception if unsuccessful response
11331133
if (throwExceptionOnExecuteError && !response.isSuccessStatusCode()) {
11341134
try {
1135-
throw new HttpResponseException(response);
1135+
throw new HttpResponseException.Builder(response)
1136+
.setAttemptCount(numRetries - retriesRemaining)
1137+
.build();
11361138
} finally {
11371139
response.disconnect();
11381140
}

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ public class HttpResponseException extends IOException {
4242
/** HTTP response content or {@code null} for none. */
4343
private final String content;
4444

45+
/** Number of attempts performed */
46+
private final int attemptCount;
47+
4548
/**
4649
* Constructor that constructs a detail message from the given HTTP response that includes the
4750
* status code, status message and HTTP response content.
@@ -73,6 +76,7 @@ protected HttpResponseException(Builder builder) {
7376
statusMessage = builder.statusMessage;
7477
headers = builder.headers;
7578
content = builder.content;
79+
attemptCount = builder.attemptCount;
7680
}
7781

7882
/**
@@ -121,6 +125,15 @@ public final String getContent() {
121125
return content;
122126
}
123127

128+
/**
129+
* Returns the attempt count
130+
*
131+
* @since 1.41
132+
*/
133+
public final int getAttemptCount() {
134+
return attemptCount;
135+
}
136+
124137
/**
125138
* Builder.
126139
*
@@ -145,6 +158,9 @@ public static class Builder {
145158
/** Detail message to use or {@code null} for none. */
146159
String message;
147160

161+
/** Number of attempts performed */
162+
int attemptCount;
163+
148164
/**
149165
* @param statusCode HTTP status code
150166
* @param statusMessage status message or {@code null}
@@ -260,6 +276,18 @@ public Builder setContent(String content) {
260276
return this;
261277
}
262278

279+
/** Returns the request attempt count */
280+
public final int getAttemptCount() {
281+
return attemptCount;
282+
}
283+
284+
/** Sets the attempt count for the related HTTP request execution. */
285+
public Builder setAttemptCount(int attemptCount) {
286+
Preconditions.checkArgument(attemptCount >= 0);
287+
this.attemptCount = attemptCount;
288+
return this;
289+
}
290+
263291
/** Returns a new instance of {@link HttpResponseException} based on this builder. */
264292
public HttpResponseException build() {
265293
return new HttpResponseException(this);

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ public class HttpRequestTracingTest {
4444
public void setupTestTracer() {
4545
Tracing.getExportComponent().getSpanExporter().registerHandler("test", testHandler);
4646
TraceParams params =
47-
Tracing.getTraceConfig()
48-
.getActiveTraceParams()
49-
.toBuilder()
47+
Tracing.getTraceConfig().getActiveTraceParams().toBuilder()
5048
.setSampler(Samplers.alwaysSample())
5149
.build();
5250
Tracing.getTraceConfig().updateActiveTraceParams(params);

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@
2323
import com.google.api.client.testing.http.MockHttpTransport;
2424
import com.google.api.client.testing.http.MockLowLevelHttpRequest;
2525
import com.google.api.client.testing.http.MockLowLevelHttpResponse;
26+
import com.google.api.client.util.ExponentialBackOff;
2627
import java.io.ByteArrayInputStream;
2728
import java.io.ByteArrayOutputStream;
2829
import java.io.IOException;
2930
import java.io.ObjectInputStream;
3031
import java.io.ObjectOutput;
3132
import java.io.ObjectOutputStream;
3233
import junit.framework.TestCase;
34+
import org.junit.Assert;
3335
import org.junit.function.ThrowingRunnable;
3436

3537
/**
@@ -208,6 +210,8 @@ public void run() throws Throwable {
208210
+ SIMPLE_GENERIC_URL
209211
+ LINE_SEPARATOR
210212
+ "Unable to find resource");
213+
// no retries expected
214+
assertEquals(1, responseException.getAttemptCount());
211215
}
212216

213217
public void testInvalidCharset() throws Exception {
@@ -245,6 +249,50 @@ public void run() throws Throwable {
245249
.isEqualTo("404 Not Found\nGET " + SIMPLE_GENERIC_URL);
246250
}
247251

252+
public void testAttemptCountWithBackOff() throws Exception {
253+
HttpTransport fakeTransport =
254+
new MockHttpTransport() {
255+
@Override
256+
public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
257+
return new MockLowLevelHttpRequest() {
258+
@Override
259+
public LowLevelHttpResponse execute() throws IOException {
260+
MockLowLevelHttpResponse result = new MockLowLevelHttpResponse();
261+
result.setStatusCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR);
262+
result.setReasonPhrase("Error");
263+
result.setContent("Unknown Error");
264+
return result;
265+
}
266+
};
267+
}
268+
};
269+
ExponentialBackOff backoff = new ExponentialBackOff.Builder().build();
270+
final HttpRequest request =
271+
fakeTransport.createRequestFactory().buildGetRequest(new GenericUrl("http://not/used"));
272+
request.setUnsuccessfulResponseHandler(
273+
new HttpBackOffUnsuccessfulResponseHandler(backoff)
274+
.setBackOffRequired(
275+
new HttpBackOffUnsuccessfulResponseHandler.BackOffRequired() {
276+
public boolean isRequired(HttpResponse response) {
277+
return true;
278+
}
279+
}));
280+
request.setNumberOfRetries(1);
281+
HttpResponseException responseException =
282+
assertThrows(
283+
HttpResponseException.class,
284+
new ThrowingRunnable() {
285+
@Override
286+
public void run() throws Throwable {
287+
request.execute();
288+
}
289+
});
290+
291+
Assert.assertEquals(500, responseException.getStatusCode());
292+
// original request and 1 retry - total 2
293+
assertEquals(2, responseException.getAttemptCount());
294+
}
295+
248296
public void testUnsupportedCharset() throws Exception {
249297
HttpTransport transport =
250298
new MockHttpTransport() {

0 commit comments

Comments
 (0)