Example #1
0
    def main(self):
        def _watch(w):
            for m in w.wait(self.apiroutine):
                yield m
            print('Watcher returns:', dump(self.apiroutine.retvalue))

        def _watchall(watchers):
            for w in watchers:
                if w is not None:
                    self.apiroutine.subroutine(_watch(w))

        self.apiroutine.subroutine(self.watcher(), False, daemon=True)
        up = ZooKeeperSessionStateChanged.createMatcher(
            ZooKeeperSessionStateChanged.CREATED, self.client)
        yield (up, )
        print('Connection is up: %r' % (self.client.currentserver, ))
        for m in self.client.requests(
            [zk.create(b'/vlcptest', b'test'),
             zk.getdata(b'/vlcptest', True)], self.apiroutine):
            yield m
        print(self.apiroutine.retvalue)
        pprint(dump(self.apiroutine.retvalue[0]))
        _watchall(self.apiroutine.retvalue[3])
        for m in self.apiroutine.waitWithTimeout(0.2):
            yield m
        for m in self.client.requests(
            [zk.delete(b'/vlcptest'),
             zk.getdata(b'/vlcptest', watch=True)], self.apiroutine):
            yield m
        print(self.apiroutine.retvalue)
        pprint(dump(self.apiroutine.retvalue[0]))
        _watchall(self.apiroutine.retvalue[3])
        for m in self.client.requests([
                zk.multi(zk.multi_create(b'/vlcptest2', b'test'),
                         zk.multi_create(b'/vlcptest2/subtest', 'test2')),
                zk.getchildren2(b'/vlcptest2', True)
        ], self.apiroutine):
            yield m
        print(self.apiroutine.retvalue)
        pprint(dump(self.apiroutine.retvalue[0]))
        _watchall(self.apiroutine.retvalue[3])
        for m in self.client.requests([
                zk.multi(zk.multi_delete(b'/vlcptest2/subtest'),
                         zk.multi_delete(b'/vlcptest2')),
                zk.getchildren2(b'/vlcptest2', True)
        ], self.apiroutine):
            yield m
        print(self.apiroutine.retvalue)
        pprint(dump(self.apiroutine.retvalue[0]))
        _watchall(self.apiroutine.retvalue[3])
Example #2
0
 def main(self):
     self.apiroutine.subroutine(self.watcher(), False, daemon=True)
     up = ZooKeeperConnectionStateEvent.createMatcher(
         ZooKeeperConnectionStateEvent.UP, self.client)
     notconn = ZooKeeperConnectionStateEvent.createMatcher(
         ZooKeeperConnectionStateEvent.NOTCONNECTED, self.client)
     yield (up, notconn)
     if self.apiroutine.matcher is notconn:
         print('Not connected')
         return
     else:
         print('Connection is up: %r' % (self.client, ))
     # Handshake
     for m in self.protocol.handshake(
             self.client,
             zk.ConnectRequest(
                 timeOut=int(self.sessiontimeout * 1000),
                 passwd=b'\x00' * 16,  # Why is it necessary...
             ),
             self.apiroutine,
         []):
         yield m
     for m in self.protocol.requests(
             self.client,
         [zk.create(b'/vlcptest', b'test'),
          zk.getdata(b'/vlcptest', True)], self.apiroutine):
         yield m
     pprint(dump(self.apiroutine.retvalue[0]))
     for m in self.apiroutine.waitWithTimeout(0.2):
         yield m
     for m in self.protocol.requests(
             self.client,
         [zk.delete(b'/vlcptest'),
          zk.getdata(b'/vlcptest', watch=True)], self.apiroutine):
         yield m
     pprint(dump(self.apiroutine.retvalue[0]))
     for m in self.protocol.requests(self.client, [
             zk.multi(zk.multi_create(b'/vlcptest2', b'test'),
                      zk.multi_create(b'/vlcptest2/subtest', 'test2')),
             zk.getchildren2(b'/vlcptest2', True)
     ], self.apiroutine):
         yield m
     pprint(dump(self.apiroutine.retvalue[0]))
     for m in self.protocol.requests(self.client, [
             zk.multi(zk.multi_delete(b'/vlcptest2/subtest'),
                      zk.multi_delete(b'/vlcptest2')),
             zk.getchildren2(b'/vlcptest2', True)
     ], self.apiroutine):
         yield m
     pprint(dump(self.apiroutine.retvalue[0]))
Example #3
0
 def main(self):
     def _watch(w):
         for m in w.wait(self.apiroutine):
             yield m
         print('Watcher returns:', dump(self.apiroutine.retvalue))
     def _watchall(watchers):
         for w in watchers:
             if w is not None:
                 self.apiroutine.subroutine(_watch(w))
     self.apiroutine.subroutine(self.watcher(), False, daemon = True)
     up = ZooKeeperSessionStateChanged.createMatcher(ZooKeeperSessionStateChanged.CREATED, self.client)
     yield (up,)
     print('Connection is up: %r' % (self.client.currentserver,))
     for m in self.client.requests([zk.create(b'/vlcptest', b'test'),
                                    zk.getdata(b'/vlcptest', True)], self.apiroutine):
         yield m
     print(self.apiroutine.retvalue)
     pprint(dump(self.apiroutine.retvalue[0]))
     _watchall(self.apiroutine.retvalue[3])
     for m in self.apiroutine.waitWithTimeout(0.2):
         yield m
     for m in self.client.requests([zk.delete(b'/vlcptest'),
                                     zk.getdata(b'/vlcptest', watch = True)], self.apiroutine):
         yield m
     print(self.apiroutine.retvalue)
     pprint(dump(self.apiroutine.retvalue[0]))
     _watchall(self.apiroutine.retvalue[3])
     for m in self.client.requests([zk.multi(
                                     zk.multi_create(b'/vlcptest2', b'test'),
                                     zk.multi_create(b'/vlcptest2/subtest', 'test2')
                                 ),
                               zk.getchildren2(b'/vlcptest2', True)], self.apiroutine):
         yield m
     print(self.apiroutine.retvalue)
     pprint(dump(self.apiroutine.retvalue[0]))
     _watchall(self.apiroutine.retvalue[3])
     for m in self.client.requests([zk.multi(
                                     zk.multi_delete(b'/vlcptest2/subtest'),
                                     zk.multi_delete(b'/vlcptest2')),
                               zk.getchildren2(b'/vlcptest2', True)], self.apiroutine):
         yield m
     print(self.apiroutine.retvalue)
     pprint(dump(self.apiroutine.retvalue[0]))
     _watchall(self.apiroutine.retvalue[3])
Example #4
0
    async def main(self):
        async def _watch(w):
            r = await w.wait(self.apiroutine)
            print('Watcher returns:', dump(r))

        async def _watchall(watchers):
            for w in watchers:
                if w is not None:
                    self.apiroutine.subroutine(_watch(w))

        self.apiroutine.subroutine(self.watcher(), False, daemon=True)
        up = ZooKeeperSessionStateChanged.createMatcher(
            ZooKeeperSessionStateChanged.CREATED, self.client)
        await up
        print('Connection is up: %r' % (self.client.currentserver, ))
        r = await self.client.requests(
            [zk.create(b'/vlcptest', b'test'),
             zk.getdata(b'/vlcptest', True)], self.apiroutine)
        print(r)
        pprint(dump(r[0]))
        _watchall(r[3])
        await self.apiroutine.wait_with_timeout(0.2)
        r = await self.client.requests(
            [zk.delete(b'/vlcptest'),
             zk.getdata(b'/vlcptest', watch=True)], self.apiroutine)
        print(r)
        pprint(dump(r[0]))
        _watchall(r[3])
        r = await self.client.requests([
            zk.multi(zk.multi_create(b'/vlcptest2', b'test'),
                     zk.multi_create(b'/vlcptest2/subtest', 'test2')),
            zk.getchildren2(b'/vlcptest2', True)
        ], self.apiroutine)
        print(r)
        pprint(dump(r[0]))
        _watchall(r[3])
        r = await self.client.requests([
            zk.multi(zk.multi_delete(b'/vlcptest2/subtest'),
                     zk.multi_delete(b'/vlcptest2')),
            zk.getchildren2(b'/vlcptest2', True)
        ], self.apiroutine)
        print(r)
        pprint(dump(r[0]))
        _watchall(r[3])
Example #5
0
 def main(self):
     self.apiroutine.subroutine(self.watcher(), False, daemon = True)
     up = ZooKeeperConnectionStateEvent.createMatcher(ZooKeeperConnectionStateEvent.UP, self.client)
     notconn = ZooKeeperConnectionStateEvent.createMatcher(ZooKeeperConnectionStateEvent.NOTCONNECTED, self.client)
     yield (up, notconn)
     if self.apiroutine.matcher is notconn:
         print('Not connected')
         return
     else:
         print('Connection is up: %r' % (self.client,))
     # Handshake
     for m in self.protocol.handshake(self.client, zk.ConnectRequest(
                                                     timeOut = int(self.sessiontimeout * 1000),
                                                     passwd = b'\x00' * 16,      # Why is it necessary...
                                                 ), self.apiroutine, []):
         yield m
     for m in self.protocol.requests(self.client, [zk.create(b'/vlcptest', b'test'),
                                                   zk.getdata(b'/vlcptest', True)], self.apiroutine):
         yield m
     pprint(dump(self.apiroutine.retvalue[0]))
     for m in self.apiroutine.waitWithTimeout(0.2):
         yield m
     for m in self.protocol.requests(self.client, [zk.delete(b'/vlcptest'),
                                                   zk.getdata(b'/vlcptest', watch = True)], self.apiroutine):
         yield m
     pprint(dump(self.apiroutine.retvalue[0]))
     for m in self.protocol.requests(self.client, [zk.multi(
                                                         zk.multi_create(b'/vlcptest2', b'test'),
                                                         zk.multi_create(b'/vlcptest2/subtest', 'test2')
                                                     ),
                                                   zk.getchildren2(b'/vlcptest2', True)], self.apiroutine):
         yield m
     pprint(dump(self.apiroutine.retvalue[0]))
     for m in self.protocol.requests(self.client, [zk.multi(
                                                         zk.multi_delete(b'/vlcptest2/subtest'),
                                                         zk.multi_delete(b'/vlcptest2')),
                                                   zk.getchildren2(b'/vlcptest2', True)], self.apiroutine):
         yield m
     pprint(dump(self.apiroutine.retvalue[0]))