Пример #1
0
    def _socket_connect(self, tracer):
        """
        Connects to the socket or raise a QdbFailedToConnect error.
        """
        log.info('Connecting to (%s, %d)' % tracer.address)

        for n in range(tracer.retry_attepts):
            # Try to connect to the server.
            try:
                self.socket = socket.create_connection(tracer.address)
                # If we made it here, we connected and no longer need to retry.
                break
            except socket.error:
                log.warn(
                    'Client %s failed to connect to (%s, %d) on attempt %d...'
                    % (tracer.uuid, tracer.address[0],
                       tracer.address[1], n + 1)
                )
        if self.socket is None:
            log.warn(
                'Failed to connect to (%s, %d), no longer retying.'
                % tracer.address
            )
            raise QdbFailedToConnect(
                tracer.address,
                tracer.retry_attepts
            )
        log.info('Client %s connected to (%s, %d)'
                 % (tracer.uuid, tracer.address[0],
                    tracer.address[1]))
Пример #2
0
Файл: comm.py Проект: wixb50/qdb
    def _socket_connect(self, tracer):
        """
        Connects to the socket or raise a QdbFailedToConnect error.
        """
        log.info('Connecting to (%s, %d)' % tracer.address)

        for n in range(tracer.retry_attepts):
            # Try to connect to the server.
            try:
                self.socket = socket.create_connection(tracer.address)
                # If we made it here, we connected and no longer need to retry.
                break
            except socket.error:
                log.warn(
                    'Client %s failed to connect to (%s, %d) on attempt %d...'
                    % (tracer.uuid, tracer.address[0],
                       tracer.address[1], n + 1)
                )
        if self.socket is None:
            log.warn(
                'Failed to connect to (%s, %d), no longer retying.'
                % tracer.address
            )
            raise QdbFailedToConnect(
                tracer.address,
                tracer.retry_attepts
            )
        log.info('Client %s connected to (%s, %d)'
                 % (tracer.uuid, tracer.address[0],
                    tracer.address[1]))
Пример #3
0
    def test_file_cache_from_string(self):
        """
        Asserts that manual caching from a string works.
        """
        contents = dedent("""\
            line 1
            line 2
            line 3
            line 4
            """)
        db = Qdb(cmd_manager=NopCommandManager())
        db.cache_file('file', contents=contents)

        # Check the whole 'file'.
        self.assertEquals(db.get_file('file'), contents[:-1])  # drop '\n'

        for n in range(1, 5):
            # Check all the lines.
            self.assertEquals('line %d' % n, db.get_line('file', n))
Пример #4
0
    def test_file_cache_from_string(self):
        """
        Asserts that manual caching from a string works.
        """
        contents = dedent(
            """\
            line 1
            line 2
            line 3
            line 4
            """
        )
        db = Qdb(cmd_manager=NopCommandManager())
        db.cache_file('file', contents=contents)

        # Check the whole 'file'.
        self.assertEquals(db.get_file('file'), contents[:-1])  # drop '\n'

        for n in range(1, 5):
            # Check all the lines.
            self.assertEquals('line %d' % n, db.get_line('file', n))