Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ public abstract class GoogleAdsClient extends AbstractGoogleAdsClient {
/** The default endpoint for Google Ads API services. */
private static final String DEFAULT_ENDPOINT = "googleads.googleapis.com:443";

/**
* Default max inbound metadata (headers) size. Inbound headers for the Google Ads API may exceed
* the default max of 8KB.
*/
@VisibleForTesting static final Integer DEFAULT_MAX_INBOUND_METADATA_SIZE = 16 * 1024 * 1024;

/**
* Default max inbound message (response) size. Large response will often exceed the default of
* 4MB.
*/
@VisibleForTesting static final Integer DEFAULT_MAX_INBOUND_MESSAGE_SIZE = 64 * 1024 * 1024;
Comment thread
jradcliff marked this conversation as resolved.

static {
// Alpha feature to optimize the client startup time.
Primer.primeBasicsIfEnabled();
Expand All @@ -88,12 +100,8 @@ public static Builder newBuilder() {
new RequestLogger(),
clientBuilder.getHeaders(),
clientBuilder.getEndpoint())))
// Issue 131: inbound headers may exceed default (8kb) max header size.
// Sets max header size to 16MB, which should be more than necessary.
.setMaxInboundMetadataSize(16 * 1024 * 1024)
// Sets max response size to 64MB, since large responses will often exceed the default
// (4MB).
.setMaxInboundMessageSize(64 * 1024 * 1024)
.setMaxInboundMetadataSize(DEFAULT_MAX_INBOUND_METADATA_SIZE)
.setMaxInboundMessageSize(DEFAULT_MAX_INBOUND_MESSAGE_SIZE)
.build();
clientBuilder
.setEndpoint(DEFAULT_ENDPOINT)
Expand Down Expand Up @@ -584,6 +592,8 @@ public GoogleAdsClient build() {
ImmutableList.of(
new LoggingInterceptor(
new RequestLogger(), getHeaders(), getEndpoint())))
.setMaxInboundMetadataSize(DEFAULT_MAX_INBOUND_METADATA_SIZE)
.setMaxInboundMessageSize(DEFAULT_MAX_INBOUND_MESSAGE_SIZE)
.build();
}
if (transportChannelProvider.needsHeaders()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.google.ads.googleads.v10.services.SearchGoogleAdsStreamResponse;
import com.google.api.gax.grpc.GaxGrpcProperties;
import com.google.api.gax.grpc.GrpcStatusCode;
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
import com.google.api.gax.grpc.testing.LocalChannelProvider;
import com.google.api.gax.grpc.testing.MockServiceHelper;
import com.google.api.gax.rpc.ApiClientHeaderProvider;
Expand Down Expand Up @@ -190,10 +191,7 @@ public void testBuildFromPropertiesFile_withoutLoginCustomerId() throws IOExcept

// Build a new client from the file.
GoogleAdsClient client =
GoogleAdsClient.newBuilder()
.fromPropertiesFile(propertiesFile)
.setTransportChannelProvider(localChannelProvider)
.build();
GoogleAdsClient.newBuilder().fromPropertiesFile(propertiesFile).build();
assertGoogleAdsClient(client, null, true);
}

Expand Down Expand Up @@ -253,7 +251,7 @@ public void setLoginCustomerId_canClearOnceSet() {

/** Tests building a client without the use of a properties file. */
@Test
public void buildWithoutPropertiesFile_supportsAllFields() throws IOException {
public void buildWithoutPropertiesFile_supportsAllFields() {
Credentials credentials =
UserCredentials.newBuilder()
.setClientId(CLIENT_ID)
Expand All @@ -265,7 +263,6 @@ public void buildWithoutPropertiesFile_supportsAllFields() throws IOException {
.setCredentials(credentials)
.setDeveloperToken(DEVELOPER_TOKEN)
.setLoginCustomerId(LOGIN_CUSTOMER_ID)
.setTransportChannelProvider(localChannelProvider)
.build();
assertGoogleAdsClient(client, true);
}
Expand Down Expand Up @@ -888,6 +885,20 @@ private void assertGoogleAdsClient(
serviceAccountCredentials.getScopes());
}

if (client.getTransportChannelProvider() == client.getDefaultTransportChannelProvider()) {
InstantiatingGrpcChannelProvider channelProvider =
(InstantiatingGrpcChannelProvider) client.getTransportChannelProvider();
assertEquals(
"Max inbound metadata size",
GoogleAdsClient.DEFAULT_MAX_INBOUND_METADATA_SIZE,
channelProvider.getMaxInboundMetadataSize());
assertEquals(
"Max inbound message size",
GoogleAdsClient.DEFAULT_MAX_INBOUND_MESSAGE_SIZE,
// For some reason, this setting is only available on the builder.
channelProvider.toBuilder().getMaxInboundMessageSize());
}

assertEquals("Developer token", DEVELOPER_TOKEN, client.getDeveloperToken());
assertEquals("Login customer id", loginCustomerId, client.getLoginCustomerId());
}
Expand Down