public ClientFSM(RoleName name, IPEndPoint controllerAddr) { _settings = TestConductor.Get(Context.System).Settings; _handler = new PlayerHandler(controllerAddr, _settings.ClientReconnects, _settings.ReconnectBackoff, _settings.ClientSocketWorkerPoolSize, Self, Logging.GetLogger(Context.System, "PlayerHandler"), Context.System.Scheduler); _name = name; InitFSM(); }
public void MultiNodeSpecAfterAll() { // wait for all nodes to remove themselves before we shut the conductor down if (SelfIndex == 0) { TestConductor.RemoveNode(_myself); Within(TestConductor.Settings.BarrierTimeout, () => AwaitCondition(() => TestConductor.GetNodes().Result.All(n => n.Equals(_myself)))); } Shutdown(Sys); AfterTermination(); }
public void MultiNodeSpecAfterAll() { // wait for all nodes to remove themselves before we shut the conductor down if (SelfIndex == 0) { TestConductor.RemoveNode(_myself); //TODO: Async stuff here AwaitCondition(() => TestConductor.GetNodes().Result.Any(n => !n.Equals(_myself)) , TestConductor.Settings.BarrierTimeout); } Shutdown(Sys); AfterTermination(); }
protected void AttachConductor(TestConductor tc) { var timeout = tc.Settings.BarrierTimeout; try { //TODO: Async stuff if (SelfIndex == 0) { tc.StartController(InitialParticipants, _myself, _controllerAddr).Wait(timeout); } else { tc.StartClient(_myself, _controllerAddr).Wait(timeout); } } catch (Exception e) { throw new Exception("failure while attaching new conductor", e); } TestConductor = tc; }
public void InitFSM() { StartWith(State.Connecting, new Data(null, null)); When(State.Connecting, @event => { if (@event.FsmEvent is IClientOp) { return(Stay().Replying(new Status.Failure(new IllegalStateException("not connected yet")))); } var connected = @event.FsmEvent as Connected; if (connected != null) { connected.Channel.Write(new Hello(_name.Name, TestConductor.Get(Context.System).Address)); return(GoTo(State.AwaitDone).Using(new Data(connected.Channel, null))); } if (@event.FsmEvent is ConnectionFailure) { return(GoTo(State.Failed)); } if (@event.FsmEvent is StateTimeout) { Log.Error("connect timeout to TestConductor"); return(GoTo(State.Failed)); } return(null); }, _settings.ConnectTimeout); When(State.AwaitDone, @event => { if (@event.FsmEvent is Done) { Log.Debug("received Done: starting test"); return(GoTo(State.Connected)); } if (@event.FsmEvent is INetworkOp) { Log.Error("Received {0} instead of Done", @event.FsmEvent); return(GoTo(State.Failed)); } if (@event.FsmEvent is IServerOp) { return(Stay().Replying(new Failure(new IllegalStateException("not connected yet")))); } if (@event.FsmEvent is StateTimeout) { Log.Error("connect timeout to TestConductor"); return(GoTo(State.Failed)); } return(null); }, _settings.BarrierTimeout); When(State.Connected, @event => { if (@event.FsmEvent is Disconnected) { Log.Info("disconnected from TestConductor"); throw new ConnectionFailure("disconnect"); } if (@event.FsmEvent is ToServer <Done> && @event.StateData.Channel != null && @event.StateData.RunningOp == null) { @event.StateData.Channel.Write(Done.Instance); return(Stay()); } var toServer = @event.FsmEvent as IToServer; if (toServer != null && @event.StateData.Channel != null && @event.StateData.RunningOp == null) { @event.StateData.Channel.Write(toServer.Msg); string token = null; var enterBarrier = @event.FsmEvent as ToServer <EnterBarrier>; if (enterBarrier != null) { token = enterBarrier.Msg.Name; } else { var getAddress = @event.FsmEvent as ToServer <GetAddress>; if (getAddress != null) { token = getAddress.Msg.Node.Name; } } return(Stay().Using(@event.StateData.Copy(runningOp: Tuple.Create(token, Sender)))); } if (toServer != null && @event.StateData.Channel != null && @event.StateData.RunningOp != null) { Log.Error("cannot write {0} while waiting for {1}", toServer.Msg, @event.StateData.RunningOp); return(Stay()); } if (@event.FsmEvent is IClientOp && @event.StateData.Channel != null) { var barrierResult = @event.FsmEvent as BarrierResult; if (barrierResult != null) { if (@event.StateData.RunningOp == null) { Log.Warning("did not expect {1}", @event.FsmEvent); } else { object response; if (barrierResult.Name != @event.StateData.RunningOp.Item1) { response = new Failure( new Exception("wrong barrier " + barrierResult + " received while waiting for " + @event.StateData.RunningOp.Item1)); } else if (!barrierResult.Success) { response = new Failure( new Exception("barrier failed:" + @event.StateData.RunningOp.Item1)); } else { response = barrierResult.Name; } @event.StateData.RunningOp.Item2.Tell(response); } return(Stay().Using(@event.StateData.Copy(runningOp: null))); } var addressReply = @event.FsmEvent as AddressReply; if (addressReply != null) { if (@event.StateData.RunningOp == null) { Log.Warning("did not expect {0}", @event.FsmEvent); } else { @event.StateData.RunningOp.Item2.Tell(addressReply.Addr); } return(Stay().Using(@event.StateData.Copy(runningOp: null))); } var throttleMsg = @event.FsmEvent as ThrottleMsg; if (@event.FsmEvent is ThrottleMsg) { ThrottleMode mode; if (throttleMsg.RateMBit < 0.0f) { mode = Unthrottled.Instance; } else if (throttleMsg.RateMBit < 0.0f) { mode = Blackhole.Instance; } else { mode = new TokenBucket(1000, throttleMsg.RateMBit * 125000, 0, 0); } var cmdTask = TestConductor.Get(Context.System) .Transport.ManagementCommand(new SetThrottle(throttleMsg.Target, throttleMsg.Direction, mode)); cmdTask.ContinueWith(t => { if (t.IsFaulted) { throw new Exception("Throttle was requested from the TestConductor, but no transport " + "adapters available that support throttling. Specify 'testTransport(on=true)' in your MultiNodeConfig"); } Self.Tell(new ToServer <Done>(Done.Instance)); }); return(Stay()); } if (@event.FsmEvent is DisconnectMsg) { return(Stay()); //FIXME is this the right EC for the future below? } // FIXME: Currently ignoring, needs support from Remoting var terminateMsg = @event.FsmEvent as TerminateMsg; if (terminateMsg != null) { if (terminateMsg.ShutdownOrExit.IsLeft && terminateMsg.ShutdownOrExit.ToLeft().Value == false) { Context.System.Shutdown(); return(Stay()); } if (terminateMsg.ShutdownOrExit.IsLeft && terminateMsg.ShutdownOrExit.ToLeft().Value == true) { //TODO: terminate more aggressively with Abort //Context.System.AsInstanceOf<ActorSystemImpl>().Abort(); Context.System.Shutdown(); return(Stay()); } if (terminateMsg.ShutdownOrExit.IsRight) { Environment.Exit(terminateMsg.ShutdownOrExit.ToRight().Value); return(Stay()); } } if (@event.FsmEvent is Done) { return(Stay()); //FIXME what should happen? } } return(null); }); When(State.Failed, @event => { if (@event.FsmEvent is IClientOp) { return(Stay().Replying(new Status.Failure(new Exception("cannot do " + @event.FsmEvent + " while failed")))); } if (@event.FsmEvent is INetworkOp) { Log.Warning("ignoring network message {0} while Failed", @event.FsmEvent); return(Stay()); } return(null); }); OnTermination(@event => { if (@event.StateData.Channel != null) { @event.StateData.Channel.Close(); } }); Initialize(); }
public Deadline GetDeadline(TimeSpan?timeout) { return(Deadline.Now + timeout.GetOrElse(TestConductor.Get(Context.System).Settings.BarrierTimeout)); }