Exemple #1
0
def test_one_success(simple_iter, session, chain):
    iterator = simple_iter()
    one = Sentinel("one")
    session.search_items.side_effect = build_responses(chain, items=[one])

    assert iterator.one() is one
    # SearchIterator.one should advance exactly twice, every time
    expected_calls = calls_for_current_steps(chain, 2)
    assert session.search_items.call_count == expected_calls
Exemple #2
0
def response(count=1, terminate=False, item=Sentinel("item"), items=None):
    """This fills in the required response structure from a single query/scan call:

    Count, ScannedCount
        required fields but not important.
    LastEvaluatedKey
        tells the iterator if there are more pages available.  When it's not falsey,
        it should be fed directly back into the next request's "ExclusiveStartKey".
    Item
        is the number of items in this page.  By passing 0, 1, or 2 we can verify that the buffer is
        fully drained before the next page is loaded.  It also lets us verify that the while loop will
        follow LastEvaluatedKeys until it hits a non-empty page.
    """
    items = items or [item] * count
    return {
        "Count": count,
        "ScannedCount": count * 3,
        "Items": items,
        "LastEvaluatedKey": None if terminate else proceed
    }
Exemple #3
0
import datetime
import random

from bloop.stream.shard import Shard
from bloop.util import Sentinel


missing = Sentinel("missing")


def build_shards(n, shape=None, session=None, stream_arn=None, shard_id_prefix=""):
    """Shape describes the parent/child relationships.

    a -> b -> c -> d
           -> e -> f

    is expressed as:

    build_shards(session, 6, {0: 1, 1: [2, 3], 2: 4, 3: 5})
    """
    # Default to flat shards, no hierarchy
    shape = shape or {}
    shard_id = lambda i: "{}shard-id-{}".format(shard_id_prefix + "-" if shard_id_prefix else "", i)
    shards = [
        Shard(stream_arn=stream_arn, shard_id=shard_id(i), session=session)
        for i in range(n)
    ]
    for shard_index, child_indexes in shape.items():
        if isinstance(child_indexes, int):
            shards[shard_index].children.append(shards[child_indexes])
            shards[child_indexes].parent = shards[shard_index]
Exemple #4
0
def test_sentinel_repr():
    foo = Sentinel("foo")
    assert repr(foo) == "<Sentinel[foo]>"
Exemple #5
0
def test_sentinel_uniqueness():
    sentinel = Sentinel("name")
    same_sentinel = Sentinel("NAME")
    assert sentinel is same_sentinel
Exemple #6
0
    ScanIterator,
    Search,
    SearchIterator,
    SearchModelIterator,
    printable_query,
    search_repr,
    validate_filter_condition,
    validate_key_condition,
    validate_search_projection,
)
from bloop.types import Integer
from bloop.util import Sentinel

from ..helpers.models import ComplexModel, User

proceed = Sentinel("proceed")

all_conditions = {
    AndCondition, BeginsWithCondition, BetweenCondition, ComparisonCondition,
    Condition, ContainsCondition, InCondition, NotCondition, OrCondition
}
meta_conditions = {AndCondition, OrCondition, NotCondition}
range_conditions = {BeginsWithCondition, BetweenCondition, ComparisonCondition}
# Needed with an include != since all other comparisons are valid
bad_range_conditions = all_conditions - {BeginsWithCondition, BetweenCondition}


def model_for(has_model_range=False,
              has_index=False,
              has_index_range=False,
              index_type="gsi",