public void StartListening_ShouldThrowExceptionWhenAgentAndGameMasterOnSamePort()
        {
            var config = CommunicationServerConfiguration.GetDefault();

            config.AgentPort      = 55555;
            config.GameMasterPort = 55555;

            server = new CommunicationServer.CommunicationServer(config);
            var exception = Assert.Throws <CommunicationErrorException>(() => server.Run());

            Assert.IsNotNull(exception);
            Assert.AreEqual(CommunicationExceptionType.SocketNotCreated, exception.Type);
            Assert.AreNotEqual("", exception.Message);
        }
Beispiel #2
0
        public static void RunCommunicationServer(object state)
        {
            var config = state == null?CommunicationServerConfiguration.GetDefault() : (CommunicationServerConfiguration)state;

            CommunicationServer.CommunicationServer server = new CommunicationServer.CommunicationServer(config);

            try
            {
                server.Run();
            }
            catch
            {
                server.OnDestroy();
                throw;
            }
        }
        private void GetConfigurationsForTest(int testId, out AgentConfiguration agentConfig, out GameMasterConfiguration gmConfig, out CommunicationServerConfiguration csConfig)
        {
            const int baseAgentPort = 50000;
            const int baseGmPort    = 60000;

            var agentPortForTest = baseAgentPort + testId;
            var gmPortForTest    = baseGmPort - testId;

            csConfig = CommunicationServerConfiguration.GetDefault();

            agentConfig        = AgentConfiguration.GetDefault();
            agentConfig.CsPort = agentPortForTest;
            csConfig.AgentPort = agentPortForTest;

            gmConfig                = GameMasterConfiguration.GetDefault();
            gmConfig.CsPort         = gmPortForTest;
            csConfig.GameMasterPort = gmPortForTest;
        }
Beispiel #4
0
        public void ConnectingAgentsState_ShouldConnectAgent()
        {
            // Setup
            var config = GameMasterConfiguration.GetDefault();

            config.TeamSize = 3;
            var gameMaster = new GameMaster.GameMaster(config);

            agentsInTeam = gameMaster.Configuration.TeamSize;
            gmTaskState  = new IntegrationTestsHelper.GameMasterTaskState(gameMaster, 30);

            var csConfig = CommunicationServerConfiguration.GetDefault();
            var csTask   = new Task(IntegrationTestsHelper.RunCommunicationServer, csConfig);

            csTask.Start();
            Thread.Sleep(100);

            var gmTask = new Task(IntegrationTestsHelper.RunGameMaster, gmTaskState);

            gmTask.Start();
            gmTaskState.GameMaster.ConnectToCommunicationServer();

            var agentTaskStates = IntegrationTestsHelper.CreateAgents(agentsInTeam)
                                  .Select(agent => new IntegrationTestsHelper.AgentTaskState(agent, agentSleepMs)).ToList();

            var agentTasks = agentTaskStates
                             .Select(agentTaskState => new Task(IntegrationTestsHelper.RunAgent, agentTaskState)).ToList();

            foreach (var agentTask in agentTasks)
            {
                Thread.Sleep(100);
                agentTask.Start();
            }

            gmTask.Wait();

            List <GameMaster.Agent> lobby = gmTaskState.GameMaster.ConnectionLogic.FlushLobby();

            Assert.AreEqual(agentsInTeam * 2, lobby.Count);
            Assert.AreEqual(2, lobby.Where(agent => agent.IsTeamLeader).Count());
            Assert.AreEqual(agentsInTeam, lobby.Where(agent => agent.Team == TeamId.Blue).Count());
            Assert.AreEqual(agentsInTeam, lobby.Where(agent => agent.Team == TeamId.Red).Count());

            // Cleanup
            gmTaskState.GameMaster.OnDestroy();
            try
            {
                gmTaskState.GameMaster.OnDestroy();
                csTask.Wait(200);
            }
            catch (AggregateException ex)
            {
                Assert.AreEqual(TaskStatus.Faulted, csTask.Status);
                var exception = ex.InnerException as CommunicationErrorException;
                Assert.IsNotNull(exception);
                Assert.AreEqual(CommunicationExceptionType.GameMasterDisconnected, exception.Type);

                for (int i = 0; i < agentTasks.Count; i++)
                {
                    agentTasks[i].Wait(100);
                    agentTaskStates[i].Agent.OnDestroy();
                }
            }
        }
        public void Setup()
        {
            var config = CommunicationServerConfiguration.GetDefault();

            server = new CommunicationServer.CommunicationServer(config);
        }