def test_set_position(self):
        test_buffer = PostFixBuffer(self.__format)
        test_buffer.set_client_timestamp(1)

        self.assertTrue(
            test_buffer.add_log_and_thread_entry("log_5", "histogram_builder", {})
        )

        position = test_buffer.position

        self.assertTrue(
            test_buffer.add_log_and_thread_entry("log_6", "histogram2_builder", {})
        )

        test_buffer.set_position(position)

        self.assertEquals(
            test_buffer.length, len(test_buffer.content(cache_size=False))
        )

        self.assertEquals(
            test_buffer.content(),
            """], logs: [{"attrs":{},"id":"log_5"}], threads: [{"id":"log_5","name":"histogram_builder"}], """
            """client_time: 1 }""",
        )
    def test_add_thread_fail(self):
        test_buffer = PostFixBuffer(self.__format)
        test_buffer.set_client_timestamp(1)

        self.assertTrue(
            test_buffer.add_log_and_thread_entry(
                "log_5",
                "histogram_builder", {},
                fail_if_buffer_exceeds=1000000))
        self.assertEquals(test_buffer.length,
                          len(test_buffer.content(cache_size=False)))

        self.assertFalse(
            test_buffer.add_log_and_thread_entry("log_6",
                                                 "histogram", {},
                                                 fail_if_buffer_exceeds=10))

        self.assertEquals(test_buffer.length,
                          len(test_buffer.content(cache_size=False)))

        self.assertEquals(
            test_buffer.content(),
            b"""], logs: [{"attrs":{},"id":"log_5"}], """
            b"""threads: [{"id":"log_5","name":"histogram_builder"}], client_time: 1 }""",
        )
Esempio n. 3
0
    def test_set_client_time_fail(self):
        test_buffer = PostFixBuffer(self.__format)
        self.assertTrue(test_buffer.set_client_timestamp(1, fail_if_buffer_exceeds=1000000))
        self.assertFalse(test_buffer.set_client_timestamp(433423, fail_if_buffer_exceeds=test_buffer.length+3))

        expected_length = test_buffer.length

        content = test_buffer.content(cache_size=False)

        self.assertEquals(content, '], threads: [], client_time: 1 }')
        self.assertEquals(expected_length, len(content))
Esempio n. 4
0
    def test_add_thread_fail(self):
        test_buffer = PostFixBuffer(self.__format)
        test_buffer.set_client_timestamp(1)

        self.assertTrue(test_buffer.add_thread_entry('log_5', 'histogram_builder', fail_if_buffer_exceeds=1000000))
        self.assertEquals(test_buffer.length, len(test_buffer.content(cache_size=False)))

        self.assertFalse(test_buffer.add_thread_entry('log_6', 'histogram', fail_if_buffer_exceeds=10))

        self.assertEquals(test_buffer.length, len(test_buffer.content(cache_size=False)))

        self.assertEquals(test_buffer.content(), """], threads: [{"id":"log_5","name":"histogram_builder"}], """
                                                 """client_time: 1 }""")
Esempio n. 5
0
    def test_basic_case(self):
        test_buffer = PostFixBuffer(self.__format)
        test_buffer.set_client_timestamp(1)

        test_buffer.add_thread_entry('log_5', 'histogram_builder')
        self.assertEquals(test_buffer.content(),
                          """], threads: [{"id":"log_5","name":"histogram_builder"}], client_time: 1 }""")
    def test_set_position(self):
        test_buffer = PostFixBuffer(self.__format)
        test_buffer.set_client_timestamp(1)

        self.assertTrue(test_buffer.add_thread_entry('log_5', 'histogram_builder'))

        position = test_buffer.position

        self.assertTrue(test_buffer.add_thread_entry('log_6', 'histogram2_builder'))

        test_buffer.set_position(position)

        self.assertEquals(test_buffer.length, len(test_buffer.content(cache_size=False)))

        self.assertEquals(test_buffer.content(), """], threads: [{"id":"log_5","name":"histogram_builder"}], """
                                                 """client_time: 1 }""")
    def test_basic_case(self):
        test_buffer = PostFixBuffer(self.__format)
        test_buffer.set_client_timestamp(1)

        test_buffer.add_log_and_thread_entry("log_5", "histogram_builder", {})
        self.assertEquals(
            test_buffer.content(),
            b"""], logs: [{"attrs":{},"id":"log_5"}], threads: [{"id":"log_5","name":"histogram_builder"}], client_time: 1 }""",
        )
Esempio n. 8
0
    def test_set_client_time(self):
        test_buffer = PostFixBuffer(self.__format)
        test_buffer.set_client_timestamp(1)
        self.assertTrue(test_buffer.set_client_timestamp(433423))

        expected_length = test_buffer.length

        content = test_buffer.content(cache_size=False)

        self.assertEquals(content, '], threads: [], client_time: 433423 }')
        self.assertEquals(expected_length, len(content))
Esempio n. 9
0
    def test_add_thread(self):
        test_buffer = PostFixBuffer(self.__format)
        test_buffer.set_client_timestamp(1)

        self.assertTrue(test_buffer.add_thread_entry('log_5', 'histogram_builder'))
        self.assertEquals(test_buffer.length, len(test_buffer.content(cache_size=False)))

        self.assertTrue(test_buffer.add_thread_entry('log_12', 'ok_builder'))
        self.assertEquals(test_buffer.length, len(test_buffer.content(cache_size=False)))

        self.assertTrue(test_buffer.add_thread_entry('log', 'histogram_builder_foo'))
        self.assertEquals(test_buffer.length, len(test_buffer.content(cache_size=False)))

        self.assertEquals(test_buffer.content(), """], threads: [{"id":"log_5","name":"histogram_builder"},"""
                                                 """{"id":"log_12","name":"ok_builder"},"""
                                                 """{"id":"log","name":"histogram_builder_foo"}], client_time: 1 }""")
Esempio n. 10
0
    def test_add_thread(self):
        test_buffer = PostFixBuffer(self.__format)
        test_buffer.set_client_timestamp(1)

        self.assertTrue(
            test_buffer.add_log_and_thread_entry("log_5", "histogram_builder",
                                                 {}))
        self.assertEquals(test_buffer.length,
                          len(test_buffer.content(cache_size=False)))

        self.assertTrue(
            test_buffer.add_log_and_thread_entry("log_12", "ok_builder", {}))
        self.assertEquals(test_buffer.length,
                          len(test_buffer.content(cache_size=False)))

        self.assertTrue(
            test_buffer.add_log_and_thread_entry("log",
                                                 "histogram_builder_foo", {}))
        self.assertEquals(test_buffer.length,
                          len(test_buffer.content(cache_size=False)))

        self.assertEquals(
            test_buffer.content(),
            b"""], logs: [{"attrs":{},"id":"log_5"},{"attrs":{},"id":"log_12"},{"attrs":{},"id":"log"}], """
            b"""threads: [{"id":"log_5","name":"histogram_builder"},"""
            b"""{"id":"log_12","name":"ok_builder"},"""
            b"""{"id":"log","name":"histogram_builder_foo"}], client_time: 1 }""",
        )
Esempio n. 11
0
    def test_add_thread_fail(self):
        test_buffer = PostFixBuffer(self.__format)
        test_buffer.set_client_timestamp(1)

        # NOTE: Order is important since .length call depends on the cached size
        self.assertTrue(
            test_buffer.add_log_and_thread_entry(
                "log_5",
                "histogram_builder", {},
                fail_if_buffer_exceeds=1000000))

        content = test_buffer.content(cache_size=True)
        length = test_buffer.length

        self.assertEquals(
            length,
            len(content),
            "Buffer content: %s" % (test_buffer.content(cache_size=False)),
        )

        self.assertFalse(
            test_buffer.add_log_and_thread_entry("log_6",
                                                 "histogram", {},
                                                 fail_if_buffer_exceeds=10))

        content = test_buffer.content(cache_size=True)
        length = test_buffer.length

        self.assertEquals(
            length,
            len(content),
            "Buffer content: %s" % (test_buffer.content(cache_size=False)),
        )

        self.assertEquals(
            test_buffer.content(),
            b"""], logs: [{"attrs":{},"id":"log_5"}], """
            b"""threads: [{"id":"log_5","name":"histogram_builder"}], client_time: 1 }""",
        )