Ejemplo n.º 1
0
def test_looking_up_an_actor_by_its_absolute_path_returns_the_original_reference_to_it(defer):
    node = DummyNode()
    defer(node.stop)
    toplevel_actor = node.spawn(Actor, name='toplevel')
    ok_(node.lookup_str('/toplevel') is toplevel_actor)
    ok_(node.lookup(Uri.parse('/toplevel')) is toplevel_actor)

    child_actor = toplevel_actor._cell.spawn_actor(Actor, name='child')
    ok_(node.lookup_str('/toplevel/child') is child_actor)
    ok_(node.lookup(Uri.parse('/toplevel/child')) is child_actor)
Ejemplo n.º 2
0
def test_looking_up_an_actor_by_its_absolute_path_returns_the_original_reference_to_it(
        defer):
    node = DummyNode()
    defer(node.stop)
    toplevel_actor = node.spawn(Actor, name='toplevel')
    ok_(node.lookup_str('/toplevel') is toplevel_actor)
    ok_(node.lookup(Uri.parse('/toplevel')) is toplevel_actor)

    child_actor = toplevel_actor._cell.spawn_actor(Actor, name='child')
    ok_(node.lookup_str('/toplevel/child') is child_actor)
    ok_(node.lookup(Uri.parse('/toplevel/child')) is child_actor)
Ejemplo n.º 3
0
 def _deliver_local(self, path, msg, sender_addr):
     cell = self.guardian.lookup_cell(Uri.parse(path))
     if not cell:
         if ("_watched", ANY) == msg:
             watched_ref = Ref(cell=None, is_local=True, uri=Uri.parse(self.nodeid + path))
             _, watcher = msg
             watcher << ("terminated", watched_ref)
         else:
             if msg not in (("terminated", ANY), ("_watched", ANY), ("_unwatched", ANY)):
                 self._remote_dead_letter(path, msg, sender_addr)
     else:
         cell.receive(msg)  # XXX: force_async=True perhaps?
Ejemplo n.º 4
0
def test_relative_uri():
    #
    uri = Uri.parse('foo')
    eq_(str(uri), 'foo')
    eq_(uri.name, 'foo')
    eq_(uri.path, 'foo')
    ok_(not uri.url)

    eq_(uri, Uri.parse('foo'))
    eq_(uri, 'foo', "Uri.__eq__ supports str")

    ok_(not uri.parent)
    ok_(not uri.node)
    eq_(uri.root, uri)

    eq_(list(uri.steps), ['foo'])

    ok_(uri.local is uri)

    #
    uri = Uri.parse('foo/bar')
    eq_(str(uri), 'foo/bar')
    eq_(uri.name, 'bar')
    eq_(uri.path, 'foo/bar')
    ok_(not uri.url)

    eq_(uri, Uri.parse('foo/bar'))
    eq_(uri, 'foo/bar', "Uri.__eq__ supports str")

    eq_(uri.parent, 'foo')
    ok_(not uri.node)
    eq_(uri.root, 'foo')

    eq_(list(uri.steps), ['foo', 'bar'])

    ok_(uri.local is uri)
Ejemplo n.º 5
0
def test_relative_uri():
    #
    uri = Uri.parse('foo')
    eq_(str(uri), 'foo')
    eq_(uri.name, 'foo')
    eq_(uri.path, 'foo')
    ok_(not uri.url)

    eq_(uri, Uri.parse('foo'))
    eq_(uri, 'foo', "Uri.__eq__ supports str")

    ok_(not uri.parent)
    ok_(not uri.node)
    eq_(uri.root, uri)

    eq_(list(uri.steps), ['foo'])

    ok_(uri.local is uri)

    #
    uri = Uri.parse('foo/bar')
    eq_(str(uri), 'foo/bar')
    eq_(uri.name, 'bar')
    eq_(uri.path, 'foo/bar')
    ok_(not uri.url)

    eq_(uri, Uri.parse('foo/bar'))
    eq_(uri, 'foo/bar', "Uri.__eq__ supports str")

    eq_(uri.parent, 'foo')
    ok_(not uri.node)
    eq_(uri.root, 'foo')

    eq_(list(uri.steps), ['foo', 'bar'])

    ok_(uri.local is uri)
Ejemplo n.º 6
0
def test_sending_to_a_remote_ref_that_points_to_a_local_ref_is_redirected(defer):
    node = Node('localhost:20000', enable_remoting=True)
    defer(node.stop)

    msgs = obs_list()
    node.spawn(Props(MockActor, msgs), name='localactor')

    ref = Ref(cell=None, uri=Uri.parse('localhost:20000/localactor'), is_local=False, node=node)
    ref << 'foo'

    msgs.wait_eq(['foo'])
    ok_(ref.is_local)

    ref << 'bar'
    msgs.wait_eq(['foo', 'bar'])
Ejemplo n.º 7
0
def test_fully_qualified_uri():
    #
    uri = Uri.parse('localhost:123')
    eq_(str(uri), 'localhost:123')
    eq_(uri.name, '')
    eq_(uri.path, '')
    eq_(uri.url, 'tcp://localhost:123')

    eq_(uri, Uri.parse('localhost:123'))
    eq_(uri, 'localhost:123')

    ok_(not uri.parent)
    eq_(uri.node, 'localhost:123')
    eq_(uri.root, uri)

    eq_(list(uri.steps), [''])

    eq_(uri.local, '')

    #
    uri = Uri.parse('localhost:123/foo')
    eq_(str(uri), 'localhost:123/foo')
    eq_(uri.name, 'foo')
    eq_(uri.path, '/foo')
    eq_(uri.url, 'tcp://localhost:123/foo')

    eq_(uri, Uri.parse('localhost:123/foo'))
    eq_(uri, 'localhost:123/foo', "Uri.__eq__ supports str")

    eq_(uri.parent, 'localhost:123')
    eq_(uri.node, 'localhost:123')
    eq_(uri.root, 'localhost:123')

    eq_(list(uri.steps), ['', 'foo'])

    eq_(uri.local, '/foo')

    #
    uri = Uri.parse('localhost:123/foo/bar')
    eq_(str(uri), 'localhost:123/foo/bar')
    eq_(uri.name, 'bar')
    eq_(uri.path, '/foo/bar')
    eq_(uri.url, 'tcp://localhost:123/foo/bar')

    eq_(uri, Uri.parse('localhost:123/foo/bar'))
    eq_(uri, 'localhost:123/foo/bar', "Uri.__eq__ supports str")

    eq_(uri.parent, 'localhost:123/foo')
    eq_(uri.node, 'localhost:123')
    eq_(uri.root, 'localhost:123')

    eq_(list(uri.steps), ['', 'foo', 'bar'])

    eq_(uri.local, '/foo/bar')
Ejemplo n.º 8
0
def test_fully_qualified_uri():
    #
    uri = Uri.parse('localhost:123')
    eq_(str(uri), 'localhost:123')
    eq_(uri.name, '')
    eq_(uri.path, '')
    eq_(uri.url, 'tcp://localhost:123')

    eq_(uri, Uri.parse('localhost:123'))
    eq_(uri, 'localhost:123')

    ok_(not uri.parent)
    eq_(uri.node, 'localhost:123')
    eq_(uri.root, uri)

    eq_(list(uri.steps), [''])

    eq_(uri.local, '')

    #
    uri = Uri.parse('localhost:123/foo')
    eq_(str(uri), 'localhost:123/foo')
    eq_(uri.name, 'foo')
    eq_(uri.path, '/foo')
    eq_(uri.url, 'tcp://localhost:123/foo')

    eq_(uri, Uri.parse('localhost:123/foo'))
    eq_(uri, 'localhost:123/foo', "Uri.__eq__ supports str")

    eq_(uri.parent, 'localhost:123')
    eq_(uri.node, 'localhost:123')
    eq_(uri.root, 'localhost:123')

    eq_(list(uri.steps), ['', 'foo'])

    eq_(uri.local, '/foo')

    #
    uri = Uri.parse('localhost:123/foo/bar')
    eq_(str(uri), 'localhost:123/foo/bar')
    eq_(uri.name, 'bar')
    eq_(uri.path, '/foo/bar')
    eq_(uri.url, 'tcp://localhost:123/foo/bar')

    eq_(uri, Uri.parse('localhost:123/foo/bar'))
    eq_(uri, 'localhost:123/foo/bar', "Uri.__eq__ supports str")

    eq_(uri.parent, 'localhost:123/foo')
    eq_(uri.node, 'localhost:123')
    eq_(uri.root, 'localhost:123')

    eq_(list(uri.steps), ['', 'foo', 'bar'])

    eq_(uri.local, '/foo/bar')
Ejemplo n.º 9
0
def test_sending_to_a_remote_ref_that_points_to_a_local_ref_is_redirected(
        defer):
    node = Node('localhost:20000', enable_remoting=True)
    defer(node.stop)

    msgs = obs_list()
    node.spawn(Props(MockActor, msgs), name='localactor')

    ref = Ref(cell=None,
              uri=Uri.parse('localhost:20000/localactor'),
              is_local=False,
              node=node)
    ref << 'foo'

    msgs.wait_eq(['foo'])
    ok_(ref.is_local)

    ref << 'bar'
    msgs.wait_eq(['foo', 'bar'])
Ejemplo n.º 10
0
def test_uri_hash():
    eq_(hash(Uri.parse('foo')), hash(Uri.parse('foo')))
    eq_(hash(Uri.parse('/foo')), hash(Uri.parse('/foo')))
    eq_(hash(Uri.parse('localhost:123/foo')),
        hash(Uri.parse('localhost:123/foo')))
Ejemplo n.º 11
0
 def _remote_dead_letter(self, path, msg, from_):
     uri = Uri.parse(self.nodeid + path)
     ref = Ref(cell=self.guardian.lookup_cell(uri), uri=uri, is_local=True)
     Events.log(RemoteDeadLetter(ref, msg, from_))
Ejemplo n.º 12
0
def test_uri_hash():
    eq_(hash(Uri.parse('foo')), hash(Uri.parse('foo')))
    eq_(hash(Uri.parse('/foo')), hash(Uri.parse('/foo')))
    eq_(hash(Uri.parse('localhost:123/foo')), hash(Uri.parse('localhost:123/foo')))