pull/1/head
a.bozhenov 5 years ago
parent a16c574add
commit fca123e13a

@ -34,5 +34,29 @@ namespace ZeroLevel.UnitTests
Assert.True(0 == storage.ReadAndTruncate().ToArray().Length);
}
[Fact]
public void DumpStorageLongTest()
{
// Arrange
var storage = new DumpStorage<TestSerializableDTO>();
long index = 0;
for (int i = 0; i < 1000; i++)
{
// Dump
for (int j = 0; j < 100; j++)
{
storage.Dump(new TestSerializableDTO { Id = i * 1000 + j, Timestamp = DateTime.UtcNow.Ticks, Title = $"#{i * j}" });
}
// Clean
foreach (var entry in storage.ReadAndTruncate())
{
Assert.True(entry.Id == index);
index++;
}
}
Assert.True(0 == storage.ReadAndTruncate().ToArray().Length);
}
}
}

@ -1,4 +1,5 @@
using FASTER.core;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
@ -28,9 +29,16 @@ namespace ZeroLevel.Services.Microservices.Dump
public void Dump(T value)
{
var packet = MessageSerializer.SerializeCompatible(value);
try
{
while (!log.TryEnqueue(packet, out _)) ;
log.Commit();
}
catch (Exception ex)
{
}
}
public async Task DumpAsync(T value)
{
@ -41,7 +49,7 @@ namespace ZeroLevel.Services.Microservices.Dump
public IEnumerable<T> ReadAndTruncate()
{
byte[] result;
using (var iter = log.Scan(log.BeginAddress, log.TailAddress))
using (var iter = log.Scan(log.BeginAddress, long.MaxValue))
{
while (iter.GetNext(out result, out int length))
{

Loading…
Cancel
Save

Powered by TurnKey Linux.