Exemple #1
0
def test_token(caplog):
    parent = Shard(stream_arn="parent-stream-arn", shard_id="parent-id")
    shard = Shard(stream_arn="stream-arn",
                  shard_id="shard-id",
                  iterator_id="iterator-id",
                  iterator_type="at_sequence",
                  sequence_number="sequence-number",
                  parent=parent)
    expected = {
        "stream_arn": "stream-arn",
        "shard_id": "shard-id",
        "iterator_type": "at_sequence",
        "sequence_number": "sequence-number",
        "parent": "parent-id"
    }
    assert shard.token == expected

    # Removing parent omits it from the token entirely
    shard.parent = None
    expected.pop("parent")
    assert shard.token == expected
    assert not caplog.records

    shard.iterator_type = "trim_horizon"
    shard.token
    assert caplog.record_tuples == [
        ("bloop.stream", logging.WARNING,
         "creating shard token at non-exact location \"trim_horizon\"")
    ]
Exemple #2
0
def test_token():
    parent = Shard(stream_arn="parent-stream-arn", shard_id="parent-id")
    shard = Shard(stream_arn="stream-arn",
                  shard_id="shard-id",
                  iterator_id="iterator-id",
                  iterator_type="at_sequence",
                  sequence_number="sequence-number",
                  parent=parent)
    expected = {
        "stream_arn": "stream-arn",
        "shard_id": "shard-id",
        "iterator_type": "at_sequence",
        "sequence_number": "sequence-number",
        "parent": "parent-id"
    }
    assert shard.token == expected

    # Removing parent omits it from the token entirely
    shard.parent = None
    expected.pop("parent")
    assert shard.token == expected