Example #1
0
    def test_write_and_reconnect(self):
        with scribed_sandbox(self.scribe_port, self.scribe_logdir):
            logger = self.create_logger()
            logger.log_line('foo', '1')
            logger.log_line('foo', '2')
            logger.log_line('foo', u'ā˜ƒ')
            wait_on_log_data(
                get_log_path(self.scribe_logdir, 'foo'),
                u'1\n2\nā˜ƒ\n'.encode('UTF-8'),
            )

        # make sure we haven't logged any errors
        assert not any(is_error for (is_error, msg) in self.status_reports)

        # write some more data, make sure we ignore that scribe server is
        # down, don't block too long
        self.timed_writes(logger, 10000, 2.0)

        # make sure we didn't log too many error reports
        assert len(self.status_reports) < 10
        # make sure we did log at least one error
        assert any(is_error for (is_error, msg) in self.status_reports)

        with scribed_sandbox(self.scribe_port, self.scribe_logdir):
            logger.log_line('foo', '3')
            logger.log_line('foo', '4')
            wait_on_log_data(
                get_log_path(self.scribe_logdir, 'foo'),
                u'1\n2\nā˜ƒ\n3\n4\n'.encode('UTF-8'),
            )
    def setup_sandbox(self):
        self.scribe_logdir = tempfile.mkdtemp()
        self.stream = "foo"
        self.scribe_port = find_open_port()
        self.log_path = get_log_path(self.scribe_logdir, self.stream)

        self.logger = ScribeLogger("localhost", self.scribe_port, retry_interval=10, report_status=mock.Mock())

        with scribed_sandbox(self.scribe_port, self.scribe_logdir):
            yield
        shutil.rmtree(self.scribe_logdir)
Example #3
0
    def test_init_while_down(self):
        logger = self.create_logger()
        self.timed_writes(logger, 10000, 2.0)

        # make sure we didn't log too many error reports
        assert len(self.status_reports) < 10
        # make sure we did log at least one error
        assert any(is_error for (is_error, msg) in self.status_reports)

        with scribed_sandbox(self.scribe_port, self.scribe_logdir):
            logger.log_line('bar', 'A')
            logger.log_line('bar', 'B')
            wait_on_log_data(get_log_path(self.scribe_logdir, 'bar'), b'A\nB\n')
Example #4
0
    def test_init_while_down(self):
        logger = self.create_logger()
        self.timed_writes(logger, 10000, 2.0)

        # make sure we didn't log too many error reports
        assert len(self.status_reports) < 10
        # make sure we did log at least one error
        assert any(is_error for (is_error, msg) in self.status_reports)

        with scribed_sandbox(self.scribe_port, self.scribe_logdir):
            logger.log_line('bar', 'A')
            logger.log_line('bar', 'B')
            wait_on_log_data(get_log_path(self.scribe_logdir, 'bar'), b'A\nB\n')
Example #5
0
    def test_write_and_reconnect(self):
        with scribed_sandbox(self.scribe_port, self.scribe_logdir):
            logger = self.create_logger()
            logger.log_line('foo', '1')
            logger.log_line('foo', '2')
            wait_on_log_data(get_log_path(self.scribe_logdir, 'foo'), b'1\n2\n')

        # make sure we haven't logged any errors
        assert not any(is_error for (is_error, msg) in self.status_reports)

        # write some more data, make sure we ignore that scribe server is
        # down, don't block too long
        self.timed_writes(logger, 10000, 2.0)

        # make sure we didn't log too many error reports
        assert_lt(len(self.status_reports), 10)
        # make sure we did log at least one error
        assert any(is_error for (is_error, msg) in self.status_reports)

        with scribed_sandbox(self.scribe_port, self.scribe_logdir):
            logger.log_line('foo', '3')
            logger.log_line('foo', '4')
            wait_on_log_data(get_log_path(self.scribe_logdir, 'foo'), b'1\n2\n3\n4\n')
Example #6
0
    def setup_sandbox(self):
        self.scribe_logdir = tempfile.mkdtemp()
        self.stream = 'foo'
        self.scribe_port = find_open_port()
        self.log_path = get_log_path(self.scribe_logdir, self.stream)

        self.logger = ScribeLogger('localhost',
                                   self.scribe_port,
                                   retry_interval=10,
                                   report_status=mock.Mock())

        with scribed_sandbox(self.scribe_port, self.scribe_logdir):
            yield
        shutil.rmtree(self.scribe_logdir)
Example #7
0
    def setup_sandbox(self):
        scribe_logdir = tempfile.mkdtemp()
        self.stream = TEST_STREAM_PREFIX + get_nonce_str(8)
        scribed_port = sandbox.find_open_port()
        tailer_port = sandbox.find_open_port()

        log_path = os.path.join(scribe_logdir,
                                '%s/%s_current' % (self.stream, self.stream))

        self.tailer = readers.StreamTailer(self.stream,
                                           add_newlines=False,
                                           automagic_recovery=False,
                                           timeout=0.2,
                                           host='localhost',
                                           port=tailer_port)

        self.logger = loggers.ScribeLogger('localhost', scribed_port, 10)

        with sandbox.scribed_sandbox(scribed_port, scribe_logdir):
            with sandbox.tailer_sandbox(tailer_port, log_path):
                yield
        shutil.rmtree(scribe_logdir)
Example #8
0
    def setup_sandbox(self):
        scribe_logdir = tempfile.mkdtemp()
        self.stream = TEST_STREAM_PREFIX + get_nonce_str(8)
        scribed_port = sandbox.find_open_port()
        tailer_port = sandbox.find_open_port()

        log_path = os.path.join(scribe_logdir,
                                '%s/%s_current' % (self.stream, self.stream))

        self.tailer = readers.StreamTailer(
                self.stream,
                add_newlines=False,
                automagic_recovery=False,
                timeout=0.2,
                host='localhost',
                port=tailer_port)

        self.logger = loggers.ScribeLogger('localhost', scribed_port, 10)

        with sandbox.scribed_sandbox(scribed_port, scribe_logdir):
            with sandbox.tailer_sandbox(tailer_port, log_path):
                yield
        shutil.rmtree(scribe_logdir)