Ejemplo n.º 1
0
    def test_update_config_return_value(self):
        client = mock.Mock()

        client_config = trace_config_pb2.TraceConfig(
            constant_sampler=trace_config_pb2.ConstantSampler(decision=True))

        agent_config = trace_config_pb2.TraceConfig(
            probability_sampler=trace_config_pb2.ProbabilitySampler(
                samplingProbability=0.1))

        exporter = TraceExporter(service_name=SERVICE_NAME,
                                 client=client,
                                 transport=MockTransport)

        client.Config.return_value = iter([agent_config])
        actual_response = exporter.update_config(client_config)

        self.assertEqual(actual_response, agent_config)
Ejemplo n.º 2
0
    def test_config_generator(self):

        config = trace_config_pb2.TraceConfig(
            constant_sampler=trace_config_pb2.ConstantSampler(decision=True))
        exporter = TraceExporter(service_name=SERVICE_NAME,
                                 transport=MockTransport)

        config_requests = list(exporter.generate_config_request(config))

        self.assertEqual(len(config_requests), 1)
        self.assertEqual(config_requests[0].node, exporter.node)
        self.assertEqual(config_requests[0].config, config)
Ejemplo n.º 3
0
    def test_config_update_exception(self):
        client = mock.Mock()

        config = trace_config_pb2.TraceConfig(
            constant_sampler=trace_config_pb2.ConstantSampler(decision=True))

        exporter = TraceExporter(service_name=SERVICE_NAME,
                                 client=client,
                                 transport=MockTransport)

        client.Config.side_effect = grpc.RpcError()
        with self.assertRaises(grpc.RpcError):
            exporter.update_config(config)

        client.Config.side_effect = lambda config: iter([config])

        exporter.update_config(config)

        self.assertEqual(len(client.Config.mock_calls), 2)
        actual_request = list(client.Config.call_args[0][0])[0]
        self.assertEqual(actual_request.node, exporter.node)