public void WithMethods() { var options = new CallOptions(); var metadata = new Metadata(); Assert.AreSame(metadata, options.WithHeaders(metadata).Headers); var deadline = DateTime.UtcNow; Assert.AreEqual(deadline, options.WithDeadline(deadline).Deadline.Value); var cancellationToken = new CancellationTokenSource().Token; Assert.AreEqual(cancellationToken, options.WithCancellationToken(cancellationToken).CancellationToken); var writeOptions = new WriteOptions(); Assert.AreSame(writeOptions, options.WithWriteOptions(writeOptions).WriteOptions); var propagationToken = new ContextPropagationToken(CallSafeHandle.NullInstance, DateTime.UtcNow, CancellationToken.None, ContextPropagationOptions.Default); Assert.AreSame(propagationToken, options.WithPropagationToken(propagationToken).PropagationToken); var credentials = new FakeCallCredentials(); Assert.AreSame(credentials, options.WithCredentials(credentials).Credentials); // Check that the original instance is unchanged. Assert.IsNull(options.Headers); Assert.IsNull(options.Deadline); Assert.AreEqual(CancellationToken.None, options.CancellationToken); Assert.IsNull(options.WriteOptions); Assert.IsNull(options.PropagationToken); Assert.IsNull(options.Credentials); }
/// <summary> /// Creates a new instance of <c>CallOptions</c> struct. /// </summary> /// <param name="headers">Headers to be sent with the call.</param> /// <param name="deadline">Deadline for the call to finish. null means no deadline.</param> /// <param name="cancellationToken">Can be used to request cancellation of the call.</param> /// <param name="writeOptions">Write options that will be used for this call.</param> /// <param name="propagationToken">Context propagation token obtained from <see cref="ServerCallContext"/>.</param> public CallOptions(Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken), WriteOptions writeOptions = null, ContextPropagationToken propagationToken = null) { this.headers = headers; this.deadline = deadline; this.cancellationToken = cancellationToken; this.writeOptions = writeOptions; this.propagationToken = propagationToken; }
/// <summary> /// Creates a new instance of <c>CallOptions</c>. /// </summary> /// <param name="headers">Headers to be sent with the call.</param> /// <param name="deadline">Deadline for the call to finish. null means no deadline.</param> /// <param name="cancellationToken">Can be used to request cancellation of the call.</param> /// <param name="writeOptions">Write options that will be used for this call.</param> /// <param name="propagationToken">Context propagation token obtained from <see cref="ServerCallContext"/>.</param> public CallOptions(Metadata headers = null, DateTime? deadline = null, CancellationToken? cancellationToken = null, WriteOptions writeOptions = null, ContextPropagationToken propagationToken = null) { // TODO(jtattermusch): consider only creating metadata object once it's really needed. this.headers = headers ?? new Metadata(); this.deadline = deadline ?? (propagationToken != null ? propagationToken.Deadline : DateTime.MaxValue); this.cancellationToken = cancellationToken ?? (propagationToken != null ? propagationToken.CancellationToken : CancellationToken.None); this.writeOptions = writeOptions; this.propagationToken = propagationToken; }
/// <summary> /// Constructs an instance with the specified settings. /// </summary> /// <param name="cancellationToken">Cancellation token that can be used for cancelling the call.</param> /// <param name="credentials">Credentials to use for the call.</param> /// <param name="timing"><see cref="CallTiming"/> to use, or null for default retry/expiration behavior.</param> /// <param name="headerMutation">Action to modify the headers to send at the beginning of the call.</param> /// <param name="writeOptions"><see cref="global::Grpc.Core.WriteOptions"/> that will be used for the call.</param> /// <param name="propagationToken"><see cref="ContextPropagationToken"/> for propagating settings from a parent call.</param> public CallSettings( CancellationToken? cancellationToken, CallCredentials credentials, CallTiming timing, Action<Metadata> headerMutation, WriteOptions writeOptions, ContextPropagationToken propagationToken) { CancellationToken = cancellationToken; Credentials = credentials; Timing = timing; HeaderMutation = headerMutation; WriteOptions = writeOptions; PropagationToken = propagationToken; }
/// <summary> /// Returns new instance of <see cref="CallOptions"/> with /// <c>WriteOptions</c> set to the value provided. Values of all other fields are preserved. /// </summary> /// <param name="writeOptions">The write options.</param> public CallOptions WithWriteOptions(WriteOptions writeOptions) { var newOptions = this; newOptions.writeOptions = writeOptions; return newOptions; }