Skip to content

Commit

Permalink
Rework pipeline Create methods per APIView feedback (Azure#41471)
Browse files Browse the repository at this point in the history
  • Loading branch information
annelo-msft authored Jan 23, 2024
1 parent ba41182 commit b3b421e
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 20 deletions.
3 changes: 1 addition & 2 deletions sdk/core/System.ClientModel/api/System.ClientModel.net6.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ public enum ClientErrorBehaviors
public sealed partial class ClientPipeline
{
internal ClientPipeline() { }
public static System.ClientModel.Primitives.ClientPipeline Create() { throw null; }
public static System.ClientModel.Primitives.ClientPipeline Create(System.ClientModel.Primitives.ClientPipelineOptions options, params System.ClientModel.Primitives.PipelinePolicy[] perCallPolicies) { throw null; }
public static System.ClientModel.Primitives.ClientPipeline Create(System.ClientModel.Primitives.ClientPipelineOptions? options = null) { throw null; }
public static System.ClientModel.Primitives.ClientPipeline Create(System.ClientModel.Primitives.ClientPipelineOptions options, System.ReadOnlySpan<System.ClientModel.Primitives.PipelinePolicy> perCallPolicies, System.ReadOnlySpan<System.ClientModel.Primitives.PipelinePolicy> perTryPolicies, System.ReadOnlySpan<System.ClientModel.Primitives.PipelinePolicy> beforeTransportPolicies) { throw null; }
public System.ClientModel.Primitives.PipelineMessage CreateMessage() { throw null; }
public void Send(System.ClientModel.Primitives.PipelineMessage message) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ public enum ClientErrorBehaviors
public sealed partial class ClientPipeline
{
internal ClientPipeline() { }
public static System.ClientModel.Primitives.ClientPipeline Create() { throw null; }
public static System.ClientModel.Primitives.ClientPipeline Create(System.ClientModel.Primitives.ClientPipelineOptions options, params System.ClientModel.Primitives.PipelinePolicy[] perCallPolicies) { throw null; }
public static System.ClientModel.Primitives.ClientPipeline Create(System.ClientModel.Primitives.ClientPipelineOptions? options = null) { throw null; }
public static System.ClientModel.Primitives.ClientPipeline Create(System.ClientModel.Primitives.ClientPipelineOptions options, System.ReadOnlySpan<System.ClientModel.Primitives.PipelinePolicy> perCallPolicies, System.ReadOnlySpan<System.ClientModel.Primitives.PipelinePolicy> perTryPolicies, System.ReadOnlySpan<System.ClientModel.Primitives.PipelinePolicy> beforeTransportPolicies) { throw null; }
public System.ClientModel.Primitives.PipelineMessage CreateMessage() { throw null; }
public void Send(System.ClientModel.Primitives.PipelineMessage message) { }
Expand Down
12 changes: 3 additions & 9 deletions sdk/core/System.ClientModel/src/Pipeline/ClientPipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,12 @@ private ClientPipeline(ReadOnlyMemory<PipelinePolicy> policies, TimeSpan network

#region Factory methods for creating a pipeline instance

public static ClientPipeline Create()
=> Create(ClientPipelineOptions.Default,
public static ClientPipeline Create(ClientPipelineOptions? options = default)
=> Create(options ?? ClientPipelineOptions.Default,
ReadOnlySpan<PipelinePolicy>.Empty,
ReadOnlySpan<PipelinePolicy>.Empty,
ReadOnlySpan<PipelinePolicy>.Empty);

public static ClientPipeline Create(ClientPipelineOptions options, params PipelinePolicy[] perCallPolicies)
=> Create(options,
perCallPolicies,
ReadOnlySpan<PipelinePolicy>.Empty,
ReadOnlySpan<PipelinePolicy>.Empty);

public static ClientPipeline Create(
ClientPipelineOptions options,
ReadOnlySpan<PipelinePolicy> perCallPolicies,
Expand Down Expand Up @@ -217,4 +211,4 @@ public PipelinePolicy Current

public void Dispose() { }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ public async Task HeaderPolicySetsKey()
Transport = new MockPipelineTransport("Transport", new int[] { 200 })
};

ClientPipeline pipeline = ClientPipeline.Create(options, keyPolicy);
ClientPipeline pipeline = ClientPipeline.Create(options,
perCallPolicies: ReadOnlySpan<PipelinePolicy>.Empty,
perTryPolicies: new PipelinePolicy[] { keyPolicy },
beforeTransportPolicies: ReadOnlySpan<PipelinePolicy>.Empty);

using PipelineMessage message = pipeline.CreateMessage();
await pipeline.SendSyncOrAsync(message, IsAsync);
Expand All @@ -54,7 +57,10 @@ public async Task HeaderPolicySetsKeyWithPrefix()
Transport = new MockPipelineTransport("Transport", new int[] { 200 })
};

ClientPipeline pipeline = ClientPipeline.Create(options, keyPolicy);
ClientPipeline pipeline = ClientPipeline.Create(options,
perCallPolicies: ReadOnlySpan<PipelinePolicy>.Empty,
perTryPolicies: new PipelinePolicy[] { keyPolicy },
beforeTransportPolicies: ReadOnlySpan<PipelinePolicy>.Empty);

using PipelineMessage message = pipeline.CreateMessage();
await pipeline.SendSyncOrAsync(message, IsAsync);
Expand All @@ -77,7 +83,10 @@ public async Task HeaderPolicyAddsSingleKeyWhenRetried()
Transport = new MockPipelineTransport("Transport", new int[] { 200, 200 })
};

ClientPipeline pipeline = ClientPipeline.Create(options, keyPolicy);
ClientPipeline pipeline = ClientPipeline.Create(options,
perCallPolicies: ReadOnlySpan<PipelinePolicy>.Empty,
perTryPolicies: new PipelinePolicy[] { keyPolicy },
beforeTransportPolicies: ReadOnlySpan<PipelinePolicy>.Empty);

using PipelineMessage message = pipeline.CreateMessage();
await pipeline.SendSyncOrAsync(message, IsAsync);
Expand All @@ -102,7 +111,10 @@ public async Task HeaderPolicyWithPrefixAddsSingleKeyWhenRetried()
Transport = new MockPipelineTransport("Transport", new int[] { 200, 200 })
};

ClientPipeline pipeline = ClientPipeline.Create(options, keyPolicy);
ClientPipeline pipeline = ClientPipeline.Create(options,
perCallPolicies: ReadOnlySpan<PipelinePolicy>.Empty,
perTryPolicies: new PipelinePolicy[] { keyPolicy },
beforeTransportPolicies: ReadOnlySpan<PipelinePolicy>.Empty);

using PipelineMessage message = pipeline.CreateMessage();
await pipeline.SendSyncOrAsync(message, IsAsync);
Expand All @@ -125,7 +137,10 @@ public async Task BasicPolicySetsKey()
Transport = new MockPipelineTransport("Transport", new int[] { 200 })
};

ClientPipeline pipeline = ClientPipeline.Create(options, keyPolicy);
ClientPipeline pipeline = ClientPipeline.Create(options,
perCallPolicies: ReadOnlySpan<PipelinePolicy>.Empty,
perTryPolicies: new PipelinePolicy[] { keyPolicy },
beforeTransportPolicies: ReadOnlySpan<PipelinePolicy>.Empty);

using PipelineMessage message = pipeline.CreateMessage();
await pipeline.SendSyncOrAsync(message, IsAsync);
Expand All @@ -147,7 +162,10 @@ public async Task BearerPolicySetsKey()
Transport = new MockPipelineTransport("Transport", new int[] { 200 })
};

ClientPipeline pipeline = ClientPipeline.Create(options, keyPolicy);
ClientPipeline pipeline = ClientPipeline.Create(options,
perCallPolicies: ReadOnlySpan<PipelinePolicy>.Empty,
perTryPolicies: new PipelinePolicy[] { keyPolicy },
beforeTransportPolicies: ReadOnlySpan<PipelinePolicy>.Empty);

using PipelineMessage message = pipeline.CreateMessage();
await pipeline.SendSyncOrAsync(message, IsAsync);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ public async Task CanCreateWithPerCallPolicies()
new ObservablePolicy("PerCallPolicyB"),
};

ClientPipeline pipeline = ClientPipeline.Create(options, perCallPolicies);
ClientPipeline pipeline = ClientPipeline.Create(options,
perCallPolicies: perCallPolicies,
perTryPolicies: ReadOnlySpan<PipelinePolicy>.Empty,
beforeTransportPolicies: ReadOnlySpan<PipelinePolicy>.Empty);

PipelineMessage message = pipeline.CreateMessage();
await pipeline.SendSyncOrAsync(message, IsAsync);
Expand Down

0 comments on commit b3b421e

Please sign in to comment.