Skip to content

Commit 501497d

Browse files
committed
Add scenarios for route handler filters
1 parent 2637bdc commit 501497d

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

build/trend-scenarios.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,16 @@ parameters:
3838
arguments: --scenario mapaction $(plaintextJobs) --property scenario=PlaintextMapAction --property protocol=http
3939
- displayName: Plaintext Endpoint
4040
arguments: --scenario endpoint $(plaintextJobs) --property scenario=PlaintextEndpoint --property protocol=http
41+
- displayName: Plaintext (No Filters)
42+
arguments: --scenario plainTextSansFilter $(plaintextJobs) --property scenario=PlaintextWithParameterNoFilter --property protocol=http
43+
- displayName: Plaintext (Empty Filters)
44+
arguments: --scenario plainTextEmptyFilter $(plaintextJobs) --property scenario=PlaintextWithParameterEmptyFilter --property protocol=http
45+
- displayName: Plaintext (With Filters)
46+
arguments: --scenario plainTextWithFilter $(plaintextJobs) --property scenario=PlaintextWithParametertWithFilter --property protocol=http
4147
- displayName: Plaintext Connection Close
4248
arguments: --scenario connectionclose $(plaintextJobs) --property scenario=ConnectionClose --property protocol=http --variable connections=32 --property connections=32
4349
- displayName: Plaintext Connection Close Https
4450
arguments: --scenario connectionclosehttps $(plaintextJobs) --property scenario=ConnectionCloseHttps --property protocol=https --variable connections=32 --property connections=32
45-
- displayName: Plaintext Connection Close Https HttpSys
4651
arguments: --scenario connectionclosehttps $(plaintextJobs) --property scenario=ConnectionCloseHttpsHttpSys --property protocol=https --variable connections=32 --property connections=32 --variable server=HttpSys --application.options.requiredOperatingSystem windows
4752

4853
# Json

scenarios/plaintext.benchmarks.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,36 @@ scenarios:
9292
presetHeaders: plaintext
9393
path: /plaintext
9494
pipeline: 16
95+
96+
plainTextSansFilter:
97+
application:
98+
job: mapaction
99+
load:
100+
job: wrk
101+
variables:
102+
presetHeaders: plaintext
103+
path: /hello/TesterName
104+
pipeline: 16
105+
106+
plainTextEmptyFilter:
107+
application:
108+
job: mapaction
109+
load:
110+
job: wrk
111+
variables:
112+
presetHeaders: plaintext
113+
path: /helloEmptyFilter/TesterName
114+
pipeline: 16
115+
116+
plainTextWithFilter:
117+
application:
118+
job: mapaction
119+
load:
120+
job: wrk
121+
variables:
122+
presetHeaders: plaintext
123+
path: /helloFiltered/TesterName
124+
pipeline: 16
95125

96126
connectionclose:
97127
application:

src/BenchmarksApps/MapAction/Program.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
2+
using System.Reflection;
23
using Microsoft.AspNetCore.Builder;
34
using Microsoft.AspNetCore.Hosting;
5+
using Microsoft.AspNetCore.Http;
46
using Microsoft.AspNetCore.Mvc;
57
using Microsoft.Extensions.Hosting;
68
using Microsoft.Extensions.Logging;
@@ -23,6 +25,29 @@
2325

2426
object Json() => new { message = "Hello, World!" };
2527
endpoints.MapGet("/json", (Func<object>)Json);
28+
29+
// Parameterized plain-text endpoint
30+
string SayHello(string name) => $"Hello, {name}!";
31+
// With no filters
32+
endpoints.MapGet("/hello/{name}", SayHello);
33+
// With a filter that no-ops
34+
endpoints.MapGet("/helloEmptyFilter/{name}", SayHello)
35+
.AddFilter((context, next) => next(context));
36+
endpoints
37+
.MapGet("/helloFiltered/{name}", SayHello)
38+
.AddFilter((routeHandlerContext, next) => {
39+
var hasSingleParam = routeHandlerContext.MethodInfo.GetParameters().Length == 1;
40+
var isStringParam = routeHandlerContext.MethodInfo.GetParameters()[0].ParameterType == typeof(string);
41+
42+
return (context) =>
43+
{
44+
if (hasSingleParam && isStringParam)
45+
{
46+
context.Parameters[0] = context.Parameters[0].ToUpperInvariant();
47+
}
48+
return next(context);
49+
};
50+
});
2651
});
2752

2853
});

0 commit comments

Comments
 (0)