예제 #1
0
    def test_referenceable(self):
        t1 = Tub()
        t1.setServiceParent(self.s)
        l = t1.listenOn("tcp:0:interface=127.0.0.1")
        t1.setLocation("127.0.0.1:%d" % l.getPortnum())
        r1 = Referenceable()
        # the serialized blob can't keep the reference alive, so you must
        # arrange for that separately
        t1.registerReference(r1)
        t2 = Tub()
        t2.setServiceParent(self.s)
        obj = ("graph tangly", r1)
        d = t1.serialize(obj)
        del r1
        del obj

        def _done(data):
            self.failUnless("their-reference" in data)
            return data

        d.addCallback(_done)
        d.addCallback(lambda data: t2.unserialize(data))

        def _check(obj2):
            self.failUnlessEqual(obj2[0], "graph tangly")
            self.failUnless(isinstance(obj2[1], RemoteReference))

        d.addCallback(_check)
        return d
예제 #2
0
 def test_referenceable(self):
     t1 = Tub()
     t1.setServiceParent(self.s)
     portnum = allocate_tcp_port()
     t1.listenOn("tcp:%d:interface=127.0.0.1" % portnum)
     t1.setLocation("127.0.0.1:%d" % portnum)
     r1 = Referenceable()
     # the serialized blob can't keep the reference alive, so you must
     # arrange for that separately
     t1.registerReference(r1)
     t2 = Tub()
     t2.setServiceParent(self.s)
     obj = ("graph tangly", r1)
     d = t1.serialize(obj)
     del r1; del obj
     def _done(data):
         self.failUnless("their-reference" in data)
         return data
     d.addCallback(_done)
     d.addCallback(lambda data: t2.unserialize(data))
     def _check(obj2):
         self.failUnlessEqual(obj2[0], "graph tangly")
         self.failUnless(isinstance(obj2[1], RemoteReference))
     d.addCallback(_check)
     return d
예제 #3
0
 def test_referenceables_die(self):
     # serialized data will not keep the referenceable alive
     t1 = Tub()
     t1.setServiceParent(self.s)
     l = t1.listenOn("tcp:0:interface=127.0.0.1")
     t1.setLocation("127.0.0.1:%d" % l.getPortnum())
     r1 = Referenceable()
     t2 = Tub()
     t2.setServiceParent(self.s)
     obj = ("graph tangly", r1)
     d = t1.serialize(obj)
     del r1
     del obj
     gc.collect()
     d.addCallback(lambda data: self.shouldFail(
         KeyError, "test_referenceables_die",
         "unable to find reference for name", t2.unserialize, data))
     return d
예제 #4
0
 def test_referenceables_die(self):
     # serialized data will not keep the referenceable alive
     t1 = Tub()
     t1.setServiceParent(self.s)
     l = t1.listenOn("tcp:0:interface=127.0.0.1")
     t1.setLocation("127.0.0.1:%d" % l.getPortnum())
     r1 = Referenceable()
     t2 = Tub()
     t2.setServiceParent(self.s)
     obj = ("graph tangly", r1)
     d = t1.serialize(obj)
     del r1; del obj
     gc.collect()
     d.addCallback(lambda data:
                   self.shouldFail(KeyError, "test_referenceables_die",
                                   "unable to find reference for name",
                                   t2.unserialize, data))
     return d
예제 #5
0
    def test_referenceable(self):
        t1 = Tub()
        t1.setServiceParent(self.s)

        portnum = allocate_tcp_port()

        t1.listenOn('tcp:%d:interface=127.0.0.1' % portnum)
        t1.setLocation('127.0.0.1:%d' % portnum)

        r1 = Referenceable()

        # the serialized blob can't keep the reference alive, so you must
        # arrange for that separately

        t1.registerReference(r1)

        t2 = Tub()
        t2.setServiceParent(self.s)

        obj = ('graph tangly', r1)
        d = t1.serialize(obj)

        del r1, obj

        def _done(data):
            self.assertIn(b'their-reference', data)
            return data

        d.addCallback(_done)
        d.addCallback(t2.unserialize)

        def _check(obj2):
            self.assertEqual(obj2[0], 'graph tangly')
            self.assertTrue(isinstance(obj2[1], RemoteReference))

        return d.addCallback(_check)