示例#1
0
        public void TestUnknownClientExceptionFinishCommunication()
        {
            //testing only the acks
            SimulatedActorSystem system     = new SimulatedActorSystem();
            Dispatcher           dispatcher = new Dispatcher(system, 2);

            system.Spawn(dispatcher);
            TestClient client = new TestClient();

            system.Spawn(client);

            dispatcher.Tell(new InitCommunication(client, 10));

            while (client.ReceivedMessages.Count == 0)
            {
                system.RunFor(1);
            }
            Message initAckMessage = client.ReceivedMessages.Dequeue();

            Assert.AreEqual(typeof(InitAck), initAckMessage.GetType());
            InitAck initAck = (InitAck)initAckMessage;

            Assert.AreEqual(10, initAck.CommunicationId);

            SimulatedActor worker = initAck.Worker;

            worker.Tell(new FinishCommunication(11));
            while (client.ReceivedMessages.Count == 0)
            {
                system.RunFor(1);
            }
        }
示例#2
0
        public void TestDispatcherStoppingFail()
        {
            //testing only the acks
            SimulatedActorSystem system     = new SimulatedActorSystem();
            Dispatcher           dispatcher = new Dispatcher(system, 2);

            system.Spawn(dispatcher);
            TestClient client = new TestClient();

            system.Spawn(client);

            dispatcher.Tell(new Stop());

            dispatcher.Tell(new InitCommunication(client, 10));

            while (client.ReceivedMessages.Count == 0)
            {
                system.RunFor(1);
            }
            Message initAckMessage = client.ReceivedMessages.Dequeue();

            Assert.AreEqual(typeof(OperationFailed), initAckMessage.GetType());
            OperationFailed initAck = (OperationFailed)initAckMessage;

            Assert.AreEqual(10, initAck.CommunicationId);

            // TODO run system until workers and dispatcher are stopped
            int endtime = system.currentTime + 20;

            system.RunUntil(endtime);
            Assert.AreEqual(system.currentTime, endtime + 1);
        }
示例#3
0
        public void TestCommunication()
        {
            //testing only the acks
            SimulatedActorSystem system     = new SimulatedActorSystem();
            Dispatcher           dispatcher = new Dispatcher(system, 2);

            system.Spawn(dispatcher);
            TestClient client = new TestClient();

            system.Spawn(client);
            // send request and run system until a response is received
            // communication id is chosen by clients
            dispatcher.Tell(new InitCommunication(client, 10));
            while (client.ReceivedMessages.Count == 0)
            {
                system.RunFor(1);
            }
            Message initAckMessage = client.ReceivedMessages.Dequeue();

            Assert.AreEqual(typeof(InitAck), initAckMessage.GetType());
            InitAck initAck = (InitAck)initAckMessage;

            Assert.AreEqual(10, initAck.CommunicationId);

            SimulatedActor worker = initAck.Worker;

            initAck.Worker.Tell(new FinishCommunication(10));
            while (client.ReceivedMessages.Count == 0)
            {
                system.RunFor(1);
            }

            Message finAckMessage = client.ReceivedMessages.Dequeue();

            Assert.AreEqual(typeof(FinishAck), finAckMessage.GetType());
            FinishAck finAck = (FinishAck)finAckMessage;

            Assert.AreEqual(10, finAck.CommunicationId);
            dispatcher.Tell(new Stop());

            // TODO run system until workers and dispatcher are stopped
            int endtime = system.currentTime + 20;

            system.RunUntil(endtime);
            Assert.AreEqual(system.currentTime, endtime + 1);
        }
示例#4
0
        public void test_setup()
        {
            //Testclient 1
            testclient_ = new TestClient();

            system_.Spawn(testclient_);

            dispatcher_.Tell(new InitCommunication(testclient_, 10));
            while (testclient_.ReceivedMessages.Count == 0)
            {
                system_.RunFor(1);
            }
            Message initAckMessage = testclient_.ReceivedMessages.Dequeue();
            InitAck initAck        = (InitAck)initAckMessage;

            worker_ = initAck.Worker;
        }