-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from InCerryGit/ls_deleteOnClose
Add try recover
- Loading branch information
Showing
7 changed files
with
326 additions
and
10 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
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
138 changes: 138 additions & 0 deletions
138
tests/FasterKv.Cache.Core.Tests/KvStore/DeleteFileOnClose/DeleteOnCloseTest.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,138 @@ | ||
using FasterKv.Cache.Core.Abstractions; | ||
using FasterKv.Cache.Core.Configurations; | ||
using FasterKv.Cache.MessagePack; | ||
|
||
namespace FasterKv.Cache.Core.Tests.KvStore.DeleteFileOnClose; | ||
|
||
public class DeleteOnCloseTest | ||
{ | ||
private string GetPath() | ||
{ | ||
var guid = Guid.NewGuid().ToString("N"); | ||
return $"./unit-test/faster-kv-store-delete-on-close-test/{guid}/log"; | ||
} | ||
|
||
[Fact] | ||
public void Should_Not_Delete_On_Close() | ||
{ | ||
var path = GetPath(); | ||
var fasterKv = new FasterKvCache<string>(null!, | ||
new DefaultSystemClock(), | ||
new FasterKvCacheOptions | ||
{ | ||
SerializerName = "MessagePack", | ||
ExpiryKeyScanInterval = TimeSpan.Zero, | ||
IndexCount = 16384, | ||
MemorySizeBit = 10, | ||
PageSizeBit = 10, | ||
ReadCacheMemorySizeBit = 10, | ||
ReadCachePageSizeBit = 10, | ||
PreallocateFile = false, | ||
DeleteFileOnClose = false, | ||
LogPath = path | ||
}, | ||
new IFasterKvCacheSerializer[] | ||
{ | ||
new MessagePackFasterKvCacheSerializer | ||
{ | ||
Name = "MessagePack" | ||
} | ||
}, | ||
null); | ||
|
||
fasterKv.Set("key", "value"); | ||
|
||
Assert.Equal("value", fasterKv.Get("key")); | ||
|
||
fasterKv.Dispose(); | ||
|
||
Assert.True(File.Exists($"{path}.log.0")); | ||
Assert.True(File.Exists($"{path}.obj.log.0")); | ||
|
||
Cleanup(path); | ||
} | ||
|
||
[Fact] | ||
public void Should_Restore_The_Data() | ||
{ | ||
var path = GetPath(); | ||
var fasterKv = new FasterKvCache<string>(null!, | ||
new DefaultSystemClock(), | ||
new FasterKvCacheOptions | ||
{ | ||
SerializerName = "MessagePack", | ||
ExpiryKeyScanInterval = TimeSpan.Zero, | ||
IndexCount = 16384, | ||
MemorySizeBit = 10, | ||
PageSizeBit = 10, | ||
ReadCacheMemorySizeBit = 10, | ||
ReadCachePageSizeBit = 10, | ||
PreallocateFile = false, | ||
DeleteFileOnClose = false, | ||
LogPath = path | ||
}, | ||
new IFasterKvCacheSerializer[] | ||
{ | ||
new MessagePackFasterKvCacheSerializer | ||
{ | ||
Name = "MessagePack" | ||
} | ||
}, | ||
null); | ||
|
||
for (int i = 0; i < 100; i++) | ||
{ | ||
fasterKv.Set($"key{i}", $"value{i}"); | ||
} | ||
|
||
Assert.Equal("value0", fasterKv.Get("key0")); | ||
|
||
fasterKv.Dispose(); | ||
|
||
Assert.True(File.Exists($"{path}.log.0")); | ||
Assert.True(File.Exists($"{path}.obj.log.0")); | ||
|
||
fasterKv = new FasterKvCache<string>(null!, | ||
new DefaultSystemClock(), | ||
new FasterKvCacheOptions | ||
{ | ||
SerializerName = "MessagePack", | ||
ExpiryKeyScanInterval = TimeSpan.Zero, | ||
IndexCount = 16384, | ||
MemorySizeBit = 10, | ||
PageSizeBit = 10, | ||
ReadCacheMemorySizeBit = 10, | ||
ReadCachePageSizeBit = 10, | ||
PreallocateFile = false, | ||
DeleteFileOnClose = false, | ||
TryRecoverLatest = true, | ||
LogPath = path | ||
}, | ||
new IFasterKvCacheSerializer[] | ||
{ | ||
new MessagePackFasterKvCacheSerializer | ||
{ | ||
Name = "MessagePack" | ||
} | ||
}, | ||
null); | ||
|
||
for (int i = 0; i < 100; i++) | ||
{ | ||
Assert.Equal($"value{i}", fasterKv.Get($"key{i}")); | ||
} | ||
|
||
fasterKv.Dispose(); | ||
|
||
Cleanup(path); | ||
} | ||
|
||
private static void Cleanup(string path) | ||
{ | ||
var dir = Path.GetDirectoryName(path); | ||
if (Directory.Exists(dir)) | ||
{ | ||
Directory.Delete(dir, true); | ||
} | ||
} | ||
} |
138 changes: 138 additions & 0 deletions
138
tests/FasterKv.Cache.Core.Tests/KvStore/DeleteFileOnClose/DeleteOnCloseTestObject.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,138 @@ | ||
using FasterKv.Cache.Core.Abstractions; | ||
using FasterKv.Cache.Core.Configurations; | ||
using FasterKv.Cache.MessagePack; | ||
|
||
namespace FasterKv.Cache.Core.Tests.KvStore.DeleteFileOnClose; | ||
|
||
public class DeleteOnCloseTestObject | ||
{ | ||
private string GetPath() | ||
{ | ||
var guid = Guid.NewGuid().ToString("N"); | ||
return $"./unit-test/faster-kv-store-delete-on-close-object-test/{guid}/log"; | ||
} | ||
|
||
[Fact] | ||
public void Should_Not_Delete_On_Close() | ||
{ | ||
var path = GetPath(); | ||
var fasterKv = new FasterKvCache(null!, | ||
new DefaultSystemClock(), | ||
new FasterKvCacheOptions | ||
{ | ||
SerializerName = "MessagePack", | ||
ExpiryKeyScanInterval = TimeSpan.Zero, | ||
IndexCount = 16384, | ||
MemorySizeBit = 10, | ||
PageSizeBit = 10, | ||
ReadCacheMemorySizeBit = 10, | ||
ReadCachePageSizeBit = 10, | ||
PreallocateFile = false, | ||
DeleteFileOnClose = false, | ||
LogPath = path | ||
}, | ||
new IFasterKvCacheSerializer[] | ||
{ | ||
new MessagePackFasterKvCacheSerializer | ||
{ | ||
Name = "MessagePack" | ||
} | ||
}, | ||
null); | ||
|
||
fasterKv.Set("key", "value"); | ||
|
||
Assert.Equal("value", fasterKv.Get<string>("key")); | ||
|
||
fasterKv.Dispose(); | ||
|
||
Assert.True(File.Exists($"{path}.log.0")); | ||
Assert.True(File.Exists($"{path}.obj.log.0")); | ||
|
||
Cleanup(path); | ||
} | ||
|
||
[Fact] | ||
public void Should_Restore_The_Data() | ||
{ | ||
var path = GetPath(); | ||
var fasterKv = new FasterKvCache(null!, | ||
new DefaultSystemClock(), | ||
new FasterKvCacheOptions | ||
{ | ||
SerializerName = "MessagePack", | ||
ExpiryKeyScanInterval = TimeSpan.Zero, | ||
IndexCount = 16384, | ||
MemorySizeBit = 10, | ||
PageSizeBit = 10, | ||
ReadCacheMemorySizeBit = 10, | ||
ReadCachePageSizeBit = 10, | ||
PreallocateFile = false, | ||
DeleteFileOnClose = false, | ||
LogPath = path | ||
}, | ||
new IFasterKvCacheSerializer[] | ||
{ | ||
new MessagePackFasterKvCacheSerializer | ||
{ | ||
Name = "MessagePack" | ||
} | ||
}, | ||
null); | ||
|
||
for (int i = 0; i < 100; i++) | ||
{ | ||
fasterKv.Set($"key{i}", $"value{i}"); | ||
} | ||
|
||
Assert.Equal("value0", fasterKv.Get<string>("key0")); | ||
|
||
fasterKv.Dispose(); | ||
|
||
Assert.True(File.Exists($"{path}.log.0")); | ||
Assert.True(File.Exists($"{path}.obj.log.0")); | ||
|
||
fasterKv = new FasterKvCache(null!, | ||
new DefaultSystemClock(), | ||
new FasterKvCacheOptions | ||
{ | ||
SerializerName = "MessagePack", | ||
ExpiryKeyScanInterval = TimeSpan.Zero, | ||
IndexCount = 16384, | ||
MemorySizeBit = 10, | ||
PageSizeBit = 10, | ||
ReadCacheMemorySizeBit = 10, | ||
ReadCachePageSizeBit = 10, | ||
PreallocateFile = false, | ||
DeleteFileOnClose = false, | ||
TryRecoverLatest = true, | ||
LogPath = path | ||
}, | ||
new IFasterKvCacheSerializer[] | ||
{ | ||
new MessagePackFasterKvCacheSerializer | ||
{ | ||
Name = "MessagePack" | ||
} | ||
}, | ||
null); | ||
|
||
for (int i = 0; i < 100; i++) | ||
{ | ||
Assert.Equal($"value{i}", fasterKv.Get<string>($"key{i}")); | ||
} | ||
|
||
fasterKv.Dispose(); | ||
|
||
Cleanup(path); | ||
} | ||
|
||
private static void Cleanup(string path) | ||
{ | ||
var dir = Path.GetDirectoryName(path); | ||
if (Directory.Exists(dir)) | ||
{ | ||
Directory.Delete(dir, true); | ||
} | ||
} | ||
} |
Oops, something went wrong.