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

Loading…
Cancel
Save

Powered by TurnKey Linux.