Exemple #1
0
def test_context_manager():
    """
    Opaque.initialize should act as a context manager and resets state properly.

    """
    opaque = Opaque()

    opaque[THIS] = VALUE
    assert_that(opaque.as_dict(), is_(equal_to({THIS: VALUE})))

    with opaque.initialize(example_func, OTHER, OTHER):
        assert_that(opaque.as_dict(), is_(equal_to(example_func(OTHER,
                                                                OTHER))))
        assert_that(opaque.as_dict(), is_(equal_to({
            THIS: OTHER,
            THAT: OTHER
        })))

    with opaque.initialize(example_func, OTHER, OTHER):
        assert_that(opaque.as_dict(), is_(equal_to(example_func(OTHER,
                                                                OTHER))))
        assert_that(opaque.as_dict(), is_(equal_to({
            THIS: OTHER,
            THAT: OTHER
        })))

    assert_that(opaque.as_dict(), is_(equal_to({THIS: VALUE})))
def trace_incoming_message_process(opaque: Opaque, message: SQSMessage,
                                   queue_url: str):
    if not oneagent:
        yield
    else:
        try:
            queue_name = queue_url.split("/")[-1]
        except IndexError:
            queue_name = queue_url

        sdk = oneagent.get_sdk()
        messaging_system = sdk.create_messaging_system_info(
            AWS_SQS,
            queue_name,
            MessagingDestinationType.QUEUE,
            Channel(ChannelType.TCP_IP, None),
        )
        tag = opaque.get(OPAQUE_TAG_KEY)
        request_id = opaque.get("X-Request-Id")
        with sdk.trace_incoming_message_process(messaging_system,
                                                str_tag=tag) as tracer:
            tracer.set_vendor_message_id(message.message_id)
            if request_id:
                tracer.set_correlation_id(request_id)
            yield
def test_dict_usage():
    """
    Opaque should be dict-like.

    """
    opaque = Opaque()
    assert_that(opaque.as_dict(), is_(equal_to(dict())))

    opaque[THIS] = VALUE
    assert_that(opaque.as_dict(), is_(equal_to({THIS: VALUE})))
    assert_that(opaque[THIS], is_(equal_to(VALUE)))
Exemple #4
0
def test_dict_usage():
    """
    Opaque should be dict-like.

    """
    opaque = Opaque()
    assert_that(opaque.as_dict(), is_(equal_to(dict())))

    opaque[THIS] = VALUE
    assert_that(opaque.as_dict(), is_(equal_to({THIS: VALUE})))
    assert_that(opaque[THIS], is_(equal_to(VALUE)))
Exemple #5
0
def test_decorator():
    """
    Opaque.initialize should act as a decorator and resets state properly.

    """
    opaque = Opaque()
    opaque[THIS] = VALUE

    @opaque.initialize(example_func, OTHER, OTHER)
    def function_to_decorate():
        return opaque.as_dict()

    assert_that(opaque.as_dict(), is_(equal_to({THIS: VALUE})))
    assert_that(function_to_decorate(), is_(equal_to(example_func(OTHER, OTHER))))
    assert_that(opaque.as_dict(), is_(equal_to({THIS: VALUE})))
    assert_that(function_to_decorate(), is_(equal_to(example_func(OTHER, OTHER))))
    assert_that(opaque.as_dict(), is_(equal_to({THIS: VALUE})))
def test_decorator():
    """
    Opaque.initialize should act as a decorator and resets state properly.

    """
    opaque = Opaque()
    opaque[THIS] = VALUE

    @opaque.initialize(example_func, OTHER, OTHER)
    def function_to_decorate():
        return opaque.as_dict()

    assert_that(opaque.as_dict(), is_(equal_to({THIS: VALUE})))
    assert_that(function_to_decorate(), is_(equal_to(example_func(OTHER, OTHER))))
    assert_that(opaque.as_dict(), is_(equal_to({THIS: VALUE})))
    assert_that(function_to_decorate(), is_(equal_to(example_func(OTHER, OTHER))))
    assert_that(opaque.as_dict(), is_(equal_to({THIS: VALUE})))
Exemple #7
0
def test_composition():
    """
    Opaque.initialize should compose (within reason).

    """
    opaque = Opaque()
    opaque[THIS] = VALUE

    assert_that(opaque.as_dict(), is_(equal_to({THIS: VALUE})))
    with opaque.initialize(example_func, OTHER, OTHER):
        assert_that(opaque.as_dict(), is_(equal_to(example_func(OTHER, OTHER))))
        with opaque.initialize(example_func, ALSO, OTHER):
            assert_that(opaque.as_dict(), is_(equal_to(example_func(ALSO, OTHER))))
        assert_that(opaque.as_dict(), is_(equal_to(example_func(OTHER, OTHER))))
    assert_that(opaque.as_dict(), is_(equal_to({THIS: VALUE})))
def test_composition():
    """
    Opaque.initialize should compose (within reason).

    """
    opaque = Opaque()
    opaque[THIS] = VALUE

    assert_that(opaque.as_dict(), is_(equal_to({THIS: VALUE})))
    with opaque.initialize(example_func, OTHER, OTHER):
        assert_that(opaque.as_dict(), is_(equal_to(example_func(OTHER, OTHER))))
        with opaque.initialize(example_func, ALSO, OTHER):
            assert_that(opaque.as_dict(), is_(equal_to(example_func(ALSO, OTHER))))
        assert_that(opaque.as_dict(), is_(equal_to(example_func(OTHER, OTHER))))
    assert_that(opaque.as_dict(), is_(equal_to({THIS: VALUE})))
def test_context_manager():
    """
    Opaque.initialize should act as a context manager and resets state properly.

    """
    opaque = Opaque()

    opaque[THIS] = VALUE
    assert_that(opaque.as_dict(), is_(equal_to({THIS: VALUE})))

    with opaque.initialize(example_func, OTHER, OTHER):
        assert_that(opaque.as_dict(), is_(equal_to(example_func(OTHER, OTHER))))
        assert_that(opaque.as_dict(), is_(equal_to({THIS: OTHER, THAT: OTHER})))

    with opaque.initialize(example_func, OTHER, OTHER):
        assert_that(opaque.as_dict(), is_(equal_to(example_func(OTHER, OTHER))))
        assert_that(opaque.as_dict(), is_(equal_to({THIS: OTHER, THAT: OTHER})))

    assert_that(opaque.as_dict(), is_(equal_to({THIS: VALUE})))