Skip to content

Commit

Permalink
fixed examples
Browse files Browse the repository at this point in the history
  • Loading branch information
AntyaDev committed Oct 25, 2023
1 parent eacc992 commit f8075f1
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 24 deletions.
14 changes: 9 additions & 5 deletions examples/Demo/Cluster/AutoCluster/AutoClusterExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace Demo.Cluster.AutoCluster;

public class AutoClusterExample
{
readonly HttpClient _httpClient = new();

public void Run()
{
var scenario = BuildScenario();
Expand All @@ -29,20 +31,22 @@ private void StartNode(ScenarioProps scenario)

private ScenarioProps BuildScenario()
{
using var httpClient = new HttpClient();

return Scenario.Create("http_scenario", async context =>
{
var request =
Http.CreateRequest("GET", "https://nbomber.com")
.WithHeader("Content-Type", "application/json");
// .WithBody(new StringContent("{ some JSON }", Encoding.UTF8, "application/json"));
// .WithBody(new StringContent("{ some JSON }", Encoding.UTF8, "application/json"));

var response = await Http.Send(httpClient, request);
var response = await Http.Send(_httpClient, request);

return response;
})
.WithoutWarmUp()
.WithLoadSimulations(Simulation.Inject(rate: 10, interval: TimeSpan.FromSeconds(1), during: TimeSpan.FromSeconds(30)));
.WithLoadSimulations(
Simulation.RampingInject(rate: 200, interval: TimeSpan.FromSeconds(1), during: TimeSpan.FromMinutes(1)),
Simulation.Inject(rate: 200, interval: TimeSpan.FromSeconds(1), during: TimeSpan.FromMinutes(1)),
Simulation.RampingInject(rate: 0, interval: TimeSpan.FromSeconds(1), during: TimeSpan.FromMinutes(1))
);
}
}
7 changes: 3 additions & 4 deletions examples/Demo/Cluster/ManualCluster/ManualClusterExample.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using NBomber.Contracts;
using NBomber.Contracts.Stats;
using NBomber.CSharp;
using NBomber.Http;
using NBomber.Http.CSharp;
Expand All @@ -9,6 +8,8 @@ namespace Demo.Cluster.ManualCluster;

public class ManualClusterExample
{
readonly HttpClient _httpClient = new();

public void Run(string[] args)
{
var scenario = BuildScenario();
Expand All @@ -30,16 +31,14 @@ private void StartNode(ScenarioProps scenario, string[] args)

private ScenarioProps BuildScenario()
{
using var httpClient = new HttpClient();

return Scenario.Create("http_scenario", async context =>
{
var request =
Http.CreateRequest("GET", "https://nbomber.com")
.WithHeader("Content-Type", "application/json");
// .WithBody(new StringContent("{ some JSON }", Encoding.UTF8, "application/json"));

var response = await Http.Send(httpClient, request);
var response = await Http.Send(_httpClient, request);

return response;
})
Expand Down
4 changes: 3 additions & 1 deletion examples/Demo/Demo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<ServerGarbageCollection>false</ServerGarbageCollection>
<ConcurrentGarbageCollection>true</ConcurrentGarbageCollection>
</PropertyGroup>

<ItemGroup>
Expand All @@ -17,7 +19,7 @@
</None>
<None Update="Features\RealtimeReporting\InfluxDB\influx_v2\infra-config.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</None>
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion examples/Demo/HTTP/SequentialHttpSteps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void Run()
return Response.Ok();
})
.WithoutWarmUp()
.WithLoadSimulations(Simulation.Inject(rate: 100, interval: TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(30)));
.WithLoadSimulations(Simulation.Inject(rate: 10, interval: TimeSpan.FromSeconds(1), TimeSpan.FromMinutes(3)));

NBomberRunner
.RegisterScenarios(scenario)
Expand Down
25 changes: 14 additions & 11 deletions examples/Demo/HTTP/SimpleHttpExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,22 @@ public void Run()
using var httpClient = new HttpClient();

var scenario = Scenario.Create("http_scenario", async context =>
{
var request =
Http.CreateRequest("GET", "https://nbomber.com")
.WithHeader("Content-Type", "application/json");
// .WithBody(new StringContent("{ some JSON }", Encoding.UTF8, "application/json"));
{
var request =
Http.CreateRequest("GET", "https://nbomber.com")
.WithHeader("Content-Type", "application/json");
// .WithBody(new StringContent("{ some JSON }", Encoding.UTF8, "application/json"));

var response = await Http.Send(httpClient, request);

var response = await Http.Send(httpClient, request);

return response;
})
.WithoutWarmUp()
.WithLoadSimulations(Simulation.Inject(rate: 100, interval: TimeSpan.FromSeconds(1), during: TimeSpan.FromSeconds(30)));
return response;
})
.WithoutWarmUp()
.WithLoadSimulations(
Simulation.RampingInject(rate: 10, interval: TimeSpan.FromSeconds(1), during: TimeSpan.FromMinutes(1)),
Simulation.Inject(rate: 10, interval: TimeSpan.FromSeconds(1), during: TimeSpan.FromMinutes(1)),
Simulation.RampingInject(rate: 0, interval: TimeSpan.FromSeconds(1), during: TimeSpan.FromMinutes(1))
);

NBomberRunner
.RegisterScenarios(scenario)
Expand Down
4 changes: 2 additions & 2 deletions examples/Demo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@
// in order to run this example you should start 2 instances of NBomber,
// for this, you need to run this NBomber application twice

// new AutoClusterExample().Run();
// new AutoClusterExample().Run();
// new AutoClusterExample().Run(); // 1 instance
// new AutoClusterExample().Run(); // 2 instance

// ----- Manual Cluster -------
// in order to run this example you should start 2 instances of NBomber,
Expand Down

0 comments on commit f8075f1

Please sign in to comment.