Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Commit

Permalink
make ClientContext work properly with old surface (#312)
Browse files Browse the repository at this point in the history
This fixes a bug introduced in #305.
UnaryCallable uses ClientContext to pass values.
To ease transition, old surfaces are marked deprecated
but reimplemented using ClientContext.

These old surfaces did not populate closeables,
so ClientContext cannot be initialized.
This PR side steps this problem by initializing closeables
to empty list.
  • Loading branch information
pongad authored May 24, 2017
1 parent bfe8064 commit 042cbfe
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import io.grpc.ManagedChannel;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.concurrent.ScheduledExecutorService;
import javax.annotation.Nullable;

Expand All @@ -59,7 +60,8 @@ public abstract class ClientContext {
public abstract Credentials getCredentials();

static Builder newBuilder() {
return new AutoValue_ClientContext.Builder();
return new AutoValue_ClientContext.Builder()
.setCloseables(Collections.<AutoCloseable>emptyList());
}

public static ClientContext create(ClientSettings settings) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.google.api.gax.batching.RequestBuilder;
import com.google.api.gax.batching.TrackedFlowController;
import com.google.api.gax.core.FakeApiClock;
import com.google.api.gax.grpc.testing.FakeMethodDescriptor;
import com.google.api.gax.paging.FixedSizeCollection;
import com.google.api.gax.paging.Page;
import com.google.api.gax.retrying.RetrySettings;
Expand Down Expand Up @@ -137,6 +138,27 @@ public ApiFuture<ResponseT> futureCall(RequestT request, CallContext context) {
}
}

@Test
public void createNoThrow() {
SimpleCallSettings settings =
SimpleCallSettings.newBuilder(FakeMethodDescriptor.create())
.setRetryableCodes()
.setRetrySettingsBuilder(
RetrySettings.newBuilder()
.setTotalTimeout(Duration.ZERO)
.setInitialRetryDelay(Duration.ZERO)
.setRetryDelayMultiplier(1)
.setMaxRetryDelay(Duration.ZERO)
.setMaxAttempts(1)
.setInitialRpcTimeout(Duration.ZERO)
.setRpcTimeoutMultiplier(1)
.setMaxRpcTimeout(Duration.ZERO))
.build();
Channel channel = Mockito.mock(Channel.class);
ScheduledExecutorService executor = Mockito.mock(ScheduledExecutorService.class);
UnaryCallable.<Integer, Integer>create(settings, channel, executor);
}

@Test
public void simpleCall() throws Exception {
StashCallable<Integer, Integer> stash = new StashCallable<>(1);
Expand Down

0 comments on commit 042cbfe

Please sign in to comment.