Skip to content

Commit

Permalink
Merge pull request #11 from JohnPKosh/jpk-wip
Browse files Browse the repository at this point in the history
Jpk wip to master
  • Loading branch information
JohnPKosh committed Feb 2, 2021
2 parents 9655d59 + d1036f9 commit 558be62
Show file tree
Hide file tree
Showing 4 changed files with 187 additions and 1 deletion.
43 changes: 43 additions & 0 deletions src/Azos/IO/Archiving/accessors/StringArchiveReader.cs
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;
}
}
}
59 changes: 59 additions & 0 deletions src/testing/Azos.Tests.Nub/IO/Archiving/LogMsgTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,64 @@ public void WriteRead_1()

volume.Dispose();
}


[Run("compress=null count=2")]
[Run("compress=null count=100")]
[Run("compress=null count=1000")]
[Run("compress=null count=16000")]
[Run("compress=null count=128000")]
public void Write_Read_Compare(string compress, int count)
{
var expected = FakeLogMessage.BuildRandomArr(count);
var ms = new MemoryStream();

var meta = VolumeMetadataBuilder.Make("Log archive")
.SetVersion(1, 0)
.SetDescription("Testing log 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 LogMessageArchiveAppender(volume,
NOPApplication.Instance.TimeSource,
NOPApplication.Instance.AppId, "dima@zhaba"))
{
for (var i = 0; i < count; i++)
{
appender.Append(expected[i]);
}
}

var reader = new LogMessageArchiveReader(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].App, got[i].App);
Aver.AreEqual(expected[i].ArchiveDimensions, got[i].ArchiveDimensions);
Aver.AreEqual(expected[i].Channel, got[i].Channel);
Aver.AreEqual(expected[i].Exception?.Message, got[i].Exception?.Message);
Aver.AreEqual(expected[i].From, got[i].From);
Aver.AreEqual(expected[i].Gdid, got[i].Gdid);
Aver.AreEqual(expected[i].Guid.ToString(), got[i].Guid.ToString());
Aver.AreEqual(expected[i].Host, got[i].Host);
Aver.AreEqual(expected[i].Parameters, got[i].Parameters);
Aver.AreEqual(expected[i].RelatedTo.ToString(), got[i].RelatedTo.ToString());
Aver.AreEqual(expected[i].Text, got[i].Text);
Aver.AreEqual(expected[i].Topic, got[i].Topic);
Aver.AreEqual((int)expected[i].Type, (int)got[i].Type);
Aver.AreEqual(expected[i].UTCTimeStamp, got[i].UTCTimeStamp);
}

volume.Dispose();
}
}
}
70 changes: 70 additions & 0 deletions src/testing/Azos.Tests.Nub/IO/Archiving/StringTests.cs
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();
}
}
}
16 changes: 15 additions & 1 deletion src/testing/Azos.Tests.Nub/IO/Archiving/fakes/FakeLogMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</FILE_LICENSE>*/

using System;

using System.Linq;
using Azos.Log;

namespace Azos.Tests.Nub.IO.Archiving
Expand Down Expand Up @@ -39,6 +39,20 @@ public static Message BuildRandom()
return message;
}

public static Message[] BuildRandomArr(int count)
{
var rv = new Message[count];
for (int i = 0; i < count; i++)
{
rv[i] = BuildRandom();
}
return rv;
}

public static string[] BuildRandomStringArr(int count)
=> BuildRandomArr(count).Select(x => x.ToJsonDataMap().ToString()).ToArray();



public static readonly BuilderBase[] BUILDERS =
{
Expand Down

0 comments on commit 558be62

Please sign in to comment.