def test_offer__ipc__no_subscribers(aeron_directory, stream_id):
    context = Context(aeron_dir=aeron_directory)
    publication = context.add_exclusive_publication('aeron:ipc', stream_id)
    assert_that(publication.is_connected, is_(False))

    result = publication.offer(b'abc')
    assert_that(result, is_(equal_to(NOT_CONNECTED)))
def test_offer__multicast(aeron_directory, mcast_subscriber, stream_id):
    context = Context(aeron_dir=aeron_directory)
    publication = context.add_exclusive_publication('aeron:udp?endpoint=224.0.1.1:40456|ttl=0', stream_id)
    sleep(0.5)

    result = publication.offer(b'abc')
    assert_that(result, is_(greater_than_or_equal_to(0)))
def test_offer__ipc__closed(aeron_directory, ipc_subscriber, stream_id):
    context = Context(aeron_dir=aeron_directory)
    publication = context.add_exclusive_publication('aeron:ipc', stream_id)
    publication.close()
    assert_that(publication.is_closed, is_(True))

    result = publication.offer(b'abc')
    assert_that(result, is_(equal_to(PUBLICATION_CLOSED)))
Example #4
0
def test_add_exclusive_publication__with_handler(aeron_directory):
    class Handler(object):
        def __init__(self):
            self.publications = list()

        def on_new_exclusive_publication(self, *args):
            self.publications.append(args)

    handler = Handler()
    context = Context(
        aeron_dir=aeron_directory,
        new_exclusive_publication_handler=handler.on_new_exclusive_publication)
    publication = context.add_exclusive_publication('aeron:ipc', 5000)

    assert_that(handler.publications, is_not(empty()))
    assert_that(handler.publications, has_length(equal_to(1)))
    assert_that(handler.publications[0][0], is_(equal_to('aeron:ipc')))
    assert_that(handler.publications[0][1], is_(equal_to(5000)))
def test_offer__multiple_publishers__same_stream(aeron_directory, ipc_subscriber, stream_id):
    context = Context(aeron_dir=aeron_directory)
    publication_1 = context.add_exclusive_publication('aeron:ipc', stream_id)
    publication_2 = context.add_exclusive_publication('aeron:ipc', stream_id)
    assert_that(publication_1.session_id, is_not(equal_to(publication_2.session_id)))

    result = publication_1.offer(b'abc')
    assert_that(result, is_(greater_than_or_equal_to(0)))

    result = publication_2.offer(b'def')
    assert_that(result, is_(greater_than_or_equal_to(0)))

    sleep(0.5)

    messages = list()
    ipc_subscriber.poll(lambda data: messages.append(data))

    assert_that(messages, has_length(equal_to(2)))
    assert_that(bytes(messages[0]), is_(equal_to(b'abc')))
    assert_that(bytes(messages[1]), is_(equal_to(b'def')))
def test_offer__ipc(aeron_directory, ipc_subscriber, stream_id):
    context = Context(aeron_dir=aeron_directory)
    publication = context.add_exclusive_publication('aeron:ipc', stream_id)
    result = publication.offer(b'abc')
    assert_that(result, is_(greater_than_or_equal_to(0)))
def test_offer__ipc__message_too_large(aeron_directory, ipc_subscriber, stream_id):
    context = Context(aeron_dir=aeron_directory)
    publication = context.add_exclusive_publication('aeron:ipc', stream_id)

    blob = bytearray(50 * 1024 * 1024)
    assert_that(calling(publication.offer).with_args(blob), raises(RuntimeError))
Example #8
0
def test_add_exclusive_publication(aeron_directory):
    context = Context(aeron_dir=aeron_directory)
    publication = context.add_exclusive_publication('aeron:ipc', 4000)
    assert_that(publication, is_not(None))
    assert_that(publication.channel, is_('aeron:ipc'))
    assert_that(publication.stream_id, is_(4000))