Skip to content

Commit

Permalink
chore: some renamings and clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
ericbrunner committed Nov 11, 2024
1 parent 652d8ea commit 6f21e7c
Show file tree
Hide file tree
Showing 18 changed files with 36 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.Tests.Readers;

public class PerformanceTestConfigurationJsonReaderTests : SnapshotCreatorTestsBase
public class PoolConfigurationJsonReaderTests : SnapshotCreatorTestsBase
{
#region Deserialize From Json Tests

Expand All @@ -16,7 +16,7 @@ public async Task Read_InputPoolConfigJson_ReturnsPoolConfiguration(string poolC
// Arrange
var poolConfigJsonFile = Path.Combine(TestDataFolder, poolConfigJsonFilename);
var expectedPoolConfig = await GetExpectedPoolConfiguration(expectedPoolConfigJsonFilename);
var sut = new PerformanceTestConfigurationJsonReader();
var sut = new PoolConfigurationJsonReader();

// Act
var actualPoolConfig = await sut.Read(poolConfigJsonFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.Tests.Readers;

public class PerformanceTestConfigurationExcelReaderTests : SnapshotCreatorTestsBase
public class PoolConfigurationExcelReaderTests : SnapshotCreatorTestsBase
{
#region Verify Json Pool Config

Expand All @@ -17,7 +17,7 @@ public async Task Read_InputPerformanceTestDataExcel_ReturnsPoolConfiguration(st
var poolConfigExcelFile = Path.Combine(TestDataFolder, excelFile);
var expectedPoolConfig = await GetExpectedPoolConfiguration(expectedPoolConfigJsonFilename);
expectedPoolConfig.RelationshipAndMessages.Clear(); //Note: Excel reader does only read the pool config, not the relationships and messages
var sut = new PerformanceTestConfigurationExcelReader();
var sut = new PoolConfigurationExcelReader();

// Act
var actualPoolConfig = await sut.Read(poolConfigExcelFile, loadTestTag);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using Backbone.ConsumerApi.Sdk.Authentication;
using Backbone.ConsumerApi.Sdk.Authentication;
using Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Shared.Interfaces;
using Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Shared.Models;
using MediatR;
Expand All @@ -17,7 +16,7 @@ public record Command(

public record CommandHandler(
ILogger<CommandHandler> Logger,
IPerformanceTestConfigurationJsonReader PerformanceTestConfigurationJsonReader,
IPoolConfigurationJsonReader PoolConfigurationJsonReader,
IMediator Mediator)
: IRequestHandler<Command, StatusMessage>
{
Expand All @@ -27,7 +26,7 @@ public async Task<StatusMessage> Handle(Command request, CancellationToken cance
{
Logger.LogInformation("Creating pool configuration with relationships and messages ...");

var poolConfig = await PerformanceTestConfigurationJsonReader.Read(request.JsonFilePath);
var poolConfig = await PoolConfigurationJsonReader.Read(request.JsonFilePath);
var clientCredentials = new ClientCredentials(request.ClientId, request.ClientSecret);

var identities = await Mediator.Send(new CreateIdentities.Command(poolConfig.IdentityPoolConfigurations, request.BaseAddress, clientCredentials), cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public record GenerateConfig
public record Command(string ExcelFilePath, string WorkSheetName) : IRequest<StatusMessage>;

public class CommandHandler(
IPerformanceTestConfigurationExcelReader performanceTestConfigurationExcelReader,
IPoolConfigurationExcelReader poolConfigurationExcelReader,
IRelationshipAndMessagesGenerator relationshipAndMessagesGenerator,
IPoolConfigurationJsonWriter poolConfigurationJsonWriter)
: IRequestHandler<Command, StatusMessage>
Expand All @@ -19,7 +19,7 @@ public async Task<StatusMessage> Handle(Command request, CancellationToken cance
StatusMessage result;
try
{
var poolConfigFromExcel = await performanceTestConfigurationExcelReader.Read(request.ExcelFilePath, request.WorkSheetName);
var poolConfigFromExcel = await poolConfigurationExcelReader.Read(request.ExcelFilePath, request.WorkSheetName);

var relationshipAndMessages = relationshipAndMessagesGenerator.Generate(poolConfigFromExcel);

Expand All @@ -37,7 +37,7 @@ public async Task<StatusMessage> Handle(Command request, CancellationToken cance

Directory.CreateDirectory(snapshotFolder);

var poolConfigJsonFilePath = Path.Combine(snapshotFolder!, $"{POOL_CONFIG_JSON_WITH_RELATIONSHIP_AND_MESSAGES}.{request.WorkSheetName}.{JSON_FILE_EXT}");
var poolConfigJsonFilePath = Path.Combine(snapshotFolder!, $"pool-config.{request.WorkSheetName}.json");
result = await poolConfigurationJsonWriter.Write(poolConfigFromExcel, poolConfigJsonFilePath);
}
catch (Exception e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ namespace Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Gen

public interface IPoolConfigurationJsonWriter
{
Task<StatusMessage> Write(PerformanceTestConfiguration poolConfigFromExcel, string filePath);
Task<StatusMessage> Write(PerformanceTestConfiguration poolConfiguration, string filePath);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ namespace Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Gen

public interface IRelationshipAndMessagesGenerator
{
RelationshipAndMessages[] Generate(PerformanceTestConfiguration performanceTestConfiguration);
RelationshipAndMessages[] Generate(PerformanceTestConfiguration poolConfiguration);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ namespace Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Gen

public class PoolConfigurationJsonWriter : IPoolConfigurationJsonWriter
{
public async Task<StatusMessage> Write(PerformanceTestConfiguration poolConfigFromExcel, string filePath)
public async Task<StatusMessage> Write(PerformanceTestConfiguration poolConfiguration, string filePath)
{
try
{
var poolConfigJson = JsonSerializer.Serialize(poolConfigFromExcel, new JsonSerializerOptions { WriteIndented = true });
var poolConfigJson = JsonSerializer.Serialize(poolConfiguration, new JsonSerializerOptions { WriteIndented = true });
await File.WriteAllTextAsync(filePath, poolConfigJson);
}
catch (Exception e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ namespace Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Gen

public class RelationshipAndMessagesGenerator : IRelationshipAndMessagesGenerator
{
public RelationshipAndMessages[] Generate(PerformanceTestConfiguration performanceTestConfiguration)
public RelationshipAndMessages[] Generate(PerformanceTestConfiguration poolConfiguration)
{
if (!performanceTestConfiguration.IsIdentityPoolConfigurationCreated) throw new InvalidOperationException(IDENTITY_POOL_CONFIGURATION_NOT_CREATED);
if (!poolConfiguration.IsIdentityPoolConfigurationCreated) throw new InvalidOperationException(IDENTITY_POOL_CONFIGURATION_NOT_CREATED);

var identityPools = performanceTestConfiguration.IdentityPoolConfigurations;
var identityPools = poolConfiguration.IdentityPoolConfigurations;

var appIdentityPools = identityPools.Where(ip => ip.Type == IdentityPoolType.App).ToList();
var connectorIdentityPools = identityPools.Where(ip => ip.Type == IdentityPoolType.Connector).ToList();
Expand Down Expand Up @@ -103,13 +103,13 @@ public RelationshipAndMessages[] Generate(PerformanceTestConfiguration performan

var relationShipCount = relationshipAndMessagesList.Length / 2; // Note: Div by 2 because a pair of relationships (forward/reverse) is equal to 1 relationship

if (relationShipCount != performanceTestConfiguration.VerificationConfiguration.TotalNumberOfRelationships)
if (relationShipCount != poolConfiguration.VerificationConfiguration.TotalNumberOfRelationships)
{
throw new InvalidOperationException(string.Format(RELATIONSHIP_COUNT_MISMATCH, performanceTestConfiguration.VerificationConfiguration.TotalNumberOfRelationships, relationShipCount));
throw new InvalidOperationException(string.Format(RELATIONSHIP_COUNT_MISMATCH, poolConfiguration.VerificationConfiguration.TotalNumberOfRelationships, relationShipCount));
}

VerifyNumberOfSentMessages(relationshipAndMessagesList, IdentityPoolType.Connector, performanceTestConfiguration.VerificationConfiguration.TotalAppSentMessages);
VerifyNumberOfSentMessages(relationshipAndMessagesList, IdentityPoolType.App, performanceTestConfiguration.VerificationConfiguration.TotalConnectorSentMessages);
VerifyNumberOfSentMessages(relationshipAndMessagesList, IdentityPoolType.Connector, poolConfiguration.VerificationConfiguration.TotalAppSentMessages);
VerifyNumberOfSentMessages(relationshipAndMessagesList, IdentityPoolType.App, poolConfiguration.VerificationConfiguration.TotalConnectorSentMessages);


return relationshipAndMessagesList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,9 @@ public static class Resources
public const string POOL_TYPE_CONNECTOR = "connector";
public const string POOL_TYPE_UNKNOWN = "Invalid identity pool type";

public const string POOL_NAME_NEVER = "NeverUse";
public const string POOL_NAME_APP_LIGHT = "AppLight";
public const string POOL_NAME_APP_MEDIUM = "AppMedium";
public const string POOL_NAME_APP_HEAVY = "AppHeavy";
public const string POOL_NAME_CONNECTOR_LIGHT = "ConnectorLight";
public const string POOL_NAME_CONNECTOR_MEDIUM = "ConnectorMedium";
public const string POOL_NAME_CONNECTOR_HEAVY = "ConnectorHeavy";

public const string POOL_ALIAS_NEVER = "e";
public const string POOL_ALIAS_APP_LIGHT = "a1";
public const string POOL_ALIAS_APP_MEDIUM = "a2";
public const string POOL_ALIAS_APP_HEAVY = "a3";
public const string POOL_ALIAS_CONNECTOR_LIGHT = "c1";
public const string POOL_ALIAS_CONNECTOR_MEDIUM = "c2";
public const string POOL_ALIAS_CONNECTOR_HEAVY = "c3";

public const string PERFORMANCE_TEST_CONFIGURATION_EXCEL_FILE_EMPTY = "Excel file is empty";
public const string PERFORMANCE_TEST_CONFIGURATION_FIRST_ROW_MISMATCH = "First row is not of type";

public const string POOL_CONFIG_JSON_WITH_RELATIONSHIP_AND_MESSAGES = "pool-config-relationships";
public const string JSON_FILE_EXT = "json";

public const string WORKBOOK_SHEET_TEST_LOAD = "test";
public const string WORKBOOK_SHEET_LIGHT_LOAD = "light";
public const string WORKBOOK_SHEET_HEAVY_LOAD = "heavy";

public const string TOTAL_NUMBER_OF_RELATIONSHIPS = "App.TotalNumberOfRelationships";
public const string APP_TOTAL_NUMBER_OF_SENT_MESSAGES = "App.TotalNumberOfSentMessages";
public const string CONNECTOR_TOTAL_NUMBER_OF_SENT_MESSAGES = "Connector.TotalNumberOfSentMessages";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Shared.Interfaces;

public interface IPerformanceTestConfigurationExcelReader
public interface IPoolConfigurationExcelReader
{
Task<PerformanceTestConfiguration> Read(string filePath, string workSheet);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Shared.Interfaces;

public interface IPerformanceTestConfigurationJsonReader
public interface IPoolConfigurationJsonReader
{
Task<PerformanceTestConfiguration> Read(string filePath);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Shared.Readers.Base;

public abstract class PerformanceTestConfigurationReaderBase
public abstract class PoolConfigurationReaderBase
{
protected abstract string[] ValidExtensions { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Shared.Readers;

public class PerformanceTestConfigurationExcelReader : PerformanceTestConfigurationReaderBase, IPerformanceTestConfigurationExcelReader
public class PoolConfigurationExcelReader : PoolConfigurationReaderBase, IPoolConfigurationExcelReader
{
protected override string[] ValidExtensions { get; } = [".xlsx", ".xls"];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Shared.Readers;

public class PerformanceTestConfigurationJsonReader : PerformanceTestConfigurationReaderBase, IPerformanceTestConfigurationJsonReader
public class PoolConfigurationJsonReader : PoolConfigurationReaderBase, IPoolConfigurationJsonReader
{
protected override string[] ValidExtensions { get; } = [".json"];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ namespace Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Ver

public interface IPoolConfigurationJsonValidator
{
Task<bool> Validate(PerformanceTestConfiguration poolConfigJsonFile, PerformanceTestConfiguration poolConfigFromExcel);
Task<bool> Validate(PerformanceTestConfiguration poolConfigurationFromJson, PerformanceTestConfiguration poolConfigurationFromExcel);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ namespace Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Ver

public class PoolConfigurationJsonValidator : IPoolConfigurationJsonValidator
{
public Task<bool> Validate(PerformanceTestConfiguration poolConfigJsonFile, PerformanceTestConfiguration poolConfigFromExcel)
public Task<bool> Validate(PerformanceTestConfiguration poolConfigurationFromJson, PerformanceTestConfiguration poolConfigurationFromExcel)
{
var result = poolConfigJsonFile.Equals(poolConfigFromExcel);
var result = poolConfigurationFromJson.Equals(poolConfigurationFromExcel);
return Task.FromResult(result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ public record VerifyConfig
public record Command(string ExcelFilePath, string WorkSheetName, string JsonFilePath) : IRequest<bool>;

public record CommandHandler(
IPerformanceTestConfigurationExcelReader PerformanceTestConfigurationExcelReader,
IPerformanceTestConfigurationJsonReader PerformanceTestConfigurationJsonReader,
IPoolConfigurationExcelReader PoolConfigurationExcelReader,
IPoolConfigurationJsonReader PoolConfigurationJsonReader,
IRelationshipAndMessagesGenerator RelationshipAndMessagesGenerator,
IPoolConfigurationJsonValidator PoolConfigurationJsonValidator) : IRequestHandler<Command, bool>
{
public async Task<bool> Handle(Command request, CancellationToken cancellationToken)
{
var poolConfigFromExcel = await PerformanceTestConfigurationExcelReader.Read(request.ExcelFilePath, request.WorkSheetName);
var poolConfigFromExcel = await PoolConfigurationExcelReader.Read(request.ExcelFilePath, request.WorkSheetName);

var relationshipAndMessages = RelationshipAndMessagesGenerator.Generate(poolConfigFromExcel);
poolConfigFromExcel.RelationshipAndMessages.Clear();
poolConfigFromExcel.RelationshipAndMessages.AddRange(relationshipAndMessages);

var poolConfigFromJson = await PerformanceTestConfigurationJsonReader.Read(request.JsonFilePath);
var poolConfigFromJson = await PoolConfigurationJsonReader.Read(request.JsonFilePath);

var result = await PoolConfigurationJsonValidator.Validate(poolConfigFromJson, poolConfigFromExcel);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ private static Task<int> Main(string[] args)
{
services.AddMediatR(configuration => configuration.RegisterServicesFromAssemblyContaining<Program>());
services.AddSingleton<IPerformanceTestConfigurationExcelReader, PerformanceTestConfigurationExcelReader>();
services.AddSingleton<IPoolConfigurationExcelReader, PoolConfigurationExcelReader>();
services.AddSingleton<IPoolConfigurationJsonWriter, PoolConfigurationJsonWriter>();
services.AddSingleton<IPerformanceTestConfigurationJsonReader, PerformanceTestConfigurationJsonReader>();
services.AddSingleton<IPoolConfigurationJsonReader, PoolConfigurationJsonReader>();
services.AddSingleton<IPoolConfigurationJsonValidator, PoolConfigurationJsonValidator>();
services.AddSingleton<IRelationshipAndMessagesGenerator, RelationshipAndMessagesGenerator>();
})
.RunCommandLineApplicationAsync(args, app =>
Expand Down

0 comments on commit 6f21e7c

Please sign in to comment.