Example #1
0
def test_unpack_shards_from_token(session):
    # multiple roots, 1:1 and 1:2 relations
    shards = build_shards(5, {0: 1, 2: [3, 4]}, session, stream_arn="stream_arn")
    by_id = {shard.shard_id: shard for shard in shards}

    # unpacking shouldn't rely on ordering over the wire
    tokens = [shard.token for shard in shards]
    random.shuffle(tokens)
    unpacked = unpack_shards(tokens, "stream_arn", session)

    assert unpacked == by_id
Example #2
0
def test_unpack_shards_from_describe_stream(session):
    # multiple roots, 1:1 and 1:2 relations
    shards = stream_description(5, {0: 1, 2: [3, 4]})["Shards"]
    by_id = {shard["ShardId"]: shard for shard in shards}

    # unpacking shouldn't rely on ordering over the wire
    random.shuffle(shards)
    unpacked = unpack_shards(shards, "stream_arn", session=session)

    assert by_id.keys() == unpacked.keys()
    for shard_id, shard in unpacked.items():
        if shard.parent is None:
            assert "ParentShardId" not in by_id[shard_id]
        else:
            assert shard.parent.shard_id == by_id[shard_id].get("ParentShardId")
Example #3
0
def test_unpack_shards_with_deleted_parent_shard(session):
    # multiple roots, 1:1 and 1:2 relations
    shards = stream_description(6, {0: 1, 1: 2, 3: [4, 5]})["Shards"]
    # removing old shard
    shards = shards[1:]

    by_id = {shard["ShardId"]: shard for shard in shards}
    unpacked = unpack_shards(shards, "stream_arn", session=session)

    assert by_id.keys() == unpacked.keys()
    assert len([shard for shard in unpacked.values() if not shard.parent]) == 2
    for shard_id, shard in unpacked.items():
        if by_id[shard_id].get("ParentShardId") not in by_id:
            assert shard.parent is None
        else:
            assert shard.parent.shard_id == by_id[shard_id].get("ParentShardId")
Example #4
0
def test_unpack_empty_shards_list(session):
    assert unpack_shards([], "stream-arn", session) == {}