def test_equality(self): self.assertEqual(Annotation('foo', 'bar', 'string'), Annotation('foo', 'bar', 'string')) self.assertEqual( Annotation('foo', 'bar', 'string', Endpoint('127.0.0.1', 0, 'test')), Annotation('foo', 'bar', 'string', Endpoint('127.0.0.1', 0, 'test')))
def test_repr(self): annotation = Annotation('foo', 'bar', 'string', Endpoint('127.0.0.1', 0, 'test')) self.assertEqual(repr(annotation), ("Annotation('foo', 'bar', 'string', " "Endpoint('127.0.0.1', 0, 'test'))")) self.assertEqual(repr(Annotation('foo', 'bar', 'string')), "Annotation('foo', 'bar', 'string', None)")
def render_POST(self, request): print "For CORS by john" request.setHeader('Access-Control-Allow-Origin', '*') request.setHeader('Access-Control-Allow-Methods', 'POST') request.responseHeaders.setRawHeaders('content-type', ['application/json']) body = request.content.read() try: spans = json.loads(body) except ValueError: log.err(None, 'Failed to decode request body') msg = 'Could not decode request body (invalid JSON)' return json.dumps({'error': msg}) succeeded, failed = 0, 0 for json_span in spans: trace_id = None span_id = None try: trace_id = decode_hex_number('trace_id', json_span['trace_id']) span_id = decode_hex_number('span_id', json_span['span_id']) parent_span_id = json_span.get('parent_span_id', None) if parent_span_id is not None: parent_span_id = decode_hex_number('parent_span_id', parent_span_id) t = Trace(json_span['name'], trace_id, span_id, parent_span_id) for json_annotation in json_span['annotations']: annotation = Annotation(json_annotation['key'], json_annotation['value'], json_annotation['type']) host = json_annotation.get('host', None) if host: annotation.endpoint = Endpoint(host['ipv4'], host['port'], host['service_name']) t.record(annotation) succeeded = succeeded + 1 except Exception: log.err( None, 'Failed to insert a trace: trace_id=%r,span_id=%r' % (trace_id, span_id)) failed = failed + 1 continue return json.dumps({'succeeded': succeeded, 'failed': failed})
def test_inequality(self): annotation = Annotation('foo', 'bar', 'string') self.assertNotEqual(annotation, None) self.assertNotEqual(annotation, Annotation('foo1', 'bar', 'string')) self.assertNotEqual(annotation, Annotation('foo', 'bar1', 'string')) self.assertNotEqual(annotation, Annotation('foo', 'bar', 'string1')) self.assertNotEqual( annotation, Annotation('foo', 'bar', 'string', Endpoint('127.0.0.1', 0, 'test'))) self.assertNotEqual( Annotation('foo', 'bar', 'string', Endpoint('127.0.0.1', 0, 'test2')), Annotation('foo', 'bar', 'string', Endpoint('127.0.0.1', 0, 'test')))
def test_verifyObject(self): verifyObject(IAnnotation, Annotation('foo', 'bar', 'string'))