def test_same_sequence_id( self ): expected_id = '1234' expected_number = 1234 expected_delta = 1 request = AddEventsRequest(self.__body) request.set_client_time(1) self.assertTrue(request.add_event({'name': 'eventOne'}, timestamp=1L, sequence_id=expected_id, sequence_number=expected_number))
def test_different_sequence_id( self ): first_id = '1234' second_id = '1235' first_number = 1234 second_number = 1234 request = AddEventsRequest(self.__body) request.set_client_time(1) self.assertTrue(request.add_event({'name': 'eventOne'}, timestamp=1L, sequence_id=first_id, sequence_number=first_number))
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({'name': 'eventOne'}, timestamp=1L, sequence_id=first_id, sequence_number=first_number))
def test_exceeds_size_doesnt_effect_sequence( self ): first_id = '1234' second_id = '1235' first_number = 1234 second_number = 4321 expected_delta = 10 request = AddEventsRequest(self.__body, max_size=180) request.set_client_time(1) self.assertTrue(request.add_event({'name': 'eventOne'}, timestamp=1L, sequence_id=first_id, sequence_number=first_number))
def test_sequence_id_and_number(self): expected_id = '1234' expected_number = 1234 request = AddEventsRequest(self.__body) request.set_client_time(1) self.assertTrue( request.add_event(Event().set_message('eventOne'), timestamp=1L, sequence_id=expected_id, sequence_number=expected_number))
def test_sequence_id_and_number(self): expected_id = "1234" expected_number = 1234 request = AddEventsRequest(self.__body) request.set_client_time(1) self.assertTrue( request.add_event( Event().set_message("eventOne"), timestamp=1L, sequence_id=expected_id, sequence_number=expected_number ) )
def test_maximum_bytes_exceeded(self): request = AddEventsRequest(self.__body, max_size=90) request.set_client_time(1) self.assertTrue(request.add_event({'name': 'eventOne'}, timestamp=1L)) self.assertFalse(request.add_event({'name': 'eventTwo'}, timestamp=2L)) self.assertEquals(request.get_payload(), """{"token":"fakeToken", events: [{"name":"eventOne","ts":"1"}], client_time: 1 }""") request.close()
def test_same_sequence_id(self): expected_id = b"1234" expected_number = 1234 expected_delta = 1 request = AddEventsRequest(self.__body) request.set_client_time(1) self.assertTrue( request.add_event( Event().set_message("eventOne"), timestamp=1, sequence_id=expected_id, sequence_number=expected_number, )) self.assertTrue( request.add_event( Event().set_message("eventTwo"), timestamp=2, sequence_id=expected_id, sequence_number=expected_number + expected_delta, )) self.assertEquals(request.total_events, 2) json = test_util.parse_scalyr_request(request.get_payload()) event = json["events"][1] self.assertFalse("si" in event) self.assertFalse("sn" in event) self.assertEquals(expected_delta, event["sd"]) request.close()
def test_multiple_calls_to_get_payload(self): request = AddEventsRequest(self.__body) request.set_client_time(1) self.assertTrue( request.add_event(Event().set_message(b"eventOne"), timestamp=1)) self.assertTrue( request.add_event(Event().set_message(b"eventTwo"), timestamp=2)) self.assertEquals(request.get_payload(), request.get_payload()) request.close()
def test_maximum_bytes_exceeded(self): request = AddEventsRequest(self.__body, max_size=103) request.set_client_time(1) self.assertTrue(request.add_event(Event().set_message("eventOne"), timestamp=1L)) self.assertFalse(request.add_event(Event().set_message("eventTwo"), timestamp=2L)) self.assertEquals( request.get_payload(), """{"token":"fakeToken", events: [{attrs:{message:`s\x00\x00\x00\x08eventOne},ts:"1"}], threads: [], client_time: 1 }""", ) request.close()
def test_different_sequence_id(self): first_id = '1234' second_id = '1235' first_number = 1234 second_number = 1234 request = AddEventsRequest(self.__body) request.set_client_time(1) self.assertTrue( request.add_event(Event().set_message('eventOne'), timestamp=1L, sequence_id=first_id, sequence_number=first_number))
def test_different_sequence_id(self): first_id = "1234" second_id = "1235" first_number = 1234 second_number = 1234 request = AddEventsRequest(self.__body) request.set_client_time(1) self.assertTrue( request.add_event( Event().set_message("eventOne"), timestamp=1L, sequence_id=first_id, sequence_number=first_number ) )
def test_multiple_calls_to_get_payload(self): request = AddEventsRequest(self.__body) request.set_client_time(1) self.assertTrue(request.add_event({'name': 'eventOne'}, timestamp=1L)) self.assertTrue(request.add_event({'name': 'eventTwo'}, timestamp=2L)) self.assertEquals(request.get_payload(), request.get_payload()) request.close()
def test_exceeds_size_doesnt_effect_sequence(self): first_id = '1234' second_id = '1235' first_number = 1234 second_number = 4321 expected_delta = 10 request = AddEventsRequest(self.__body, max_size=180) request.set_client_time(1) self.assertTrue( request.add_event(Event().set_message('eventOne'), timestamp=1L, sequence_id=first_id, sequence_number=first_number))
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=1L, sequence_id=first_id, sequence_number=first_number ) )
def test_exceeds_size_doesnt_effect_sequence(self): first_id = "1234" second_id = "1235" first_number = 1234 second_number = 4321 expected_delta = 10 request = AddEventsRequest(self.__body, max_size=180) request.set_client_time(1) self.assertTrue( request.add_event( Event().set_message("eventOne"), timestamp=1L, sequence_id=first_id, sequence_number=first_number ) )
def test_no_monotonically_increasing_timestamp(self): request = AddEventsRequest(self.__body) ts = 2000 self.assertTrue( request.add_event(Event().set_message("eventOne"), timestamp=ts)) self.assertTrue( request.add_event(Event().set_message("eventTwo"), timestamp=1)) json = test_util.parse_scalyr_request(request.get_payload()) event = json["events"][1] self.assertEquals(event["ts"], "1")
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=1L, sequence_id=first_id, sequence_number=first_number))
def test_same_sequence_id(self): expected_id = "1234" expected_number = 1234 expected_delta = 1 request = AddEventsRequest(self.__body) request.set_client_time(1) self.assertTrue( request.add_event( Event().set_message("eventOne"), timestamp=1L, sequence_id=expected_id, sequence_number=expected_number, ))
def test_maximum_bytes_exceeded(self): request = AddEventsRequest(self.__body, max_size=103) request.set_client_time(1) self.assertTrue(request.add_event({'name': 'eventOne'}, timestamp=1L)) self.assertFalse(request.add_event({'name': 'eventTwo'}, timestamp=2L)) self.assertEquals( request.get_payload(), """{"token":"fakeToken", events: [{"name":"eventOne","ts":"1"}], threads: [], client_time: 1 }""") request.close()
def test_maximum_bytes_exceeded(self): request = AddEventsRequest(self.__body, max_size=112) request.set_client_time(1) self.assertTrue(request.add_event(Event().set_message('eventOne'), timestamp=1L)) self.assertFalse(request.add_event(Event().set_message('eventTwo'), timestamp=2L)) self.assertEquals( request.get_payload(), """{"token":"fakeToken", events: [{attrs:{message:`s\x00\x00\x00\x08eventOne},ts:"1"}], logs: [], threads: [], client_time: 1 }""") request.close()
def test_maximum_bytes_exceeded_from_threads(self): request = AddEventsRequest(self.__body, max_size=100) request.set_client_time(1) self.assertTrue(request.add_thread("t1", "name1")) self.assertFalse(request.add_thread("t2", "name2")) self.assertEquals( request.get_payload(), """{"token":"fakeToken", events: [], threads: [{"id":"t1","name":"name1"}], client_time: 1 }""") request.close()
def test_set_log_line_attributes(self): request = AddEventsRequest(self.__body) request.set_client_time(1) request.add_log_and_thread("log2", "Log two", {}) event_one = Event().set_message("eventOne") event_one.add_attributes({"source": "stdout"}, overwrite_existing=True) self.assertTrue(request.add_event(event_one, timestamp=1)) self.assertEquals( request.get_payload(), b"""{"token":"fakeToken", events: [{attrs:{"source":"stdout",message:`s\x00\x00\x00\x08eventOne},ts:"1"}], """ b"""logs: [{"attrs":{},"id":"log2"}], threads: [{"id":"log2","name":"Log two"}], client_time: 1 }""", ) request.close()
def test_monotonically_increasing_timestamp(self): request = AddEventsRequest(self.__body, enforce_monotonic_timestamps=True) scalyr_client._set_last_timestamp(0) ts = 2000 expected = str(ts + 1) self.assertTrue( request.add_event(Event().set_message("eventOne"), timestamp=ts)) self.assertTrue( request.add_event(Event().set_message("eventTwo"), timestamp=1)) json = test_util.parse_scalyr_request(request.get_payload()) event = json["events"][1] self.assertEquals(event["ts"], expected)
def _create_add_events_request(self, session_info=None, max_size=None): # Need to override this to return an AddEventsRequest even though we don't have a real scalyr client instance. if session_info is None: body = JsonObject(server_attributes=session_info, token='fake') else: body = JsonObject(token='fake') return AddEventsRequest(body, max_size=max_size)
def test_timing_data(self): request = AddEventsRequest(self.__body) request.increment_timing_data(**{"foo": 1, "bar": 2}) request.increment_timing_data(foo=5) # can't rely on stable order in "get_timing_data()" return value self.assertEquals(sorted(request.get_timing_data()), sorted("foo=6.0 bar=2.0"))
def test_basic_case(self): request = AddEventsRequest(self.__body) request.set_client_time(1) self.assertTrue(request.add_event({'name': 'eventOne'}, timestamp=1L)) self.assertTrue(request.add_event({'name': 'eventTwo'}, timestamp=2L)) self.assertEquals( request.get_payload(), """{"token":"fakeToken", events: [{"name":"eventOne","ts":"1"},{"name":"eventTwo","ts":"2"}]""" """, client_time: 1 }""") request.close()
def test_exceeds_size_doesnt_effect_sequence(self): first_id = "1234" second_id = "1235" first_number = 1234 second_number = 4321 expected_delta = 10 request = AddEventsRequest(self.__body, max_size=180) request.set_client_time(1) self.assertTrue( request.add_event( Event().set_message("eventOne"), timestamp=1, sequence_id=first_id, sequence_number=first_number, ) ) self.assertFalse( request.add_event( Event( attrs={"name": "eventTwo", "long": "some really long text"} ).set_message("eventTwo"), timestamp=2, sequence_id=second_id, sequence_number=second_number, ) ) self.assertTrue( request.add_event( Event().set_message("eventThree"), timestamp=3, sequence_id=first_id, sequence_number=first_number + expected_delta, ) ) self.assertEquals(request.total_events, 2) json = test_util.parse_scalyr_request(request.get_payload()) event = json["events"][1] self.assertFalse("si" in event) self.assertEquals(expected_delta, event["sd"]) self.assertFalse("sn" in event) request.close()
def generate_add_events_request(num_events, line_length, attributes_count): # type: (int, int, int) -> AddEventsRequest """ Generate AddEventsRequest object with the num_events number of events with the same payload payload (line length) size. """ base_body = {"token": "api key", "session": "sessionbar", "threads": []} add_events_request = AddEventsRequest(base_body=base_body) for index in range(0, num_events): line = generate_random_line(length=line_length) attributes = generate_random_dict(keys_count=attributes_count) event = Event(thread_id=100) event.set_message(line) event.add_attributes(attributes) add_events_request.add_event(event) return add_events_request
def test_basic_case(self): request = AddEventsRequest(self.__body) request.set_client_time(1) self.assertEquals(request.total_events, 0) self.assertTrue( request.add_event(Event().set_message("eventOne"), timestamp=1L)) self.assertTrue( request.add_event(Event().set_message("eventTwo"), timestamp=2L)) self.assertEquals( request.get_payload(), """{"token":"fakeToken", events: [{attrs:{message:`s\x00\x00\x00\x08eventOne},ts:"1"},{attrs:{message:`s\x00\x00\x00\x08eventTwo},ts:"2"}]""" """, threads: [], client_time: 1 }""") self.assertEquals(request.total_events, 2) request.close()
def test_different_sequence_id(self): first_id = "1234" second_id = "1235" first_number = 1234 second_number = 1234 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, ) ) self.assertTrue( request.add_event( Event().set_message("eventTwo"), timestamp=2, sequence_id=first_id, sequence_number=first_number + 1, ) ) self.assertTrue( request.add_event( Event().set_message("eventThree"), timestamp=3, sequence_id=second_id, sequence_number=second_number, ) ) self.assertEquals(request.total_events, 3) json = test_util.parse_scalyr_request(request.get_payload()) event = json["events"][2] self.assertEquals(second_id, event["si"]) self.assertEquals(second_number, event["sn"]) self.assertFalse("sd" in event) request.close()
def test_basic_case(self): request = AddEventsRequest(self.__body) request.set_client_time(1) self.assertEquals(request.total_events, 0) self.assertTrue(request.add_event({'name': 'eventOne'}, timestamp=1L)) self.assertTrue(request.add_event({'name': 'eventTwo'}, timestamp=2L)) self.assertEquals( request.get_payload(), """{"token":"fakeToken", events: [{"name":"eventOne","ts":"1"},{"name":"eventTwo","ts":"2"}]""" """, threads: [], client_time: 1 }""") self.assertEquals(request.total_events, 2) request.close()
def test_basic_case(self): request = AddEventsRequest(self.__body) request.set_client_time(1) self.assertEquals(request.total_events, 0) self.assertTrue(request.add_event(Event().set_message("eventOne"), timestamp=1L)) self.assertTrue(request.add_event(Event().set_message("eventTwo"), timestamp=2L)) self.assertEquals( request.get_payload(), """{"token":"fakeToken", events: [{attrs:{message:`s\x00\x00\x00\x08eventOne},ts:"1"},{attrs:{message:`s\x00\x00\x00\x08eventTwo},ts:"2"}]""" """, threads: [], client_time: 1 }""", ) self.assertEquals(request.total_events, 2) request.close()
def test_sequence_number_but_no_id(self): request = AddEventsRequest(self.__body) request.set_client_time(1) self.assertTrue( request.add_event(Event().set_message("eventOne"), timestamp=1, sequence_number=1234)) self.assertEquals(request.total_events, 1) json = test_util.parse_scalyr_request(request.get_payload()) event = json["events"][0] self.assertFalse("si" in event) self.assertFalse("sn" in event) self.assertFalse("sd" in event) request.close()
def test_send_request_body_is_logged_raw_uncompressed(self): """ When sending a request with compression available / enabled, raw (uncompressed) request body (payload) should be logged under DEBUG log level. """ session = ScalyrClientSession("https://dummserver.com", "DUMMY API KEY", SCALYR_VERSION) session._ScalyrClientSession__connection = mock.Mock() session._ScalyrClientSession__receive_response = mock.Mock() session._ScalyrClientSession__compress = mock.Mock( return_value="compressed") add_events_request = AddEventsRequest({"foo": "bar"}) event1 = Event(thread_id="foo1", attrs={ "parser": "bar1" }).set_message("eventOne") event2 = Event(thread_id="foo2", attrs={ "parser": "bar2" }).set_message("eventTwo") add_events_request.add_event(event=event1, timestamp=1) add_events_request.add_event(event=event2, timestamp=2) session.send(add_events_request=add_events_request) # Should log raw (uncompressed) request body / payload expected_body = r'{"foo":"bar", events: \[{thread:"foo1", .*' self.assertLogFileContainsRegex(expected_body, file_path=self.agent_debug_log_path) expected_body = r'.*,{thread:"foo2", log:"foo2", attrs:{"parser":"bar2",.*' self.assertLogFileContainsRegex(expected_body, file_path=self.agent_debug_log_path) # Verify that the compression was indeed enabled since that's the scenario we are testing call_kwargs = session._ScalyrClientSession__connection.post.call_args_list[ 0][1] self.assertEqual(call_kwargs["body"], "compressed")
def test_sequence_id_and_number(self): expected_id = "1234" expected_number = 1234 request = AddEventsRequest(self.__body) request.set_client_time(1) self.assertTrue( request.add_event( Event().set_message("eventOne"), timestamp=1, sequence_id=expected_id, sequence_number=expected_number, )) self.assertEquals(request.total_events, 1) json = test_util.parse_scalyr_request(request.get_payload()) event = json["events"][0] self.assertEquals(expected_id, event["si"]) self.assertEquals(expected_number, event["sn"]) self.assertFalse("sd" in event) request.close()
def test_timestamp_none(self): request = AddEventsRequest(self.__body) request.set_client_time(100) ts = int(time.time() * 1e9) self.assertTrue( request.add_event(Event().set_message("eventOne"), timestamp=None)) json = test_util.parse_scalyr_request(request.get_payload()) event = json["events"][0] event_ts = int(event["ts"]) threshold = abs(event_ts - ts) # allow a threshold of 1 second to have elapsed between reading the time.time and # setting the event timestamp in add_event self.assertTrue(threshold < 1e9)
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): scalyr_client._set_last_timestamp( 0 ) 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()
def test_set_client_time(self): scalyr_client._set_last_timestamp( 0 ) request = AddEventsRequest(self.__body) request.set_client_time(100) self.assertTrue(request.add_event(Event().set_message('eventOne'), timestamp=1L)) self.assertTrue(request.add_event(Event().set_message('eventTwo'), timestamp=2L)) self.assertEquals( request.get_payload(), """{"token":"fakeToken", events: [{attrs:{message:`s\x00\x00\x00\x08eventOne},ts:"1"},{attrs:{message:`s\x00\x00\x00\x08eventTwo},ts:"2"}]""" """, threads: [], client_time: 100 }""") request.set_client_time(2) self.assertEquals( request.get_payload(), """{"token":"fakeToken", events: [{attrs:{message:`s\x00\x00\x00\x08eventOne},ts:"1"},{attrs:{message:`s\x00\x00\x00\x08eventTwo},ts:"2"}]""" """, threads: [], client_time: 2 }""") request.close()
def test_add_thread(self): request = AddEventsRequest(self.__body) request.set_client_time(1) self.assertEquals(request.total_events, 0) self.assertTrue(request.add_event(Event().set_message("eventOne"), timestamp=1L)) self.assertTrue(request.add_thread('t1', 'n1')) self.assertTrue(request.add_event(Event().set_message("eventTwo"), timestamp=2L)) self.assertTrue(request.add_thread('t2', 'n2')) self.assertEquals( request.get_payload(), """{"token":"fakeToken", events: [{attrs:{message:`s\x00\x00\x00\x08eventOne},ts:"1"},{attrs:{message:`s\x00\x00\x00\x08eventTwo},ts:"2"}]""" """, threads: [{"id":"t1","name":"n1"},{"id":"t2","name":"n2"}], client_time: 1 }""") self.assertEquals(request.total_events, 2) request.close()
def test_sequence_number_but_no_id( self ): request = AddEventsRequest(self.__body) request.set_client_time(1) self.assertTrue(request.add_event({'name': 'eventOne'}, timestamp=1L, sequence_number=1234))
def test_sequence_number_but_no_id(self): request = AddEventsRequest(self.__body) request.set_client_time(1) self.assertTrue(request.add_event(Event().set_message("eventOne"), timestamp=1L, sequence_number=1234))
def test_set_position_resets_sequence_compression(self): first_id = "1234" 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_timing_data(self): request = AddEventsRequest(self.__body) request.increment_timing_data(foo=1, bar=2) request.increment_timing_data(foo=5) self.assertEquals(request.get_timing_data(), "foo=6.0 bar=2.0")
def test_add_thread(self): request = AddEventsRequest(self.__body) request.set_client_time(1) self.assertEquals(request.total_events, 0) self.assertTrue(request.add_event({'name': 'eventOne'}, timestamp=1L)) self.assertTrue(request.add_thread('t1', 'n1')) self.assertTrue(request.add_event({'name': 'eventTwo'}, timestamp=2L)) self.assertTrue(request.add_thread('t2', 'n2')) self.assertEquals( request.get_payload(), """{"token":"fakeToken", events: [{"name":"eventOne","ts":"1"},{"name":"eventTwo","ts":"2"}]""" """, threads: [{"id":"t1","name":"n1"},{"id":"t2","name":"n2"}], client_time: 1 }""") self.assertEquals(request.total_events, 2) 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({'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_add_log_and_thread(self): request = AddEventsRequest(self.__body) request.set_client_time(1) self.assertEquals(request.total_events, 0) self.assertTrue( request.add_event(Event().set_message(b"eventOne"), timestamp=1)) self.assertTrue(request.add_log_and_thread("t1", "n1", {"l1": "L1"})) self.assertTrue( request.add_event(Event().set_message(b"eventTwo"), timestamp=2)) self.assertTrue(request.add_log_and_thread("t2", "n2", {"l2": "L2"})) self.assertEquals( request.get_payload(), b"""{"token":"fakeToken", events: [{attrs:{message:`s\x00\x00\x00\x08eventOne},ts:"1"},{attrs:{message:`s\x00\x00\x00\x08eventTwo},ts:"2"}]""" b""", logs: [{"attrs":{"l1":"L1"},"id":"t1"},{"attrs":{"l2":"L2"},"id":"t2"}], threads: [{"id":"t1","name":"n1"},{"id":"t2","name":"n2"}], client_time: 1 }""", ) self.assertEquals(request.total_events, 2) 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()