public void ChangeLoad(LoadChangeAction changeAction) { var finalLoad = LoadFactory.GetUpdatedContainerLoad(this.ContainerId, changeAction, NeededLoad); switch (Global.LoadChangeStrategy) { case LoadChangeStrategy.Force: NeededLoad = finalLoad; break; case LoadChangeStrategy.Incremental: Task t = new Task(async() => { var initalLoad = NeededLoad; int steps = Global.Steps; for (int i = 1; i <= steps; i++) { var newCurrent = (finalLoad - initalLoad) * i / steps + initalLoad; lock (lck) { NeededLoad = newCurrent; } await Task.Delay(10 * Global.Second); } }); t.Start(); break; default: throw new ArgumentOutOfRangeException(); } }
public void CreateAutomobile_ReturnsTheConfiguredIAutoInstance() { //arrange IAutoFactory autoFactory = LoadFactory.GetInstance(); Type expectedAutomobileType = typeof(MiniCooper); //act IAuto actualAutomobile = autoFactory.CreateAutomobile(); //assert actualAutomobile.Should().BeOfType(expectedAutomobileType); }
void Start() { LoadFactory.LoadAssetText(downPath, this, callBack, false); //this.transform.parent //this.transform U3DSocket socket = U3DSocket.shareSocket(); socket.ConnectTo(IP.ip, IP.port, (str) => { EventDispatch.addEventListener(this, "do"); print("连接成功"); isCon = true; }, (str) => { print("连接失败"); isCon = false; }); }
public void StartSimulation() { //Common Load Manager for Zhao (refactor to be a network resource) Global.CommonLoadManager = new CommonLoadManager(AccountingModuleObject); //Master Machine MasterMachine masterMachine = (MasterMachine)_masterFactory.GetMachine(); MachineControllerObject.AddMachine(masterMachine); //Host Machines for (int i = 1; i <= (int)CurrentConfiguration.SimulationSize; i++) { MachineControllerObject.AddMachine(_hostFactory.GetMachine()); } //Add registry when needed if (CurrentConfiguration.ContainersType == ContainersType.D) { Machine registry = _registryFactory.GetMachine(); MachineControllerObject.AddMachine(registry); } var hosts = MachineTableObject.GetAllMachines(); for (int i = 1; i <= (int)CurrentConfiguration.SimulationSize; i++) { List <Load> loads = LoadFactory.GenerateLoadList(CurrentConfiguration.StartPercent, CurrentConfiguration.SimulationSize); foreach (var load in loads) { var container = _containerFactory.GetContainer(load); if (container.ContainerType == ContainersType.D) { var dockerregistry = hosts.Last() as DockerRegistryMachine; var dockercontainer = container as DockerContainer; List <Image> images = dockerregistry.GetImagesList(dockercontainer.ImageId); (hosts[i] as HostMachine).AddContainer(container, images); } else { (hosts[i] as HostMachine).AddContainer(container); } } } MachineControllerObject.StartSimulation(); var done = false; int c = 0; for (int x = 0; x <= Global.GetSimulationTime; x += Global.AccountTime, c++) { Debug.WriteLine($"Time = {x}/{Global.GetSimulationTime}"); AccountingModuleObject.ReadCurrentState(); Thread.Sleep(Global.AccountTime); if (x >= Global.GetSimulationTime / 2 && !done) { if (CurrentConfiguration.ChangeAction == LoadChangeAction.Opposite) { StartWaveSimmulationAction(LoadChangeAction.Burst, m => true, m => m.ContainerId % 2 == 0); StartWaveSimmulationAction(LoadChangeAction.Drain, m => true, m => m.ContainerId % 2 == 1); } else if (CurrentConfiguration.ChangeAction == LoadChangeAction.None) { } else { StartWaveSimmulationAction(CurrentConfiguration.ChangeAction, m => true, m => m.ContainerId % 2 == 0); } done = true; } //Add container to queue if (CurrentConfiguration.ChangeAction == LoadChangeAction.None) { int s = 0; Predicate <int> anotherTest = new Predicate <int>(n => true); switch (CurrentConfiguration.SimulationSize) { case SimulationSize.Twenty: s = 3; anotherTest = n => n % 4 == 0; break; case SimulationSize.Fifty: s = 2; break; case SimulationSize.Hundred: s = 7; anotherTest = n => n % 2 == 0; break; case SimulationSize.TwoHundred: s = 7; break; default: throw new ArgumentOutOfRangeException(); } for (int i = 0; i < s & anotherTest(c); i++) { masterMachine.AddContainer(_containerFactory.GetContainer(LoadFactory.GetRandomLoad())); } } } EndSimulation(); }