From 8f48b7027b95e8e75872d1f9dac537ea697d0acc Mon Sep 17 00:00:00 2001 From: Mattie Fu Date: Mon, 9 Aug 2021 17:36:52 -0400 Subject: [PATCH] fix: fix httpjson executor (#1448) --- .../api/gax/httpjson/ManagedHttpJsonChannel.java | 2 +- .../InstantiatingHttpJsonChannelProviderTest.java | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/gax-httpjson/src/main/java/com/google/api/gax/httpjson/ManagedHttpJsonChannel.java b/gax-httpjson/src/main/java/com/google/api/gax/httpjson/ManagedHttpJsonChannel.java index af3e9bbd7..760f3f0b1 100644 --- a/gax-httpjson/src/main/java/com/google/api/gax/httpjson/ManagedHttpJsonChannel.java +++ b/gax-httpjson/src/main/java/com/google/api/gax/httpjson/ManagedHttpJsonChannel.java @@ -153,7 +153,7 @@ public static class Builder { private Builder() {} public Builder setExecutor(Executor executor) { - this.executor = Preconditions.checkNotNull(executor); + this.executor = executor == null ? DEFAULT_EXECUTOR : executor; return this; } diff --git a/gax-httpjson/src/test/java/com/google/api/gax/httpjson/InstantiatingHttpJsonChannelProviderTest.java b/gax-httpjson/src/test/java/com/google/api/gax/httpjson/InstantiatingHttpJsonChannelProviderTest.java index bc00f164b..4061ff8ba 100644 --- a/gax-httpjson/src/test/java/com/google/api/gax/httpjson/InstantiatingHttpJsonChannelProviderTest.java +++ b/gax-httpjson/src/test/java/com/google/api/gax/httpjson/InstantiatingHttpJsonChannelProviderTest.java @@ -62,6 +62,13 @@ public void basicTest() throws IOException { provider = provider.withEndpoint(endpoint); assertThat(provider.needsEndpoint()).isFalse(); + assertThat(provider.needsHeaders()).isTrue(); + provider = provider.withHeaders(Collections.emptyMap()); + assertThat(provider.needsHeaders()).isFalse(); + + // Make sure getTransportChannel works without setting executor + assertThat(provider.getTransportChannel()).isInstanceOf(HttpJsonTransportChannel.class); + assertThat(provider.needsExecutor()).isTrue(); provider = provider.withExecutor((Executor) executor); assertThat(provider.needsExecutor()).isFalse(); @@ -71,10 +78,6 @@ public void basicTest() throws IOException { provider = provider.withExecutor(executor); assertThat(provider.needsExecutor()).isFalse(); - assertThat(provider.needsHeaders()).isTrue(); - provider = provider.withHeaders(Collections.emptyMap()); - assertThat(provider.needsHeaders()).isFalse(); - assertThat(provider.acceptsPoolSize()).isFalse(); Exception thrownException = null; try {