Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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 @@ -696,6 +696,7 @@ public static class Builder
private CloseableExecutorProvider asyncExecutorProvider;
private String compressorName;
private String emulatorHost = System.getenv("SPANNER_EMULATOR_HOST");
private boolean userSpecifiedNumChannels = false;

private Builder() {
// Manually set retry and polling settings that work.
Expand Down Expand Up @@ -815,6 +816,7 @@ public Builder setInterceptorProvider(GrpcInterceptorProvider interceptorProvide
*/
public Builder setNumChannels(int numChannels) {
this.numChannels = numChannels;
this.userSpecifiedNumChannels = true;
return this;
}

Expand Down Expand Up @@ -1123,6 +1125,9 @@ public Builder setHost(String host) {
/** Enables gRPC-GCP extension with the default settings. */
public Builder enableGrpcGcpExtension() {
this.grpcGcpExtensionEnabled = true;
if (!userSpecifiedNumChannels) { // If numChannels is not set through options
this.numChannels = 8; // default when grpc-gcp channel pool is enabled
}
return this;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.google.cloud.spanner;

import static com.google.common.truth.Truth.assertThat;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
public class DefaultNumChannelsTest {

// With GRPC GCP channel pool enabled
@Test
public void testDefaultNumChannelsWithGrpcGcpEnabled() {
SpannerOptions.Builder builder = SpannerOptions.newBuilder()
.setProjectId("test-project")
.enableGrpcGcpExtension();

SpannerOptions options = builder.build();
assertThat(options.getNumChannels()).isEqualTo(8);
}

@Test
public void testNumChannelsWithGrpcGcpEnabledLater() {
SpannerOptions.Builder builder = SpannerOptions.newBuilder()
.setProjectId("test-project")
.setNumChannels(5)
.enableGrpcGcpExtension();

SpannerOptions options = builder.build();
assertThat(options.getNumChannels()).isEqualTo(5);
}

@Test
public void testNumChannelsWithGrpcGcpEnabled() {
SpannerOptions.Builder builder = SpannerOptions.newBuilder()
.setProjectId("test-project")
.enableGrpcGcpExtension()
.setNumChannels(5);

SpannerOptions options = builder.build();
assertThat(options.getNumChannels()).isEqualTo(5);
}

// Without enabling GRPC GCP channel pool
@Test
public void testDefaultNumChannelsWithOutGrpcGcpEnabled() {
SpannerOptions.Builder builder = SpannerOptions.newBuilder()
.setProjectId("test-project");

SpannerOptions options = builder.build();
assertThat(options.getNumChannels()).isEqualTo(4);
}

@Test
public void testNumChannelsWithOutGrpcGcpEnabled() {
SpannerOptions.Builder builder = SpannerOptions.newBuilder()
.setProjectId("test-project")
.setNumChannels(7);

SpannerOptions options = builder.build();
assertThat(options.getNumChannels()).isEqualTo(7);
}
}