Skip to content

Commit

Permalink
Removed DropIfExists-method from stores
Browse files Browse the repository at this point in the history
  • Loading branch information
stidsborg committed Jul 29, 2024
1 parent 22ed6df commit 48bc021
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 51 deletions.
9 changes: 6 additions & 3 deletions Samples/Sample.ConsoleApp/WorkDistribution/Example.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ public static class Example
public static async Task Perform()
{
var postgresStore = new PostgreSqlFunctionStore("Server=localhost;Database=rfunctions;User Id=postgres;Password=Pa55word!; Include Error Detail=true;");
await postgresStore.DropIfExists();
await postgresStore.Initialize();
await postgresStore.TruncateTables();
var sqlServerStore = new SqlServerFunctionStore("Server=localhost;Database=rfunctions;User Id=sa;Password=Pa55word!;Encrypt=True;TrustServerCertificate=True;Max Pool Size=200;");
await sqlServerStore.DropIfExists();
await sqlServerStore.Initialize();
await sqlServerStore.TruncateTables();
var mySqlStore = new MySqlFunctionStore("server=localhost;userid=root;password=Pa55word!;database=rfunctions;AllowPublicKeyRetrieval=True;");
await mySqlStore.DropIfExists();
await mySqlStore.Initialize();
await mySqlStore.TruncateTables();

Console.WriteLine();
Console.WriteLine("Postgres: ");
Expand Down
2 changes: 1 addition & 1 deletion Samples/Sample.OrderProcessing/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public static async Task Main(string[] args)

var connStr = "Server=localhost;Database=rfunctions;User Id=postgres;Password=Pa55word!; Include Error Detail=true;";
var store = new PostgreSqlFunctionStore(connStr);
await store.DropIfExists();
await store.Initialize();
await store.TruncateTables();
var functionsRegistry = new FunctionsRegistry(
store,
new Settings(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public static void AssemblyInit(TestContext testContext)
private static async Task<MySqlFunctionStore> CreateAndInitializeStore(string testClass, string testMethod)
{
var store = new MySqlFunctionStore(ConnectionString);
await store.DropIfExists();
await store.Initialize();
await store.TruncateTables();
return store;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,6 @@ PRIMARY KEY (type, instance),
await command.ExecuteNonQueryAsync();
}

private string? _dropIfExistsSql;
public async Task DropIfExists()
{
await _messageStore.DropUnderlyingTable();
await _mySqlUnderlyingRegister.DropUnderlyingTable();
await _timeoutStore.DropUnderlyingTable();

await using var conn = await CreateOpenConnection(_connectionString);
_dropIfExistsSql ??= $"DROP TABLE IF EXISTS {_tablePrefix}";
await using var command = new MySqlCommand(_dropIfExistsSql, conn);
await command.ExecuteNonQueryAsync();
}

private string? _truncateTablesSql;
public async Task TruncateTables()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private static async Task<PostgreSqlFunctionStore> CreateAndInitializeStore(stri
{
var store = new PostgreSqlFunctionStore(ConnectionString);
await store.Initialize();
await store.TruncateTable();
await store.TruncateTables();
return store;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,22 +98,9 @@ CREATE INDEX IF NOT EXISTS idx_{_tablePrefix}_succeeded
await using var command = new NpgsqlCommand(_initializeSql, conn);
await command.ExecuteNonQueryAsync();
}

private string? _dropIfExistsSql;
public async Task DropIfExists()
{
await _postgresSqlUnderlyingRegister.DropUnderlyingTable();
await _messageStore.DropUnderlyingTable();
await _timeoutStore.DropUnderlyingTable();

await using var conn = await CreateConnection();
_dropIfExistsSql ??= $"DROP TABLE IF EXISTS {_tablePrefix}";
await using var command = new NpgsqlCommand(_dropIfExistsSql, conn);
await command.ExecuteNonQueryAsync();
}


private string? _truncateTableSql;
public async Task TruncateTable()
public async Task TruncateTables()
{
await _messageStore.TruncateTable();
await _timeoutStore.Truncate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public static void AssemblyInit(TestContext testContext)
private static async Task<SqlServerFunctionStore> CreateAndInitializeStore(string testClass, string testMethod)
{
var store = new SqlServerFunctionStore(ConnectionString);//, tablePrefix: ComputeSha256Hash(testClass + "§" + testMethod));
await store.DropIfExists();
await store.Initialize();
await store.TruncateTables();
return store;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,8 @@ CREATE INDEX {_tablePrefix}_idx_Succeeded
} catch (SqlException exception) when (exception.Number == 2714) {}
}

private string? _dropIfExistsSql;
public async Task DropIfExists()
{
await _underlyingRegister.DropUnderlyingTable();
await _messageStore.DropUnderlyingTable();
await _timeoutStore.DropUnderlyingTable();

await using var conn = await _connFunc();
_dropIfExistsSql ??= $"DROP TABLE IF EXISTS {_tablePrefix}";
await using var command = new SqlCommand(_dropIfExistsSql, conn);
await command.ExecuteNonQueryAsync();
}

private string? _truncateSql;
public async Task Truncate()
public async Task TruncateTables()
{
await _underlyingRegister.TruncateTable();
await _messageStore.TruncateTable();
Expand Down
2 changes: 1 addition & 1 deletion Stores/StressTests/Engines/PostgreSqlEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public async Task InitializeDatabaseAndInitializeAndTruncateTable()

var store = new PostgreSqlFunctionStore(ConnectionString);
await store.Initialize();
await store.TruncateTable();
await store.TruncateTables();
}

public async Task<int> NumberOfNonCompleted()
Expand Down
2 changes: 1 addition & 1 deletion Stores/StressTests/Engines/SqlServerEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public async Task InitializeDatabaseAndInitializeAndTruncateTable()

var store = new SqlServerFunctionStore(ConnectionString);
await store.Initialize();
await store.Truncate();
await store.TruncateTables();
}

public async Task<int> NumberOfNonCompleted()
Expand Down

0 comments on commit 48bc021

Please sign in to comment.