From 9a1c9840931058b9ac79707e2c30d30985b07c06 Mon Sep 17 00:00:00 2001 From: Eric Brunner Date: Mon, 16 Dec 2024 12:43:02 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20added=C2=A0a=20clearOnly=20and=20a=20sn?= =?UTF-8?q?apshot=20backupDB=20cli=20command=20switch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Features/Create/CreateSnapshotTests.cs | 13 ++- .../Features/Create/CreateSnapshot.cs | 31 +++++- .../Create/Helper/DatabaseRestoreHelper.cs | 98 ++++++++++++++----- .../Create/Helper/IDatabaseRestoreHelper.cs | 3 +- .../Features/Create/Helper/IProcessHelper.cs | 2 +- .../Features/Create/Helper/ProcessHelper.cs | 8 +- .../Features/Shared/Constants/Resources.cs | 1 + .../Shared/Models/DatabaseRestoreResult.cs | 3 - .../Features/Shared/Models/DatabaseResult.cs | 3 + .../tools/snapshot-creator-v2/Program.cs | 6 +- .../Properties/launchSettings.json | 12 +++ 11 files changed, 139 insertions(+), 41 deletions(-) delete mode 100644 Applications/ConsumerApi/test/ConsumerApi.Tests.Performance/tools/snapshot-creator-v2/Features/Shared/Models/DatabaseRestoreResult.cs create mode 100644 Applications/ConsumerApi/test/ConsumerApi.Tests.Performance/tools/snapshot-creator-v2/Features/Shared/Models/DatabaseResult.cs diff --git a/Applications/ConsumerApi/test/ConsumerApi.Tests.Performance.SnapshotCreator.Tests/Features/Create/CreateSnapshotTests.cs b/Applications/ConsumerApi/test/ConsumerApi.Tests.Performance.SnapshotCreator.Tests/Features/Create/CreateSnapshotTests.cs index d308c0d2e3..f3983426ed 100644 --- a/Applications/ConsumerApi/test/ConsumerApi.Tests.Performance.SnapshotCreator.Tests/Features/Create/CreateSnapshotTests.cs +++ b/Applications/ConsumerApi/test/ConsumerApi.Tests.Performance.SnapshotCreator.Tests/Features/Create/CreateSnapshotTests.cs @@ -17,7 +17,6 @@ public class CreateSnapshotTests : SnapshotCreatorTestsBase private readonly IMediator _mediator; private readonly IOutputHelper _outputHelper; private readonly CreateSnapshot.CommandHandler _sut; - private readonly IDatabaseRestoreHelper _databaseRestoreHelper; public CreateSnapshotTests() { @@ -25,8 +24,8 @@ public CreateSnapshotTests() _poolConfigurationJsonReader = A.Fake(); _mediator = A.Fake(); _outputHelper = A.Fake(); - _databaseRestoreHelper = A.Fake(); - _sut = new CreateSnapshot.CommandHandler(logger, _poolConfigurationJsonReader, _mediator, _outputHelper, _databaseRestoreHelper); + var databaseRestoreHelper = A.Fake(); + _sut = new CreateSnapshot.CommandHandler(logger, _poolConfigurationJsonReader, _mediator, _outputHelper, databaseRestoreHelper); } [Theory] @@ -37,7 +36,7 @@ public async Task Handle_ShouldReturnSuccessStatusMessage_WhenPoolConfigurationI { // Arrange var fullFilePath = GetFullFilePath(poolConfigJsonFilename); - var command = new CreateSnapshot.Command("http://baseaddress", "clientId", "clientSecret", fullFilePath, ClearDatabase: false); + var command = new CreateSnapshot.Command("http://baseaddress", "clientId", "clientSecret", fullFilePath, ClearDatabase: false, BackupDatabase: false); A.CallTo(() => _poolConfigurationJsonReader.Read(command.JsonFilePath)).Returns( new PerformanceTestConfiguration( @@ -83,7 +82,7 @@ public async Task Handle_ShouldReturnFailureStatusMessage_WhenPoolConfigurationI { // Arrange var fullFilePath = GetFullFilePath(poolConfigJsonFilename); - var command = new CreateSnapshot.Command("http://baseaddress", "clientId", "clientSecret", fullFilePath, ClearDatabase: false); + var command = new CreateSnapshot.Command("http://baseaddress", "clientId", "clientSecret", fullFilePath, ClearDatabase: false, BackupDatabase: false); A.CallTo(() => _poolConfigurationJsonReader.Read(command.JsonFilePath)).Returns(null as PerformanceTestConfiguration); @@ -103,7 +102,7 @@ public async Task Handle_ShouldReturnFailureStatusMessage_WhenPoolConfigurationI public async Task Handle_ShouldReturnFailureStatusMessage_WhenExceptionIsThrown() { // Arrange - var command = new CreateSnapshot.Command("http://baseaddress", "clientId", "clientSecret", GetFullFilePath("pool-config.test.json"), ClearDatabase: false); + var command = new CreateSnapshot.Command("http://baseaddress", "clientId", "clientSecret", GetFullFilePath("pool-config.test.json"), ClearDatabase: false, BackupDatabase: false); var expectedException = new Exception("some exception"); A.CallTo(() => _poolConfigurationJsonReader.Read(command.JsonFilePath)).ThrowsAsync(expectedException); @@ -124,7 +123,7 @@ public async Task Handle_ShouldReturnFailureStatusMessage_WhenPoolConfigurationF { // Arrange var fullFilePath = GetFullFilePath("not-existing-pool-config.test.json"); - var command = new CreateSnapshot.Command("http://baseaddress", "clientId", "clientSecret", fullFilePath, ClearDatabase: false); + var command = new CreateSnapshot.Command("http://baseaddress", "clientId", "clientSecret", fullFilePath, ClearDatabase: false, BackupDatabase: false); // Act var result = await _sut.Handle(command, CancellationToken.None); diff --git a/Applications/ConsumerApi/test/ConsumerApi.Tests.Performance/tools/snapshot-creator-v2/Features/Create/CreateSnapshot.cs b/Applications/ConsumerApi/test/ConsumerApi.Tests.Performance/tools/snapshot-creator-v2/Features/Create/CreateSnapshot.cs index 4cd60ed373..237291aaf7 100644 --- a/Applications/ConsumerApi/test/ConsumerApi.Tests.Performance/tools/snapshot-creator-v2/Features/Create/CreateSnapshot.cs +++ b/Applications/ConsumerApi/test/ConsumerApi.Tests.Performance/tools/snapshot-creator-v2/Features/Create/CreateSnapshot.cs @@ -16,7 +16,9 @@ public record Command( string ClientId, string ClientSecret, string JsonFilePath, - bool ClearDatabase) : IRequest; + bool ClearDatabase, + bool BackupDatabase, + bool ClearOnly) : IRequest; public class CommandHandler( ILogger logger, @@ -32,6 +34,19 @@ public async Task Handle(Command request, CancellationToken cance { try { + if (request.ClearOnly) + { + var result = await databaseRestoreHelper.RestoreCleanDatabase(); + + if (!result.Status) + { + return result; + } + + logger.LogInformation("Restore clean-db completed: {Message}", result.Message); + return new StatusMessage(true, CLEAN_DB_SUCCEED_MESSAGE); + } + logger.LogInformation("Creating pool configuration with relationships and messages ..."); if (request.ClearDatabase) @@ -43,7 +58,7 @@ public async Task Handle(Command request, CancellationToken cance return result; } - logger.LogInformation("RestoreCleanDatabase: {Message}", result.Message); + logger.LogInformation("Restore clean-db completed: {Message}", result.Message); } @@ -122,6 +137,18 @@ public async Task Handle(Command request, CancellationToken cance logger.LogInformation("Messages created in {ElapsedTime}", stopwatch.Elapsed); logger.LogInformation("Pool configuration with relationships and messages created in {ElapsedTime}", totalRunTime); + + if (request.BackupDatabase) + { + var result = await databaseRestoreHelper.BackupDatabase(OutputDirName); + + if (!result.Status) + { + return result; + } + + logger.LogInformation("Backup completed: {Message}", result.Message); + } } catch (Exception e) { diff --git a/Applications/ConsumerApi/test/ConsumerApi.Tests.Performance/tools/snapshot-creator-v2/Features/Create/Helper/DatabaseRestoreHelper.cs b/Applications/ConsumerApi/test/ConsumerApi.Tests.Performance/tools/snapshot-creator-v2/Features/Create/Helper/DatabaseRestoreHelper.cs index c2e4a4f6fc..97409e0bc0 100644 --- a/Applications/ConsumerApi/test/ConsumerApi.Tests.Performance/tools/snapshot-creator-v2/Features/Create/Helper/DatabaseRestoreHelper.cs +++ b/Applications/ConsumerApi/test/ConsumerApi.Tests.Performance/tools/snapshot-creator-v2/Features/Create/Helper/DatabaseRestoreHelper.cs @@ -11,6 +11,7 @@ public class DatabaseRestoreHelper(ILogger logger, IProce private const string DB_NAME = "enmeshed"; private const string CONTAINER_NAME = "tmp-postgres-container"; private const string CLEAN_DB_NAME = "clean-db.rg"; + private const string SNAPHOT_DB_NAME = "snapshot-db.rg"; private static bool QueryUserConsent() { @@ -25,7 +26,7 @@ private static bool QueryUserConsent() return input == 'y'; } - public async Task RestoreCleanDatabase() + public async Task RestoreCleanDatabase() { try { @@ -43,8 +44,7 @@ public async Task RestoreCleanDatabase() switch (checkForOpenConnectionsResult.Status) { case false when checkForOpenConnectionsResult.IsError: - //Note; Error shouldn't stop the snapshot creation process, therefore, return true - return new DatabaseRestoreResult(true, checkForOpenConnectionsResult.Message); + return new DatabaseResult(false, checkForOpenConnectionsResult.Message); case true: { logger.LogInformation("Open connections checked successfully: {Message}", checkForOpenConnectionsResult.Message); @@ -53,7 +53,7 @@ public async Task RestoreCleanDatabase() if (!consent) { - return new DatabaseRestoreResult(true, "User chose not to drop db and create a clean-db"); + return new DatabaseResult(true, "User chose not to drop db and create a clean-db"); } var forceDropOpenConnectionsResult = await ForceDropOpenConnections(CONTAINER_NAME, HOSTNAME, USERNAME, PASSWORD, DB_NAME); @@ -107,17 +107,51 @@ public async Task RestoreCleanDatabase() } catch (Exception e) { - return new DatabaseRestoreResult(false, e.Message, Exception: e); + return new DatabaseResult(false, e.Message, Exception: e); } finally { await StopTemporaryPostgresDockerContainer(CONTAINER_NAME); } - return new DatabaseRestoreResult(true, "Database restored successfully"); + return new DatabaseResult(true, "Database restored successfully"); } - private async Task DropDatabase(string containerName, string password, string hostname, string username, string dbname) + public async Task BackupDatabase(string outputDirName) + { + try + { + var createContainerResult = await CreateTemporaryPostgresDockerContainer(CONTAINER_NAME, PASSWORD, forceRecreate: true, outputDirName); + + if (!createContainerResult.Status) + { + throw new InvalidOperationException(createContainerResult.Message, createContainerResult.Exception); + } + + logger.LogInformation("Postgres container created successfully: {Message}", createContainerResult.Message); + + var result = await DumpDatabase(CONTAINER_NAME, PASSWORD, HOSTNAME, USERNAME, DB_NAME, SNAPHOT_DB_NAME); + + if (!result.Status) + { + throw new InvalidOperationException(result.Message); + } + } + catch (Exception e) + { + return new DatabaseResult(false, e.Message, Exception: e); + } + finally + { + await StopTemporaryPostgresDockerContainer(CONTAINER_NAME); + } + + + return new DatabaseResult(true, "Database backup completed successfully"); + } + + + private async Task DropDatabase(string containerName, string password, string hostname, string username, string dbname) { var command = $"docker exec --env PGPASSWORD=\"{password}\" {containerName} psql -h {hostname} -U {username} postgres -c \"DROP DATABASE IF EXISTS {dbname}\""; return await processHelper.ExecuteProcess(command, processParams => processParams.Process.ExitCode == 0 && @@ -125,7 +159,14 @@ private async Task DropDatabase(string containerName, str !processParams.HasError); } - private async Task CreateDatabase(string containerName, string password, string hostname, string username, string dbname) + private async Task DumpDatabase(string containerName, string password, string hostname, string username, string dbname, string backupFile) + { + var command = $"docker exec --env PGPASSWORD=\"{password}\" {containerName} pg_dump -h {hostname} -U {username} {dbname} -f /dump/{backupFile}"; + return await processHelper.ExecuteProcess(command, processParams => processParams.Process.ExitCode == 0 && + !processParams.HasError); + } + + private async Task CreateDatabase(string containerName, string password, string hostname, string username, string dbname) { var command = $"docker exec --env PGPASSWORD=\"{password}\" {containerName} psql -h {hostname} -U {username} postgres -c \"CREATE DATABASE {dbname}\""; return await processHelper.ExecuteProcess(command, processParams => processParams.Process.ExitCode == 0 && @@ -133,7 +174,7 @@ private async Task CreateDatabase(string containerName, s !processParams.HasError); } - private async Task AlterDatabase(string containerName, string password, string hostname, string username, string dbname) + private async Task AlterDatabase(string containerName, string password, string hostname, string username, string dbname) { var command = $"docker exec --env PGPASSWORD=\"{password}\" {containerName} psql -h {hostname} -U {username} postgres -c \"ALTER DATABASE {dbname} OWNER TO {username};\""; return await processHelper.ExecuteProcess(command, processParams => processParams.Process.ExitCode == 0 && @@ -141,33 +182,45 @@ private async Task AlterDatabase(string containerName, st !processParams.HasError); } - private async Task RestoreDatabase(string containerName, string password, string hostname, string username, string dbname, string backupFile) + private async Task RestoreDatabase(string containerName, string password, string hostname, string username, string dbname, string restoreFile) { - var command = $"docker exec --env PGPASSWORD=\"{password}\" {containerName} psql -h {hostname} -U {username} {dbname} -f /dump/{backupFile}"; + var command = $"docker exec --env PGPASSWORD=\"{password}\" {containerName} psql -h {hostname} -U {username} {dbname} -f /dump/{restoreFile}"; return await processHelper.ExecuteProcess(command, processParams => processParams.Process.ExitCode == 0 && !string.IsNullOrWhiteSpace(processParams.Output) && !processParams.HasError); } - private async Task CreateTemporaryPostgresDockerContainer(string containerName, string password) + private async Task CreateTemporaryPostgresDockerContainer(string containerName, string password, bool forceRecreate = false, string? outputDirectory = null) { try { - var result = await IsTemporaryContainerRunning(containerName); - if (result.Status) return result; + if (forceRecreate) + { + await StopTemporaryPostgresDockerContainer(containerName); + } + else + { + var result = await IsTemporaryContainerRunning(containerName); + if (result.Status) return result; - var directory = Path.Combine(AppContext.BaseDirectory, @"Config\Database\dump-files"); + if (result.IsError) + { + return new DatabaseResult(false, result.Message); + } + } + + var directory = outputDirectory ?? Path.Combine(AppContext.BaseDirectory, @"Config\Database\dump-files"); var command = $"docker run -d --rm --name {containerName} -v \"{directory}:/dump\" -e POSTGRES_PASSWORD=\"{password}\" postgres"; // docker run -d --rm --name $ContainerName -v "$PSScriptRoot\dump-files:/dump" -e POSTGRES_PASSWORD="admin" postgres return await processHelper.ExecuteProcess(command, processParams => !string.IsNullOrEmpty(processParams.Output?.Trim())); } catch (Exception e) { - return new DatabaseRestoreResult(false, e.Message, Exception: e); + return new DatabaseResult(false, e.Message, Exception: e); } } - private async Task IsTemporaryContainerRunning(string containerName) + private async Task IsTemporaryContainerRunning(string containerName) { try { @@ -178,7 +231,7 @@ private async Task IsTemporaryContainerRunning(string con } catch (Exception e) { - return new DatabaseRestoreResult(false, e.Message, Exception: e); + return new DatabaseResult(false, e.Message, Exception: e); } } @@ -199,8 +252,7 @@ private async Task StopTemporaryPostgresDockerContainer(string containerName) } } - - private async Task CheckForOpenConnections(string containerName, string hostname, string username, string password, string dbName) + private async Task CheckForOpenConnections(string containerName, string hostname, string username, string password, string dbName) { try { @@ -213,11 +265,11 @@ private async Task CheckForOpenConnections(string contain } catch (Exception e) { - return new DatabaseRestoreResult(false, e.Message, Exception: e); + return new DatabaseResult(false, e.Message, Exception: e); } } - private async Task ForceDropOpenConnections(string containerName, string hostname, string username, string password, string dbName) + private async Task ForceDropOpenConnections(string containerName, string hostname, string username, string password, string dbName) { try { @@ -230,7 +282,7 @@ private async Task ForceDropOpenConnections(string contai } catch (Exception e) { - return new DatabaseRestoreResult(false, e.Message, Exception: e); + return new DatabaseResult(false, e.Message, Exception: e); } } } diff --git a/Applications/ConsumerApi/test/ConsumerApi.Tests.Performance/tools/snapshot-creator-v2/Features/Create/Helper/IDatabaseRestoreHelper.cs b/Applications/ConsumerApi/test/ConsumerApi.Tests.Performance/tools/snapshot-creator-v2/Features/Create/Helper/IDatabaseRestoreHelper.cs index fc3ca8dfd1..2089f14691 100644 --- a/Applications/ConsumerApi/test/ConsumerApi.Tests.Performance/tools/snapshot-creator-v2/Features/Create/Helper/IDatabaseRestoreHelper.cs +++ b/Applications/ConsumerApi/test/ConsumerApi.Tests.Performance/tools/snapshot-creator-v2/Features/Create/Helper/IDatabaseRestoreHelper.cs @@ -4,5 +4,6 @@ namespace Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Cre public interface IDatabaseRestoreHelper { - Task RestoreCleanDatabase(); + Task RestoreCleanDatabase(); + Task BackupDatabase(string outputDirName); } diff --git a/Applications/ConsumerApi/test/ConsumerApi.Tests.Performance/tools/snapshot-creator-v2/Features/Create/Helper/IProcessHelper.cs b/Applications/ConsumerApi/test/ConsumerApi.Tests.Performance/tools/snapshot-creator-v2/Features/Create/Helper/IProcessHelper.cs index 04838c8d85..79804700f0 100644 --- a/Applications/ConsumerApi/test/ConsumerApi.Tests.Performance/tools/snapshot-creator-v2/Features/Create/Helper/IProcessHelper.cs +++ b/Applications/ConsumerApi/test/ConsumerApi.Tests.Performance/tools/snapshot-creator-v2/Features/Create/Helper/IProcessHelper.cs @@ -5,5 +5,5 @@ namespace Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Cre public interface IProcessHelper { - Task ExecuteProcess(string command, Predicate processPredicate); + Task ExecuteProcess(string command, Predicate processPredicate); } diff --git a/Applications/ConsumerApi/test/ConsumerApi.Tests.Performance/tools/snapshot-creator-v2/Features/Create/Helper/ProcessHelper.cs b/Applications/ConsumerApi/test/ConsumerApi.Tests.Performance/tools/snapshot-creator-v2/Features/Create/Helper/ProcessHelper.cs index 1632f8f980..a1165167b6 100644 --- a/Applications/ConsumerApi/test/ConsumerApi.Tests.Performance/tools/snapshot-creator-v2/Features/Create/Helper/ProcessHelper.cs +++ b/Applications/ConsumerApi/test/ConsumerApi.Tests.Performance/tools/snapshot-creator-v2/Features/Create/Helper/ProcessHelper.cs @@ -6,7 +6,7 @@ namespace Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Cre public class ProcessHelper : IProcessHelper { - public async Task ExecuteProcess(string command, Predicate processPredicate) + public async Task ExecuteProcess(string command, Predicate processPredicate) { var psi = new ProcessStartInfo("cmd", $"/c {command}") { @@ -26,7 +26,7 @@ public async Task ExecuteProcess(string command, Predicat var status = processPredicate(new ProcessParams(process, output, hasError)); - return new DatabaseRestoreResult(status, $"{output} {errorMessage}", IsError: hasError); + return new DatabaseResult(status, $"{output} {errorMessage}", IsError: hasError); } private static string GetErrorMessage(string error) @@ -34,7 +34,9 @@ private static string GetErrorMessage(string error) return !string.IsNullOrWhiteSpace(error) ? error.StartsWith("psql: error: connection to server", StringComparison.OrdinalIgnoreCase) ? $"Is enmeshed backbone postgres container running?{Environment.NewLine}{ERROR}: {error}" - : $"{Environment.NewLine}{ERROR}:{error}" + : error.Contains("error during connect", StringComparison.OrdinalIgnoreCase) + ? $"Is docker running?{Environment.NewLine}{ERROR}: {error}" + : $"{Environment.NewLine}{ERROR}:{error}" : string.Empty; } } diff --git a/Applications/ConsumerApi/test/ConsumerApi.Tests.Performance/tools/snapshot-creator-v2/Features/Shared/Constants/Resources.cs b/Applications/ConsumerApi/test/ConsumerApi.Tests.Performance/tools/snapshot-creator-v2/Features/Shared/Constants/Resources.cs index 28857a0baa..543c574c74 100644 --- a/Applications/ConsumerApi/test/ConsumerApi.Tests.Performance/tools/snapshot-creator-v2/Features/Shared/Constants/Resources.cs +++ b/Applications/ConsumerApi/test/ConsumerApi.Tests.Performance/tools/snapshot-creator-v2/Features/Shared/Constants/Resources.cs @@ -32,6 +32,7 @@ public static class Resources public const string POOL_CONFIG_FILE_READ_ERROR = "Pool configuration could not be read."; public const string POOL_CONFIG_FILE_NOT_FOUND_ERROR = "Pool configuration file not found."; public const string SNAPSHOT_CREATION_SUCCEED_MESSAGE = "Pool configuration with relationships and messages created successfully."; + public const string CLEAN_DB_SUCCEED_MESSAGE = "Restore of Clean-DB completed successfully."; public static string BuildErrorDetails(string message, DomainIdentity? senderIdentity, DomainIdentity? recipientIdentity, ApiResponse? apiResponse = null) { diff --git a/Applications/ConsumerApi/test/ConsumerApi.Tests.Performance/tools/snapshot-creator-v2/Features/Shared/Models/DatabaseRestoreResult.cs b/Applications/ConsumerApi/test/ConsumerApi.Tests.Performance/tools/snapshot-creator-v2/Features/Shared/Models/DatabaseRestoreResult.cs deleted file mode 100644 index cbc87b8d66..0000000000 --- a/Applications/ConsumerApi/test/ConsumerApi.Tests.Performance/tools/snapshot-creator-v2/Features/Shared/Models/DatabaseRestoreResult.cs +++ /dev/null @@ -1,3 +0,0 @@ -namespace Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Shared.Models; - -public record DatabaseRestoreResult(bool Status, string Message, bool IsError = false, Exception? Exception = null) : StatusMessage(Status, Message, Exception); diff --git a/Applications/ConsumerApi/test/ConsumerApi.Tests.Performance/tools/snapshot-creator-v2/Features/Shared/Models/DatabaseResult.cs b/Applications/ConsumerApi/test/ConsumerApi.Tests.Performance/tools/snapshot-creator-v2/Features/Shared/Models/DatabaseResult.cs new file mode 100644 index 0000000000..65a46463a7 --- /dev/null +++ b/Applications/ConsumerApi/test/ConsumerApi.Tests.Performance/tools/snapshot-creator-v2/Features/Shared/Models/DatabaseResult.cs @@ -0,0 +1,3 @@ +namespace Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Shared.Models; + +public record DatabaseResult(bool Status, string Message, bool IsError = false, Exception? Exception = null) : StatusMessage(Status, Message, Exception); diff --git a/Applications/ConsumerApi/test/ConsumerApi.Tests.Performance/tools/snapshot-creator-v2/Program.cs b/Applications/ConsumerApi/test/ConsumerApi.Tests.Performance/tools/snapshot-creator-v2/Program.cs index 13884a6fae..fabc5dff8d 100644 --- a/Applications/ConsumerApi/test/ConsumerApi.Tests.Performance/tools/snapshot-creator-v2/Program.cs +++ b/Applications/ConsumerApi/test/ConsumerApi.Tests.Performance/tools/snapshot-creator-v2/Program.cs @@ -150,6 +150,8 @@ private static void CreateSnapshotCommand(CommandLineApplication command) var clientSecretOption = command.Option("-s|--clientSecret ", "Client Secret of the Consumer API", CommandOptionType.SingleValue); var poolConfigOption = command.Option("-p|--pool-config ", "Pool Config JSON File", CommandOptionType.SingleValue); var clearDatabaseOption = command.Option("-r|--clearDB", "Clear the Database before applying the Pool Config", CommandOptionType.NoValue); + var clearOnlyOption = command.Option("-l|--clearOnly", "Just clear the Database, without created a snapshot", CommandOptionType.NoValue); + var backupDatabaseOption = command.Option("-b|--backupDB", "Backup the Database after snapshot is created", CommandOptionType.NoValue); command.OnExecuteAsync(async cancellationToken => { @@ -158,11 +160,13 @@ private static void CreateSnapshotCommand(CommandLineApplication command) var clientSecret = clientSecretOption.Value(); var poolConfigJsonFilePath = poolConfigOption.Value(); var clearDatabase = clearDatabaseOption.ParsedValue; + var clearOnly = clearOnlyOption.ParsedValue; + var backupDatabase = backupDatabaseOption.ParsedValue; var mediator = command.GetRequiredService(); var logger = command.GetRequiredService>(); - var result = await mediator.Send(new CreateSnapshot.Command(baseAddress, clientId!, clientSecret!, poolConfigJsonFilePath!, clearDatabase), cancellationToken); + var result = await mediator.Send(new CreateSnapshot.Command(baseAddress, clientId!, clientSecret!, poolConfigJsonFilePath!, clearDatabase, backupDatabase, clearOnly), cancellationToken); if (result.Status) { diff --git a/Applications/ConsumerApi/test/ConsumerApi.Tests.Performance/tools/snapshot-creator-v2/Properties/launchSettings.json b/Applications/ConsumerApi/test/ConsumerApi.Tests.Performance/tools/snapshot-creator-v2/Properties/launchSettings.json index 2ad0b949df..757d096221 100644 --- a/Applications/ConsumerApi/test/ConsumerApi.Tests.Performance/tools/snapshot-creator-v2/Properties/launchSettings.json +++ b/Applications/ConsumerApi/test/ConsumerApi.Tests.Performance/tools/snapshot-creator-v2/Properties/launchSettings.json @@ -51,6 +51,18 @@ "SnapshotCreator.V2 - create-snapshot test (clean-db)": { "commandName": "Project", "commandLineArgs": "create-snapshot --baseAddress http://localhost:8081 --clientId test --clientSecret test --pool-config .\\Config\\PoolConfig-TEST\\pool-config.test.json --clearDB" + }, + "SnapshotCreator.V2 - create-snapshot test (backup-db)": { + "commandName": "Project", + "commandLineArgs": "create-snapshot --baseAddress http://localhost:8081 --clientId test --clientSecret test --pool-config .\\Config\\PoolConfig-TEST\\pool-config.test.json --backupDB" + }, + "SnapshotCreator.V2 - create-snapshot test (clean-db + backup-db)": { + "commandName": "Project", + "commandLineArgs": "create-snapshot --baseAddress http://localhost:8081 --clientId test --clientSecret test --pool-config .\\Config\\PoolConfig-TEST\\pool-config.test.json --clearDB --backupDB" + }, + "SnapshotCreator.V2 - create-snapshot test (clean-db ONLY)": { + "commandName": "Project", + "commandLineArgs": "create-snapshot --baseAddress http://localhost:8081 --clientId test --clientSecret test --pool-config .\\Config\\PoolConfig-TEST\\pool-config.test.json --clearOnly" } } }