예제 #1
0
파일: test_stream.py 프로젝트: xuru/bloop
def test_token(engine):
    engine.bind(Email)
    shards = build_shards(3, {0: [1, 2]}, stream_arn=Email.Meta.stream["arn"])
    shards[1].iterator_type = "latest"
    shards[2].iterator_type = "at_sequence"
    shards[2].sequence_number = "sequence-number"

    stream = Stream(model=Email, engine=engine)
    stream.coordinator.roots.append(shards[0])
    stream.coordinator.active.extend(shards[1:])

    assert ordered(stream.token) == ordered({
        "stream_arn":
        "stream-arn",
        "active": ["shard-id-1", "shard-id-2"],
        "shards": [
            {
                "shard_id": "shard-id-0"
            },
            {
                "shard_id": "shard-id-1",
                "parent": "shard-id-0",
                "iterator_type": "latest"
            },
            {
                "shard_id": "shard-id-2",
                "parent": "shard-id-0",
                "iterator_type": "at_sequence",
                "sequence_number": "sequence-number"
            },
        ]
    })
예제 #2
0
def test_token(coordinator):
    coordinator.stream_arn = "token-arn"
    # Two roots, each with 3 descendants.
    shards = build_shards(8, {
        0: 2,
        1: [3, 4],
        2: [5, 6],
        3: 7
    },
                          session=coordinator.session,
                          stream_arn="token-arn")

    # First two are roots to the rest of the trees
    coordinator.roots = [shards[0], shards[1]]
    # Only the leaves are active
    coordinator.active = [shards[4], shards[5], shards[6], shards[7]]

    expected_token = {
        "stream_arn": "token-arn",
        "active": [shard.shard_id for shard in coordinator.active],
        "shards": [shard.token for shard in shards]
    }
    # stream_arn is the same for all shards, so it's not stored per-shard.
    for shard_token in expected_token["shards"]:
        del shard_token["stream_arn"]

    assert ordered(expected_token) == ordered(coordinator.token)
예제 #3
0
def test_describe_stream_no_results(no_shards, next_ids, session, dynamodbstreams):
    stream_arn = "arn"
    responses = [build_describe_stream_response(shards=no_shards, next_id=next_id) for next_id in next_ids]
    dynamodbstreams.describe_stream.side_effect = responses

    description = session.describe_stream(stream_arn=stream_arn, first_shard="first-token")
    assert description["Shards"] == []

    empty_response = build_describe_stream_response(shards=[])["StreamDescription"]
    assert ordered(description) == ordered(empty_response)

    dynamodbstreams.describe_stream.assert_any_call(StreamArn=stream_arn, ExclusiveStartShardId="first-token")
    assert dynamodbstreams.describe_stream.call_count == len(next_ids)
예제 #4
0
def test_ordered_iterable(it):
    """Any non-mapping iterable is sorted, even if it's consumable"""
    expected = ["a", "b", "c"]
    assert ordered(it) == expected
예제 #5
0
def test_ordered_basic_objects(obj):
    """Things that don't need to be unpacked or flattened for comparison"""
    assert ordered(obj) is obj
예제 #6
0
def test_ordered_recursion(obj, expected):
    """Mappings and iterables inside each other are sorted and flattened"""
    assert ordered(obj) == expected
예제 #7
0
def test_ordered_mapping(mapping):
    """Mappings are flattened into (key, value) tuples and then those tuples are sorted"""
    expected = [("a", "zebra"), ("b", True), ("c", None)]
    assert ordered(mapping) == expected
예제 #8
0
 def respond(RequestItems):
     assert ordered(RequestItems) == ordered(expected)
     return response
예제 #9
0
def assert_unordered(obj, other):
    assert ordered(obj) == ordered(other)
예제 #10
0
 def handle(**table):
     assert ordered(table) == ordered(expected)