def testTwoDictsWithParray(self): import sasync.parray as parray x = PersistentDict('foo') y = PersistentDict('bar') z = PersistentArray('whatever') def first(): x['a'] = 1 y['a'] = 10 return defer.DeferredList([x.deferToWrites(), y.deferToWrites()]) def second(null): d = x['a'] d.addCallback(self.failUnlessEqual, 1) d.addCallback(lambda _: y['a']) d.addCallback(self.failUnlessEqual, 10) return d def third(null): return defer.DeferredList( [x.shutdown(), y.shutdown(), z.shutdown()]) d = first() d.addCallback(second) d.addCallback(third) return d
def testShutdown(self): def first(null): y = PersistentDict('alpha') d = y['eagle'] d.addCallback(self.failUnlessEqual, 'bald') return d x = PersistentDict('alpha') x['eagle'] = 'bald' d = x.shutdown() d.addCallback(first) return d
def testThreeSeparatePreloadedDicts(self): def first(): d1 = self.x.preload() d2 = self.y.preload() d3 = self.z.preload() d4 = defer.Deferred() reactor.callLater(0.5, d4.callback, None) return defer.DeferredList([d1,d2,d3,d4]) def second(null): self.x['a'] = 1 self.y['a'] = 10 self.z['a'] = 100 return defer.DeferredList([ self.x.deferToWrites(), self.y.deferToWrites(), self.z.deferToWrites()]) def third(null): self.failUnlessEqual(self.x['a'], 1) self.failUnlessEqual(self.y['a'], 10) self.failUnlessEqual(self.z['a'], 100) def fourth(null): def wait(): d = defer.Deferred() reactor.callLater(1.0, d.callback, None) return d def thisOneShutdown(null, objectName): print "Done shutting down PDict '%s'" % objectName dList = [] for objectName in ('x', 'y', 'z'): d1 = getattr(self, objectName).shutdown() if VERBOSE: print "\nAbout to shut down Pdict '%s'" % objectName d1.addCallback(thisOneShutdown, objectName) d2 = wait() dList.append(defer.DeferredList([d1,d2])) return defer.DeferredList(dList) self.x = PersistentDict('alpha') self.y = PersistentDict('bravo') self.z = PersistentDict('charlie') d = first() d.addCallback(second) d.addCallback(third) d.addCallback(fourth) return d
def setUp(self): def started(null): self.pit = self.p.i.t self.p.data.clear() return self.pit.deferToQueue(clear) def clear(): si = self.pit.sasync_items si.delete(si.c.group_id == ID).execute() self.p = PersistentDict(ID) d = self.p.preload() d.addCallback(started) return d
def testSequentiallyStartedDicts(self): x = PersistentDict('alpha') y = PersistentDict('bravo') def first(): d = x.preload() d.addCallback(lambda _: y.preload()) return d def second(null): x['a'] = 1 y['a'] = 10 return defer.DeferredList([x.deferToWrites(), y.deferToWrites()]) def third(null): self.failUnlessEqual(x['a'], 1) self.failUnlessEqual(y['a'], 10) return defer.DeferredList([x.shutdown(), y.shutdown()]) d = first() d.addCallback(second) d.addCallback(third) return d
def testThreeSeparatePreloadedDicts(self): def first(): d1 = self.x.preload() d2 = self.y.preload() d3 = self.z.preload() d4 = defer.Deferred() reactor.callLater(0.5, d4.callback, None) return defer.DeferredList([d1, d2, d3, d4]) def second(null): self.x['a'] = 1 self.y['a'] = 10 self.z['a'] = 100 return defer.DeferredList([ self.x.deferToWrites(), self.y.deferToWrites(), self.z.deferToWrites() ]) def third(null): self.failUnlessEqual(self.x['a'], 1) self.failUnlessEqual(self.y['a'], 10) self.failUnlessEqual(self.z['a'], 100) def fourth(null): def wait(): d = defer.Deferred() reactor.callLater(1.0, d.callback, None) return d def thisOneShutdown(null, objectName): print "Done shutting down PDict '%s'" % objectName dList = [] for objectName in ('x', 'y', 'z'): d1 = getattr(self, objectName).shutdown() if VERBOSE: print "\nAbout to shut down Pdict '%s'" % objectName d1.addCallback(thisOneShutdown, objectName) d2 = wait() dList.append(defer.DeferredList([d1, d2])) return defer.DeferredList(dList) self.x = PersistentDict('alpha') self.y = PersistentDict('bravo') self.z = PersistentDict('charlie') d = first() d.addCallback(second) d.addCallback(third) d.addCallback(fourth) return d
def testOneDictWithParray(self): import sasync.parray as parray x = PersistentDict('foo') y = PersistentArray('bar') def first(): x['a'] = 1 return x.deferToWrites() def second(null): d = x['a'] d.addCallback(self.failUnlessEqual, 1) return d def third(null): return defer.DeferredList([x.shutdown(), y.shutdown()]) d = first() d.addCallback(second) d.addCallback(third) return d
def first(null): y = PersistentDict('alpha') d = y['eagle'] d.addCallback(self.failUnlessEqual, 'bald') return d
class TestPlayNice(TestCase): def testShutdown(self): def first(null): y = PersistentDict('alpha') d = y['eagle'] d.addCallback(self.failUnlessEqual, 'bald') return d x = PersistentDict('alpha') x['eagle'] = 'bald' d = x.shutdown() d.addCallback(first) return d def testSequentiallyStartedDicts(self): x = PersistentDict('alpha') y = PersistentDict('bravo') def first(): d = x.preload() d.addCallback(lambda _: y.preload()) return d def second(null): x['a'] = 1 y['a'] = 10 return defer.DeferredList([x.deferToWrites(), y.deferToWrites()]) def third(null): self.failUnlessEqual(x['a'], 1) self.failUnlessEqual(y['a'], 10) return defer.DeferredList([x.shutdown(), y.shutdown()]) d = first() d.addCallback(second) d.addCallback(third) return d def testThreeSeparateDicts(self): def first(): self.x['a'] = 1 self.y['a'] = 10 self.z['a'] = 100 return defer.DeferredList([ self.x.deferToWrites(), self.y.deferToWrites(), self.z.deferToWrites() ]) def second(null): d = self.x['a'] d.addCallback(self.failUnlessEqual, 1) d.addCallback(lambda _: self.y['a']) d.addCallback(self.failUnlessEqual, 10) d.addCallback(lambda _: self.z['a']) d.addCallback(self.failUnlessEqual, 100) return d def third(null): def wait(): d = defer.Deferred() reactor.callLater(1.0, d.callback, None) return d def thisOneShutdown(null, objectName): print "Done shutting down PDict '%s'" % objectName dList = [] for objectName in ('x', 'y', 'z'): d1 = getattr(self, objectName).shutdown() if VERBOSE: print "\nAbout to shut down Pdict '%s'" % objectName d1.addCallback(thisOneShutdown, objectName) d2 = wait() dList.append(defer.DeferredList([d1, d2])) return defer.DeferredList(dList) self.x = PersistentDict('alpha') self.y = PersistentDict('bravo') self.z = PersistentDict('charlie') d = first() d.addCallback(second) d.addCallback(third) return d def testThreeSeparatePreloadedDicts(self): def first(): d1 = self.x.preload() d2 = self.y.preload() d3 = self.z.preload() d4 = defer.Deferred() reactor.callLater(0.5, d4.callback, None) return defer.DeferredList([d1, d2, d3, d4]) def second(null): self.x['a'] = 1 self.y['a'] = 10 self.z['a'] = 100 return defer.DeferredList([ self.x.deferToWrites(), self.y.deferToWrites(), self.z.deferToWrites() ]) def third(null): self.failUnlessEqual(self.x['a'], 1) self.failUnlessEqual(self.y['a'], 10) self.failUnlessEqual(self.z['a'], 100) def fourth(null): def wait(): d = defer.Deferred() reactor.callLater(1.0, d.callback, None) return d def thisOneShutdown(null, objectName): print "Done shutting down PDict '%s'" % objectName dList = [] for objectName in ('x', 'y', 'z'): d1 = getattr(self, objectName).shutdown() if VERBOSE: print "\nAbout to shut down Pdict '%s'" % objectName d1.addCallback(thisOneShutdown, objectName) d2 = wait() dList.append(defer.DeferredList([d1, d2])) return defer.DeferredList(dList) self.x = PersistentDict('alpha') self.y = PersistentDict('bravo') self.z = PersistentDict('charlie') d = first() d.addCallback(second) d.addCallback(third) d.addCallback(fourth) return d def testOneDictWithParray(self): import sasync.parray as parray x = PersistentDict('foo') y = PersistentArray('bar') def first(): x['a'] = 1 return x.deferToWrites() def second(null): d = x['a'] d.addCallback(self.failUnlessEqual, 1) return d def third(null): return defer.DeferredList([x.shutdown(), y.shutdown()]) d = first() d.addCallback(second) d.addCallback(third) return d def testTwoDictsWithParray(self): import sasync.parray as parray x = PersistentDict('foo') y = PersistentDict('bar') z = PersistentArray('whatever') def first(): x['a'] = 1 y['a'] = 10 return defer.DeferredList([x.deferToWrites(), y.deferToWrites()]) def second(null): d = x['a'] d.addCallback(self.failUnlessEqual, 1) d.addCallback(lambda _: y['a']) d.addCallback(self.failUnlessEqual, 10) return d def third(null): return defer.DeferredList( [x.shutdown(), y.shutdown(), z.shutdown()]) d = first() d.addCallback(second) d.addCallback(third) return d
class TestPlayNice(TestCase): def testShutdown(self): def first(null): y = PersistentDict('alpha') d = y['eagle'] d.addCallback(self.failUnlessEqual, 'bald') return d x = PersistentDict('alpha') x['eagle'] = 'bald' d = x.shutdown() d.addCallback(first) return d def testSequentiallyStartedDicts(self): x = PersistentDict('alpha') y = PersistentDict('bravo') def first(): d = x.preload() d.addCallback(lambda _: y.preload()) return d def second(null): x['a'] = 1 y['a'] = 10 return defer.DeferredList([x.deferToWrites(), y.deferToWrites()]) def third(null): self.failUnlessEqual(x['a'], 1) self.failUnlessEqual(y['a'], 10) return defer.DeferredList([x.shutdown(), y.shutdown()]) d = first() d.addCallback(second) d.addCallback(third) return d def testThreeSeparateDicts(self): def first(): self.x['a'] = 1 self.y['a'] = 10 self.z['a'] = 100 return defer.DeferredList([ self.x.deferToWrites(), self.y.deferToWrites(), self.z.deferToWrites()]) def second(null): d = self.x['a'] d.addCallback(self.failUnlessEqual, 1) d.addCallback(lambda _: self.y['a']) d.addCallback(self.failUnlessEqual, 10) d.addCallback(lambda _: self.z['a']) d.addCallback(self.failUnlessEqual, 100) return d def third(null): def wait(): d = defer.Deferred() reactor.callLater(1.0, d.callback, None) return d def thisOneShutdown(null, objectName): print "Done shutting down PDict '%s'" % objectName dList = [] for objectName in ('x', 'y', 'z'): d1 = getattr(self, objectName).shutdown() if VERBOSE: print "\nAbout to shut down Pdict '%s'" % objectName d1.addCallback(thisOneShutdown, objectName) d2 = wait() dList.append(defer.DeferredList([d1,d2])) return defer.DeferredList(dList) self.x = PersistentDict('alpha') self.y = PersistentDict('bravo') self.z = PersistentDict('charlie') d = first() d.addCallback(second) d.addCallback(third) return d def testThreeSeparatePreloadedDicts(self): def first(): d1 = self.x.preload() d2 = self.y.preload() d3 = self.z.preload() d4 = defer.Deferred() reactor.callLater(0.5, d4.callback, None) return defer.DeferredList([d1,d2,d3,d4]) def second(null): self.x['a'] = 1 self.y['a'] = 10 self.z['a'] = 100 return defer.DeferredList([ self.x.deferToWrites(), self.y.deferToWrites(), self.z.deferToWrites()]) def third(null): self.failUnlessEqual(self.x['a'], 1) self.failUnlessEqual(self.y['a'], 10) self.failUnlessEqual(self.z['a'], 100) def fourth(null): def wait(): d = defer.Deferred() reactor.callLater(1.0, d.callback, None) return d def thisOneShutdown(null, objectName): print "Done shutting down PDict '%s'" % objectName dList = [] for objectName in ('x', 'y', 'z'): d1 = getattr(self, objectName).shutdown() if VERBOSE: print "\nAbout to shut down Pdict '%s'" % objectName d1.addCallback(thisOneShutdown, objectName) d2 = wait() dList.append(defer.DeferredList([d1,d2])) return defer.DeferredList(dList) self.x = PersistentDict('alpha') self.y = PersistentDict('bravo') self.z = PersistentDict('charlie') d = first() d.addCallback(second) d.addCallback(third) d.addCallback(fourth) return d def testOneDictWithParray(self): import sasync.parray as parray x = PersistentDict('foo') y = PersistentArray('bar') def first(): x['a'] = 1 return x.deferToWrites() def second(null): d = x['a'] d.addCallback(self.failUnlessEqual, 1) return d def third(null): return defer.DeferredList([x.shutdown(), y.shutdown()]) d = first() d.addCallback(second) d.addCallback(third) return d def testTwoDictsWithParray(self): import sasync.parray as parray x = PersistentDict('foo') y = PersistentDict('bar') z = PersistentArray('whatever') def first(): x['a'] = 1 y['a'] = 10 return defer.DeferredList([x.deferToWrites(), y.deferToWrites()]) def second(null): d = x['a'] d.addCallback(self.failUnlessEqual, 1) d.addCallback(lambda _: y['a']) d.addCallback(self.failUnlessEqual, 10) return d def third(null): return defer.DeferredList([ x.shutdown(), y.shutdown(), z.shutdown()]) d = first() d.addCallback(second) d.addCallback(third) return d