Skip to content

Commit b2f5178

Browse files
committed
Remove unused IFunctionStore.SetResult and its tests
`SetResult` was never called from production code; the only callers were the three `StoreTests` cases that exist to test the method itself. Drop the interface method, all four store implementations (InMemory + Postgres + SqlServer + MariaDB), the test wrappers in `CrashableFunctionStore`, and the abstract test methods plus their overrides in each store's test project.
1 parent 880eea2 commit b2f5178

12 files changed

Lines changed: 0 additions & 204 deletions

File tree

Core/Cleipnir.ResilientFunctions.Tests/InMemoryTests/StoreTests.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -269,16 +269,4 @@ public override Task GetResultsReturnsEmptyDictionaryForEmptyInput()
269269
[TestMethod]
270270
public override Task GetResultsReturnsOnlyExistingFunctionResults()
271271
=> GetResultsReturnsOnlyExistingFunctionResults(FunctionStoreFactory.Create());
272-
273-
[TestMethod]
274-
public override Task SetResultSucceedsWhenOwnerMatches()
275-
=> SetResultSucceedsWhenOwnerMatches(FunctionStoreFactory.Create());
276-
277-
[TestMethod]
278-
public override Task SetResultDoesNothingWhenOwnerDoesNotMatch()
279-
=> SetResultDoesNothingWhenOwnerDoesNotMatch(FunctionStoreFactory.Create());
280-
281-
[TestMethod]
282-
public override Task SetResultDoesNothingWhenFunctionDoesNotExist()
283-
=> SetResultDoesNothingWhenFunctionDoesNotExist(FunctionStoreFactory.Create());
284272
}

Core/Cleipnir.ResilientFunctions.Tests/TestTemplates/StoreTests.cs

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -2357,72 +2357,4 @@ await store.SucceedFunction(
23572357
results.ContainsKey(nonExistentFunctionId).ShouldBeFalse();
23582358
}
23592359

2360-
public abstract Task SetResultSucceedsWhenOwnerMatches();
2361-
protected async Task SetResultSucceedsWhenOwnerMatches(Task<IFunctionStore> storeTask)
2362-
{
2363-
var store = await storeTask;
2364-
var functionId = TestStoredId.Create();
2365-
var owner = ReplicaId.NewId();
2366-
var result = "test result".ToJson().ToUtf8Bytes();
2367-
2368-
// Create function with owner
2369-
await store.CreateFunction(
2370-
functionId,
2371-
"humanInstanceId",
2372-
param: Test.SimpleStoredParameter,
2373-
leaseExpiration: DateTime.UtcNow.Ticks,
2374-
postponeUntil: null,
2375-
timestamp: DateTime.UtcNow.Ticks,
2376-
parent: null,
2377-
owner: owner
2378-
).ShouldNotBeNullAsync();
2379-
2380-
// Set result
2381-
await store.SetResult(functionId, result, owner);
2382-
2383-
// Verify result was set
2384-
var results = await store.GetResults([functionId]);
2385-
results[functionId].ShouldBe(result);
2386-
}
2387-
2388-
public abstract Task SetResultDoesNothingWhenOwnerDoesNotMatch();
2389-
protected async Task SetResultDoesNothingWhenOwnerDoesNotMatch(Task<IFunctionStore> storeTask)
2390-
{
2391-
var store = await storeTask;
2392-
var functionId = TestStoredId.Create();
2393-
var owner = ReplicaId.NewId();
2394-
var wrongOwner = ReplicaId.NewId();
2395-
var result = "test result".ToJson().ToUtf8Bytes();
2396-
2397-
// Create function with owner
2398-
await store.CreateFunction(
2399-
functionId,
2400-
"humanInstanceId",
2401-
param: Test.SimpleStoredParameter,
2402-
leaseExpiration: DateTime.UtcNow.Ticks,
2403-
postponeUntil: null,
2404-
timestamp: DateTime.UtcNow.Ticks,
2405-
parent: null,
2406-
owner: owner
2407-
).ShouldNotBeNullAsync();
2408-
2409-
// Try to set result with wrong owner
2410-
await store.SetResult(functionId, result, wrongOwner);
2411-
2412-
// Verify result was not set
2413-
var results = await store.GetResults([functionId]);
2414-
results[functionId].ShouldBeNull();
2415-
}
2416-
2417-
public abstract Task SetResultDoesNothingWhenFunctionDoesNotExist();
2418-
protected async Task SetResultDoesNothingWhenFunctionDoesNotExist(Task<IFunctionStore> storeTask)
2419-
{
2420-
var store = await storeTask;
2421-
var nonExistentFunctionId = TestStoredId.Create();
2422-
var owner = ReplicaId.NewId();
2423-
var result = "test result".ToJson().ToUtf8Bytes();
2424-
2425-
// Try to set result for non-existent function (should not throw)
2426-
await store.SetResult(nonExistentFunctionId, result, owner);
2427-
}
24282360
}

Core/Cleipnir.ResilientFunctions.Tests/TestTemplates/WatchDogsTests/CrashableFunctionStore.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,6 @@ public Task<bool> DeleteFunction(StoredId storedId)
215215
? Task.FromException<IReadOnlyDictionary<StoredId, byte[]?>>(new TimeoutException())
216216
: _inner.GetResults(storedIds);
217217

218-
public Task SetResult(StoredId storedId, byte[] result, ReplicaId expectedReplica)
219-
=> _crashed
220-
? Task.FromException(new TimeoutException())
221-
: _inner.SetResult(storedId, result, expectedReplica);
222-
223218
public IFunctionStore WithPrefix(string prefix) => _inner.WithPrefix(prefix);
224219
}
225220

Core/Cleipnir.ResilientFunctions/Storage/IFunctionStore.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,4 @@ Task<bool> SuspendFunction(
110110

111111
IFunctionStore WithPrefix(string prefix);
112112
Task<IReadOnlyDictionary<StoredId, byte[]?>> GetResults(IEnumerable<StoredId> storedIds);
113-
Task SetResult(StoredId storedId, byte[] result, ReplicaId expectedReplica);
114113
}

Core/Cleipnir.ResilientFunctions/Storage/InMemoryFunctionStore.cs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -563,22 +563,6 @@ public virtual Task<bool> DeleteFunction(StoredId storedId)
563563
}
564564
}
565565

566-
public Task SetResult(StoredId storedId, byte[] result, ReplicaId expectedReplica)
567-
{
568-
lock (_sync)
569-
{
570-
if (!_states.ContainsKey(storedId))
571-
return Task.CompletedTask;
572-
573-
var state = _states[storedId];
574-
if (state.Owner != expectedReplica)
575-
return Task.CompletedTask;
576-
577-
state.Result = result;
578-
return Task.CompletedTask;
579-
}
580-
}
581-
582566
private class InnerState
583567
{
584568
public StoredId StoredId { get; init; } = null!;

Samples/Sample.ConsoleApp/Utils/CrashableFunctionStore.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,6 @@ public Task<bool> DeleteFunction(StoredId storedId)
196196
? Task.FromException<IReadOnlyDictionary<StoredId, byte[]?>>(new TimeoutException())
197197
: _inner.GetResults(storedIds);
198198

199-
public Task SetResult(StoredId storedId, byte[] result, ReplicaId expectedReplica)
200-
=> _crashed
201-
? Task.FromException(new TimeoutException())
202-
: _inner.SetResult(storedId, result, expectedReplica);
203-
204199
public IFunctionStore WithPrefix(string prefix)
205200
=> _inner.WithPrefix(prefix);
206201
}

Stores/MariaDB/Cleipnir.ResilientFunctions.MariaDB.Tests/StoreTests.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -258,16 +258,4 @@ public override Task GetResultsReturnsEmptyDictionaryForEmptyInput()
258258
[TestMethod]
259259
public override Task GetResultsReturnsOnlyExistingFunctionResults()
260260
=> GetResultsReturnsOnlyExistingFunctionResults(FunctionStoreFactory.Create());
261-
262-
[TestMethod]
263-
public override Task SetResultSucceedsWhenOwnerMatches()
264-
=> SetResultSucceedsWhenOwnerMatches(FunctionStoreFactory.Create());
265-
266-
[TestMethod]
267-
public override Task SetResultDoesNothingWhenOwnerDoesNotMatch()
268-
=> SetResultDoesNothingWhenOwnerDoesNotMatch(FunctionStoreFactory.Create());
269-
270-
[TestMethod]
271-
public override Task SetResultDoesNothingWhenFunctionDoesNotExist()
272-
=> SetResultDoesNothingWhenFunctionDoesNotExist(FunctionStoreFactory.Create());
273261
}

Stores/MariaDB/Cleipnir.ResilientFunctions.MariaDB/MariaDbFunctionStore.cs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -913,28 +913,6 @@ public IFunctionStore WithPrefix(string prefix)
913913
return results;
914914
}
915915

916-
private string? _setResultSql;
917-
public async Task SetResult(StoredId storedId, byte[] result, ReplicaId expectedReplica)
918-
{
919-
await using var conn = await CreateOpenConnection(_connectionString);
920-
_setResultSql ??= $@"
921-
UPDATE {_tablePrefix}
922-
SET result_json = ?
923-
WHERE id = ? AND owner = ?";
924-
925-
await using var command = new MySqlCommand(_setResultSql, conn)
926-
{
927-
Parameters =
928-
{
929-
new() { Value = result },
930-
new() { Value = storedId.AsGuid.ToString("N") },
931-
new() { Value = expectedReplica.AsGuid.ToString("N") }
932-
}
933-
};
934-
935-
await command.ExecuteNonQueryAsync();
936-
}
937-
938916
private string? _deleteFunctionSql;
939917
private async Task<bool> DeleteStoredFunction(StoredId storedId)
940918
{

Stores/PostgreSQL/Cleipnir.ResilientFunctions.PostgreSQL.Tests/StoreTests.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -261,16 +261,4 @@ public override Task GetResultsReturnsEmptyDictionaryForEmptyInput()
261261
[TestMethod]
262262
public override Task GetResultsReturnsOnlyExistingFunctionResults()
263263
=> GetResultsReturnsOnlyExistingFunctionResults(FunctionStoreFactory.Create());
264-
265-
[TestMethod]
266-
public override Task SetResultSucceedsWhenOwnerMatches()
267-
=> SetResultSucceedsWhenOwnerMatches(FunctionStoreFactory.Create());
268-
269-
[TestMethod]
270-
public override Task SetResultDoesNothingWhenOwnerDoesNotMatch()
271-
=> SetResultDoesNothingWhenOwnerDoesNotMatch(FunctionStoreFactory.Create());
272-
273-
[TestMethod]
274-
public override Task SetResultDoesNothingWhenFunctionDoesNotExist()
275-
=> SetResultDoesNothingWhenFunctionDoesNotExist(FunctionStoreFactory.Create());
276264
}

Stores/PostgreSQL/Cleipnir.ResilientFunctions.PostgreSQL/PostgreSqlFunctionStore.cs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -831,28 +831,6 @@ public IFunctionStore WithPrefix(string prefix)
831831
return results;
832832
}
833833

834-
private string? _setResultSql;
835-
public async Task SetResult(StoredId storedId, byte[] result, ReplicaId expectedReplica)
836-
{
837-
await using var conn = await CreateConnection();
838-
_setResultSql ??= $@"
839-
UPDATE {_tableName}
840-
SET result_json = $1
841-
WHERE id = $2 AND owner = $3";
842-
843-
await using var command = new NpgsqlCommand(_setResultSql, conn)
844-
{
845-
Parameters =
846-
{
847-
new() { Value = result },
848-
new() { Value = storedId.AsGuid },
849-
new() { Value = expectedReplica.AsGuid }
850-
}
851-
};
852-
853-
await command.ExecuteNonQueryAsync();
854-
}
855-
856834
private string? _deleteFunctionSql;
857835
private async Task<bool> DeleteStoredFunction(StoredId storedId)
858836
{

0 commit comments

Comments
 (0)