Exemplo n.º 1
0
    def test_paired(self):
        output = StringIO()
        printer = PairedPrinter(format_options(), output)

        message_sniffer = MessageSniffer(options(), printer)
        message_sniffer.join()

        self._assertMessages(output)
Exemplo n.º 2
0
    def test_paired(self):
        output = StringIO()
        printer = PairedPrinter(format_options(), output)

        message_sniffer = MessageSniffer(options(), printer)
        message_sniffer.join()

        self._assertMessages(output)
Exemplo n.º 3
0
    def test_latency_printer(self):
        output = StringIO()
        printer = LatencyPrinter(expected_calls=3, output=output)

        message_sniffer = MessageSniffer(options(), printer)
        message_sniffer.join()

        self.assertIn(
            'method       count          avg          min          max          p90          p95          p99         p999',
            output.getvalue())
        self.assertIn(
            'ping             1  0.000156164  0.000156164  0.000156164  0.000156164  0.000156164  0.000156164  0.000156164',
            output.getvalue())
        self.assertIn(
            'calculate        1  0.000144005  0.000144005  0.000144005  0.000144005  0.000144005  0.000144005  0.000144005',
            output.getvalue())
        self.assertIn(
            'add              1  0.000103951  0.000103951  0.000103951  0.000103951  0.000103951  0.000103951  0.000103951',
            output.getvalue())
Exemplo n.º 4
0
    def test_latency_printer(self):
        output = StringIO()
        printer = LatencyPrinter(expected_calls=3, output=output)

        message_sniffer = MessageSniffer(options(), printer)
        message_sniffer.join()

        self.assertIn(
            'method       count          avg          min          max          p90          p95          p99         p999',
            output.getvalue())
        self.assertIn(
            'ping             1  0.000156164  0.000156164  0.000156164  0.000156164  0.000156164  0.000156164  0.000156164',
            output.getvalue())
        self.assertIn(
            'calculate        1  0.000144005  0.000144005  0.000144005  0.000144005  0.000144005  0.000144005  0.000144005',
            output.getvalue())
        self.assertIn(
            'add              1  0.000103951  0.000103951  0.000103951  0.000103951  0.000103951  0.000103951  0.000103951',
            output.getvalue())
Exemplo n.º 5
0
def discover_on_port(port, iface, handler):
    options = MessageSnifferOptions(iface=iface,
                                    port=port,
                                    ip=None,
                                    pcap_file=None,
                                    protocol=None,
                                    finagle_thrift=False,
                                    read_values=False,
                                    max_queued=20000,
                                    max_message_size=2000,
                                    debug=False)

    return MessageSniffer(options, handler)
Exemplo n.º 6
0
    def test_paired_idl(self):
        output = StringIO()
        format_opts = format_options(
            show_fields=True,
            idl_file=get_thrift_path('tutorial'),
        )
        printer = PairedPrinter(format_opts, output)

        message_sniffer = MessageSniffer(options(), printer)
        message_sniffer.join()

        out = '\n'.join(
            re.sub(r'\[\d+:\d+:\d+:\d+\] ', '', line)
            for line in output.getvalue().splitlines())
        expected = '\n'.join([
            "127.0.0.1:51112 -> 127.0.0.1:9090: method=ping, type=call, seqid=0",
            "fields: []",
            "------>127.0.0.1:9090 -> 127.0.0.1:51112: method=ping, type=reply, seqid=0",
            "        fields: fields=[]",
            "127.0.0.1:51112 -> 127.0.0.1:9090: method=add, type=call, seqid=0",
            "fields: [('num1', 1), ('num2', 1)]",
            "------>127.0.0.1:9090 -> 127.0.0.1:51112: method=add, type=reply, seqid=0",
            "        fields: 2",
            "127.0.0.1:51112 -> 127.0.0.1:9090: method=calculate, type=call, seqid=0",
            "fields: [('logid', 1), ('w', ('Work', [('num1', 1), ('num2', 0), ('op', 'DIVIDE'), ('comment', None)]))]",
            "------>127.0.0.1:9090 -> 127.0.0.1:51112: method=calculate, type=reply, seqid=0",
            "        fields: ('InvalidOperation', [('whatOp', 4), ('why', 'Cannot divide by 0')])",
            "127.0.0.1:51112 -> 127.0.0.1:9090: method=calculate, type=call, seqid=0",
            "fields: [('logid', 1), ('w', ('Work', [('num1', 15), ('num2', 10), ('op', 'SUBTRACT'), ('comment', None)]))]",
            "------>127.0.0.1:9090 -> 127.0.0.1:51112: method=calculate, type=reply, seqid=0",
            "        fields: 5",
            "127.0.0.1:51112 -> 127.0.0.1:9090: method=getStruct, type=call, seqid=0",
            "fields: [('key', 1)]",
            "------>127.0.0.1:9090 -> 127.0.0.1:51112: method=getStruct, type=reply, seqid=0",
            "        fields: ('SharedStruct', [('key', 1), ('value', '5')])",
        ])
        self.assertEqual(out, expected)