Ejemplo n.º 1
0
def test_encode_message():
    addstuff()
    session = Session()
    message = PullMessage()
    version = session.query(models.Version).first()
    message.add_version(version)
    assert message.to_json() == json.loads(json.dumps(message.to_json()))
Ejemplo n.º 2
0
def test_create_message():
    addstuff()
    session = Session()
    message = PullMessage()
    version = session.query(models.Version).first()
    message.add_version(version)
    assert message.to_json() == PullMessage(message.to_json()).to_json()
Ejemplo n.º 3
0
def test_encode_message():
    addstuff()
    session = Session()
    message = PullMessage()
    version = session.query(models.Version).first()
    message.add_version(version)
    msg_json = json.dumps(message.to_json(), cls=SyncdbJSONEncoder)
    assert message.to_json() == json.loads(msg_json)
Ejemplo n.º 4
0
async def handle_pull(connection: Connection):
    """
    Handle the pull request and return a dictionary object to be sent
    back to the node.

    *data* must be a dictionary-like object, usually one obtained from
    decoding a JSON dictionary in the POST body.
    """
    swell = False,
    include_extensions = True
    data_str = await connection.socket.recv()
    data = json.loads(data_str)
    try:
        request_message = PullRequestMessage(data)
    except KeyError:
        raise PullRejected("request object isn't a valid PullRequestMessage",
                           data)

    message = PullMessage()
    st = time.time()
    message.fill_for(request_message,
                     swell=swell,
                     include_extensions=include_extensions,
                     connection=connection)
    logger.info(
        f"composed message with fill_for() in {time.time()-st} seconds")

    # sends the whole bunch to the client,
    # there it is received by client's run_pull and handled by pull.py/merge
    st = time.time()
    await connection.socket.send(
        json.dumps(message.to_json(), indent=4, cls=SyncdbJSONEncoder))
    logger.info(f"sent msg to client in {time.time() - st} seconds")
    # fetch messages from client
    logger.debug(f"server listening for messages after sending object")
    async for msg_ in connection.socket:
        logger.debug(f"server getting for msg: {msg_}")
        msg = json.loads(msg_)
        # logger.debug(f"msg: {msg}")
        if msg['type'] == "request_field_payload":
            # sends payload data to client here
            logger.info(f"obj from client:{msg}")
            await send_field_payload(connection, msg)
        elif msg['type'] == 'result':
            new_version_id = msg['new_version_id']
            if new_version_id is None:
                break
        else:
            logger.debug(f"response from server:{msg}")
Ejemplo n.º 5
0
def handle_pull(data, swell=False, include_extensions=True):
    """
    Handle the pull request and return a dictionary object to be sent
    back to the node.

    *data* must be a dictionary-like object, usually one obtained from
    decoding a JSON dictionary in the POST body.
    """
    try:
        request_message = PullRequestMessage(data)
    except KeyError:
        raise PullRejected("request object isn't a valid PullRequestMessage",
                           data)

    message = PullMessage()
    message.fill_for(request_message,
                     swell=swell,
                     include_extensions=include_extensions)
    return message.to_json()
Ejemplo n.º 6
0
def handle_pull(data, swell=False, include_extensions=True):
    """
    Handle the pull request and return a dictionary object to be sent
    back to the node.

    *data* must be a dictionary-like object, usually one obtained from
    decoding a JSON dictionary in the POST body.
    """
    try:
        request_message = PullRequestMessage(data)
    except KeyError:
        raise PullRejected("request object isn't a valid PullRequestMessage", data)

    message = PullMessage()
    message.fill_for(
        request_message,
        swell=swell,
        include_extensions=include_extensions)
    return message.to_json()