/// <inheritdoc /> private static async Task <SpannerClient> CreateClientAsync(SpannerClientCreationOptions channelOptions, SpannerSettings spannerSettings, Logger logger) { var credentials = await channelOptions.GetCredentialsAsync().ConfigureAwait(false); var apiConfig = new ApiConfig { ChannelPool = new ChannelPoolConfig { MaxSize = (uint)channelOptions.MaximumGrpcChannels, MaxConcurrentStreamsLowWatermark = channelOptions.MaximumConcurrentStreamsLowWatermark }, Method = { s_methodConfigs } }; var grpcOptions = new List <ChannelOption> { // Keep the channel alive for streaming requests. new ChannelOption("grpc.keepalive_time_ms", 60_000), new ChannelOption(GcpCallInvoker.ApiConfigChannelArg, apiConfig.ToString()) }; var endpoint = channelOptions.Endpoint; var callInvoker = new GcpCallInvoker(channelOptions.Endpoint, credentials, grpcOptions); return(new SpannerClientBuilder { CallInvoker = callInvoker, Settings = spannerSettings }.Build()); } }
/// <inheritdoc /> private static async Task <SpannerClient> CreateClientAsync(SpannerClientCreationOptions channelOptions) { var credentials = await channelOptions.GetCredentialsAsync().ConfigureAwait(false); var channel = new Channel(channelOptions.Endpoint.Host, channelOptions.Endpoint.Port, credentials); var apiConfig = new ApiConfig { ChannelPool = new ChannelPoolConfig { MaxSize = (uint)channelOptions.MaximumGrpcChannels, MaxConcurrentStreamsLowWatermark = channelOptions.MaximumConcurrentStreamsLowWatermark }, Method = { s_methodConfigs } }; var grpcOptions = new List <ChannelOption> { // Keep the channel alive for streaming requests. new ChannelOption("grpc.keepalive_time_ms", 60_000), new ChannelOption(GcpCallInvoker.ApiConfigChannelArg, apiConfig.ToString()) }; var endpoint = channelOptions.Endpoint; var callInvoker = new GcpCallInvoker(endpoint.Host, endpoint.Port, credentials, grpcOptions); // We don't need to modify the default timeouts themselves, because we always go through a PooledSession call that accepts // a per-call timeout. var settings = new SpannerSettings { AllowImmediateTimeouts = channelOptions.AllowImmediateTimeouts }; return(SpannerClient.Create(callInvoker, settings)); } }
/// <summary> /// Starts up a service, creates a call invoker and a client, using an optional API config, /// then executes the asynchronous and/or synchronous test methods provided. /// </summary> private static async Task RunWithServer( TestService.TestServiceBase serviceImpl, ApiConfig apiConfig, Func <GcpCallInvoker, TestService.TestServiceClient, Task> asyncTestAction, Action <GcpCallInvoker, TestService.TestServiceClient> testAction) { var server = new Server { Services = { TestService.BindService(serviceImpl) }, Ports = { new ServerPort("localhost", 0, ServerCredentials.Insecure) } }; server.Start(); try { var port = server.Ports.First(); var options = new List <ChannelOption>(); if (apiConfig != null) { options.Add(new ChannelOption(GcpCallInvoker.ApiConfigChannelArg, apiConfig.ToString())); } var invoker = new GcpCallInvoker(port.Host, port.BoundPort, ChannelCredentials.Insecure, options); var client = new TestService.TestServiceClient(invoker); await(asyncTestAction?.Invoke(invoker, client) ?? Task.FromResult(0)); testAction?.Invoke(invoker, client); } finally { await server.ShutdownAsync(); } }
public void CreateClientWithEmptyOptions() { GoogleCredential credential = GoogleCredential.GetApplicationDefault(); invoker = new GcpCallInvoker(Target, credential.ToChannelCredentials()); client = new Bigtable.BigtableClient(invoker); MutateRowRequest mutateRowRequest = new MutateRowRequest { TableName = TableName, RowKey = ByteString.CopyFromUtf8(RowKey) }; Mutation mutation = new Mutation { SetCell = new Mutation.Types.SetCell { FamilyName = ColumnFamily, ColumnQualifier = ByteString.CopyFromUtf8(ColumnQualifier), Value = ByteString.CopyFromUtf8(TestValue), } }; mutateRowRequest.Mutations.Add(mutation); client.MutateRow(mutateRowRequest); Assert.AreEqual(1, invoker.GetChannelRefsForTest().Count); }
private void AssertNoAffinity(GcpCallInvoker invoker) { var channelRefs = invoker.GetChannelRefsForTest(); Assert.AreEqual(0, channelRefs.Sum(cr => cr.AffinityCount)); Assert.AreEqual(0, invoker.GetChannelRefsByAffinityKeyForTest().Count); }
private void InitClient() { GoogleCredential credential = GoogleCredential.GetApplicationDefault(); IList <ChannelOption> options = new List <ChannelOption>() { new ChannelOption(GcpCallInvoker.ApiConfigChannelArg, config.ToString()) }; invoker = new GcpCallInvoker(Target, credential.ToChannelCredentials(), options); client = new Spanner.SpannerClient(invoker); }
private void InitGcpClient() { InitApiConfig(100, 10); GoogleCredential credential = GoogleCredential.GetApplicationDefault(); IList <ChannelOption> options = new List <ChannelOption>() { new ChannelOption(GcpCallInvoker.ApiConfigChannelArg, config.ToString()) }; var invoker = new GcpCallInvoker(Target, credential.ToChannelCredentials(), options); client = new Bigtable.BigtableClient(invoker); }
public void AppProfileId() { var callInvoker = new GcpCallInvoker( target: BigtableServiceApiClient.DefaultEndpoint.ToString(), credentials: ChannelCredentials.Insecure); var client = CreateClient(callInvoker, null); Assert.Null(client.AppProfileId); client = CreateClient(callInvoker, "xyz"); Assert.Equal("xyz", client.AppProfileId); }
private void AssertNoActiveStreams(GcpCallInvoker invoker) { var channelRefs = invoker.GetChannelRefsForTest(); Assert.AreEqual(0, channelRefs.Sum(cr => cr.ActiveStreamCount)); }