public ChaosDestination(IActorRef probe)
            {
                Probe               = probe;
                State               = new List <int>();
                _config             = Context.System.Settings.Config.GetConfig("akka.persistence.destination.chaos");
                _confirmFailureRate = _config.GetDouble("confirm-failure-rate");

                Receive <Msg>(m =>
                {
                    if (ChaosSupportExtensions.ShouldFail(_confirmFailureRate))
                    {
                        Log.Error(string.Format("[destination] confirm message failed (message = {0}, {1})", m.DeliveryId, m.I));
                    }
                    else if (State.Contains(m.I))
                    {
                        Log.Debug(string.Format("[destination] ignored duplicate (message = {0}, {1})", m.DeliveryId, m.I));
                        Sender.Tell(new Confirm(m.DeliveryId, m.I));
                    }
                    else
                    {
                        this.Add(m.I);
                        Sender.Tell(new Confirm(m.DeliveryId, m.I));
                        Log.Debug(string.Format("[destination] received and confirmed (message = {0}, {1})", m.DeliveryId, m.I));
                    }
                });
            }
예제 #2
0
 protected override bool ReceiveCommand(object message)
 {
     return(message.Match()
            .With <int>(i =>
     {
         if (State.Contains(i))
         {
             Log.Debug(DebugMessage("ignored duplicate"));
             Sender.Tell(new Ack(i));
         }
         else
         {
             Persist(new MsgSent(i), sent =>
             {
                 UpdateState(sent);
                 if (ChaosSupportExtensions.ShouldFail(_liveProcessingFailureRate))
                 {
                     throw new TestException(DebugMessage(string.Format("failed at payload {0}", sent.I)));
                 }
                 Log.Debug(DebugMessage(String.Format("processed payload {0}", sent.I)));
             });
         }
     })
            .With <Confirm>(confirm =>
     {
         Persist(new MsgConfirmed(confirm.DeliveryId, confirm.I), x => UpdateState(x));
     })
            .WasHandled);
 }
예제 #3
0
 protected override bool ReceiveRecover(object message)
 {
     return(message.Match()
            .With <IEvt>(evt =>
     {
         UpdateState(evt);
         if (ChaosSupportExtensions.ShouldFail(_replayProcessingFailureRate))
         {
             throw new TestException(DebugMessage(string.Format("replay failed at event {0}", evt)));
         }
         Log.Debug(DebugMessage(string.Format("replayed event {0}", evt)));
     }).WasHandled);
 }
 protected override bool ReceiveCommand(object message)
 {
     return(message.Match()
            .With <int>(i =>
     {
         var failureRate = IsRecovering ? _replayProcessingFailureRate : _liveProcessingFailureRate;
         if (State.Contains(i))
         {
             Log.Debug(DebugMessage("ignored duplicate"));
         }
         else
         {
             Persist(new MsgSent(i), sent =>
             {
                 UpdateState(sent);
                 if (ChaosSupportExtensions.ShouldFail(failureRate))
                 {
                     throw new TestException(DebugMessage("failed at payload " + sent.I));
                 }
                 else
                 {
                     Log.Debug(DebugMessage("processed payload " + sent.I));
                 }
             });
         }
     })
            .With <Confirm>(confirm =>
     {
         Persist(new MsgConfirmed(confirm.DeliveryId, confirm.I), x => UpdateState(x));
     })
            .With <PersistenceFailure>(failure =>
     {
         failure.Payload.Match()
         .With <MsgSent>(sent =>
         {
             // inform sender about journaling failure so that it can resend
             Sender.Tell(new JournalingFailure(sent.I));
         })
         .With <MsgConfirmed>(() =>
         {
             // ok, will be redelivered
         });
     })
            .WasHandled);
 }