Example #1
0
 def testGift(self):
     self.bob = HelperTarget("bob")
     self.bob_url = self.tubB.registerReference(self.bob)
     self.carol = HelperTarget("carol")
     self.carol_url = self.tubC.registerReference(self.carol)
     d = self.tubA.getReference(self.bob_url)
     d.addCallback(self._aliceGotBob)
     return d
Example #2
0
    def testGift(self):
        # we must start by giving Alice a reference to both Bob and Carol.

        self.bob = HelperTarget("bob")
        self.bob_url = self.tubB.registerReference(self.bob)
        self.carol = HelperTarget("carol")
        self.carol_url = self.tubC.registerReference(self.carol)

        # now, from Alice's point of view:
        d = self.tubA.getReference(self.bob_url)
        d.addCallback(self._aliceGotBob)
        return d
Example #3
0
    def testGift(self):
        # we must start by giving Alice a reference to both Bob and Carol.

        self.bob = HelperTarget("bob")
        self.bob_url = self.tubB.registerReference(self.bob)
        self.carol = HelperTarget("carol")
        self.carol_url = self.tubC.registerReference(self.carol)

        # now, from Alice's point of view:
        d = self.tubA.getReference(self.bob_url)
        d.addCallback(self._aliceGotBob)
        return d
Example #4
0
 def testRef4(self):
     # sending the same Referenceable in multiple calls will result in
     # equivalent RRs
     r = Target()
     rr, target = self.setupTarget(HelperTarget())
     d = rr.callRemote("set", obj=r)
     d.addCallback(self._testRef4_1, rr, r, target)
     return d
Example #5
0
 def testAnswer1(self):
     # also, shared objects in a return value should be shared
     r = [1, 2]
     rr, target = self.setupTarget(HelperTarget())
     target.obj = (r, r)
     d = rr.callRemote("get")
     d.addCallback(lambda res: self.failUnlessIdentical(res[0], res[1]))
     return d
Example #6
0
 def testAnswer2(self):
     # but objects returned by separate method calls should be distinct
     rr, target = self.setupTarget(HelperTarget())
     r = [1, 2]
     target.obj = r
     d = rr.callRemote("get")
     d.addCallback(self._testAnswer2_1, rr, target)
     return d
Example #7
0
 def testDisconnect2(self):
     rr, target = self.setupTarget(HelperTarget())
     self.lost = 0
     rr.notifyOnDisconnect(self.disconnected)
     rr.tracker.broker.transport.loseConnection(CONNECTION_LOST)
     d = eventually()
     d.addCallback(lambda res: self.failUnless(self.lost))
     return d
Example #8
0
 def testDisconnect1(self):
     rr, target = self.setupTarget(HelperTarget())
     d = rr.callRemote("hang")
     e = RuntimeError("lost connection")
     rr.tracker.broker.transport.loseConnection(e)
     d.addCallbacks(lambda res: self.fail("should have failed"),
                    lambda why: why.trap(RuntimeError) and None)
     return d
Example #9
0
 def send(self, arg):
     rr, target = self.setupTarget(HelperTarget())
     d = rr.callRemote("set", obj=arg)
     d.addCallback(self.failUnless)
     # some of these tests require that we return a Failure object, so we
     # have to wrap this in a tuple to survive the Deferred.
     d.addCallback(lambda res: (target.obj, ))
     return d
Example #10
0
 def testArgs2(self):
     # but sending them as multiple arguments of the *same* method call
     # results in identical objects
     r = [1, 2]
     rr, target = self.setupTarget(HelperTarget())
     d = rr.callRemote("set2", obj1=r, obj2=r)
     d.addCallback(self._testArgs2_1, rr, target)
     return d
Example #11
0
class Test3Way(unittest.TestCase):
    def setUp(self):
        self.services = [pb.PBService(), pb.PBService(), pb.PBService()]
        self.tubA, self.tubB, self.tubC = self.services
        for s in self.services:
            s.startService()
            l = s.listenOn("tcp:0:interface=127.0.0.1")
            s.setLocation("localhost:%d" % l.getPortnum())
    def tearDown(self):
        return defer.DeferredList([s.stopService() for s in self.services])
    def testGift(self):
        self.bob = HelperTarget("bob")
        self.bob_url = self.tubB.registerReference(self.bob)
        self.carol = HelperTarget("carol")
        self.carol_url = self.tubC.registerReference(self.carol)
        d = self.tubA.getReference(self.bob_url)
        d.addCallback(self._aliceGotBob)
        return d
    testGift.timeout = 2
    def _aliceGotBob(self, abob):
        self.abob = abob # Alice's reference to Bob
        d = self.tubA.getReference(self.carol_url)
        d.addCallback(self._aliceGotCarol)
        return d
    def _aliceGotCarol(self, acarol):
        self.acarol = acarol # Alice's reference to Carol
        d2 = self.bob.waitfor()
        d = self.abob.callRemote("set", obj=self.acarol) # send the gift
        d.addCallback(lambda res: d2)
        d.addCallback(self._bobGotCarol)
        return d
    def _bobGotCarol(self, bcarol):
        self.bcarol = bcarol
        brokerAB = self.abob.tracker.broker
        self.failIf(brokerAB.myGifts)
        self.failIf(brokerAB.myGiftsByGiftID)
        d2 = self.carol.waitfor()
        d = self.bcarol.callRemote("set", obj=12)
        d.addCallback(lambda res: d2)
        d.addCallback(self._carolCalled)
        return d
    def _carolCalled(self, res):
        self.failUnlessEqual(res, 12)
Example #12
0
    def NOTtestRemoteRef1(self):
        # known URLRemoteReferences turn into Referenceables
        root = Target()
        rr, target = self.setupTarget(HelperTarget())
        self.targetBroker.factory = pb.PBServerFactory(root)
        urlRRef = self.callingBroker.remoteReferenceForName("", [])
        # urlRRef points at root
        d = rr.callRemote("set", obj=urlRRef)
        self.failUnless(dr(d))

        self.failUnlessIdentical(target.obj, root)
Example #13
0
 def testArgs1(self):
     # sending the same non-Referenceable object in multiple calls results
     # in distinct objects, because the serialization scope is bounded by
     # each method call
     r = [1, 2]
     rr, target = self.setupTarget(HelperTarget())
     d = rr.callRemote("set", obj=r)
     d.addCallback(self._testArgs1_1, rr, r, target)
     # TODO: also make sure the original list goes out of scope once the
     # method call has finished, to guard against a leaky
     # reference-tracking implementation.
     return d
Example #14
0
 def NOTtestRemoteRef2(self):
     # unknown URLRemoteReferences are errors
     root = Target()
     rr, target = self.setupTarget(HelperTarget())
     self.targetBroker.factory = pb.PBServerFactory(root)
     urlRRef = self.callingBroker.remoteReferenceForName("bogus", [])
     # urlRRef points at nothing
     d = rr.callRemote("set", obj=urlRRef)
     f = de(d)
     #print f
     #self.failUnlessEqual(f.type, tokens.Violation)
     self.failUnlessEqual(type(f.value), str)
     self.failUnless(f.value.find("unknown clid 'bogus'") != -1)
Example #15
0
class Test3Way(unittest.TestCase):
    # Here we test the three-party introduction process as depicted in the
    # classic Granovetter diagram. Alice has a reference to Bob and another
    # one to Carol. Alice wants to give her Carol-reference to Bob, by
    # including it as the argument to a method she invokes on her
    # Bob-reference.

    def setUp(self):
        self.services = [pb.PBService(), pb.PBService(), pb.PBService()]
        self.tubA, self.tubB, self.tubC = self.services
        for s in self.services:
            s.startService()
            l = s.listenOn("tcp:0:interface=127.0.0.1")
            s.setLocation("localhost:%d" % l.getPortnum())

    def tearDown(self):
        return defer.DeferredList([s.stopService() for s in self.services])

    def testGift(self):
        # we must start by giving Alice a reference to both Bob and Carol.

        self.bob = HelperTarget("bob")
        self.bob_url = self.tubB.registerReference(self.bob)
        self.carol = HelperTarget("carol")
        self.carol_url = self.tubC.registerReference(self.carol)

        # now, from Alice's point of view:
        d = self.tubA.getReference(self.bob_url)
        d.addCallback(self._aliceGotBob)
        return d

    testGift.timeout = 2

    def _aliceGotBob(self, abob):
        self.abob = abob  # Alice's reference to Bob
        d = self.tubA.getReference(self.carol_url)
        d.addCallback(self._aliceGotCarol)
        return d

    def _aliceGotCarol(self, acarol):
        self.acarol = acarol  # Alice's reference to Carol
        d2 = self.bob.waitfor()
        d = self.abob.callRemote("set", obj=self.acarol)  # send the gift
        # TODO: at this point, 'del self.acarol' should not lose alice's
        # reference to carol, because it will still be in the gift table. The
        # trick is how to test that, we would need a way to stall the gift
        # delivery while we verify everything
        d.addCallback(lambda res: d2)
        d.addCallback(self._bobGotCarol)
        return d

    def _bobGotCarol(self, bcarol):
        # Bob has received the gift
        self.bcarol = bcarol
        #  alice's gift table should be empty
        brokerAB = self.abob.tracker.broker
        self.failIf(brokerAB.myGifts)
        self.failIf(brokerAB.myGiftsByGiftID)

        d2 = self.carol.waitfor()
        d = self.bcarol.callRemote("set", obj=12)
        d.addCallback(lambda res: d2)
        d.addCallback(self._carolCalled)
        return d

    def _carolCalled(self, res):
        self.failUnlessEqual(res, 12)
Example #16
0
class Test3Way(unittest.TestCase):
    # Here we test the three-party introduction process as depicted in the
    # classic Granovetter diagram. Alice has a reference to Bob and another
    # one to Carol. Alice wants to give her Carol-reference to Bob, by
    # including it as the argument to a method she invokes on her
    # Bob-reference.

    def setUp(self):
        self.services = [pb.PBService(), pb.PBService(), pb.PBService()]
        self.tubA, self.tubB, self.tubC = self.services
        for s in self.services:
            s.startService()
            l = s.listenOn("tcp:0:interface=127.0.0.1")
            s.setLocation("localhost:%d" % l.getPortnum())

    def tearDown(self):
        return defer.DeferredList([s.stopService() for s in self.services])

    def testGift(self):
        # we must start by giving Alice a reference to both Bob and Carol.

        self.bob = HelperTarget("bob")
        self.bob_url = self.tubB.registerReference(self.bob)
        self.carol = HelperTarget("carol")
        self.carol_url = self.tubC.registerReference(self.carol)

        # now, from Alice's point of view:
        d = self.tubA.getReference(self.bob_url)
        d.addCallback(self._aliceGotBob)
        return d
    testGift.timeout = 2

    def _aliceGotBob(self, abob):
        self.abob = abob # Alice's reference to Bob
        d = self.tubA.getReference(self.carol_url)
        d.addCallback(self._aliceGotCarol)
        return d

    def _aliceGotCarol(self, acarol):
        self.acarol = acarol # Alice's reference to Carol
        d2 = self.bob.waitfor()
        d = self.abob.callRemote("set", obj=self.acarol) # send the gift
        # TODO: at this point, 'del self.acarol' should not lose alice's
        # reference to carol, because it will still be in the gift table. The
        # trick is how to test that, we would need a way to stall the gift
        # delivery while we verify everything
        d.addCallback(lambda res: d2)
        d.addCallback(self._bobGotCarol)
        return d

    def _bobGotCarol(self, bcarol):
        # Bob has received the gift
        self.bcarol = bcarol
        #  alice's gift table should be empty
        brokerAB = self.abob.tracker.broker
        self.failIf(brokerAB.myGifts)
        self.failIf(brokerAB.myGiftsByGiftID)

        d2 = self.carol.waitfor()
        d = self.bcarol.callRemote("set", obj=12)
        d.addCallback(lambda res: d2)
        d.addCallback(self._carolCalled)
        return d

    def _carolCalled(self, res):
        self.failUnlessEqual(res, 12)
Example #17
0
 def testDefer(self):
     rr, target = self.setupTarget(HelperTarget())
     d = rr.callRemote("defer", obj=12)
     d.addCallback(lambda res: self.failUnlessEqual(res, 12))
     return d
Example #18
0
 def testUnsendable(self):
     rr, target = self.setupTarget(HelperTarget())
     d = rr.callRemote("set", obj=Unsendable())
     d.addCallbacks(lambda res: self.fail("should have failed"),
                    self._testUnsendable_1)
     return d
Example #19
0
 def send(self, arg):
     rr, target = self.setupTarget(HelperTarget())
     d = rr.callRemote("set", obj=arg)
     d.addCallback(self.failUnless)
     d.addCallback(lambda res: target.obj)
     return d
Example #20
0
 def send2(self, arg1, arg2):
     rr, target = self.setupTarget(HelperTarget())
     d = rr.callRemote("set2", obj1=arg1, obj2=arg2)
     d.addCallback(self.failUnless)
     d.addCallback(lambda res: (target.obj1, target.obj2))
     return d
Example #21
0
 def echo(self, arg):
     rr, target = self.setupTarget(HelperTarget())
     d = rr.callRemote("echo", obj=arg)
     return d