Skip to content

Commit

Permalink
added AutoCluster example
Browse files Browse the repository at this point in the history
  • Loading branch information
AntyaDev committed Aug 15, 2023
1 parent 72a6d30 commit fc702e8
Show file tree
Hide file tree
Showing 74 changed files with 181 additions and 132 deletions.
24 changes: 6 additions & 18 deletions NBomber.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "NBomber.IntegrationTests",
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{10398A75-959D-4271-913A-BE99E4ED5744}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CSharpDev", "examples\CSharpDev\CSharpDev.csproj", "{EF73804A-06F8-4E67-AEB5-F85F44AFC51A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CSharpProd", "examples\CSharpProd\CSharpProd.csproj", "{657861BD-19DA-4B93-937D-88B5C25E6D87}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Demo", "examples\Demo\Demo.csproj", "{657861BD-19DA-4B93-937D-88B5C25E6D87}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "xUnitExample", "examples\xUnitExample\xUnitExample.csproj", "{062DD1FF-B466-4F40-BE1F-8D85EA3BDB6A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebAppSimulator", "examples\WebAppSimulator\WebAppSimulator.csproj", "{37D936ED-619C-47F8-95BD-63B966590A15}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BookstoreSimulator", "examples\BookstoreSimulator\BookstoreSimulator.csproj", "{9BC9E01E-C12A-45D6-9910-B0642F36338B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "simulators", "simulators", "{B20C9B19-52F5-4AF1-B41D-D01294BEC6C9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -53,18 +53,6 @@ Global
{1CD9AA0E-5EF7-45E9-8987-4A6279DC2693}.Release|x64.Build.0 = Release|Any CPU
{1CD9AA0E-5EF7-45E9-8987-4A6279DC2693}.Release|x86.ActiveCfg = Release|Any CPU
{1CD9AA0E-5EF7-45E9-8987-4A6279DC2693}.Release|x86.Build.0 = Release|Any CPU
{EF73804A-06F8-4E67-AEB5-F85F44AFC51A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EF73804A-06F8-4E67-AEB5-F85F44AFC51A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EF73804A-06F8-4E67-AEB5-F85F44AFC51A}.Debug|x64.ActiveCfg = Debug|Any CPU
{EF73804A-06F8-4E67-AEB5-F85F44AFC51A}.Debug|x64.Build.0 = Debug|Any CPU
{EF73804A-06F8-4E67-AEB5-F85F44AFC51A}.Debug|x86.ActiveCfg = Debug|Any CPU
{EF73804A-06F8-4E67-AEB5-F85F44AFC51A}.Debug|x86.Build.0 = Debug|Any CPU
{EF73804A-06F8-4E67-AEB5-F85F44AFC51A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EF73804A-06F8-4E67-AEB5-F85F44AFC51A}.Release|Any CPU.Build.0 = Release|Any CPU
{EF73804A-06F8-4E67-AEB5-F85F44AFC51A}.Release|x64.ActiveCfg = Release|Any CPU
{EF73804A-06F8-4E67-AEB5-F85F44AFC51A}.Release|x64.Build.0 = Release|Any CPU
{EF73804A-06F8-4E67-AEB5-F85F44AFC51A}.Release|x86.ActiveCfg = Release|Any CPU
{EF73804A-06F8-4E67-AEB5-F85F44AFC51A}.Release|x86.Build.0 = Release|Any CPU
{657861BD-19DA-4B93-937D-88B5C25E6D87}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{657861BD-19DA-4B93-937D-88B5C25E6D87}.Debug|Any CPU.Build.0 = Debug|Any CPU
{657861BD-19DA-4B93-937D-88B5C25E6D87}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -118,11 +106,11 @@ Global
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{EF73804A-06F8-4E67-AEB5-F85F44AFC51A} = {10398A75-959D-4271-913A-BE99E4ED5744}
{657861BD-19DA-4B93-937D-88B5C25E6D87} = {10398A75-959D-4271-913A-BE99E4ED5744}
{062DD1FF-B466-4F40-BE1F-8D85EA3BDB6A} = {10398A75-959D-4271-913A-BE99E4ED5744}
{37D936ED-619C-47F8-95BD-63B966590A15} = {10398A75-959D-4271-913A-BE99E4ED5744}
{9BC9E01E-C12A-45D6-9910-B0642F36338B} = {10398A75-959D-4271-913A-BE99E4ED5744}
{B20C9B19-52F5-4AF1-B41D-D01294BEC6C9} = {10398A75-959D-4271-913A-BE99E4ED5744}
{9BC9E01E-C12A-45D6-9910-B0642F36338B} = {B20C9B19-52F5-4AF1-B41D-D01294BEC6C9}
{37D936ED-619C-47F8-95BD-63B966590A15} = {B20C9B19-52F5-4AF1-B41D-D01294BEC6C9}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C7E9329B-84FE-436E-8A44-26D8176C5C6F}
Expand Down
15 changes: 0 additions & 15 deletions examples/CSharpDev/CSharpDev.csproj

This file was deleted.

21 changes: 0 additions & 21 deletions examples/CSharpDev/Program.cs

This file was deleted.

38 changes: 38 additions & 0 deletions examples/Demo/Cluster/AutoCluster/AutoClusterExample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using NBomber.CSharp;
using NBomber.Http;
using NBomber.Http.CSharp;
using NBomber.Plugins.Network.Ping;

namespace Demo.Cluster.AutoCluster;

public class AutoClusterExample
{
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 response = await Http.Send(httpClient, request);
return response;
})
.WithoutWarmUp()
.WithLoadSimulations(Simulation.Inject(rate: 10, interval: TimeSpan.FromSeconds(1), during: TimeSpan.FromSeconds(30)));

NBomberRunner
.RegisterScenarios(scenario)
.WithWorkerPlugins(
new PingPlugin(PingPluginConfig.CreateDefault("nbomber.com")),
new HttpMetricsPlugin(new [] { HttpVersion.Version1 })
)
.LoadConfig("Cluster/AutoCluster/autocluster-config.json")
.EnableLocalDevCluster(true)
.Run();
}
}
21 changes: 21 additions & 0 deletions examples/Demo/Cluster/AutoCluster/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## AutoCluster Example

In this example we will run 2 NBomber instances (nodes) in the cluster mode.

- http_scenario will be executed on Coordinator
- http_scenario will be executed on Agent

You can take a look at `autocluster-config.json` config to check the ClusterSettings.

In order to run that demo you should spin-up NATS message broker via docker-compose CLI (there is `docker-compose.yaml`)

```
docker compose up
```

After this you need start 2 instances of NBomber.

Useful links:
- [Cluster overview](https://nbomber.com/docs/cluster/overview)
- [How to run cluster](https://nbomber.com/docs/cluster/run-cluster)
- [AutoCluster](https://nbomber.com/docs/cluster/auto-cluster)
22 changes: 22 additions & 0 deletions examples/Demo/Cluster/AutoCluster/autocluster-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"TestSuite": "my test suite",
"TestName": "my test",

"ClusterSettings": {

"AutoCluster": {
"ClusterId": "test_cluster",
"NATSServerURL": "nats://localhost",

"Coordinator": {
"TargetScenarios": ["http_scenario"]
},

"Agent": {
"TargetScenarios": ["http_scenario"],
"AgentsCount": 1
}
}

}
}
9 changes: 9 additions & 0 deletions examples/Demo/Cluster/AutoCluster/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: "3.4"
services:

nats:
image: "nats:2.9.6"
command: --js
ports:
- "8222:8222"
- "4222:4222"
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using NBomber.Contracts;
using NBomber.CSharp;

namespace CSharpProd.DB.LiteDB
namespace Demo.DB.LiteDB
{
public class LiteDBCustomSettings
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using LiteDB;
using NBomber.CSharp;

namespace CSharpProd.DB.LiteDB
namespace Demo.DB.LiteDB
{
public class LiteDBExample
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace CSharpProd.DB.LiteDB
namespace Demo.DB.LiteDB
{
public enum Gender
{
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using NBomber.CSharp;

namespace CSharpProd.DB.Redis;
namespace Demo.DB.Redis;

public class RedisExample
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using NBomber.Data;
using StackExchange.Redis;

namespace CSharpProd.DB.Redis;
namespace Demo.DB.Redis;

public class RedisDbConfig
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using NBomber.CSharp;
using StackExchange.Redis;

namespace CSharpProd.DB.Redis;
namespace Demo.DB.Redis;

public class RedisReadScenario
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using NBomber.Data;
using StackExchange.Redis;

namespace CSharpProd.DB.Redis;
namespace Demo.DB.Redis;

public class RedisWriteScenario
{
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Data.SQLite;
using Dapper.Contrib.Extensions;

namespace CSharpProd.DB.SQLiteDB
namespace Demo.DB.SQLiteDB
{
public class SQLiteDBCustomSettings
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using NBomber;
using NBomber.CSharp;

namespace CSharpProd.DB.SQLiteDB
namespace Demo.DB.SQLiteDB
{
public class SQLiteDBExample
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace CSharpProd.DB.SQLiteDB
namespace Demo.DB.SQLiteDB
{
public enum Gender
{
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
<ItemGroup>
<None Remove="HTTP\SimpleBookstore\config.json" />
<None Remove="HTTP\WebAppSimulator\config.json" />
<None Update="Cluster\AutoCluster\autocluster-config.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
Expand All @@ -28,7 +31,7 @@
<PackageReference Include="Bogus" Version="34.0.2" />
<PackageReference Include="Dapper.Contrib" Version="2.0.78" />
<PackageReference Include="LiteDB" Version="5.0.15" />
<PackageReference Include="NBomber" Version="5.1.2" />
<PackageReference Include="NBomber" Version="5.2.0" />
<PackageReference Include="NBomber.Data" Version="5.0.0" />
<PackageReference Include="NBomber.Http" Version="5.0.0" />
<PackageReference Include="NBomber.Sinks.InfluxDB" Version="5.0.0" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using NBomber.CSharp;

namespace CSharpProd.Features.CliArgs;
namespace Demo.Features.CliArgs;

public class CliArgsExample
{
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using NBomber.Data;
// ReSharper disable CheckNamespace

namespace CSharpProd.Features;
namespace Demo.Features;

public class CustomScenarioSettings
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using NBomber.Contracts.Stats;
using NBomber.CSharp;

namespace CSharpProd.Features.CustomSettings;
namespace Demo.Features.CustomSettings;

public class CustomScenarioSettings
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using NBomber.Data.CSharp;
// ReSharper disable CheckNamespace

namespace CSharpProd.Features;
namespace Demo.Features;

public class User
{
Expand All @@ -23,8 +23,8 @@ public void Run()

//-------- Load by URL ---------//

//var data = Data.LoadCsv<User>("https://raw.githubusercontent.com/PragmaticFlow/NBomber/e54c45912b1826f54376a8668da556aeb922b9d6/examples/CSharpProd/DataFeed/users-feed-data.csv");
//var data = Data.LoadJson<User[]>("https://raw.githubusercontent.com/PragmaticFlow/NBomber/e54c45912b1826f54376a8668da556aeb922b9d6/examples/CSharpProd/DataFeed/users-feed-data.json");
//var data = Data.LoadCsv<User>("https://raw.githubusercontent.com/PragmaticFlow/NBomber/e54c45912b1826f54376a8668da556aeb922b9d6/examples/Demo/DataFeed/users-feed-data.csv");
//var data = Data.LoadJson<User[]>("https://raw.githubusercontent.com/PragmaticFlow/NBomber/e54c45912b1826f54376a8668da556aeb922b9d6/examples/Demo/DataFeed/users-feed-data.json");

//var feed = DataFeed.Constant(data);
//var feed = DataFeed.Random(data);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using NBomber.CSharp;
using Serilog;

namespace CSharpProd.Features.ElasticsearchLogger;
namespace Demo.Features.ElasticsearchLogger;

public class ElasticsearchExample
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using NBomber.CSharp;
using Serilog;

namespace CSharpProd.Features.RealtimeReporting.CustomReportingSink;
namespace Demo.Features.RealtimeReporting.CustomReportingSink;

class CustomReportingSink : IReportingSink
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using NBomber.CSharp;
using NBomber.Sinks.InfluxDB;

namespace CSharpProd.Features.RealtimeReporting.InfluxDB;
namespace Demo.Features.RealtimeReporting.InfluxDB;

public class InfluxDBReportingExample
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using NBomber.Http.CSharp;
using NBomber.Plugins.Network.Ping;

namespace CSharpProd.HTTP;
namespace Demo.HTTP;

public class HttpClientArgsExample
{
Expand All @@ -15,7 +15,7 @@ public void Run()
{
var request =
Http.CreateRequest("GET", "https://nbomber.com")
.WithHeader("Accept", "text/html");
.WithHeader("Content-Type", "application/json");
//.WithBody(new StringContent("{ some JSON }", Encoding.UTF8, "application/json"));
// HttpCompletionOption: https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpcompletionoption?view=net-7.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using NBomber.Http.CSharp;
using NBomber.Plugins.Network.Ping;

namespace CSharpProd.HTTP;
namespace Demo.HTTP;

public class JsonResponse
{
Expand Down
Loading

0 comments on commit fc702e8

Please sign in to comment.