Exemplo n.º 1
0
 def testIncompleteRequest(self):
     '''Test calling RPC with incomplete request.'''
    
     # Create data
     service_request = test_pb2.Request()
     
     # Fake socket with prepared response
     socket = FakeSocket()
     socket.withResponseProto(self.service_response)
     socketFactory = FakeSocketFactory()
     socketFactory.setSocket(socket)
     
     # Create channel
     channel    = ch.SocketRpcChannel("host", -1, socketFactory)
     controller = channel.newController()
     
     # Create the service
     service = test_pb2.TestService_Stub(channel)
     
     # Call RPC method
     callback = FakeCallback()
     service.TestMethod(controller,service_request,callback)
     
     self.assertFalse(callback.invoked,'Callback invoked')
     self.assertEquals(rpc_pb2.BAD_REQUEST_PROTO,controller.reason)
     self.assertTrue(controller.failed())
Exemplo n.º 2
0
 def testGoodRpc(self):
     '''Test a good RPC call.'''
     
     # Fake socket with prepared response
     socket = FakeSocket()
     socket.withResponseProto(self.service_response)
     socketFactory = FakeSocketFactory()
     socketFactory.setSocket(socket)
     
     # Create channel
     channel    = ch.SocketRpcChannel("host", -1, socketFactory)
     controller = channel.newController()
     
     # Create the service
     service = test_pb2.TestService_Stub(channel)
     
     # Call RPC method
     callback = FakeCallback()
     service.TestMethod(controller,self.service_request,callback)
     
     self.assertTrue(callback.invoked,'Callback invoked')
     self.assertEquals(self.service_response.str_data,
                       callback.response.str_data,'Response message')
     self.assertEquals(self.serialized_request,
                       socket.getRequest().request_proto,
                       'Request protocol serialisation')
     self.assertEquals(service.DESCRIPTOR.full_name,
                       socket.getRequest().service_name,'Service name')
     self.assertEquals(service.DESCRIPTOR.methods[0].name,
                       socket.getRequest().method_name,'Method name')
Exemplo n.º 3
0
    def testGoodRpc(self):
        '''Test a good RPC call.'''

        # Fake socket with prepared response
        socket = FakeSocket()
        socket.withResponseProto(self.service_response)
        socketFactory = FakeSocketFactory()
        socketFactory.setSocket(socket)

        # Create channel
        channel = ch.SocketRpcChannel("host", -1, socketFactory)

        # Create the service
        service = test_pb2.TestService_Stub(channel)

        def VerifyGoodRpc(response):
            self.assertEquals(self.service_response.str_data,
                              response.str_data, 'Response message')
            self.assertEquals(self.serialized_request,
                              socket.getRequest().request_proto,
                              'Request protocol serialisation')
            self.assertEquals(service.DESCRIPTOR.full_name,
                              socket.getRequest().service_name, 'Service name')
            self.assertEquals(service.DESCRIPTOR.methods[0].name,
                              socket.getRequest().method_name, 'Method name')
            
        # Call RPC method
        controller = channel.newController()
        callback = FakeCallback()
        service.TestMethod(controller, self.service_request, callback)

        self.assertTrue(callback.invoked, 'Callback invoked')
        VerifyGoodRpc(callback.response)
        
        # Call Blocking RPC
        controller = channel.newController()
        response = service.TestMethod(controller, self.service_request, None)
        VerifyGoodRpc(response)
Exemplo n.º 4
0
    def testIncompleteRequest(self):
        '''Test calling RPC with incomplete request.'''

        # Create data
        service_request = test_pb2.Request()

        # Fake socket with prepared response
        socket = FakeSocket()
        socket.withResponseProto(self.service_response)
        socketFactory = FakeSocketFactory()
        socketFactory.setSocket(socket)

        # Create channel
        channel = ch.SocketRpcChannel("host", -1, socketFactory)

        # Create the service
        service = test_pb2.TestService_Stub(channel)

        # Call RPC method
        controller = channel.newController()
        callback = FakeCallback()
        service.TestMethod(controller, service_request, callback)

        self.assertTrue(callback.invoked, 'Callback invoked')
        self.assertTrue(callback.response is None, 'Response')
        self.assertEquals(rpc_pb2.BAD_REQUEST_PROTO, controller.reason)
        self.assertTrue(controller.failed())

        # Call Blocking RPC
        controller = channel.newController()
        try:
            service.TestMethod(controller, service_request, None)
            self.fail('Should have thrown error')
        except RpcError:
            self.assertTrue(controller.failed())
            self.assertEquals(rpc_pb2.BAD_REQUEST_PROTO, controller.reason, 
                              'Error reason')