public async Task ActorSuccessfullyClearsStateAfterErrorWithoutRemoting()
        {
            using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(60));
            var pingProxy = this.ProxyFactory.CreateActorProxy <IRegression762Actor>(ActorId.CreateRandom(), "Regression762Actor");
            var proxy     = this.ProxyFactory.Create(ActorId.CreateRandom(), "Regression762Actor");

            await WaitForActorRuntimeAsync(pingProxy, cts.Token);

            var key          = Guid.NewGuid().ToString();
            var throwingCall = new StateCall
            {
                Key       = key,
                Value     = "Throw value",
                Operation = "ThrowException"
            };

            var setCall = new StateCall()
            {
                Key       = key,
                Value     = "Real value",
                Operation = "SetState"
            };

            var savingCall = new StateCall()
            {
                Operation = "SaveState"
            };

            // We attempt to delete it on the unlikely chance it's already there.
            await proxy.InvokeMethodAsync("RemoveState", throwingCall.Key);

            // Initiate a call that will set the state, then throw.
            await Assert.ThrowsAsync <DaprApiException>(async() => await proxy.InvokeMethodAsync("SaveState", throwingCall));

            // Save the state and assert that the old value was not persisted.
            await proxy.InvokeMethodAsync("SaveState", savingCall);

            var errorResp = await proxy.InvokeMethodAsync <string, string>("GetState", key);

            Assert.Equal(string.Empty, errorResp);

            // Persist normally and ensure it works.
            await proxy.InvokeMethodAsync("SaveState", setCall);

            var resp = await proxy.InvokeMethodAsync <string, string>("GetState", key);

            Assert.Equal("Real value", resp);
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StateMachine{T}"/> class.
        /// </summary>
        /// <param name="deviceLogger">The logger MGR.</param>
        public StateMachine(IDeviceLogger deviceLogger)
        {
            if (deviceLogger == null)
            {
                throw new ArgumentNullException("deviceLogger", "Device Logger cannot be null");
            }

            this.logger              = deviceLogger.CreateComponentLogger(className);
            this.state               = GuiState.DISCONNECTED;
            this.internalStateEnum   = default(T);
            this.stateMessage        = "Not Connected";
            this.currentState        = this.StateNone;
            this.eventExecLock       = new object();
            this.statusUpdateLockObj = new object();
            this.isDisposed          = false;
        }
Esempio n. 3
0
        public async Task SaveState(StateCall call)
        {
            if (call.Operation == "ThrowException")
            {
                await this.StateManager.SetStateAsync <string>(call.Key, call.Value);

                throw new NotImplementedException();
            }
            else if (call.Operation == "SetState")
            {
                await this.StateManager.SetStateAsync <string>(call.Key, call.Value);
            }
            else if (call.Operation == "SaveState")
            {
                await this.StateManager.SaveStateAsync();
            }
        }
        public IController Start(string command)
        {
            switch (command)
            {
            case "login":
                State = LoginGotUsername;
                return(_controller.Login());

            case "register":
                State = RegisterGotUsername;
                return(_controller.Register());

            default:
                State = null;
                return(null);
            }
        }
 public IController RegisterGotPasswordConfirmed(string command)
 {
     State = RegisterGotEmail;
     return(_controller.RegisterGotPasswordConfirmed(command));
 }
 public IController RegisterGotUsername(string command)
 {
     State = RegisterGotPassword;
     return(_controller.RegisterGotUsername(command));
 }
 public IController LoginGotUsername(string command)
 {
     State = LoginGotPassword;
     return(_controller.LoginGotUsername(command));
 }