Ejemplo n.º 1
0
    def test_push_pull(rank):
        world = get_world()
        if rank == 0:
            group = world.create_rpc_group("group", ["0", "1"])
            _server = OrderedServerSimpleImpl("server", group)
            group.barrier()
            group.barrier()
        elif rank == 1:
            group = world.create_rpc_group("group", ["0", "1"])
            group.barrier()
            server = group.get_paired("server").to_here()

            if server.push("a", "value", 1, None):
                _log(rank, "push 1 success")
            else:
                _log(rank, "push 1 failed")
            if server.push("a", "value2", 2, 1):
                _log(rank, "push 2 success")
            else:
                _log(rank, "push 2 failed")
            if server.push("a", "value3", 3, 2):
                _log(rank, "push 3 success")
            else:
                _log(rank, "push 3 failed")

            assert server.pull("a", None) == ("value3", 3)
            assert server.pull("a", 2) == ("value2", 2)
            assert server.pull("a", 1) is None
            assert server.pull("b", None) is None
            group.barrier()
        return True
Ejemplo n.º 2
0
    def test__push_pull_service(self):
        fake_group = Object()
        fake_group.pair = lambda *_: None
        fake_group.register = lambda *_: None
        fake_group.destroy = lambda: None
        fake_group.is_member = lambda *_: True
        server = OrderedServerSimpleImpl("fake_server", fake_group)
        assert server._push_service("a", "value", 1, None)
        assert not server._push_service("a", "value1", 2, 0)
        assert server._push_service("a", "value2", 2, 1)
        assert server._push_service("a", "value3", -1, 2)

        assert server._pull_service("a", None) == ("value3", -1)
        assert server._pull_service("a", 2) == ("value2", 2)
        assert server._pull_service("a", 1) is None
        assert server._pull_service("b", None) is None
Ejemplo n.º 3
0
def main(rank):
    world = World(world_size=3, rank=rank,
                  name=str(rank), rpc_timeout=20)
    # Usually, distributed services in Machin are seperated
    # into:
    # An accessor: OrderedServerSimple
    # An implementation: OrderedServerSimpleImpl
    #
    # Except DistributedBuffer and DistributedPrioritizedBuffer
    #
    # Accessor is a handle, which records the name of internal
    # service handles. Usually paired as an accessible resource
    # to the group, so any group members can get this accessor
    # and use the internal resources & services.
    #
    # Implementation is the thing that actually starts on the
    # provider process, some implementations may contain backend
    # threads, etc.

    group = world.create_rpc_group("group", ["0", "1", "2"])
    if rank == 0:
        _server = OrderedServerSimpleImpl("server", group)
        sleep(5)
    else:
        sleep(2)
        server = group.get_paired("server").to_here()

        # change key "a", set new value to "value"
        # change version from `None` to `1`
        if server.push("a", "value", 1, None):
            print(rank, "push 1 success")
        else:
            print(rank, "push 1 failed")

        # change key "a", set new value to "value2"
        # change version from `1` to `2`
        if server.push("a", "value2", 2, 1):
            print(rank, "push 2 success")
        else:
            print(rank, "push 2 failed")

        # change key "a", set new value to "value3"
        # change version from `2` to `3`
        if server.push("a", "value3", 3, 2):
            print(rank, "push 3 success")
        else:
            print(rank, "push 3 failed")

        assert server.pull("a", None) == ("value3", 3)
        assert server.pull("a", 2) == ("value2", 2)
        assert server.pull("a", 1) is None
        assert server.pull("b", None) is None
        print("Ordered server check passed")
    group.destroy()