Esempio n. 1
0
    def receive(self):
        buffer_receiver = protocol.STRING.receive()
        request = buffer_receiver.next() #pylint: disable=E1101

        while isinstance(request, protocol.Request):
            value = yield request
            request = buffer_receiver.send(value) #pylint: disable=E1101

        if not isinstance(request, protocol.Result):
            raise TypeError

        read = StringIO.StringIO(request.value).read

        routing = parse_nursery_routing(read)

        config_count = utils.read_blocking(protocol.UINT32.receive(), read)
        configs = {}

        for _ in xrange(config_count):
            cluster_id = utils.read_blocking(protocol.STRING.receive(), read)
            cluster_size = utils.read_blocking(protocol.UINT32.receive(), read)

            config = {}

            for _ in xrange(cluster_size):
                node_id = utils.read_blocking(protocol.STRING.receive(), read)
                ips = utils.read_blocking(
                    protocol.List(protocol.STRING).receive(), read)
                port = utils.read_blocking(protocol.UINT32.receive(), read)

                config[node_id] = (tuple(ips), port)

            configs[cluster_id] = config

        yield protocol.Result(NurseryConfig(routing, configs))
Esempio n. 2
0
    def test_list(self):
        '''Test encoding and decoding of list values'''

        type_ = protocol.List(protocol.BOOL)

        handle = lambda l: tuple(reversed(l))

        self._run_test(type_, (), handle)
        self._run_test(type_, (True,), handle)
        self._run_test(type_, (True, False,), handle)
Esempio n. 3
0
    def test_list(self):
        '''Test list checks'''

        type_ = protocol.List(protocol.STRING)

        self._run_test(type_, (('abc', ), True), ((
            'abc',
            'def',
        ), True), ((), True), ('abc', False), ('', False), (u'abc', False),
                       (u'', False), (('abc', None), False))
Esempio n. 4
0
    def test_complex(self):
        '''Test encoding and decoding of a complex type value'''

        type_ = protocol.Product(
            protocol.UINT32, protocol.List(protocol.STRING),
            protocol.Option(protocol.Product(
                protocol.UINT32, protocol.STRING)))

        def handler(value):
            return (value[0], tuple(reversed(value[1])), value[2])

        self._run_test(type_, ((0, ('abc', 'def',), (1, 'abc'))), handler)
        self._run_test(type_, ((0, ('abc',), None)), handler)
Esempio n. 5
0
    def test_complex(self):
        '''Test checking of a complex, nested type'''

        type_ = protocol.Product(
            protocol.UINT32, protocol.List(protocol.STRING),
            protocol.Option(protocol.Product(protocol.UINT32,
                                             protocol.STRING)))

        self._run_test(type_, ((0, (
            'abc',
            'def',
        ), (1, 'abc')), True), ((0, ('abc', ), None), True),
                       ((-1, (), None), False))
Esempio n. 6
0
        def handle_prefix_keys():
            '''Handle a "prefix_keys" command'''

            _ = recv(protocol.BOOL)
            prefix = recv(protocol.STRING)
            max_elements = recv(protocol.UINT32)

            matches = [key for key in self._values.iterkeys()
                if key.startswith(prefix)]

            matches = matches if max_elements < 0 else matches[:max_elements]

            for rbytes in protocol.UINT32.serialize(
                protocol.RESULT_SUCCESS):
                yield rbytes

            for rbytes in protocol.List(protocol.STRING).serialize(matches):
                yield rbytes