Ejemplo n.º 1
0
 def test_random_router_tell_at_load(self):
     print("Load Testing With Tell")
     sys = ActorSystem("tests")
     rr = RandomRouter("test_router")
     rr.start()
     rr.set_actor_system(sys, "tests")
 
     actors = []
 
     async def say_hello(i):
         await rr.route_tell(StringMessage("Hello {}".format(i)))
 
     async def comp(funcs):
         await asyncio.gather(*funcs)
 
     print("Starting Actor")
     for i in range(0, 100):
         a = StringTestActor()
         a.start()
         rr.add_actor(a)
         actors.append(a)
 
     print("Start Adding")
     funcs = [say_hello(i) for i in range(0, len(actors))]
     print("Waiting")
     asyncio.get_event_loop().run_until_complete(comp(funcs))
     sys.close()
     del sys
     gc.collect()
     del gc.garbage[:]
     assert(rr.get_state() is ActorState.TERMINATED), "Router Not Terminated"
     print("Load Testing With Tell Complete")
Ejemplo n.º 2
0
 def test_random_router_at_load(self):
     print("Load Testing")
     sys = ActorSystem("tests")
     rr = RandomRouter("test_router")
     rr.start()
     rr.set_actor_system(sys, "tests")
 
     actors = []
 
     async def get_addition():
         res = await rr.route_ask(AddIntMessage(1))
         return res
 
     async def get_sum(funcs):
         res = await asyncio.gather(*funcs)
         return sum(res) / 2
 
     print("Starting Actor")
     for i in range(0, 100):
         a = AddTestActor("test_actor")
         a.start()
         rr.add_actor(a)
         actors.append(a)
 
     print("Start Adding")
     funcs = [get_addition() for x in actors]
     print("Waiting")
     res = asyncio.get_event_loop().run_until_complete(get_sum(funcs))
     msg = "Result {} is not {}".format(res, len(funcs))
     assert(int(res) is len(funcs)), msg
     sys.close()
     assert(rr.get_state() is ActorState.TERMINATED), "Router Not Terminated"
     print("Done Load Testing")
Ejemplo n.º 3
0
 def test_random_router_creation(self):
     sys = ActorSystem("tests")
     kwargs = {'name': 'test_router'}
     args = []
     rr = RandomRouter("test_router")
     rr.start()
     assert(rr.get_name() == 'test_router')
     rr.set_actor_system(sys, "tests")
     sys.close()
     assert(rr.get_state() is ActorState.TERMINATED), "Router Not Terminated"
     print("Completed Router Creation Test")
Ejemplo n.º 4
0
 def test_random_router_tell(self):
     print("Starting Tell Test")
     sys = ActorSystem("tests")
     rr = RandomRouter(name="test_router")
     rr.start()
     rr.set_actor_system(sys, "tests")
 
     a = StringTestActor()
     a.start()
     rr.add_actor(a)
     print(rr.actor_set)
 
     b = StringTestActor()
     b.start()
     rr.add_actor(b)
     print(rr.actor_set)
     msg = "Actors Missing. Length {}".format(rr.get_num_actors())
     assert(rr.get_num_actors() is 2), msg
     asyncio.get_event_loop().run_until_complete(
         rr.route_tell(StringMessage("Hello World")))
     sys.close()
     assert(a.get_state() is ActorState.TERMINATED), "Actor a Not Terminated"
     assert(b.get_state() is ActorState.TERMINATED), " Actor b Not Terminated"
     assert(rr.get_state() is ActorState.TERMINATED), "Router Not Terminated"
     print("Tell Test Complete")
Ejemplo n.º 5
0
 def test_random_router_arithmetic(self):
     print("Testing multiplication")
     sys = ActorSystem("tests")
     rr = RandomRouter("test_router")
     rr.start()
     rr.set_actor_system(sys, "tests")
 
     a = AddTestActor("testa")
     a.start()
     rr.add_actor(a)
 
     b = AddTestActor("testb")
     b.start()
     rr.add_actor(b)
 
     async def get_random_router_addition():
         res = await rr.route_ask(AddIntMessage(1))
         assert(res is 2)
         return res
 
     res = asyncio.get_event_loop().run_until_complete(get_random_router_addition())
     assert(res is 2), "Addition Not Completed"
     asyncio.get_event_loop().run_until_complete(a.stop())
     asyncio.get_event_loop().run_until_complete(b.stop())
     asyncio.get_event_loop().run_until_complete(rr.stop())
     msg = "Actors Missing. Length {}".format(rr.get_num_actors())
     assert(rr.get_num_actors() is 2), msg
     
     assert(a.get_state() is ActorState.TERMINATED), "Actor a Not Terminated"
     assert(b.get_state() is ActorState.TERMINATED), " Actor b Not Terminated"
     assert(rr.get_state() is ActorState.TERMINATED), "Router Not Terminated"
     print("Done Testing Multiplication")
Ejemplo n.º 6
0
 def test_random_router_actor_addition(self):
     print("Starting Actor Addition Test")
     sys = ActorSystem("tests")
     rr = RandomRouter("test_router")
     rr.start()
     rr.set_actor_system(sys, "tests")
 
     a = BaseActor()
     a.start()
     rr.add_actor(a)
 
     b = BaseActor()
     b.start()
     rr.add_actor(b)
 
     msg = "Actors Missing. Length {}".format(rr.get_num_actors())
     assert(rr.get_num_actors() is 2), msg
 
     rr.remove_actor(a)
     assert(rr.get_num_actors() is 1), "Number of Actors Should be 1"
     asyncio.get_event_loop().run_until_complete(a.stop())
     sys.close()
     assert(a.get_state() is ActorState.TERMINATED), "Actor a Not Terminated"
     assert(b.get_state() is ActorState.TERMINATED), " Actor b Not Terminated"
     assert(rr.get_state() is ActorState.TERMINATED), "Router Not Terminated"
     print("Actor Addition Test Complete")