Browse Source

Add Watson Webserver framework (#6273)

Andreas Nägeli 4 years ago
parent
commit
2ee4a7aa8f

+ 38 - 0
frameworks/CSharp/watson/.gitignore

@@ -0,0 +1,38 @@
+[Oo]bj/
+[Bb]in/
+TestResults/
+.nuget/
+*.sln
+*.sln.ide/
+_ReSharper.*/
+.idea/
+packages/
+artifacts/
+PublishProfiles/
+.vs/
+*.user
+*.suo
+*.cache
+*.docstates
+_ReSharper.*
+nuget.exe
+*net45.csproj
+*net451.csproj
+*k10.csproj
+*.psess
+*.vsp
+*.pidb
+*.userprefs
+*DS_Store
+*.ncrunchsolution
+*.*sdf
+*.ipch
+*.swp
+*~
+.build/
+.testPublish/
+launchSettings.json
+BenchmarkDotNet.Artifacts/
+BDN.Generated/
+binaries/
+global.json

+ 24 - 0
frameworks/CSharp/watson/Benchmarks/Benchmarks.csproj

@@ -0,0 +1,24 @@
+<Project Sdk="Microsoft.NET.Sdk">
+  
+  <PropertyGroup>
+    
+    <TargetFramework>net5.0</TargetFramework>
+    <LangVersion>9.0</LangVersion>
+    
+    <AssemblyTitle>EmbedIO Benchmarks</AssemblyTitle>
+    <Description>Test suite to be executed with TechEmpower FrameworkBenchmarks.</Description>
+    
+    <StartupObject>Benchmarks.Program</StartupObject>    
+    <OutputType>Exe</OutputType>
+    
+    <ServerGarbageCollection>true</ServerGarbageCollection>
+    <TieredCompilation>false</TieredCompilation>
+    
+  </PropertyGroup>
+  
+  <ItemGroup>
+    <PackageReference Include="System.Text.Json" Version="5.0.0" />
+    <PackageReference Include="Watson" Version="4.0.0.3" />
+  </ItemGroup>
+  
+</Project>

+ 89 - 0
frameworks/CSharp/watson/Benchmarks/Program.cs

@@ -0,0 +1,89 @@
+using System;
+using System.Linq;
+using System.Net;
+using System.Text.Json;
+using System.Threading;
+using System.Threading.Tasks;
+
+using WatsonWebserver;
+
+namespace Benchmarks
+{
+
+    #region Supporting data structures
+
+    public class JsonResult
+    {
+
+        public string Message { get; set; }
+
+    }
+
+    #endregion
+
+    public static class Program
+    {
+        private static readonly ManualResetEvent _WaitEvent = new ManualResetEvent(false);
+
+        public static async Task<int> Main(string[] args)
+        {
+#if DEBUG
+            var host = "127.0.0.1";
+#else
+            var host = "tfb-server";
+#endif
+
+            using var server = new Server(host, 8080, false, DefaultRoute);
+
+            server.Routes.Static.Add(HttpMethod.GET, "/plaintext", PlaintextRoute);
+            server.Routes.Static.Add(HttpMethod.GET, "/json", JsonRoute);
+
+            try
+            {
+                AppDomain.CurrentDomain.ProcessExit += (_, __) =>
+                {
+                    _WaitEvent.Set();
+                };
+
+                await server.StartAsync();
+
+                _WaitEvent.WaitOne();
+
+                return 0;
+            }
+            catch (Exception e)
+            {
+                Console.WriteLine(e);
+
+                return -1;
+            }
+        }
+
+        static async Task DefaultRoute(HttpContext ctx)
+        {
+            ctx.Response.StatusCode = 404;
+            ctx.Response.StatusDescription = "Not Found";
+
+            await ctx.Response.Send("Not found.");
+        }
+
+        static async Task PlaintextRoute(HttpContext ctx)
+        {
+            ctx.Response.Headers.Add("Content-Type", "text/plain; charset=UTF-8");
+
+            await ctx.Response.Send("Hello, World!");
+        }
+
+        static async Task JsonRoute(HttpContext ctx)
+        {
+            var response = new JsonResult() { Message = "Hello, World!" };
+            var serialized = JsonSerializer.Serialize(response);
+
+            ctx.Response.Headers.Add("Content-Type", "application/json; charset=UTF-8");
+
+            await ctx.Response.Send(serialized);
+        }
+
+    }
+
+}

+ 22 - 0
frameworks/CSharp/watson/README.md

@@ -0,0 +1,22 @@
+# Watson Webserver Tests on Linux
+
+See the [project website](https://github.com/jchristn/WatsonWebserver) for more information.
+
+## Infrastructure Software Versions
+
+**Language**
+
+* C# 9.0
+
+**Platforms**
+
+* .NET 5
+
+**Web Servers**
+
+* [Watson Webserver](https://github.com/jchristn/WatsonWebserver)
+
+## Paths & Source for Tests
+
+* [Plaintext](Benchmarks/Program.cs): "/plaintext"
+* [JSON](Benchmarks/Program.cs): "/json"

+ 22 - 0
frameworks/CSharp/watson/benchmark_config.json

@@ -0,0 +1,22 @@
+{
+  "framework": "watson",
+  "tests": [{
+    "default": {
+      "plaintext_url": "/plaintext",
+      "json_url": "/json",
+      "port": 8080,
+      "approach": "Realistic",
+      "classification": "Fullstack",
+      "database": "None",
+      "framework": "Watson",
+      "language": "C#",
+      "orm": "Raw",
+      "platform": ".NET",
+      "webserver": "Watson",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "Watson Webserver",
+      "notes": ""
+    }
+  }]
+}

+ 15 - 0
frameworks/CSharp/watson/config.toml

@@ -0,0 +1,15 @@
+[framework]
+name = "watson"
+
+[main]
+urls.plaintext = "/plaintext"
+urls.json = "/json"
+approach = "Realistic"
+classification = "Fullstack"
+database = "None"
+database_os = "Linux"
+os = "Linux"
+orm = "Raw"
+platform = ".NET"
+webserver = "Watson"
+versus = "None"

+ 19 - 0
frameworks/CSharp/watson/watson.dockerfile

@@ -0,0 +1,19 @@
+FROM mcr.microsoft.com/dotnet/sdk:5.0-alpine AS build
+WORKDIR /source
+
+# copy csproj and restore as distinct layers
+COPY Benchmarks/*.csproj .
+RUN dotnet restore -r linux-musl-x64
+
+# copy and publish app and libraries
+COPY Benchmarks/ .
+RUN dotnet publish -c release -o /app -r linux-musl-x64
+
+# final stage/image
+FROM mcr.microsoft.com/dotnet/runtime-deps:5.0-alpine
+WORKDIR /app
+COPY --from=build /app .
+
+ENTRYPOINT ["./Benchmarks"]
+
+EXPOSE 8080