예제 #1
0
 def test_round_trip_reverse(self):
     fname = os.path.join(self._td, 'd.sock')
     ss = sample_server_cli
     self.assert_server_alive()
     with dispatch.open('', fname) as conn:
         dispatch.msg_write_type(conn, ss.ROUND_TRIP)
         dispatch.msg_write_type(conn, 2500)
         dispatch.msg_write_uint64(conn, 18446743967598447505)
         dispatch.msg_write_int64(conn, -9223372036854775807)
         dispatch.msg_write_uint32(conn, 2147477648)
         dispatch.msg_write_int32(conn, -6000)
         dispatch.msg_write_uint16(conn, 512)
         dispatch.msg_write_uint8(conn, 255)
         dispatch.msg_write_string(conn, "Hello Earth!")
         t = dispatch.msg_read_type(conn)
         self.assertEqual(t, ss.T_RESULT)
         values = []
         values.append(dispatch.msg_read_string(conn))
         values.append(dispatch.msg_read_uint8(conn))
         values.append(dispatch.msg_read_uint16(conn))
         values.append(dispatch.msg_read_int32(conn))
         values.append(dispatch.msg_read_uint32(conn))
         values.append(dispatch.msg_read_int64(conn))
         values.append(dispatch.msg_read_uint64(conn))
         values.append(dispatch.msg_read_type(conn))
         self.assertEqual(values, [
             "Hello Earth!", 255, 512, -6000, 2147477648,
             -9223372036854775807, 18446743967598447505, 2500
         ])
예제 #2
0
def round_trip_reverse(dtype, conn):
    try:
        values = []
        values.append(dispatch.msg_read_type(conn))
        values.append(dispatch.msg_read_uint64(conn))
        values.append(dispatch.msg_read_int64(conn))
        values.append(dispatch.msg_read_uint32(conn))
        values.append(dispatch.msg_read_int32(conn))
        values.append(dispatch.msg_read_uint16(conn))
        values.append(dispatch.msg_read_uint8(conn))
        values.append(dispatch.msg_read_string(conn))
        print >> sys.stderr, 'values=%r' % values
        dispatch.msg_write_type(conn, T_RESULT)
        # now the data:
        dispatch.msg_write_string(conn, values.pop())
        dispatch.msg_write_uint8(conn, values.pop())
        dispatch.msg_write_uint16(conn, values.pop())
        dispatch.msg_write_int32(conn, values.pop())
        dispatch.msg_write_uint32(conn, values.pop())
        dispatch.msg_write_int64(conn, values.pop())
        dispatch.msg_write_uint64(conn, values.pop())
        dispatch.msg_write_type(conn, values.pop())
    except Exception:
        dispatch.msg_write_type(conn, T_ERROR)
        dispatch.msg_write_uint16(conn, 1)
예제 #3
0
def echo_string(dtype, conn):
    print 'EString 01'
    s1 = dispatch.msg_read_string(conn)
    print 'EString 02', s1
    dispatch.msg_write_string(conn, s1)
    print 'EString 03'
    dispatch.msg_write_uint16(conn, 0)
    print 'EString 04'
예제 #4
0
def handle_echo(dtype, conn):
    v1 = dispatch.msg_read_string(conn)
    v2 = dispatch.msg_read_int64(conn)
    v3 = dispatch.msg_read_uint8(conn)
    dispatch.msg_write_type(conn, MSG_REPLY)
    dispatch.msg_write_string(conn, v1)
    dispatch.msg_write_int64(conn, v2)
    dispatch.msg_write_uint8(conn, v3)
    return
예제 #5
0
def handle_reverse(dtype, conn):
    v1 = dispatch.msg_read_string(conn)
    v2 = dispatch.msg_read_int64(conn)
    v3 = dispatch.msg_read_uint8(conn)
    dispatch.msg_write_type(conn, MSG_REPLY)
    dispatch.msg_write_uint8(conn, v3)
    dispatch.msg_write_int64(conn, v2)
    dispatch.msg_write_string(conn, ''.join(reversed(v1)))
    return
예제 #6
0
 def test_single_operation2(self):
     with dispatch.open('', self.SOCKF) as conn:
         dispatch.msg_write_type(conn, MSG_ECHO)
         dispatch.msg_write_string(conn, 'Hello World')
         dispatch.msg_write_int64(conn, 5050505)
         dispatch.msg_write_uint8(conn, 0xA)
         self.assertEqual(dispatch.msg_read_type(conn), MSG_REPLY)
         r1 = dispatch.msg_read_string(conn)
         r2 = dispatch.msg_read_int64(conn)
         r3 = dispatch.msg_read_uint8(conn)
         self.assertEqual(r1, 'Hello World')
         self.assertEqual(r2, 5050505)
         self.assertEqual(r3, 0xA)
예제 #7
0
    def test_foobar(self):
        self.assert_server_alive()
        fname = os.path.join(self._td, 'd.sock')
        conn = dispatch.open('', fname)
        with conn:
            dispatch.msg_write_type(conn, echo_server.ECHO_STRING)
            dispatch.msg_write_string(conn, "foobar")

            s = dispatch.msg_read_string(conn)
            # mimic the common error number style
            e = dispatch.msg_read_uint16(conn)
            self.assertEqual(s, 'foobar')
            self.assertEqual(e, 0)
예제 #8
0
 def test_multiple_rounds(self):
     self.assert_server_alive()
     fname = os.path.join(self._td, 'd.sock')
     for ii in range(0, 16):
         self.assert_server_alive()
         with dispatch.open('', fname) as conn:
             tostr = chr(0x41 + ii) * (ii + 1)
             dispatch.msg_write_type(conn, echo_server.ECHO_STRING)
             dispatch.msg_write_string(conn, tostr)
             fromstr = dispatch.msg_read_string(conn)
             err = dispatch.msg_read_uint16(conn)
         self.assertEqual(err, 0)
         self.assertEqual(tostr, fromstr)
예제 #9
0
def echo_hello(dtype, conn):
    dispatch.msg_write_string(conn, "Hello, World")
    dispatch.msg_write_uint16(conn, 0)