예제 #1
0
    async def transport_provider():
        try:
            client_connection = await asyncio.open_connection('localhost', port)
            yield TransportTCP(*client_connection)

            yield FailingTransport()

            client_connection = await asyncio.open_connection('localhost', port)
            yield TransportTCP(*client_connection)
        except Exception:
            logger().error('Client connection error', exc_info=True)
            raise
예제 #2
0
 def session(*connection):
     container.transport = TransportTCP(*connection)
     container.server = RSocketServer(container.transport,
                                      IdentifiedHandlerFactory(next(index_iterator),
                                                               ServerHandler,
                                                               delay=timedelta(seconds=1)).factory)
     waiter.set()
예제 #3
0
 async def transport_provider():
     while True:
         try:
             nonlocal client_connection
             client_connection = await asyncio.open_connection(host, port)
             yield TransportTCP(*client_connection)
         except Exception:
             logger().error('Client connection error', exc_info=True)
             raise
예제 #4
0
    async def transport_provider():
        try:
            for i in range(3):
                client_connection = await asyncio.open_connection(
                    'localhost', unused_tcp_port)
                yield TransportTCP(*client_connection)

        except Exception:
            logger().error('Client connection error', exc_info=True)
            raise
예제 #5
0
    async def start():
        nonlocal service, client
        service = await asyncio.start_server(session, host, port)
        connection = await asyncio.open_connection(host, port)
        nonlocal client_arguments
        # test_overrides = {'keep_alive_period': timedelta(minutes=20)}
        client_arguments = client_arguments or {}

        # client_arguments.update(test_overrides)

        client = RSocketClient(single_transport_provider(TransportTCP(*connection)), **(client_arguments or {}))

        if auto_connect_client:
            await client.connect()
예제 #6
0
async def main():
    connection = await asyncio.open_connection('localhost', 7000)

    setup_payload = Payload(data=str(uuid4()).encode(),
                            metadata=composite(
                                route('shell-client'),
                                authenticate_simple('user', 'pass')))

    async with RSocketClient(single_transport_provider(
            TransportTCP(*connection)),
                             setup_payload=setup_payload,
                             metadata_encoding=WellKnownMimeTypes.
                             MESSAGE_RSOCKET_COMPOSITE_METADATA):
        await asyncio.sleep(5)
예제 #7
0
async def main(server_port):
    logging.info('Connecting to server at localhost:%s', server_port)

    connection = await asyncio.open_connection('localhost', server_port)

    async with RSocketClient(single_transport_provider(
            TransportTCP(*connection)),
                             metadata_encoding=WellKnownMimeTypes.
                             MESSAGE_RSOCKET_COMPOSITE_METADATA) as client:
        await request_response(client)
        await request_stream(client)
        await request_slow_stream(client)
        await request_channel(client)
        await request_stream_invalid_login(client)
        await request_fragmented_stream(client)
예제 #8
0
async def main(server_port):
    completion_event = Event()

    class Subscriber(DefaultSubscriber):
        def __init__(self):
            super().__init__()
            self.values = []
            self.subscription: Optional[Subscription] = None

        def on_next(self, value, is_complete=False):
            self.values.append(value)
            self.subscription.request(1)

        def on_complete(self):
            completion_event.set()

        def on_error(self, exception: Exception):
            completion_event.set()

    connection = await asyncio.open_connection('localhost', server_port)

    async with RSocketClient(single_transport_provider(
            TransportTCP(*connection)),
                             metadata_encoding=WellKnownMimeTypes.
                             MESSAGE_RSOCKET_COMPOSITE_METADATA.value.name,
                             data_encoding=WellKnownMimeTypes.APPLICATION_JSON.
                             value.name) as client:
        metadata = CompositeMetadata()
        metadata.append(
            RoutingMetadata(['investigation.getInvestigationByContext']))

        body = json.dumps({'active': True}).encode()

        request = Payload(body, metadata.serialize())

        subscriber = Subscriber()
        client.request_stream(request).subscribe(subscriber)
        await completion_event.wait()

        await asyncio.sleep(4)  # Used to show keepalive is working

        assert len(subscriber.values) == 2
예제 #9
0
async def main(server_port):
    logging.info('Connecting to server at localhost:%s', server_port)

    connection = await asyncio.open_connection('localhost', server_port)

    async with RSocketClient(single_transport_provider(
            TransportTCP(*connection)),
                             metadata_encoding=WellKnownMimeTypes.
                             MESSAGE_RSOCKET_COMPOSITE_METADATA) as client:
        rx_client = RxRSocket(client)
        await request_response(rx_client)
        await request_stream(rx_client)
        await request_slow_stream(rx_client)
        await request_channel(rx_client)
        await request_stream_invalid_login(rx_client)
        await request_fragmented_stream(rx_client)

        await metadata_push(rx_client, b'audit info')
        await request_last_metadata(rx_client)

        await fire_and_forget(rx_client, b'aux data')
        await request_last_fnf(rx_client)
예제 #10
0
async def main(server_port):
    logging.info('Connecting to server at localhost:%s', server_port)

    connection = await asyncio.open_connection('localhost', server_port)

    async with RSocketClient(
            single_transport_provider(TransportTCP(*connection))) as client:
        payload = Payload(b'%Y-%m-%d %H:%M:%S')

        async def run_request_response():
            try:
                while True:
                    result = await client.request_response(payload)
                    logging.info('Response: {}'.format(result.data))
                    await asyncio.sleep(1)
            except asyncio.CancelledError:
                pass

        task = asyncio.create_task(run_request_response())

        await asyncio.sleep(5)
        task.cancel()
        await task
예제 #11
0
 def session(*connection):
     nonlocal server
     server = RSocketServer(TransportTCP(*connection), **(server_arguments or {}))
     wait_for_server.set()
예제 #12
0
def handle_client(reader, writer):
    RSocketServer(TransportTCP(reader, writer), handler_factory=handler_factory)
예제 #13
0
 def session(*connection):
     RSocketServer(TransportTCP(*connection), handler_factory=Handler)
예제 #14
0
 def session(*connection):
     nonlocal server, transport
     transport = TransportTCP(*connection)
     server = RSocketServer(transport,
                            IdentifiedHandlerFactory(next(index_iterator), ServerHandler).factory)
     wait_for_server.set()
예제 #15
0
 async def transport_provider(max_reconnect):
     for i in range(max_reconnect):
         connection = await asyncio.open_connection('localhost',
                                                    server_port)
         yield TransportTCP(*connection)
예제 #16
0
def handle_client(reader, writer):
    RSocketServer(TransportTCP(reader, writer),
                  handler_factory=handler_factory,
                  lease_publisher=SingleLeasePublisher(
                      maximum_request_count=5,
                      maximum_lease_time=timedelta(seconds=2)))