-
Notifications
You must be signed in to change notification settings - Fork 107
A sample application using a mock server #116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.AspNetCore.Hosting; | ||
| using Microsoft.Extensions.Configuration; | ||
| using Microsoft.Extensions.Hosting; | ||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| namespace client | ||
| { | ||
| public class Program | ||
| { | ||
| public static void Main(string[] args) | ||
| { | ||
| CreateHostBuilder(args).Build().Run(); | ||
| } | ||
|
|
||
| public static IHostBuilder CreateHostBuilder(string[] args) => | ||
| Host.CreateDefaultBuilder(args) | ||
| .ConfigureWebHostDefaults(webBuilder => | ||
| { | ||
| webBuilder.UseStartup<Startup>(); | ||
| }); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System; | ||
| using System.Net.Http; | ||
| using System.Reflection; | ||
| using Microsoft.AspNetCore.Builder; | ||
| using Microsoft.AspNetCore.Hosting; | ||
| using Microsoft.AspNetCore.Http; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Microsoft.Extensions.Hosting; | ||
|
|
||
| namespace client | ||
| { | ||
| public class Startup | ||
| { | ||
| // This method gets called by the runtime. Use this method to add services to the container. | ||
| // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 | ||
| public void ConfigureServices(IServiceCollection services) | ||
| { | ||
| } | ||
|
|
||
| // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | ||
| public void Configure(IApplicationBuilder app, IWebHostEnvironment env) | ||
| { | ||
| if (env.IsDevelopment()) | ||
| { | ||
| app.UseDeveloperExceptionPage(); | ||
| } | ||
|
|
||
| app.UseRouting(); | ||
|
|
||
| app.UseEndpoints(endpoints => | ||
| { | ||
| var client = new HttpClient | ||
| { | ||
| BaseAddress = new Uri("http://localhost:8080") | ||
| }; | ||
|
|
||
| endpoints.MapGet("/", async context => | ||
| { | ||
| var content = await client.GetStringAsync("/"); | ||
|
|
||
| await context.Response.WriteAsync(content); | ||
| }); | ||
| }); | ||
|
|
||
| Console.WriteLine($"AspNetCore location: {typeof(IWebHostBuilder).GetTypeInfo().Assembly.Location}"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not necessary. Results show the version automatically. |
||
| Console.WriteLine($"AspNetCore version: {typeof(IWebHostBuilder).GetTypeInfo().Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion}"); | ||
|
|
||
| Console.WriteLine($"NETCoreApp location: {typeof(object).GetTypeInfo().Assembly.Location}"); | ||
| Console.WriteLine($"NETCoreApp version: {typeof(object).GetTypeInfo().Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion}"); | ||
|
|
||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft": "Warning", | ||
| "Microsoft.Hosting.Lifetime": "Information" | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft": "Warning", | ||
| "Microsoft.Hosting.Lifetime": "Information" | ||
| } | ||
| }, | ||
| "AllowedHosts": "*" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| imports: | ||
| - ../../src/Microsoft.Crank.Jobs.Bombardier/bombardier.yml | ||
|
|
||
| jobs: | ||
| server: | ||
| source: | ||
| localFolder: . | ||
| project: client.csproj | ||
| readyStateText: Application started. | ||
| mockserver: | ||
| source: | ||
| localFolder: mockserver | ||
| dockerFile: Dockerfile | ||
| dockerImageName: mockserver | ||
| dockerContextDirectory: . | ||
| port: 8080 | ||
|
|
||
| scenarios: | ||
| client: | ||
| mockserver: | ||
| job: mockserver | ||
| application: | ||
| job: server | ||
| load: | ||
| job: bombardier | ||
| variables: | ||
| serverPort: 5010 | ||
| path: / | ||
|
|
||
| profiles: | ||
| local: | ||
| variables: | ||
| serverUri: http://localhost | ||
| jobs: | ||
| application: | ||
| endpoints: | ||
| - http://localhost:5010 | ||
| load: | ||
| endpoints: | ||
| - http://localhost:5010 | ||
| mockserver: | ||
| endpoints: | ||
| - http://localhost:5010 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFrameworks>netcoreapp3.1;netcoreapp5.0</TargetFrameworks> | ||
| </PropertyGroup> | ||
|
|
||
| </Project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| FROM rodolpheche/wiremock as mockserver | ||
| COPY config /home/wiremock | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be nice to add a 3rd way to add a docker job by specify the docker hub name, or did I miss it?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we could add another property
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with the suggestion. Had the same issue myself which required me to create a dumb docker file. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| { | ||
| "mappings": [ | ||
| { | ||
| "request": { | ||
| "urlPath": "/", | ||
| "method": "GET" | ||
| }, | ||
| "response": { | ||
| "status": 200, | ||
| "body": "Hello World!", | ||
| "fixedDelayMilliseconds": 20 | ||
| }, | ||
| "priority": 10 | ||
| } | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1681,7 +1681,9 @@ await ProcessUtil.RunAsync("docker", dockerLoadArguments, | |
|
|
||
| var command = OperatingSystem == OperatingSystem.Linux | ||
| ? $"run -d {environmentArguments} {job.Arguments} --label benchmarks --name {containerName} --privileged --network host {imageName} {source.DockerCommand}" | ||
| : $"run -d {environmentArguments} {job.Arguments} --label benchmarks --name {containerName} --network SELF --ip {hostname} {imageName} {source.DockerCommand}"; | ||
| : string.Equals(hostname, "localhost", StringComparison.OrdinalIgnoreCase) | ||
| ? $"run -d {environmentArguments} {job.Arguments} --label benchmarks --name {containerName} -p {job.Port}:{job.Port} {imageName} {source.DockerCommand}" | ||
| : $"run -d {environmentArguments} {job.Arguments} --label benchmarks --name {containerName} --network SELF --ip {hostname} {imageName} {source.DockerCommand}"; | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had to run this to be able to run locally on windows without having to create a network and to be able to map the port. Maybe there should be a more generic argument to pass parameter to docker while I believe currently you can only specify arguemnts to the container
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can just keep the port:port version on Windows. I used SELF because I was trying to create a faster network interface, but at least if port:port works it's better for now. |
||
|
|
||
| if (job.Collect && job.CollectStartup) | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use the new WebApplicationBuilder model now