Beispiel #1
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);
        }
Beispiel #2
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);
            }
        }
Beispiel #3
0
 /// <summary>
 /// Constructs a new Dispatcher object
 /// </summary>
 /// <param name="system">system used to spawn actors</param>
 /// <param name="numberOfWorkers">number of workers to be spawned</param>
 public Dispatcher(SimulatedActorSystem system, int numberOfWorkers)
 {
     this.system        = system;
     this.workers       = new List <Worker>(numberOfWorkers);
     this.mode          = Mode.NORMAL;
     this.acksToCollect = new List <long>();
 }
Beispiel #4
0
 /// <summary>
 /// Constructs a new Worker object
 /// </summary>
 /// <param name="disp">the dispatcher</param>
 /// <param name="messageStore">the message store responsible for persistence</param>
 /// <param name="system">the actor system simulation</param>
 public Worker(SimulatedActor disp, SimulatedActor messageStore, SimulatedActorSystem system)
 {
     this.dispatcher            = disp;
     this.messageStore          = messageStore;
     this.ongoingCommunications = new Dictionary <long, SimulatedActor>();
     this.system   = system;
     this.stopping = false;
 }
Beispiel #5
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);
        }
Beispiel #6
0
 static public void setup(TestContext context)
 {
     system_     = new SimulatedActorSystem();
     dispatcher_ = new Dispatcher(system_, 2);
     system_.Spawn(dispatcher_);
 }
Beispiel #7
0
        /// <summary>
        /// Constructs a new WorkerHelper object.
        /// </summary>
        /// <param name="messageStore">message store which receives messages from helper</param>
        /// <param name="client">client to which the message from the store gets forwarded</param>
        /// <param name="message">the message to be sent to the message store</param>
        /// <param name="system">actor system used to stop the helper</param>
        public WorkerHelper(SimulatedActor messageStore, SimulatedActor client, MessageStoreMessage message, SimulatedActorSystem system)
        {
            this.message             = message;
            this.message.StoreClient = this;
            this.messageStore        = messageStore;
            this.client            = client;
            this.system            = system;
            this.timeSinceLastSent = 0;
            this.stopping          = false;
            this.retries           = 0;

            // good connection between WorkerHelper and MessageStore -> no delay
            this.channel = new DeterministicChannel(0);
        }