-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: update retry handling to retry idempotent requests that encounte…
…r unexpected EOF while parsing json responses (#1155) * fix: update retry handling to retry idempotent requests that encounter unexpected EOF while parsing json responses ### Fix Update DefaultStorageRetryStrategy to account for EOF errors from Json. When parsing json it's possible we've only received a partial document and parsing will fail. If an unexpected EOF happens from parsing and the request is idempotent retry it. #### Tests Add two new integration tests which leverage the testbench to force the EOF to happen upon the completion of the resumable session. * Add 0B offset test * Add 10B offset test Add new cases to DefaultRetryHandlingBehaviorTest to ensure continued expected handling for the new EOF behavior. #### Refactor * Make TestBench.java (and its associated Builder) public to allow for use outside the retry conformance test package * Create new JUnit @rule DataGeneration moving com.google.cloud.storage.it.ITStorageTest#randString to it and change the signature to produce a ByteBuffer rather than a string. (this should simplify use since the strings returned were immediately turned to bytes) Fixes #1154 deps: update storage-testbench to v0.10.0 * chore: update testbench rule to use a different port than retry conformance tests
- Loading branch information
1 parent
fe4b920
commit 8fbe6ef
Showing
10 changed files
with
471 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
google-cloud-storage/src/test/java/com/google/cloud/storage/DataGeneration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright 2021 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.cloud.storage; | ||
|
||
import java.nio.ByteBuffer; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Random; | ||
import org.junit.rules.TestRule; | ||
import org.junit.runner.Description; | ||
import org.junit.runners.model.Statement; | ||
|
||
public final class DataGeneration implements TestRule { | ||
|
||
private final Random rand; | ||
|
||
public DataGeneration(Random rand) { | ||
this.rand = rand; | ||
} | ||
|
||
public ByteBuffer randByteBuffer(int limit) { | ||
ByteBuffer b = ByteBuffer.allocate(limit); | ||
fillByteBuffer(b); | ||
return b; | ||
} | ||
|
||
public void fillByteBuffer(ByteBuffer b) { | ||
while (b.position() < b.limit()) { | ||
int i = rand.nextInt('z'); | ||
char c = (char) i; | ||
if (Character.isLetter(c) || Character.isDigit(c)) { | ||
b.put(Character.toString(c).getBytes(StandardCharsets.UTF_8)); | ||
} | ||
} | ||
b.position(0); | ||
} | ||
|
||
@Override | ||
public Statement apply(Statement base, Description description) { | ||
return new Statement() { | ||
@Override | ||
public void evaluate() throws Throwable { | ||
base.evaluate(); | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.