-
Notifications
You must be signed in to change notification settings - Fork 29
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 #11 from JohnPKosh/jpk-wip
Jpk wip to master
- Loading branch information
Showing
4 changed files
with
187 additions
and
1 deletion.
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,43 @@ | ||
/*<FILE_LICENSE> | ||
* Azos (A to Z Application Operating System) Framework | ||
* The A to Z Foundation (a.k.a. Azist) licenses this file to you under the MIT license. | ||
* See the LICENSE file in the project root for more information. | ||
</FILE_LICENSE>*/ | ||
|
||
using System; | ||
|
||
using Azos.Serialization.Bix; | ||
|
||
namespace Azos.IO.Archiving | ||
{ | ||
/// <summary> | ||
/// Reads archives of String items. The implementation is thread-safe | ||
/// </summary> | ||
public sealed class StringArchiveReader : ArchiveReader<string> | ||
{ | ||
public StringArchiveReader(IVolume volume) : base(volume){ } | ||
|
||
[ThreadStatic] private static BufferSegmentReadingStream ts_Stream; | ||
|
||
public override string Materialize(Entry entry) | ||
{ | ||
if (entry.State != Entry.Status.Valid) return null; | ||
|
||
var stream = ts_Stream; | ||
if (stream == null) | ||
{ | ||
stream = new BufferSegmentReadingStream(); | ||
ts_Stream = stream; | ||
} | ||
|
||
stream.UnsafeBindBuffer(entry.Raw); | ||
var reader = new BixReader(stream); | ||
|
||
string result = reader.ReadString(); | ||
|
||
stream.UnbindBuffer(); | ||
|
||
return result; | ||
} | ||
} | ||
} |
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,70 @@ | ||
/*<FILE_LICENSE> | ||
* Azos (A to Z Application Operating System) Framework | ||
* The A to Z Foundation (a.k.a. Azist) licenses this file to you under the MIT license. | ||
* See the LICENSE file in the project root for more information. | ||
</FILE_LICENSE>*/ | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using System.Linq; | ||
|
||
using Azos.Apps; | ||
using Azos.Scripting; | ||
using Azos.IO.Archiving; | ||
using Azos.Log; | ||
|
||
namespace Azos.Tests.Nub.IO.Archiving | ||
{ | ||
[Runnable] | ||
public class StringTests | ||
{ | ||
|
||
[Run("compress=null count=1")] | ||
[Run("compress=null count=100")] | ||
[Run("compress=null count=1000")] | ||
[Run("compress=null count=16000")] | ||
[Run("compress=null count=64000")] | ||
public void Write_Read_Compare_Strings(string compress, int count) | ||
{ | ||
var expected = FakeLogMessage.BuildRandomStringArr(count); | ||
var ms = new MemoryStream(); | ||
|
||
var meta = VolumeMetadataBuilder.Make("String archive") | ||
.SetVersion(1, 0) | ||
.SetDescription("Testing string messages") | ||
.SetChannel(Atom.Encode("dvop")); | ||
|
||
if (compress.IsNotNullOrWhiteSpace()) | ||
{ | ||
meta.SetCompressionScheme(compress); | ||
} | ||
|
||
var volume = new DefaultVolume(NOPApplication.Instance.SecurityManager.Cryptography, meta, ms); | ||
|
||
using (var appender = new StringArchiveAppender(volume, | ||
NOPApplication.Instance.TimeSource, | ||
NOPApplication.Instance.AppId, "dima@zhaba")) | ||
{ | ||
for (var i = 0; i < count; i++) | ||
{ | ||
appender.Append(expected[i]); | ||
} | ||
} | ||
|
||
var reader = new StringArchiveReader(volume); | ||
|
||
var got = reader.Entries(new Bookmark()).ToArray(); | ||
|
||
Aver.AreEqual(expected.Length, got.Length); | ||
for (int i = 0; i < count; i++) | ||
{ | ||
Aver.AreEqual(expected[i], got[i]); | ||
} | ||
|
||
volume.Dispose(); | ||
} | ||
} | ||
} |
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