diff --git a/java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/BidiUploadStreamingStream.java b/java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/BidiUploadStreamingStream.java index f6b9ae399e34..89624f5f0fbf 100644 --- a/java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/BidiUploadStreamingStream.java +++ b/java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/BidiUploadStreamingStream.java @@ -165,6 +165,10 @@ public void flush() { public boolean finishWrite(long length) { lock.lock(); try { + State currentState = state.getState(); + if (currentState == State.TERMINAL_SUCCESS || currentState == State.TERMINAL_ERROR) { + return true; + } // if we're already finalizing, ack rather than enqueueing again if (state.isFinalizing() && state.getTotalSentBytes() == length) { return true; @@ -192,6 +196,11 @@ public boolean closeStream(long length) { lock.lock(); try { + State currentState = state.getState(); + if (currentState == State.TERMINAL_SUCCESS || currentState == State.TERMINAL_ERROR) { + return true; + } + boolean offer = state.finalFlush(length); if (offer) { internalSend(); diff --git a/java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/BidiUploadTest.java b/java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/BidiUploadTest.java index 2774981ecd62..725d8795c837 100644 --- a/java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/BidiUploadTest.java +++ b/java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/BidiUploadTest.java @@ -1356,6 +1356,11 @@ boolean isFinalizing() { return false; } + @Override + State getState() { + return State.RUNNING; + } + @Override long getTotalSentBytes() { return 0; diff --git a/java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/ITGapicUnbufferedWritableByteChannelTest.java b/java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/ITGapicUnbufferedWritableByteChannelTest.java index 3aa567a4d6a0..7730d672881f 100644 --- a/java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/ITGapicUnbufferedWritableByteChannelTest.java +++ b/java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/ITGapicUnbufferedWritableByteChannelTest.java @@ -380,12 +380,9 @@ static class DirectWriteService extends StorageImplBase { private static final Logger LOGGER = LoggerFactory.getLogger(DirectWriteService.class); private final BiConsumer, List> c; - private ImmutableList.Builder requests; - DirectWriteService( BiConsumer, List> c) { this.c = c; - this.requests = new ImmutableList.Builder<>(); } DirectWriteService(ImmutableMap, WriteObjectResponse> writes) { @@ -420,6 +417,9 @@ private static void logUnexpectedRequest( @Override public StreamObserver writeObject(StreamObserver obs) { return new Adapter() { + private final ImmutableList.Builder requests = + new ImmutableList.Builder<>(); + @Override public void onNext(WriteObjectRequest value) { requests.add(value); @@ -432,7 +432,6 @@ public void onError(Throwable t) {} public void onCompleted() { ImmutableList build = requests.build(); c.accept(obs, build); - requests = new ImmutableList.Builder<>(); } }; } diff --git a/java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/it/runner/registry/TestBench.java b/java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/it/runner/registry/TestBench.java index 4d9340762093..fca6975c6c43 100644 --- a/java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/it/runner/registry/TestBench.java +++ b/java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/it/runner/registry/TestBench.java @@ -262,7 +262,7 @@ public void start() { dockerImage, "gunicorn", "--bind=0.0.0.0:9000", - "--worker-class=sync", + "--worker-class=gevent", "--threads=10", "--access-logfile=-", "--keep-alive=0", @@ -442,8 +442,8 @@ public String toString() { } static final class Builder { - private static final String DEFAULT_BASE_URI = "http://localhost:9000"; - private static final String DEFAULT_GRPC_BASE_URI = "http://localhost:9005"; + private static final String DEFAULT_BASE_URI = "http://127.0.0.1:9000"; + private static final String DEFAULT_GRPC_BASE_URI = "http://127.0.0.1:9005"; private static final String DEFAULT_IMAGE_NAME; private static final String DEFAULT_IMAGE_TAG;