protected override void Setup() { Console.WriteLine($"Starting a deployment with name: {DeploymentName}"); var launchConfig = File.ReadAllText(LaunchConfigFilePath); _deployment = _deploymentServiceClient.CreateDeployment(new CreateDeploymentRequest { ProjectName = ProjectName, DeploymentName = DeploymentName, LaunchConfig = new LaunchConfig { ConfigJson = launchConfig }, AssemblyName = AssemblyId, Tags = { ScenarioDeploymentTag } }).PollUntilCompleted().GetResultOrNull(); }
/// <summary> /// This contains the implementation of the "Capacity limiting" scenario. /// 1. Gets the currently running cloud deployment that has a capacity limit. /// 2. Tests that connecting more clients than the capacity limit fails. /// 3. Updates the deployment to increase the capacity limit. /// 4. Tests that additional clients are now able to connect to the deployment. /// </summary> protected override void Run() { Console.WriteLine("Finding current running deployment"); _runningDeployment = _deploymentServiceClient.GetRunningDeploymentByName(new GetRunningDeploymentByNameRequest { ProjectName = ProjectName, DeploymentName = DeploymentName }).Deployment; Console.WriteLine($"Found deployment {_runningDeployment.Id}"); Console.WriteLine("Setting capacity limit to 2"); var setWorkerCapacitiesRequest = new SetDeploymentWorkerCapacitiesRequest { DeploymentId = _runningDeployment.Id, }; setWorkerCapacitiesRequest.WorkerConnectionCapacities.Add(new WorkerCapacity { WorkerType = ScenarioWorkerType, MaxCapacity = 2 }); _deploymentServiceClient.SetDeploymentWorkerCapacities(setWorkerCapacitiesRequest); Console.WriteLine("Creating a PlayerIdentityToken"); var playerIdentityTokenResponse = _playerAuthServiceClient.CreatePlayerIdentityToken( new CreatePlayerIdentityTokenRequest { Provider = "provider", PlayerIdentifier = "player_identifier", ProjectName = ProjectName }); Console.WriteLine(JsonConvert.SerializeObject(playerIdentityTokenResponse)); Console.WriteLine("Creating a LoginToken for the selected deployment"); var createLoginTokenResponse = _playerAuthServiceClient.CreateLoginToken( new CreateLoginTokenRequest { PlayerIdentityToken = playerIdentityTokenResponse.PlayerIdentityToken, DeploymentId = _runningDeployment.Id.ToString(), LifetimeDuration = Duration.FromTimeSpan(new TimeSpan(0, 0, 30, 0)), WorkerType = ScenarioWorkerType }); Console.WriteLine(JsonConvert.SerializeObject(createLoginTokenResponse)); Console.WriteLine("Connecting 3 workers to the deployment. Expecting only 2 to succeed"); var locatorParameters = new LocatorParameters { PlayerIdentity = new PlayerIdentityCredentials { PlayerIdentityToken = playerIdentityTokenResponse.PlayerIdentityToken, LoginToken = createLoginTokenResponse.LoginToken } }; var locator = new Locator(LocatorServerAddress, LocatorServerPort, locatorParameters); for (var i = 0; i < 3; i++) { var connectionSucceeded = TryConnectWorker(locator); if (!connectionSucceeded && i != 2) { throw new Exception("Expected worker to connect successfully"); } if (connectionSucceeded && i == 2) { throw new Exception("Expected worker to fail to connect"); } } Console.WriteLine("Increasing capacity limit to 3"); setWorkerCapacitiesRequest = new SetDeploymentWorkerCapacitiesRequest { DeploymentId = _runningDeployment.Id, }; setWorkerCapacitiesRequest.WorkerConnectionCapacities.Add(new WorkerCapacity { WorkerType = ScenarioWorkerType, MaxCapacity = 3 }); _deploymentServiceClient.SetDeploymentWorkerCapacities(setWorkerCapacitiesRequest); Console.WriteLine("Connecting another worker"); if (!TryConnectWorker(locator)) { throw new Exception("Expected worker to be able to connect after capacity increase"); } }