def test_set_position(self):
        request = AddEventsRequest(self.__body)
        request.set_client_time(1)
        position = request.position()
        self.assertTrue(request.add_event(Event().set_message('eventOne'), timestamp=1L))
        self.assertTrue(request.add_event(Event().set_message('eventTwo'), timestamp=2L))

        request.set_position(position)
        self.assertTrue(request.add_event(Event().set_message('eventThree'), timestamp=3L))

        self.assertEquals(
            request.get_payload(),
            """{"token":"fakeToken", events: [{attrs:{message:`s\x00\x00\x00\neventThree},ts:"3"}], logs: [], threads: [], client_time: 1 }""")

        request.close()
Beispiel #2
0
    def test_set_position(self):
        request = AddEventsRequest(self.__body)
        request.set_client_time(1)
        position = request.position()
        self.assertTrue(request.add_event({'name': 'eventOne'}, timestamp=1L))
        self.assertTrue(request.add_event({'name': 'eventTwo'}, timestamp=2L))

        request.set_position(position)
        self.assertTrue(request.add_event({'name': 'eventThree'}, timestamp=3L))

        self.assertEquals(
            request.get_payload(),
            """{"token":"fakeToken", events: [{"name":"eventThree","ts":"3"}], threads: [], client_time: 1 }""")

        request.close()
    def test_set_position(self):
        request = AddEventsRequest(self.__body)
        request.set_client_time(1)
        position = request.position()
        self.assertTrue(request.add_event(Event().set_message("eventOne"), timestamp=1L))
        self.assertTrue(request.add_event(Event().set_message("eventTwo"), timestamp=2L))

        request.set_position(position)
        self.assertTrue(request.add_event(Event().set_message("eventThree"), timestamp=3L))

        self.assertEquals(
            request.get_payload(),
            """{"token":"fakeToken", events: [{attrs:{message:`s\x00\x00\x00\neventThree},ts:"3"}], threads: [], client_time: 1 }""",
        )

        request.close()
Beispiel #4
0
    def test_set_position_with_thread(self):
        request = AddEventsRequest(self.__body)
        request.set_client_time(1)
        position = request.position()
        request.add_thread('log1', 'Hi there')
        self.assertTrue(request.add_event({'name': 'eventOne'}, timestamp=1L))
        self.assertTrue(request.add_event({'name': 'eventTwo'}, timestamp=2L))

        request.set_position(position)
        self.assertTrue(request.add_thread('log2', 'Log two'))
        self.assertTrue(request.add_event({'name': 'eventThree'}, timestamp=3L))

        self.assertEquals(
            request.get_payload(),
            """{"token":"fakeToken", events: [{"name":"eventThree","ts":"3"}], """
            """threads: [{"id":"log2","name":"Log two"}], client_time: 1 }""")

        request.close()
    def test_set_position_with_log_and_thread(self):
        request = AddEventsRequest(self.__body)
        request.set_client_time(1)
        position = request.position()
        request.add_log_and_thread('log1', 'Hi there', {})
        self.assertTrue(request.add_event(Event().set_message('eventOne'), timestamp=1L))
        self.assertTrue(request.add_event(Event().set_message('eventTwo'), timestamp=2L))

        request.set_position(position)
        self.assertTrue(request.add_log_and_thread('log2', 'Log two', {}))
        self.assertTrue(request.add_event(Event().set_message('eventThree'), timestamp=3L))

        self.assertEquals(
            request.get_payload(),
            """{"token":"fakeToken", events: [{attrs:{message:`s\x00\x00\x00\neventThree},ts:"3"}], """
            """logs: [{"attrs":{},"id":"log2"}], threads: [{"id":"log2","name":"Log two"}], client_time: 1 }""")

        request.close()
    def test_set_position_with_thread(self):
        scalyr_client._set_last_timestamp( 0 )
        request = AddEventsRequest(self.__body)
        request.set_client_time(1)
        position = request.position()
        request.add_thread('log1', 'Hi there')
        self.assertTrue(request.add_event(Event().set_message('eventOne'), timestamp=1L))
        self.assertTrue(request.add_event(Event().set_message('eventTwo'), timestamp=2L))

        request.set_position(position)
        self.assertTrue(request.add_thread('log2', 'Log two'))
        self.assertTrue(request.add_event(Event().set_message('eventThree'), timestamp=3L))

        self.assertEquals(
            request.get_payload(),
            """{"token":"fakeToken", events: [{attrs:{message:`s\x00\x00\x00\neventThree},ts:"3"}], """
            """threads: [{"id":"log2","name":"Log two"}], client_time: 1 }""")

        request.close()
    def test_set_position_resets_sequence_compression(self):
        first_id = "1234"
        second_id = "1235"
        first_number = 1234
        second_number = 4321
        expected_delta = 10
        request = AddEventsRequest(self.__body)
        request.set_client_time(1)
        self.assertTrue(
            request.add_event(
                Event().set_message("eventOne"),
                timestamp=1,
                sequence_id=first_id,
                sequence_number=first_number,
            )
        )
        position = request.position()
        self.assertTrue(
            request.add_event(
                Event().set_message("eventTwo"),
                timestamp=2,
                sequence_id=first_id,
                sequence_number=first_number + expected_delta,
            )
        )
        request.set_position(position)
        self.assertTrue(
            request.add_event(
                Event().set_message("eventThree"),
                timestamp=3,
                sequence_id=first_id,
                sequence_number=second_number,
            )
        )
        self.assertEquals(request.total_events, 2)

        json = test_util.parse_scalyr_request(request.get_payload())
        event = json["events"][1]

        self.assertEquals(second_number, event["sn"])
        self.assertFalse("sd" in event)
        request.close()
    def test_set_position_with_thread(self):
        request = AddEventsRequest(self.__body)
        request.set_client_time(1)
        position = request.position()
        request.add_thread("log1", "Hi there")
        self.assertTrue(
            request.add_event(Event().set_message("eventOne"), timestamp=1L))
        self.assertTrue(
            request.add_event(Event().set_message("eventTwo"), timestamp=2L))

        request.set_position(position)
        self.assertTrue(request.add_thread("log2", "Log two"))
        self.assertTrue(
            request.add_event(Event().set_message("eventThree"), timestamp=3L))

        self.assertEquals(
            request.get_payload(),
            """{"token":"fakeToken", events: [{attrs:{message:`s\x00\x00\x00\neventThree},ts:"3"}], """
            """threads: [{"id":"log2","name":"Log two"}], client_time: 1 }""",
        )

        request.close()