private void CheckSerialization(object obj) { var blob = serializer.ToBinary(obj); var reference = serializer.FromBinary(blob, serializer.Manifest(obj)); reference.Should().Be(obj); }
private void Active() { Receive <Store>(store => { try { if (_writeBehindInterval == TimeSpan.Zero) { using (var env = GetLightningEnvironment()) using (var tx = env.BeginTransaction()) using (var db = tx.OpenDatabase(DatabaseName)) { try { var byteKey = Encoding.UTF8.GetBytes(store.Key); var byteValue = _serializer.ToBinary(store.Data); tx.Put(db, byteKey, byteValue); tx.Commit(); } catch (Exception) { tx.Abort(); throw; } } } else { if (_pending.Count > 0) { Context.System.Scheduler.ScheduleTellOnce(_writeBehindInterval, Self, WriteBehind.Instance, ActorRefs.NoSender); } _pending[store.Key] = store.Data; } store.Reply?.ReplyTo.Tell(store.Reply.SuccessMessage); } catch (Exception cause) { _log.Error(cause, "Failed to store [{0}]:{1}", store.Key, cause); store.Reply?.ReplyTo.Tell(store.Reply.FailureMessage); throw; } }); Receive <WriteBehind>(_ => DoWriteBehind()); }