|
20 | 20 | import static org.hamcrest.CoreMatchers.is;
|
21 | 21 | import static org.hamcrest.MatcherAssert.assertThat;
|
22 | 22 | import static org.junit.Assert.assertEquals;
|
| 23 | +import static org.junit.Assert.assertNotSame; |
23 | 24 | import static org.junit.Assert.assertSame;
|
24 | 25 | import static org.junit.Assert.assertThrows;
|
25 | 26 | import static org.mockito.Mockito.mock;
|
@@ -918,4 +919,72 @@ public void testCustomAsyncExecutorProvider() {
|
918 | 919 | .build();
|
919 | 920 | assertSame(service, options.getAsyncExecutorProvider().getExecutor());
|
920 | 921 | }
|
| 922 | + |
| 923 | + @Test |
| 924 | + public void testDefaultNumChannelsWithGrpcGcpExtensionEnabled() { |
| 925 | + SpannerOptions options = |
| 926 | + SpannerOptions.newBuilder().setProjectId("test-project").enableGrpcGcpExtension().build(); |
| 927 | + |
| 928 | + assertEquals(SpannerOptions.GRPC_GCP_ENABLED_DEFAULT_CHANNELS, options.getNumChannels()); |
| 929 | + } |
| 930 | + |
| 931 | + @Test |
| 932 | + public void testDefaultNumChannelsWithGrpcGcpExtensionDisabled() { |
| 933 | + SpannerOptions options = SpannerOptions.newBuilder().setProjectId("test-project").build(); |
| 934 | + |
| 935 | + assertEquals(SpannerOptions.DEFAULT_CHANNELS, options.getNumChannels()); |
| 936 | + } |
| 937 | + |
| 938 | + @Test |
| 939 | + public void testNumChannelsWithGrpcGcpExtensionEnabled() { |
| 940 | + // Set number of channels explicitly, before enabling gRPC-GCP channel pool in SpannerOptions |
| 941 | + // builder. |
| 942 | + int numChannels = 5; |
| 943 | + SpannerOptions options1 = |
| 944 | + SpannerOptions.newBuilder() |
| 945 | + .setProjectId("test-project") |
| 946 | + .setNumChannels(numChannels) |
| 947 | + .enableGrpcGcpExtension() |
| 948 | + .build(); |
| 949 | + |
| 950 | + assertEquals(numChannels, options1.getNumChannels()); |
| 951 | + |
| 952 | + // Set number of channels explicitly, after enabling gRPC-GCP channel pool in SpannerOptions |
| 953 | + // builder. |
| 954 | + SpannerOptions options2 = |
| 955 | + SpannerOptions.newBuilder() |
| 956 | + .setProjectId("test-project") |
| 957 | + .enableGrpcGcpExtension() |
| 958 | + .setNumChannels(numChannels) |
| 959 | + .build(); |
| 960 | + |
| 961 | + assertEquals(numChannels, options2.getNumChannels()); |
| 962 | + } |
| 963 | + |
| 964 | + @Test |
| 965 | + public void checkCreatedInstanceWhenGrpcGcpExtensionDisabled() { |
| 966 | + SpannerOptions options = SpannerOptions.newBuilder().setProjectId("test-project").build(); |
| 967 | + SpannerOptions options1 = options.toBuilder().build(); |
| 968 | + assertEquals(false, options.isGrpcGcpExtensionEnabled()); |
| 969 | + assertEquals(options.isGrpcGcpExtensionEnabled(), options1.isGrpcGcpExtensionEnabled()); |
| 970 | + |
| 971 | + Spanner spanner1 = options.getService(); |
| 972 | + Spanner spanner2 = options1.getService(); |
| 973 | + |
| 974 | + assertNotSame(spanner1, spanner2); |
| 975 | + } |
| 976 | + |
| 977 | + @Test |
| 978 | + public void checkCreatedInstanceWhenGrpcGcpExtensionEnabled() { |
| 979 | + SpannerOptions options = |
| 980 | + SpannerOptions.newBuilder().setProjectId("test-project").enableGrpcGcpExtension().build(); |
| 981 | + SpannerOptions options1 = options.toBuilder().build(); |
| 982 | + assertEquals(true, options.isGrpcGcpExtensionEnabled()); |
| 983 | + assertEquals(options.isGrpcGcpExtensionEnabled(), options1.isGrpcGcpExtensionEnabled()); |
| 984 | + |
| 985 | + Spanner spanner1 = options.getService(); |
| 986 | + Spanner spanner2 = options1.getService(); |
| 987 | + |
| 988 | + assertNotSame(spanner1, spanner2); |
| 989 | + } |
921 | 990 | }
|
0 commit comments