-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
127 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using RocksDbSharp; | ||
|
||
namespace RocksDb.Extensions; | ||
|
||
internal class ColumnFamily | ||
{ | ||
public ColumnFamilyHandle Handle { get; set; } | ||
public string Name { get; } | ||
|
||
public ColumnFamily(ColumnFamilyHandle handle, string name) | ||
{ | ||
Handle = handle; | ||
Name = name; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using NUnit.Framework; | ||
using RocksDb.Extensions.Tests.Utils; | ||
using Shouldly; | ||
|
||
namespace RocksDb.Extensions.Tests; | ||
|
||
public class ClearStoreTests | ||
{ | ||
[Test] | ||
public void should_reset_store_range_data_to_store() | ||
{ | ||
// Setup RocksDbStore | ||
using var testFixture = CreateTestFixture<int, string>(); | ||
|
||
// Put some data | ||
var store = testFixture.GetStore<RocksDbGenericStore<int, string>>(); | ||
var cacheKeys = Enumerable.Range(0, 100) | ||
.Select(x => (key: x, value: x.ToString())) | ||
.ToList(); | ||
|
||
store.PutRange(cacheKeys); | ||
|
||
// Verify that data was added | ||
foreach (var (key, expectedValue) in cacheKeys) | ||
{ | ||
store.HasKey(key).ShouldBeTrue(); | ||
store.TryGet(key, out var value).ShouldBeTrue(); | ||
value.ShouldBe(expectedValue); | ||
} | ||
|
||
// Clear the store | ||
store.Clear(); | ||
|
||
// Verify that data is no longer there | ||
foreach (var (key, expectedValue) in cacheKeys) | ||
{ | ||
store.HasKey(key).ShouldBeFalse(); | ||
store.TryGet(key, out _).ShouldBeFalse(); | ||
} | ||
|
||
// Try to put the data again | ||
store.PutRange(cacheKeys); | ||
|
||
// Verify that data is available again | ||
foreach (var (key, expectedValue) in cacheKeys) | ||
{ | ||
store.HasKey(key).ShouldBeTrue(); | ||
store.TryGet(key, out var value).ShouldBeTrue(); | ||
value.ShouldBe(expectedValue); | ||
} | ||
} | ||
|
||
private static TestFixture CreateTestFixture<TKey, TValue>() | ||
{ | ||
var testFixture = TestFixture.Create(rockDb => | ||
{ | ||
_ = rockDb.AddStore<TKey, TValue, RocksDbGenericStore<TKey, TValue>>("my-store"); | ||
}); | ||
return testFixture; | ||
} | ||
} |