-
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.
Add DeleteExistingDatabaseOnStartup option
- Loading branch information
Showing
13 changed files
with
138 additions
and
5 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
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
88 changes: 88 additions & 0 deletions
88
test/RocksDb.Extensions.Tests/DeleteExistingDatabaseOnStartupTests.cs
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,88 @@ | ||
using NScenario; | ||
using NUnit.Framework; | ||
using RocksDb.Extensions.Tests.Utils; | ||
using Shouldly; | ||
|
||
namespace RocksDb.Extensions.Tests; | ||
|
||
public class DeleteExistingDatabaseOnStartupTests | ||
{ | ||
[Test] | ||
public async Task should_delete_database_on_start_up() | ||
{ | ||
var scenario = TestScenarioFactory.Default(); | ||
var path = Path.Join(".", Guid.NewGuid().ToString("N")); | ||
|
||
await scenario.Step("Create a new RockDb database and initialize it with some values", () => | ||
{ | ||
using var testFixture = TestFixture.Create(rockDb => | ||
{ | ||
_ = rockDb.AddStore<int, int, RocksDbGenericStore<int, int>>("my-store"); | ||
}, options => | ||
{ | ||
options.Path = path; | ||
}); | ||
var store = testFixture.GetStore<RocksDbGenericStore<int, int>>(); | ||
store.Put(1, 1); | ||
}); | ||
|
||
await scenario.Step("Re-create the database using the same path", async () => | ||
{ | ||
using var testFixture = TestFixture.Create(rockDb => | ||
{ | ||
_ = rockDb.AddStore<int, int, RocksDbGenericStore<int, int>>("my-store"); | ||
}, options => | ||
{ | ||
options.Path = path; | ||
options.DeleteExistingDatabaseOnStartup = true; | ||
}); | ||
await scenario.Step("Verify that the value is not available after the restart", () => | ||
{ | ||
var store = testFixture.GetStore<RocksDbGenericStore<int, int>>(); | ||
store.TryGet(1, out _).ShouldBeFalse(); | ||
}); | ||
}); | ||
} | ||
|
||
[Test] | ||
public async Task should_not_delete_database_on_start_up() | ||
{ | ||
var scenario = TestScenarioFactory.Default(); | ||
var path = Path.Join(".", Guid.NewGuid().ToString("N")); | ||
|
||
await scenario.Step("Create a new RockDb database and initialize it with some values", () => | ||
{ | ||
using var testFixture = TestFixture.Create(rockDb => | ||
{ | ||
_ = rockDb.AddStore<int, int, RocksDbGenericStore<int, int>>("my-store"); | ||
}, options => | ||
{ | ||
options.Path = path; | ||
}); | ||
var store = testFixture.GetStore<RocksDbGenericStore<int, int>>(); | ||
store.Put(1, 1); | ||
}); | ||
|
||
await scenario.Step("Re-create the database using the same path", async () => | ||
{ | ||
using var testFixture = TestFixture.Create(rockDb => | ||
{ | ||
_ = rockDb.AddStore<int, int, RocksDbGenericStore<int, int>>("my-store"); | ||
}, options => | ||
{ | ||
options.Path = path; | ||
options.DeleteExistingDatabaseOnStartup = false; | ||
}); | ||
await scenario.Step("Verify that the value is not available after the restart", () => | ||
{ | ||
var store = testFixture.GetStore<RocksDbGenericStore<int, int>>(); | ||
store.TryGet(1, out var value).ShouldBeTrue(); | ||
value.ShouldBe(1); | ||
}); | ||
}); | ||
} | ||
} |
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
1 change: 1 addition & 0 deletions
1
test/RocksDb.Extensions.Tests/RocksDbStoreWithJsonSerializerTests.cs
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
1 change: 1 addition & 0 deletions
1
test/RocksDb.Extensions.Tests/RocksDbStoreWithPrimitiveSerializerTests.cs
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
1 change: 1 addition & 0 deletions
1
test/RocksDb.Extensions.Tests/RocksDbStoreWithProtoBufNetSerializerTests.cs
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
1 change: 1 addition & 0 deletions
1
test/RocksDb.Extensions.Tests/RocksDbStoreWithProtobufSerializerTests.cs
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
2 changes: 1 addition & 1 deletion
2
...b.Extensions.Tests/RocksDbGenericStore.cs → ...nsions.Tests/Utils/RocksDbGenericStore.cs
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
2 changes: 1 addition & 1 deletion
2
test/RocksDb.Extensions.Tests/TestFixture.cs → ...sDb.Extensions.Tests/Utils/TestFixture.cs
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
2 changes: 1 addition & 1 deletion
2
test/RocksDb.Extensions.Tests/TestUtils.cs → ...cksDb.Extensions.Tests/Utils/TestUtils.cs
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
2 changes: 1 addition & 1 deletion
2
...cksDb.Extensions.Tests/WellKnownValues.cs → ...Extensions.Tests/Utils/WellKnownValues.cs
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