コード例 #1
0
 def testPushPullSerialized(self):
     objs = [10,"hi there",1.2342354,{"p":(1,2)}]
     d = defer.succeed(None)
     for o in objs:
         self.engine.pushSerialized(key=newserialized.serialize(o))
         value = self.engine.pullSerialized('key')
         value.addCallback(lambda serial: newserialized.IUnSerialized(serial).getObject())
         d = self.assertDeferredEquals(value,o,d)
     return d
コード例 #2
0
 def pushSerialized(self, **sNamespace):
     ns = {}
     for k, v in sNamespace.iteritems():
         try:
             unserialized = newserialized.IUnSerialized(v)
             ns[k] = unserialized.getObject()
         except:
             return defer.fail()
     return defer.execute(self.shell.update, ns)
コード例 #3
0
    def pushSerialized(self, **sNamespace):
        msg = """engine %r
method: pushSerialized(**sNamespace)
sNamespace.keys() = %r""" % (self.id, sNamespace.keys())
        ns = {}
        for k, v in sNamespace.iteritems():
            try:
                unserialized = newserialized.IUnSerialized(v)
                ns[k] = unserialized.getObject()
            except:
                return defer.fail()
        return self.executeAndRaise(msg, self.shell.push, **ns)
コード例 #4
0
 def push_serialized(self, sNamespace):
     msg = {'engineid':self.id,
            'method':'push_serialized',
            'args':[repr(sNamespace.keys())]}       
     ns = {}
     for k,v in sNamespace.iteritems():
         try:
             unserialized = newserialized.IUnSerialized(v)
             ns[k] = unserialized.getObject()
         except:
             return defer.fail()
     return self.executeAndRaise(msg, self.shell.push, ns)
コード例 #5
0
 def testPushPullSerialized(self):
     self.addEngine(1)
     dikt = dict(a=10,b='hi there',c=1.2345,d={'p':(1,2)})
     sdikt = {}
     for k,v in dikt.iteritems():
         sdikt[k] = newserialized.serialize(v)
     d = self.multiengine.push_serialized(dict(a=sdikt['a']), targets=0)
     d.addCallback(lambda _: self.multiengine.pull('a',targets=0))
     d.addCallback(lambda r: self.assertEquals(r[0], dikt['a']))
     d.addCallback(lambda _: self.multiengine.pull_serialized('a', targets=0))
     d.addCallback(lambda serial: newserialized.IUnSerialized(serial[0]).getObject())
     d.addCallback(lambda r: self.assertEquals(r, dikt['a']))
     d.addCallback(lambda _: self.multiengine.push_serialized(sdikt, targets=0))
     d.addCallback(lambda _: self.multiengine.pull_serialized(sdikt.keys(), targets=0))
     d.addCallback(lambda serial: [newserialized.IUnSerialized(s).getObject() for s in serial[0]])
     d.addCallback(lambda r: self.assertEquals(r, dikt.values()))
     d.addCallback(lambda _: self.multiengine.reset(targets=0))
     d.addCallback(lambda _: self.multiengine.pull_serialized('a', targets=0))
     d.addErrback(lambda f: self.assertRaises(NameError, _raise_it, f))
     
     # Non-blocking mode
     d.addCallback(lambda r: self.multiengine.push_serialized(dict(a=sdikt['a']), targets=0, block=False))
     d.addCallback(lambda did: self.multiengine.get_pending_deferred(did, True))
     d.addCallback(lambda _: self.multiengine.pull('a',targets=0))
     d.addCallback(lambda r: self.assertEquals(r[0], dikt['a']))
     d.addCallback(lambda _: self.multiengine.pull_serialized('a', targets=0, block=False))
     d.addCallback(lambda did: self.multiengine.get_pending_deferred(did, True))
     d.addCallback(lambda serial: newserialized.IUnSerialized(serial[0]).getObject())
     d.addCallback(lambda r: self.assertEquals(r, dikt['a']))
     d.addCallback(lambda _: self.multiengine.push_serialized(sdikt, targets=0, block=False))
     d.addCallback(lambda did: self.multiengine.get_pending_deferred(did, True))
     d.addCallback(lambda _: self.multiengine.pull_serialized(sdikt.keys(), targets=0, block=False))
     d.addCallback(lambda did: self.multiengine.get_pending_deferred(did, True))
     d.addCallback(lambda serial: [newserialized.IUnSerialized(s).getObject() for s in serial[0]])
     d.addCallback(lambda r: self.assertEquals(r, dikt.values()))
     d.addCallback(lambda _: self.multiengine.reset(targets=0))
     d.addCallback(lambda _: self.multiengine.pull_serialized('a', targets=0, block=False))
     d.addCallback(lambda did: self.multiengine.get_pending_deferred(did, True))
     d.addErrback(lambda f: self.assertRaises(NameError, _raise_it, f))
     return d
コード例 #6
0
 def testPushPullSerialized(self):
     self.addEngine(1)
     objs = [10,"hi there",1.2342354,{"p":(1,2)}]        
     d = self.multiengine.push_serialized(dict(key=newserialized.serialize(objs[0])), targets=0)
     d.addCallback(lambda _: self.multiengine.pull_serialized('key', targets=0))
     d.addCallback(lambda serial: newserialized.IUnSerialized(serial[0]).getObject())
     d.addCallback(lambda r: self.assertEquals(r, objs[0]))
     d.addCallback(lambda _: self.multiengine.push_serialized(dict(key=newserialized.serialize(objs[1])), targets=0))
     d.addCallback(lambda _: self.multiengine.pull_serialized('key', targets=0))
     d.addCallback(lambda serial: newserialized.IUnSerialized(serial[0]).getObject())
     d.addCallback(lambda r: self.assertEquals(r, objs[1]))
     d.addCallback(lambda _: self.multiengine.push_serialized(dict(key=newserialized.serialize(objs[2])), targets=0))
     d.addCallback(lambda _: self.multiengine.pull_serialized('key', targets=0))
     d.addCallback(lambda serial: newserialized.IUnSerialized(serial[0]).getObject())
     d.addCallback(lambda r: self.assertEquals(r, objs[2]))        
     d.addCallback(lambda _: self.multiengine.push_serialized(dict(key=newserialized.serialize(objs[3])), targets=0))
     d.addCallback(lambda _: self.multiengine.pull_serialized('key', targets=0))
     d.addCallback(lambda serial: newserialized.IUnSerialized(serial[0]).getObject())
     d.addCallback(lambda r: self.assertEquals(r, objs[3]))
     d.addCallback(lambda _: self.multiengine.push(dict(a=10,b=range(5)), targets=0))
     d.addCallback(lambda _: self.multiengine.pull_serialized(('a','b'), targets=0))
     d.addCallback(lambda serial: [newserialized.IUnSerialized(s).getObject() for s in serial[0]])
     d.addCallback(lambda r: self.assertEquals(r, [10, range(5)]))
     d.addCallback(lambda _: self.multiengine.reset(targets=0))
     d.addCallback(lambda _: self.multiengine.pull_serialized('a', targets=0))
     d.addErrback(lambda f: self.assertRaises(NameError, _raise_it, f))
     return d
     
     objs = [10,"hi there",1.2342354,{"p":(1,2)}]    
     d = defer.succeed(None)
     for o in objs:
         self.multiengine.push_serialized(0, key=newserialized.serialize(o))
         value = self.multiengine.pull_serialized(0, 'key')
         value.addCallback(lambda serial: newserialized.IUnSerialized(serial[0]).getObject())
         d = self.assertDeferredEquals(value,o,d)
     return d