def test_registryiterseek_backward_threesegments_seek(a, b, c, d, e, f, seeks):
    assume(len(set([a, b, c, d, e, f])) == 6)
    a, b, c, d, e, f = sorted([a, b, c, d, e, f])
    assume(b + 1 < c and d + 1 < e)

    from binlog.registry import RegistryIterSeek

    r = RegistryIterSeek(Registry([S(a, b), S(c, d), S(e, f)]),
                         direction=Direction.B)

    for s in list(seeks):
        r.seek(s)
        if s < a:
            with pytest.raises(StopIteration):
                next(r)
        elif a <= s <= b or c <= s <= d or e <= s <= f:
            assert next(r) == s, s
        elif b <= s <= c:
            assert next(r) == b, s
        elif d <= s <= e:
            assert next(r) == d, s
        elif s > f:
            assert next(r) == f, s
        else:
            assert False, "Non defined %d" % s
예제 #2
0
def test_segment_support_intersection_when_no_overlap(a, b, c, d):
    from binlog.registry import S

    s0 = S(a, b)
    s1 = S(c, d)

    res0 = s0 & s1
    res1 = s1 & s0

    assert res0 == res1 == None
예제 #3
0
def test_registries_support_intersection__start_and_end_are_consecutive():
    from binlog.registry import Registry, S

    registry_a = Registry(acked=list([S(0, 10)]))
    registry_b = Registry(acked=list([S(11, 20)]))

    registry_x1 = registry_a & registry_b
    registry_x2 = registry_b & registry_a

    assert registry_x1.acked == registry_x2.acked == list([])
예제 #4
0
def test_registries_support_intersection__same_point():
    from binlog.registry import Registry, S

    registry_a = Registry(acked=list([S(0, 0)]))
    registry_b = Registry(acked=list([S(0, 0)]))

    registry_x1 = registry_a & registry_b
    registry_x2 = registry_b & registry_a

    assert registry_x1.acked == registry_x2.acked == list([S(0, 0)])
예제 #5
0
def test_registries_support_intersection__overlap_segments():
    from binlog.registry import Registry, S

    registry_a = Registry(acked=list([S(0, 10)]))
    registry_b = Registry(acked=list([S(5, 20)]))

    registry_x1 = registry_a & registry_b
    registry_x2 = registry_b & registry_a

    assert registry_x1.acked == registry_x2.acked == list([S(5, 10)])
예제 #6
0
def test_registries_support_union_one_point():
    from binlog.registry import Registry, S

    registry_a = Registry(acked=list([S(0, 0)]))
    registry_b = Registry()

    registry_x1 = registry_a | registry_b
    registry_x2 = registry_b | registry_a

    assert registry_x1.acked == registry_x2.acked == list([S(0, 0)])
예제 #7
0
def test_registries_support_union__bigger_segment():
    from binlog.registry import Registry, S

    registry_a = Registry(acked=list([S(0, 10)]))
    registry_b = Registry(acked=list([S(5, 8)]))

    registry_x1 = registry_a | registry_b
    registry_x2 = registry_b | registry_a

    assert registry_x1.acked == registry_x2.acked == list([S(0, 10)])
def test_registryiterseek_forward_twosegments_unset(a, b, c, d):
    assume(len(set([a, b, c, d])) == 4)
    a, b, c, d = sorted([a, b, c, d])
    assume(b + 1 < c)

    from binlog.registry import RegistryIterSeek

    r = RegistryIterSeek(Registry([S(a, b), S(c, d)]))

    assert list(r) == list(chain(range(a, b + 1), range(c, d + 1)))
def test_registryiterseek_backward_twosegments_unset(a, b, c, d):
    assume(len(set([a, b, c, d])) == 4)
    a, b, c, d = sorted([a, b, c, d])
    assume(b + 1 < c)

    from binlog.registry import RegistryIterSeek

    r = RegistryIterSeek(Registry([S(a, b), S(c, d)]), direction=Direction.B)

    assert list(r) == list(chain(range(d, c - 1, -1), range(b, a - 1, -1)))
def test_registryiterseek_forward_threesegments_unset(a, b, c, d, e, f):
    assume(len(set([a, b, c, d, e, f])) == 6)
    a, b, c, d, e, f = sorted([a, b, c, d, e, f])
    assume(b + 1 < c and d + 1 < e)

    from binlog.registry import RegistryIterSeek

    r = RegistryIterSeek(Registry([S(a, b), S(c, d), S(e, f)]))

    assert list(r) == list(
        chain(range(a, b + 1), range(c, d + 1), range(e, f + 1)))
def test_registryiterseek_backward_threesegments_unset(a, b, c, d, e, f):
    assume(len(set([a, b, c, d, e, f])) == 6)
    a, b, c, d, e, f = sorted([a, b, c, d, e, f])
    assume(b + 1 < c and d + 1 < e)

    from binlog.registry import RegistryIterSeek

    r = RegistryIterSeek(Registry([S(a, b), S(c, d), S(e, f)]),
                         direction=Direction.B)

    assert list(r) == list(
        chain(range(f, e - 1, -1), range(d, c - 1, -1), range(b, a - 1, -1)))
def test_registry_onesegment_invert(a, b):
    start, end = min(a, b), max(a, b)

    r = ~Registry([S(start, end)])

    if start == S.MIN:
        if end == S.MIN:
            assert r.acked == [S(start + 1, S.MAX)]
        elif end == S.MAX:
            assert r.acked == []
    elif end == S.MAX:
        assert r.acked == [S(S.MIN, start - 1)]
    else:
        assert r.acked == [S(S.MIN, start - 1), S(end + 1, S.MAX)]
예제 #13
0
def test_segment_attributes():
    from binlog.registry import S

    s = S(0, 1)

    assert s.L == 0
    assert s.R == 1
def test_registryiterseek_backward_onesegment_unset(a, b):
    assume(len(set([a, b])) == 2)
    a, b = sorted([a, b])

    from binlog.registry import RegistryIterSeek

    r = RegistryIterSeek(Registry([S(a, b)]), direction=Direction.B)

    assert list(r) == list(chain(range(b, a - 1, -1)))
def test_registryiterseek_forward_onesegment_unset(a, b):
    assume(len(set([a, b])) == 2)

    from binlog.registry import RegistryIterSeek

    a, b = sorted([a, b])

    r = RegistryIterSeek(Registry([S(a, b)]))

    assert list(r) == list(chain(range(a, b + 1)))
def test_registryiterseek_forward_twosegments_seek(a, b, c, d, seeks):
    assume(len(set([a, b, c, d])) == 4)
    a, b, c, d = sorted([a, b, c, d])
    assume(b + 1 < c)

    from binlog.registry import RegistryIterSeek

    r = RegistryIterSeek(Registry([S(a, b), S(c, d)]))

    for s in list(seeks):
        r.seek(s)
        if s < a:
            assert next(r) == a, s
        elif a <= s <= b or c <= s <= d:
            assert next(r) == s, s
        elif b <= s <= c:
            assert next(r) == c, s
        elif s > d:
            with pytest.raises(StopIteration):
                next(r)
        else:
            assert False, "Non defined %d" % s
def test_registryiterseek_forward_onesegment_seek(a, b, seeks):
    assume(len(set([a, b])) == 2)
    a, b = sorted([a, b])

    from binlog.registry import RegistryIterSeek

    r = RegistryIterSeek(Registry([S(a, b)]))

    for s in list(seeks):
        r.seek(s)
        if s < a:
            assert next(r) == a, s
        elif a <= s <= b:
            assert next(r) == s, s
        elif s > b:
            with pytest.raises(StopIteration):
                next(r)
        else:
            assert False, "Non defined %d" % s
def test_registry_empty_invert():
    r = ~Registry()
    assert r.acked == [S(S.MIN, S.MAX)]