Skip to content

Commit

Permalink
added DataFeed examples
Browse files Browse the repository at this point in the history
  • Loading branch information
AntyaDev committed Dec 12, 2022
1 parent 6a421cc commit fe9d520
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 8 deletions.
7 changes: 7 additions & 0 deletions examples/CSharpProd/CSharpProd.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

<ItemGroup>
<PackageReference Include="NBomber" Version="4.0.0-beta7" />
<PackageReference Include="NBomber.Data" Version="4.0.0-beta" />
<PackageReference Include="NBomber.Http" Version="4.0.0-beta3" />
<PackageReference Include="MQTTnet" Version="3.1.2" />
</ItemGroup>
Expand All @@ -16,6 +17,12 @@
<None Update="Features\CustomSettings\config.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Features\DataFeed\users-feed-data.csv">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Features\DataFeed\users-feed-data.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
Expand Down
49 changes: 49 additions & 0 deletions examples/CSharpProd/Features/DataFeed/DataFeedExample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using NBomber.CSharp;
using NBomber.Data;
using NBomber.Data.CSharp;
// ReSharper disable CheckNamespace

namespace CSharpProd.Features;

public class User
{
public int Id { get; set; }
public string Name { get; set; }
}

public class DataFeedExample
{
public void Run()
{
//-------- Load by file --------//

//var data = new[] {1, 2, 3, 4, 5};
//var data = Data.LoadCsv<User>("./Features/DataFeed/users-feed-data.csv");
var data = Data.LoadJson<User[]>("./Features/DataFeed/users-feed-data.json");

//-------- 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 feed = DataFeed.Constant(data);
//var feed = DataFeed.Random(data);
var feed = DataFeed.Circular(data);

var scenario = Scenario.Create("scenario", async context =>
{
var item = feed.GetNextItem(context.ScenarioInfo);
context.Logger.Information("Data from feed: {0}", item.Name);
await Task.Delay(1_000);
return Response.Ok();
})
.WithoutWarmUp()
.WithLoadSimulations(Simulation.KeepConstant(copies: 2, during: TimeSpan.FromSeconds(30)));

NBomberRunner
.RegisterScenarios(scenario)
.Run();

}
}
6 changes: 6 additions & 0 deletions examples/CSharpProd/Features/DataFeed/users-feed-data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Id,Name
1,Test User 1
2,Test User 2
3,Test User 3
4,Test User 4
5,Test User 5
10 changes: 10 additions & 0 deletions examples/CSharpProd/Features/DataFeed/users-feed-data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"Id": 1,
"Name": "Test User 1"
},
{
"Id": 2,
"Name": "Test User 2"
}
]
16 changes: 8 additions & 8 deletions examples/CSharpProd/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CSharpProd.Features.CustomSettings;
using CSharpProd.Features;
using CSharpProd.Features.CustomSettings;
using CSharpProd.HelloWorld;
using CSharpProd.HelloWorld.LoadSimulation;
using CSharpProd.HTTP;
Expand All @@ -21,6 +22,12 @@
// new ScenarioWithStepRetry().Run();
// new EmptyScenario().Run();

// ------------------
// ---- Features ----
// ------------------
// new DataFeedExample().Run();
// new CustomSettingsExample().Run();

// ----------------
// ----- HTTP -----
// ----------------
Expand All @@ -32,10 +39,3 @@
// ----- MQTT -----
// ----------------
// new PingPongMqttTest().Run();

// ------------------
// ---- Features ----
// ------------------
// new CustomSettingsExample().Run();


0 comments on commit fe9d520

Please sign in to comment.