Skip to content

Commit 0d6ed61

Browse files
[csharp] Add Effinitive (#10440)
* [csharp] Draft for Effinitive * Make plaintext no json * Add middleware for HTTP compliance * Fix copy & paste
1 parent 0220d68 commit 0d6ed61

File tree

10 files changed

+255
-0
lines changed

10 files changed

+255
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[Oo]bj/
2+
[Bb]in/
3+
TestResults/
4+
.nuget/
5+
*.sln
6+
*.sln.ide/
7+
_ReSharper.*/
8+
.idea/
9+
packages/
10+
artifacts/
11+
PublishProfiles/
12+
.vs/
13+
*.user
14+
*.suo
15+
*.cache
16+
*.docstates
17+
_ReSharper.*
18+
nuget.exe
19+
*net45.csproj
20+
*net451.csproj
21+
*k10.csproj
22+
*.psess
23+
*.vsp
24+
*.pidb
25+
*.userprefs
26+
*DS_Store
27+
*.ncrunchsolution
28+
*.*sdf
29+
*.ipch
30+
*.swp
31+
*~
32+
.build/
33+
.testPublish/
34+
launchSettings.json
35+
BenchmarkDotNet.Artifacts/
36+
BDN.Generated/
37+
binaries/
38+
global.json
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
5+
<TargetFramework>net10.0</TargetFramework>
6+
<LangVersion>14.0</LangVersion>
7+
8+
<AssemblyTitle>Effinitive Benchmarks</AssemblyTitle>
9+
<Description>Test suite to be executed with TechEmpower FrameworkBenchmarks.</Description>
10+
11+
<StartupObject>Benchmarks.Program</StartupObject>
12+
<OutputType>Exe</OutputType>
13+
14+
<ServerGarbageCollection>true</ServerGarbageCollection>
15+
<TieredCompilation>false</TieredCompilation>
16+
17+
</PropertyGroup>
18+
19+
<ItemGroup>
20+
<PackageReference Include="EffinitiveFramework.Core" Version="1.1.0" />
21+
</ItemGroup>
22+
23+
</Project>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System.Threading;
2+
using System.Threading.Tasks;
3+
4+
using EffinitiveFramework.Core;
5+
6+
namespace Benchmarks.Benchmarks;
7+
8+
public class JsonResult
9+
{
10+
public string Message { get; set; }
11+
}
12+
13+
public class Json : NoRequestEndpointBase<JsonResult>
14+
{
15+
protected override string Method => "GET";
16+
17+
protected override string Route => "/json";
18+
19+
protected override string ContentType => "application/json; charset=utf-8";
20+
21+
public override ValueTask<JsonResult> HandleAsync(CancellationToken cancellationToken = default)
22+
{
23+
return ValueTask.FromResult(new JsonResult() { Message = "Hello, World!" });
24+
}
25+
26+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.Threading;
2+
using System.Threading.Tasks;
3+
4+
using EffinitiveFramework.Core;
5+
6+
namespace Benchmarks.Benchmarks;
7+
8+
public class Plaintext : NoRequestEndpointBase<string>
9+
{
10+
protected override string Method => "GET";
11+
12+
protected override string Route => "/plaintext";
13+
14+
protected override string ContentType => "text/plain";
15+
16+
public override ValueTask<string> HandleAsync(CancellationToken cancellationToken = default)
17+
{
18+
return ValueTask.FromResult("Hello, World!");
19+
}
20+
21+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Threading;
3+
using System.Threading.Tasks;
4+
5+
using EffinitiveFramework.Core.Http;
6+
using EffinitiveFramework.Core.Middleware;
7+
8+
namespace Benchmarks;
9+
10+
public class HttpComplianceMiddleware : IMiddleware
11+
{
12+
13+
public async ValueTask<HttpResponse> InvokeAsync(HttpRequest request, RequestDelegate next, CancellationToken cancellationToken)
14+
{
15+
var response = await next(request, cancellationToken);
16+
17+
response.Headers.Add("Server", "Effinitive/1.1");
18+
response.Headers.Add("Date", DateTime.UtcNow.ToString("r"));
19+
20+
return response;
21+
}
22+
23+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System;
2+
using System.Threading;
3+
using System.Threading.Tasks;
4+
5+
using EffinitiveFramework.Core;
6+
7+
namespace Benchmarks
8+
{
9+
10+
public static class Program
11+
{
12+
private static readonly ManualResetEvent WaitEvent = new(false);
13+
14+
public static async Task<int> Main(string[] args)
15+
{
16+
var app = EffinitiveApp.Create()
17+
.UsePort(8080)
18+
.MapEndpoints()
19+
.UseMiddleware<HttpComplianceMiddleware>()
20+
.Build();
21+
22+
try
23+
{
24+
AppDomain.CurrentDomain.ProcessExit += (_, __) =>
25+
{
26+
WaitEvent.Set();
27+
};
28+
29+
await app.RunAsync();
30+
31+
WaitEvent.WaitOne();
32+
33+
return 0;
34+
}
35+
catch (Exception e)
36+
{
37+
Console.WriteLine(e);
38+
39+
return -1;
40+
}
41+
}
42+
43+
}
44+
45+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Effinitive Webserver Tests on Linux
2+
3+
See the [project website](https://github.com/HBartosch/Effinitive) for more information.
4+
5+
## Infrastructure Software Versions
6+
7+
**Language**
8+
9+
* C# 14.0
10+
11+
**Platforms**
12+
13+
* .NET 10
14+
15+
**Web Servers**
16+
17+
* [Effinitive Webserver](https://github.com/HBartosch/Effinitive)
18+
19+
## Paths \& Source for Tests
20+
21+
* [Plaintext](Benchmarks/Program.cs): "/plaintext"
22+
* [JSON](Benchmarks/Program.cs): "/json"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"framework": "effinitive",
3+
"maintainers": ["HBartosch"],
4+
"tests": [{
5+
"default": {
6+
"plaintext_url": "/plaintext",
7+
"json_url": "/json",
8+
"port": 8080,
9+
"approach": "Realistic",
10+
"classification": "Fullstack",
11+
"database": "None",
12+
"framework": "Effinitive",
13+
"language": "C#",
14+
"orm": "Raw",
15+
"platform": ".NET",
16+
"webserver": "Effinitive",
17+
"os": "Linux",
18+
"database_os": "Linux",
19+
"display_name": "Effinitive Webserver",
20+
"notes": ""
21+
}
22+
}]
23+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[framework]
2+
name = "effinitive"
3+
4+
[main]
5+
urls.plaintext = "/plaintext"
6+
urls.json = "/json"
7+
approach = "Realistic"
8+
classification = "Fullstack"
9+
database = "None"
10+
database_os = "Linux"
11+
os = "Linux"
12+
orm = "Raw"
13+
platform = ".NET"
14+
webserver = "Effinitive"
15+
versus = "None"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM mcr.microsoft.com/dotnet/sdk:10.0-alpine AS build
2+
WORKDIR /source
3+
4+
# copy csproj and restore as distinct layers
5+
COPY Benchmarks/*.csproj .
6+
RUN dotnet restore -r linux-musl-x64
7+
8+
# copy and publish app and libraries
9+
COPY Benchmarks/ .
10+
RUN dotnet publish -c release -o /app -r linux-musl-x64 --no-restore --self-contained
11+
12+
# final stage/image
13+
FROM mcr.microsoft.com/dotnet/runtime-deps:10.0-alpine
14+
WORKDIR /app
15+
COPY --from=build /app .
16+
17+
ENTRYPOINT ["./Benchmarks"]
18+
19+
EXPOSE 8080

0 commit comments

Comments
 (0)