Esempio n. 1
0
def test6():

    # Binary file chunking...
    spush = ZSocketServer(zmq.PUSH, "ipc", "test5-push.ipc", "test6")

    assert(spush is not None)
    spush.bind()

    cpull = ZSocketClient(zmq.PULL, "ipc", "test5-push.ipc", "test6")
    assert(cpull is not None)
    cpull.connect()

    nr_chunks = 0
    chunksize = 1000
    with open("testfile.bin", "rb") as f:
        while True:
            chunk = f.read(chunksize)
            if chunk:
                spush.send({'message':["CHUNK", str(nr_chunks), chunk]})
                nr_chunks += 1
            else:
                break
        f.close()

    i = 0
    with open("testfile-recv.bin", "w+") as f:
        while True:
            msg = cpull.recv()['message']
            assert(msg[0] == "CHUNK")
            f.write(msg[2])
            i += 1
            if i == nr_chunks:
                break
        f.close()

    cpull.close()
    spush.close()

    # Run md5sum on both files to ensure they are identical
    tx_md5 = zhelpers.md5sum("testfile.bin")
    rx_md5 = zhelpers.md5sum("testfile-recv.bin")
    assert(tx_md5 == rx_md5 and rx_md5 is not None)

    print "test6() - PASSED"
Esempio n. 2
0
def test7():

    # Binary file chunking.. using a zpipe.
    pipes = zpipe()
    spush = pipes[0]
    cpull = pipes[1]

    nr_chunks = 0
    chunksize = 1000
    with open("testfile.bin", "rb") as f:
        while True:
            chunk = f.read(chunksize)
            if chunk:
                spush.send({'message':["CHUNK", str(nr_chunks), chunk]})
                nr_chunks += 1
            else:
                break
        f.close()

    i = 0
    with open("testfile-recv.bin", "w+") as f:
        while True:
            msg = cpull.recv()['message']
            assert(msg[0] == "CHUNK")
            f.write(msg[2])
            i += 1
            if i == nr_chunks:
                break
        f.close()

    cpull.close()
    spush.close()

    # Run md5sum on both files to ensure they are identical
    tx_md5 = zhelpers.md5sum("testfile.bin")
    rx_md5 = zhelpers.md5sum("testfile-recv.bin")
    assert(tx_md5 == rx_md5 and rx_md5 is not None)

    print "test7() - PASSED"