Beispiel #1
0
def test_subscribe_publish_modify_unpublish(domain):
    sub_context = libpaf.attach(domain.name)

    recorder = SubscriptionRecorder()
    sub_id = sub_context.subscribe(recorder)
    assert sub_id >= 0

    pub_context = libpaf.attach(domain.name)
    props = { 'name': { 'service-x' }, 'key': { 'foo', 99 } }
    service_id = pub_context.publish(props)

    wait([sub_context, pub_context],
         until=lambda: len(recorder.notifications) > 0)

    assert recorder.notifications[libpaf.MatchType.APPEARED][service_id] == props

    props['new_key'] = { 'new_value' }
    pub_context.modify(service_id, props)
    pub_context.set_ttl(service_id, 17)

    wait([sub_context, pub_context], timeout=0.25)

    assert recorder.notifications[libpaf.MatchType.MODIFIED][service_id] == props

    pub_context.unpublish(service_id)

    wait([sub_context, pub_context], timeout=0.25)

    assert service_id in recorder.notifications[libpaf.MatchType.DISAPPEARED]
Beispiel #2
0
def test_orphan(domain):
    context = libpaf.attach(domain.name)

    recorder = SubscriptionRecorder()
    sub_id = context.subscribe(recorder)

    conn = paf.client.connect(domain.addr)
    service_id = 4711
    generation = 10
    props = { 'name': { 'foo' } }
    ttl = 1
    conn.publish(service_id, generation, props, ttl)

    wait([context], timeout=0.25)
    assert len(recorder.notifications) == 1
    assert service_id in recorder.notifications[libpaf.MatchType.APPEARED]
    assert recorder.notifications[libpaf.MatchType.APPEARED][service_id] == \
        props

    conn.close()

    wait([context], timeout=0.25)
    assert len(recorder.notifications) == 1

    wait([context], timeout=ttl)
    assert len(recorder.notifications) == 2
    assert service_id in recorder.notifications[libpaf.MatchType.DISAPPEARED]
    assert recorder.notifications[libpaf.MatchType.DISAPPEARED][service_id] == \
        None
Beispiel #3
0
def test_unsubscribe(domain):
    context = libpaf.attach(domain.name)

    recorder = SubscriptionRecorder()
    sub_id = context.subscribe(recorder)
    wait([context], timeout=0.25)

    context.unsubscribe(sub_id)

    context.publish()

    wait([context], timeout=0.25)

    assert len(recorder.notifications) == 0
Beispiel #4
0
def test_subscribe_with_filter(domain):
    context = libpaf.attach(domain.name)

    recorder = SubscriptionRecorder()
    context.subscribe(recorder, filter='(name=service-x)')

    match_props = { 'name': { 'service-x' } }
    match_service_id = context.publish(match_props)
    
    non_match_props = { 'name': { 'service-y' } }
    non_match_service_id = context.publish(non_match_props)

    wait([context], timeout=0.25)

    assert match_service_id in \
        recorder.notifications[libpaf.MatchType.APPEARED]
    assert not non_match_service_id in \
        recorder.notifications[libpaf.MatchType.APPEARED]
Beispiel #5
0
def test_publish_and_detach(domain):
    context = libpaf.attach(domain.name)
    props = { 'name': { 'service-x' }, 'key': { 'foo', 99 } }
    context.publish(props)

    conn = paf.client.connect(domain.addr)

    wait([context], until=lambda: len(conn.services()) == 1)

    context.detach()

    wait([context], until=lambda: len(conn.services()) == 0)

    context.close()

    assert len(conn.clients()) == 1

    conn.close()
Beispiel #6
0
def test_unpublish_unsynced(domain):
    domain.stop_server()

    context = libpaf.attach(domain.name)
    for num in range(0, MANY):
        service_id = context.publish()
        context.unpublish(service_id)

    wait([context], timeout=0.25)

    domain.start_server()

    wait([context], timeout=0.5)

    conn = paf.client.connect(domain.addr)
    assert len(conn.services()) == 0

    assert len(conn.clients()) == 2

    conn.close()
Beispiel #7
0
def test_publish_unpublish_many(domain):
    context = libpaf.attach(domain.name)
    service_ids = []
    for num in range(0, MANY):
        props = { 'name': { "server-%d" % num } }
        service_id = context.publish(props)
        service_ids.append(service_id)
    recorder = SubscriptionRecorder()
    sub_id = context.subscribe(recorder)
    wait([context], timeout=1)

    for service_id in service_ids:
        assert service_id in recorder.notifications[libpaf.MatchType.APPEARED]

    for service_id in service_ids:
        context.unpublish(service_id)
    wait([context], timeout=1)

    for service_id in service_ids:
        assert service_id in recorder.notifications[libpaf.MatchType.DISAPPEARED]