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); } }
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); }
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; }
public void TestMessageDrop() { SimulatedActor[] workers = new SimulatedActor[10]; TestClient[] clients = new TestClient[10]; for (int i = 0; i < 10; i++) { clients[i] = new TestClient(); system_.Spawn(clients[i]); dispatcher_.Tell(new InitCommunication(clients[i], i + 12)); while (clients[i].ReceivedMessages.Count == 0) { system_.RunFor(1); } Message initAckMessage = clients[i].ReceivedMessages.Dequeue(); Assert.AreEqual(typeof(InitAck), initAckMessage.GetType()); InitAck initAck = (InitAck)initAckMessage; Assert.AreEqual(i + 12, initAck.CommunicationId); workers[i] = initAck.Worker; } int j = 0; foreach (SimulatedActor worker in workers) { worker.Tell(new Like("group-16", 12 + j, 1)); j++; } for (int i = 0; i < 10; i++) { while (clients[i].ReceivedMessages.Count == 0) { system_.RunFor(1); } Message failedMessage = clients[i].ReceivedMessages.Dequeue(); if (failedMessage.GetType() != typeof(OperationAck)) { Assert.AreEqual(typeof(OperationFailed), failedMessage.GetType()); } } }