Skip to content

Commit

Permalink
Failing event deserialization test - for real Apache Kafka data (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
zbartos authored and Bobris committed Jul 4, 2017
1 parent 409210b commit 531e433
Show file tree
Hide file tree
Showing 5 changed files with 199 additions and 0 deletions.
1 change: 1 addition & 0 deletions BTDBTest/BTDBTest.csproj
Expand Up @@ -159,6 +159,7 @@
<Compile Include="AbstractBufferedReaderWriterTest.cs" />
<Compile Include="AssertionException.cs" />
<Compile Include="ChunkStorageTest.cs" />
<Compile Include="EventStore2TestClasses.cs" />
<Compile Include="DiskChunkCacheTest.cs" />
<Compile Include="DtoChannelTest.cs" />
<Compile Include="EventStore2Test.cs" />
Expand Down
61 changes: 61 additions & 0 deletions BTDBTest/EventStore2Test.cs
@@ -1,5 +1,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using BTDB.Buffer;
using BTDB.EventStore2Layer;
using Xunit;
using static BTDBTest.EventStoreTest;
Expand All @@ -11,6 +14,10 @@ namespace BTDBTest
{
public class EventStore2Test
{
const string GivenEventsMetadataFilePath = "..\\..\\TestData\\meta.txt";
const string GivenEventsDataFilePath = "..\\..\\TestData\\events.txt";
const char DataFileSeparator = ' ';

[Fact]
public void SerializingNewObjectsWritesNewMetadata()
{
Expand Down Expand Up @@ -82,6 +89,60 @@ public void DeserializeSimpleClass()
Assert.Equal(obj, obj2);
}

[Fact]
public void DeserializeGivenEventDataWithGivenMetadata()
{
var deserializer = new EventDeserializer();
ProcessWholeMetadataLog(deserializer, GivenEventsMetadataFilePath, DataFileSeparator);

var eventsData = GetEventsData(GivenEventsDataFilePath, DataFileSeparator);

foreach (var eventData in eventsData)
{
object obj;
Assert.True(deserializer.Deserialize(out obj, eventData));

Assert.NotNull(obj);
}
}

List<ByteBuffer> GetEventsData(string testEventFilePath, char separator)
{
var testEventDataReader = File.OpenText(testEventFilePath);
var buffers = new List<ByteBuffer>();

var line = testEventDataReader.ReadLine();
while (!string.IsNullOrEmpty(line))
{
buffers.Add(ByteBuffer.NewSync(GetItemBytes(line, separator)));
line = testEventDataReader.ReadLine();
}

return buffers;
}

void ProcessWholeMetadataLog(EventDeserializer deserializer, string testMetadataFilePath, char metadataFileSeparator)
{
var testMetadataStreamReader = File.OpenText(testMetadataFilePath);

var line = testMetadataStreamReader.ReadLine();
while (!string.IsNullOrEmpty(line))
{
deserializer.ProcessMetadataLog(ByteBuffer.NewSync(GetItemBytes(line, metadataFileSeparator)));

line = testMetadataStreamReader.ReadLine();
}
}

byte[] GetItemBytes(string metaDataLine, char metadataFileSeparator)
{
return metaDataLine
.Split(metadataFileSeparator)
.Where(s => !string.IsNullOrEmpty(s))
.Select(byte.Parse)
.ToArray();
}

public enum StateEnum
{
Dead = 0,
Expand Down
49 changes: 49 additions & 0 deletions BTDBTest/EventStore2TestClasses.cs
@@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using Gmc.Cloud.Diagnostic.Db;
using Gmc.Cloud.Infrastructure.Core;

namespace Gmc.Cloud.Infrastructure.Core
{
public interface IEvent
{
ulong Id { get; set; }
ulong ParentEventId { get; set; }
ulong UserId { get; set; }
DateTime Time { get; set; }
Guid UniqueGuid { get; set; }
ulong ImpersonatorUserId { get; set; }
ulong ImpersonatorCompanyId { get; set; }
}


public class Event : IEvent
{
public ulong Id { get; set; }
public ulong ParentEventId { get; set; }
public ulong UserId { get; set; }
public DateTime Time { get; set; }
public Guid UniqueGuid { get; set; }
public ulong ImpersonatorUserId { get; set; }
public ulong ImpersonatorCompanyId { get; set; }
}
}

namespace Gmc.Cloud.Diagnostic.Events
{
public class DiscInfoAdded : Event
{
public IList<DbDriveInfo> Infos { get; set; }
public string InstanceId { get; set; }
}
}

namespace Gmc.Cloud.Diagnostic.Db
{
public class DbDriveInfo
{
public string Name { get; set; }
public long TotalSize { get; set; }
public long AvailableFreeSpace { get; set; }
}
}
2 changes: 2 additions & 0 deletions BTDBTest/TestData/events.txt
@@ -0,0 +1,2 @@
61 4 63 4 67 58 92 252 93 3 191 240 0 252 15 74 181 144 0 63 4 68 58 92 252 232 224 191 240 0 252 106 202 205 112 0 63 4 70 58 92 252 116 112 152 2 0 252 22 158 103 182 0 8 51 110 111 100 101 45 50 0 0 0 72 212 188 160 60 112 69 131 208 245 46 41 0 24 174 79 144 38 246 105 242 219 54 121 0 0
61 62 132 72 212 188 160 92 236 11 130 132 1 128 233 132 1 72 212 188 160 92 236 11 130 0 8 100 101 102 97 117 108 116 0 0 0 0 72 212 188 160 93 12 139 179 82 126 140 85 20 165 237 67 163 201 122 77 14 194 160 185 0 0

0 comments on commit 531e433

Please sign in to comment.