Skip to content

Commit 7545a19

Browse files
committed
test(storage): fix mock finalization mapping in ITGapicBidiUnbufferedWritableByteChannelTest
1 parent 1b082c2 commit 7545a19

5 files changed

Lines changed: 49 additions & 21 deletions

File tree

java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/FakeHttpServer.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
import java.net.URI;
5151
import java.time.Duration;
5252
import java.util.Map;
53-
5453
import org.slf4j.Logger;
5554
import org.slf4j.LoggerFactory;
5655

@@ -62,7 +61,6 @@ final class FakeHttpServer implements AutoCloseable {
6261
private final Runnable shutdown;
6362
private final HttpStorageOptions httpStorageOptions;
6463

65-
6664
private FakeHttpServer(
6765
URI endpoint, Channel channel, Runnable shutdown, HttpStorageOptions httpStorageOptions) {
6866
this.endpoint = endpoint;

java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/ITGapicBidiUnbufferedWritableByteChannelTest.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -732,8 +732,18 @@ public void incremental_success() throws Exception {
732732
BidiWriteObjectResponse resp1 =
733733
BidiWriteObjectResponse.newBuilder().setPersistedSize(_256KiB).build();
734734

735+
BidiWriteObjectRequest req2 =
736+
BidiWriteObjectRequest.newBuilder().setWriteOffset(_256KiB).setFinishWrite(true).build();
737+
BidiWriteObjectResponse resp2 =
738+
BidiWriteObjectResponse.newBuilder()
739+
.setResource(Object.newBuilder().setName("obj").setSize(_256KiB).build())
740+
.build();
741+
735742
ImmutableMap<List<BidiWriteObjectRequest>, BidiWriteObjectResponse> map =
736-
ImmutableMap.of(ImmutableList.of(req1), resp1);
743+
ImmutableMap.of(
744+
ImmutableList.of(req1), resp1,
745+
ImmutableList.of(req2), resp2,
746+
ImmutableList.of(req1, req2), resp2);
737747
BidiWriteService service1 = new BidiWriteService(map);
738748

739749
try (FakeServer fakeServer = FakeServer.of(service1);
@@ -782,8 +792,18 @@ public void incremental_partialSuccess() throws Exception {
782792
BidiWriteObjectResponse resp1 =
783793
BidiWriteObjectResponse.newBuilder().setPersistedSize(_256KiB).build();
784794

795+
BidiWriteObjectRequest req2 =
796+
BidiWriteObjectRequest.newBuilder().setWriteOffset(_256KiB).setFinishWrite(true).build();
797+
BidiWriteObjectResponse resp2 =
798+
BidiWriteObjectResponse.newBuilder()
799+
.setResource(Object.newBuilder().setName("obj").setSize(_256KiB).build())
800+
.build();
801+
785802
ImmutableMap<List<BidiWriteObjectRequest>, BidiWriteObjectResponse> map =
786-
ImmutableMap.of(ImmutableList.of(req1), resp1);
803+
ImmutableMap.of(
804+
ImmutableList.of(req1), resp1,
805+
ImmutableList.of(req2), resp2,
806+
ImmutableList.of(req1, req2), resp2);
787807
BidiWriteService service1 = new BidiWriteService(map);
788808

789809
try (FakeServer fakeServer = FakeServer.of(service1);

java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/ParallelCompositeUploadWritableByteChannelTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,8 +693,10 @@ public BlobInfo compose(ComposeRequest composeRequest) {
693693
() -> assertThat(se2).hasMessageThat().contains("Checksum mismatch"),
694694
() -> {
695695
assertThat(se2).hasCauseThat().isInstanceOf(ParallelCompositeUploadException.class);
696-
ParallelCompositeUploadException pcue = (ParallelCompositeUploadException) se2.getCause();
697-
// since we fail client side with a checksum validation, we expect the object to have been
696+
ParallelCompositeUploadException pcue =
697+
(ParallelCompositeUploadException) se2.getCause();
698+
// since we fail client side with a checksum validation, we expect the object to have
699+
// been
698700
// created
699701
assertThat(pcue.getCreatedObjects().get()).containsExactly(p1, expectedId);
700702
},

java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/it/runner/registry/Registry.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,17 @@ public final class Registry extends RunListener {
7474
new ThreadFactoryBuilder().setDaemon(true).setNameFormat("test-run-%d").build()));
7575

7676
private final TestRunScopedInstance<TestBench> testBench =
77-
TestRunScopedInstance.of("fixture/TEST_BENCH", () -> {
78-
int httpPort = findFreePort();
79-
int grpcPort = findFreePort();
80-
return TestBench.newBuilder()
81-
.setBaseUri("http://localhost:" + httpPort)
82-
.setGRPCBaseUri("http://localhost:" + grpcPort)
83-
.setContainerName("fork-" + httpPort)
84-
.build();
85-
});
77+
TestRunScopedInstance.of(
78+
"fixture/TEST_BENCH",
79+
() -> {
80+
int httpPort = findFreePort();
81+
int grpcPort = findFreePort();
82+
return TestBench.newBuilder()
83+
.setBaseUri("http://localhost:" + httpPort)
84+
.setGRPCBaseUri("http://localhost:" + grpcPort)
85+
.setContainerName("fork-" + httpPort)
86+
.build();
87+
});
8688

8789
private final TestRunScopedInstance<Generator> generator =
8890
TestRunScopedInstance.of("fixture/GENERATOR", Generator::new);

java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/it/runner/registry/TestBench.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@
4242
import com.google.gson.JsonArray;
4343
import com.google.gson.JsonElement;
4444
import com.google.gson.JsonObject;
45-
import java.io.BufferedReader;
4645
import java.io.File;
47-
import java.io.FileReader;
4846
import java.io.IOException;
4947
import java.io.InputStream;
5048
import java.io.InputStreamReader;
@@ -383,13 +381,21 @@ public boolean shouldRetry(Throwable previousThrowable, List<?> previousResponse
383381
}
384382

385383
private void dumpServerLogs(Path outFile, Path errFile) throws IOException {
386-
LOGGER.warn("TestBench container failed or timeout occurred. Server stdout: {}, stderr: {}",
387-
outFile.toAbsolutePath(), errFile.toAbsolutePath());
384+
LOGGER.warn(
385+
"TestBench container failed or timeout occurred. Server stdout: {}, stderr: {}",
386+
outFile.toAbsolutePath(),
387+
errFile.toAbsolutePath());
388388
try {
389389
Path targetLogsDir = java.nio.file.Paths.get("target/testbench-logs");
390390
java.nio.file.Files.createDirectories(targetLogsDir);
391-
java.nio.file.Files.copy(outFile, targetLogsDir.resolve(outFile.getFileName()), java.nio.file.StandardCopyOption.REPLACE_EXISTING);
392-
java.nio.file.Files.copy(errFile, targetLogsDir.resolve(errFile.getFileName()), java.nio.file.StandardCopyOption.REPLACE_EXISTING);
391+
java.nio.file.Files.copy(
392+
outFile,
393+
targetLogsDir.resolve(outFile.getFileName()),
394+
java.nio.file.StandardCopyOption.REPLACE_EXISTING);
395+
java.nio.file.Files.copy(
396+
errFile,
397+
targetLogsDir.resolve(errFile.getFileName()),
398+
java.nio.file.StandardCopyOption.REPLACE_EXISTING);
393399
LOGGER.warn("Copied Testbench logs to target directory: {}", targetLogsDir.toAbsolutePath());
394400
} catch (Exception e) {
395401
// ignore failures to copy

0 commit comments

Comments
 (0)