|
26 | 26 | import com.google.api.core.ApiFutureCallback; |
27 | 27 | import com.google.api.core.ApiFutures; |
28 | 28 | import com.google.api.gax.batching.FlowController; |
| 29 | +import com.google.api.gax.core.CredentialsProvider; |
| 30 | +import com.google.api.gax.core.FixedCredentialsProvider; |
29 | 31 | import com.google.api.gax.core.GoogleCredentialsProvider; |
30 | 32 | import com.google.api.gax.core.InstantiatingExecutorProvider; |
31 | 33 | import com.google.api.gax.core.NoCredentialsProvider; |
|
38 | 40 | import com.google.api.gax.rpc.InvalidArgumentException; |
39 | 41 | import com.google.api.gax.rpc.StatusCode.Code; |
40 | 42 | import com.google.api.gax.rpc.UnknownException; |
| 43 | +import com.google.auth.oauth2.UserCredentials; |
41 | 44 | import com.google.cloud.bigquery.storage.test.Test.FooType; |
42 | 45 | import com.google.cloud.bigquery.storage.v1.AppendRowsRequest.MissingValueInterpretation; |
43 | 46 | import com.google.cloud.bigquery.storage.v1.ConnectionWorkerPool.Settings; |
@@ -924,6 +927,109 @@ public void testProtoSchemaPiping_multiplexingCase() throws Exception { |
924 | 927 | writer2.close(); |
925 | 928 | } |
926 | 929 |
|
| 930 | + @Test |
| 931 | + public void testFixedCredentialProvider_nullProvider() throws Exception { |
| 932 | + // Use the shared connection mode. |
| 933 | + ConnectionWorkerPool.setOptions( |
| 934 | + Settings.builder().setMinConnectionsPerRegion(1).setMaxConnectionsPerRegion(1).build()); |
| 935 | + ProtoSchema schema1 = createProtoSchema("Schema1"); |
| 936 | + ProtoSchema schema2 = createProtoSchema("Schema2"); |
| 937 | + CredentialsProvider credentialsProvider1 = FixedCredentialsProvider.create(null); |
| 938 | + CredentialsProvider credentialsProvider2 = FixedCredentialsProvider.create(null); |
| 939 | + StreamWriter writer1 = |
| 940 | + StreamWriter.newBuilder(TEST_STREAM_1, client) |
| 941 | + .setWriterSchema(schema1) |
| 942 | + .setLocation("US") |
| 943 | + .setEnableConnectionPool(true) |
| 944 | + .setMaxInflightRequests(1) |
| 945 | + .setCredentialsProvider(credentialsProvider1) |
| 946 | + .build(); |
| 947 | + StreamWriter writer2 = |
| 948 | + StreamWriter.newBuilder(TEST_STREAM_2, client) |
| 949 | + .setWriterSchema(schema2) |
| 950 | + .setMaxInflightRequests(1) |
| 951 | + .setEnableConnectionPool(true) |
| 952 | + .setCredentialsProvider(credentialsProvider2) |
| 953 | + .setLocation("US") |
| 954 | + .build(); |
| 955 | + // Null credential provided belong to the same connection pool. |
| 956 | + assertEquals(writer1.getTestOnlyConnectionPoolMap().size(), 1); |
| 957 | + } |
| 958 | + |
| 959 | + @Test |
| 960 | + public void testFixedCredentialProvider_twoCredentialsSplitPool() throws Exception { |
| 961 | + // Use the shared connection mode. |
| 962 | + ConnectionWorkerPool.setOptions( |
| 963 | + Settings.builder().setMinConnectionsPerRegion(1).setMaxConnectionsPerRegion(1).build()); |
| 964 | + ProtoSchema schema1 = createProtoSchema("Schema1"); |
| 965 | + ProtoSchema schema2 = createProtoSchema("Schema2"); |
| 966 | + UserCredentials userCredentials1 = |
| 967 | + UserCredentials.newBuilder() |
| 968 | + .setClientId("CLIENT_ID_1") |
| 969 | + .setClientSecret("CLIENT_SECRET_1") |
| 970 | + .setRefreshToken("REFRESH_TOKEN_1") |
| 971 | + .build(); |
| 972 | + CredentialsProvider credentialsProvider1 = FixedCredentialsProvider.create(userCredentials1); |
| 973 | + UserCredentials userCredentials2 = |
| 974 | + UserCredentials.newBuilder() |
| 975 | + .setClientId("CLIENT_ID_2") |
| 976 | + .setClientSecret("CLIENT_SECRET_2") |
| 977 | + .setRefreshToken("REFRESH_TOKEN_2") |
| 978 | + .build(); |
| 979 | + CredentialsProvider credentialsProvider2 = FixedCredentialsProvider.create(userCredentials2); |
| 980 | + StreamWriter writer1 = |
| 981 | + StreamWriter.newBuilder(TEST_STREAM_1) |
| 982 | + .setWriterSchema(schema1) |
| 983 | + .setLocation("US") |
| 984 | + .setEnableConnectionPool(true) |
| 985 | + .setMaxInflightRequests(1) |
| 986 | + .setCredentialsProvider(credentialsProvider1) |
| 987 | + .build(); |
| 988 | + StreamWriter writer2 = |
| 989 | + StreamWriter.newBuilder(TEST_STREAM_2) |
| 990 | + .setWriterSchema(schema2) |
| 991 | + .setMaxInflightRequests(1) |
| 992 | + .setEnableConnectionPool(true) |
| 993 | + .setLocation("US") |
| 994 | + .setCredentialsProvider(credentialsProvider2) |
| 995 | + .build(); |
| 996 | + assertEquals(writer1.getTestOnlyConnectionPoolMap().size(), 2); |
| 997 | + } |
| 998 | + |
| 999 | + @Test |
| 1000 | + public void testFixedCredentialProvider_twoProviderSameCredentialSharePool() throws Exception { |
| 1001 | + // Use the shared connection mode. |
| 1002 | + ConnectionWorkerPool.setOptions( |
| 1003 | + Settings.builder().setMinConnectionsPerRegion(1).setMaxConnectionsPerRegion(1).build()); |
| 1004 | + ProtoSchema schema1 = createProtoSchema("Schema1"); |
| 1005 | + ProtoSchema schema2 = createProtoSchema("Schema2"); |
| 1006 | + UserCredentials userCredentials = |
| 1007 | + UserCredentials.newBuilder() |
| 1008 | + .setClientId("CLIENT_ID_1") |
| 1009 | + .setClientSecret("CLIENT_SECRET_1") |
| 1010 | + .setRefreshToken("REFRESH_TOKEN_1") |
| 1011 | + .build(); |
| 1012 | + CredentialsProvider credentialsProvider1 = FixedCredentialsProvider.create(userCredentials); |
| 1013 | + CredentialsProvider credentialsProvider2 = FixedCredentialsProvider.create(userCredentials); |
| 1014 | + StreamWriter writer1 = |
| 1015 | + StreamWriter.newBuilder(TEST_STREAM_1) |
| 1016 | + .setWriterSchema(schema1) |
| 1017 | + .setLocation("US") |
| 1018 | + .setEnableConnectionPool(true) |
| 1019 | + .setMaxInflightRequests(1) |
| 1020 | + .setCredentialsProvider(credentialsProvider1) |
| 1021 | + .build(); |
| 1022 | + StreamWriter writer2 = |
| 1023 | + StreamWriter.newBuilder(TEST_STREAM_2) |
| 1024 | + .setWriterSchema(schema2) |
| 1025 | + .setMaxInflightRequests(1) |
| 1026 | + .setEnableConnectionPool(true) |
| 1027 | + .setLocation("US") |
| 1028 | + .setCredentialsProvider(credentialsProvider2) |
| 1029 | + .build(); |
| 1030 | + assertEquals(writer1.getTestOnlyConnectionPoolMap().size(), 1); |
| 1031 | + } |
| 1032 | + |
927 | 1033 | @Test |
928 | 1034 | public void testDefaultValueInterpretation_multiplexingCase() throws Exception { |
929 | 1035 | // Use the shared connection mode. |
|
0 commit comments