Exemplo n.º 1
0
def test_round_robin_arithmetic():
    print("Testing multiplication")
    a_sys = ActorSystem("tests")
    rr = RoundRobinRouter("test_router")
    rr.start()
    rr.set_actor_system(a_sys, "tests")

    a = AddTestActor("testa")
    a.start()
    rr.add_actor(a)

    b = AddTestActor("testb")
    b.start()
    rr.add_actor(b)

    async def get_addition():
        res = await rr.route_ask(AddIntMessage(1))
        return res

    res = asyncio.get_event_loop().run_until_complete(get_addition())
    print(rr.get_current_index())
    assert(res is 2), "Addition Not Completed"
    msg = "Actors Missing. Length {}".format(rr.get_num_actors())
    assert(rr.get_num_actors() is 2), msg
    a_sys.close()

    assert(a.get_state() is ActorState.TERMINATED), "Actor a Not Terminated"
    assert(b.get_state(), ActorState.TERMINATED)," Actor b Not Terminated"
    assert(rr.get_state(), ActorState.TERMINATED), "Router Not Terminated"
    print("Done Testing Multiplication")
Exemplo n.º 2
0
def test_round_robin_broadcast():
    print("Testing Broadcast")
    sys = ActorSystem("tests")
    rr = RoundRobinRouter("test_router")
    rr.start()
    rr.set_actor_system(sys, "tests")

    a = StringTestActor()
    a.start()
    rr.add_actor(a)

    b = StringTestActor()
    b.start()
    rr.add_actor(b)

    asyncio.get_event_loop().run_until_complete(
        rr.broadcast(StringMessage("Hello World!")))
    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("Finished Testing Broadcast")
Exemplo n.º 3
0
def test_round_robin_at_load():
    print("Load Testing")
    sys = ActorSystem("tests")
    rr = RoundRobinRouter("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("testa")
        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))
    print(res)
    assert(int(res) is len(funcs)), "Result {} is not {}".format(res, len(funcs))
    sys.close()
    assert(rr.get_state() is ActorState.TERMINATED), "Router Not Terminated"
    print("Done Load Testing")
Exemplo n.º 4
0
def test__round_robin_tell_at_load():
    print("Load Testing With Tell")
    sys = ActorSystem("tests")
    rr = RoundRobinRouter("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")
Exemplo n.º 5
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")
Exemplo n.º 6
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")
Exemplo n.º 7
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")
Exemplo n.º 8
0
def test_creation():
    print("Create Router Test")
    sys = ActorSystem("tests")
    kwargs = {'name': 'test_router'}
    args = []
    rr = RoundRobinRouter(*args, **kwargs)
    rr.start()
    assert (rr.get_name() == 'test_router')
    rr.set_actor_system(sys, "tests")
    sys.close()
    assert (rr.get_state() == ActorState.TERMINATED), "Router Not Terminated"
    print("Completed Router Creation Test")
Exemplo n.º 9
0
def test_balancing_at_load():
    print("Load Testing")
    sys = ActorSystem("tests")
    rr = BalancingRouter("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, 10):
        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))
    print("Complete")
    sys.print_tree()
    sys.close()
    rr.close_queue()
    sys.print_tree()
    print("Garbage Collecting")
    assert (rr.get_state() is ActorState.TERMINATED), "Router Not Terminated"
    print("Done Load Testing")
Exemplo n.º 10
0
def test_balancing_router_arithemetic():
    print("Testing multiplication")
    sys = ActorSystem("tests")
    rr = BalancingRouter("test_router")
    rr.start()
    rr.set_actor_system(sys, "tests")

    a = AddTestActor(name="testa", inbox=rr.get_router_queue())
    a.start()
    rr.add_actor(a)

    b = AddTestActor(name="testb", inbox=rr.get_router_queue())
    b.start()
    rr.add_actor(b)
    res = asyncio.get_event_loop().run_until_complete(
        rr.route_ask(RouteAsk(AddIntMessage(1))))
    assert (res is 2), "Addition Not Completed"
    msg = "Actors Missing. Length {}".format(rr.get_num_actors())
    assert (rr.get_num_actors() is 2), msg
    rr.close_queue()
    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())
    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")
Exemplo n.º 11
0
def test_stress_add_two_levels():
    """
    Test actors added to two levels of the tree.  150000 actors added.
    """
    level_one = []
    level_two = []
    sys = ActorSystem("test")

    async def test():
        print("Creating Actors")
        for i in range(1, 50000):
            a = BaseActor()
            a.start()
            sys.add_actor(a, "test")
            level_one.append(a)

        for i in range(1, 100000):
            # choose random
            a = BaseActor()
            a.start()
            parent = random.choice(level_one)
            path = "test/{}".format(parent.get_name().strip())
            sys.add_actor(a, path)
            level_two.append(parent)

    asyncio.get_event_loop().run_until_complete(test())
    print("Closing Actors")
    sys.close()
    print("Finished Closing System")
    assert (len([x for x in level_one if x.get_state() is ActorState.RUNNING])
            is 0)
    assert (len([
        x for x in level_one if x.get_state() is ActorState.TERMINATED
    ]) == len(level_one))
    assert (len([x for x in level_two if x.get_state() is ActorState.RUNNING])
            is 0)
    assert (len([
        x for x in level_two if x.get_state() is ActorState.TERMINATED
    ]) is len(level_two))
Exemplo n.º 12
0
def test_balancing_router_creation():
    print("Starting Creation Test")
    sys = ActorSystem("test")
    rr = BalancingRouter("test_router")
    rr.start()
    sys.add_actor(rr, "test")
    sys.close()
    assert (rr.get_state(), ActorState.TERMINATED), "Router Not Closed"
    print("Completed Creation Test")
Exemplo n.º 13
0
def test_stress_line_of_levels():
    print("Testing Long Line of Actors")
    sys = ActorSystem("test")
    path = "test"
    actors = []
    for i in range(1, 100):
        actor = BaseActor()
        actor.start()
        sys.add_actor(actor, path)
        actors.append(actor)
        path += "/{}".format(actor.get_name())
    print("Closing Actors")
    sys.close()
    assert (len([x for x in actors
                 if x.get_state() is ActorState.TERMINATED]) == len(actors))
Exemplo n.º 14
0
def test_balancing_router_actor_addition():
    print("Starting Actor Addition Test")
    sys = ActorSystem("test")
    rr = BalancingRouter("test_router")
    rr.start()
    print(rr.get_name())
    a = BaseActor()
    a.start()
    rr.add_actor(a)
    sys.add_actor(rr, "test")
    rr.remove_actor(a)
    assert (rr.get_num_actors() is 0), "Actor Still in Router"
    sys.close()
    asyncio.get_event_loop().run_until_complete(a.stop())
    assert (rr.get_state() is ActorState.TERMINATED), "Router Not Closed"
    assert (a.get_state() is ActorState.TERMINATED), "Actor is Not Closed"
    print("Actor Addition Test Complete")
Exemplo n.º 15
0
def test_branch_removal():
    """
    Add a basic branch and remove it.
    """
    print("Testing Branch Creation")
    a = BaseActor()
    a.start()
    b = BaseActor()
    b.start()
    c = BaseActor()
    c.start()
    d = BaseActor()
    d.start()

    sys = ActorSystem("test")
    sys.add_actor(a, "test")
    sys.add_actor(b, "test/{}".format(a.get_name()))
    sys.add_actor(d, "test/{}/{}".format(a.get_name(), b.get_name()))
    sys.add_actor(c, "test")

    sys.close(do_print=False)
    assert (a.get_state() is ActorState.TERMINATED), "Actor was not Terminated"
    assert (b.get_state() is ActorState.TERMINATED), "Actor was not Terminated"
    assert (c.get_state() is ActorState.TERMINATED), "Actor was not Terminated"
    assert (d.get_state() is ActorState.TERMINATED), "Actor was not Terminated"
    print("Finished Testing Branch Creation")