예제 #1
0
 def make_req(self, *args):
     proc = Process(target=self.start_service, args=(self.addr, ))
     proc.start()
     self.client = Client(self.addr)
     res, err = self.client.call('divide', *args)
     proc.terminate()
     return res, err
예제 #2
0
 def _run_test_with_encoder(self, encoder):
     proc = Process(target=self.start_service, args=(self.addr, encoder))
     proc.start()
     self.client = Client(self.addr, encoder=encoder)
     res, err = self.client.call('divide', 10, 2)
     proc.terminate()
     expected = 5
     self.assertEqual(expected, res)
예제 #3
0
 def make_req(self, *args):
     proc = Process(target=self.start_service, args=(self.addr,))
     proc.start()
     self.client = Client(self.addr)
     res, err = self.client.call('divide', *args)
     proc.terminate()
     return res, err
예제 #4
0
def main():
    clients = []
    for port in range(5001, 5008):
        clients.append(Client('tcp://127.0.0.1:{}'.format(port)))

    for c in clients:
        start = time.time()
        result, error = c.call('test')
        print('{:18} - {:.2f} ms'.format(result,
                                         (time.time() - start) * 1000))
예제 #5
0
 def _run_test_with_encoder(self, encoder):
     proc = Process(
         target=self.start_service,
         args=(self.addr, encoder)
     )
     proc.start()
     self.client = Client(self.addr, encoder=encoder)
     res, err = self.client.call('divide', 10, 2)
     proc.terminate()
     expected = 5
     self.assertEqual(expected, res)
예제 #6
0
def run(N, addr):
    # Fork service
    service_process = Process(target=start_service, args=(addr, N))
    service_process.start()
    time.sleep(0.1)  # Wait for service to connect

    # Create client and make reqs
    c = Client(addr)
    bench(c, N)
    c.sock.close()
    time.sleep(0.2)
    service_process.terminate()
예제 #7
0
class TestEncodingDecoding(BaseTestCase):
    """ Test the communication between endpoints using various
    various mechanisms """
    def _run_test_with_encoder(self, encoder):
        proc = Process(target=self.start_service, args=(self.addr, encoder))
        proc.start()
        self.client = Client(self.addr, encoder=encoder)
        res, err = self.client.call('divide', 10, 2)
        proc.terminate()
        expected = 5
        self.assertEqual(expected, res)

    def test_json_encoder(self):
        self._run_test_with_encoder(encoder.JSONEncoder())

    def test_msgpack_encoder(self):
        self._run_test_with_encoder(encoder.MsgPackEncoder())
예제 #8
0
class TestTCPProtocol(BaseTestCase):
    def make_req(self, *args):
        proc = Process(target=self.start_service, args=(self.addr, ))
        proc.start()
        self.client = Client(self.addr)
        res, err = self.client.call('divide', *args)
        proc.terminate()
        return res, err

    def test_req_rep_w_success(self):
        res, err = self.make_req(6, 2)
        self.assertEqual(3, res)
        self.assertTrue(err is None)

    def test_req_rep_w_error(self):
        res, err = self.make_req(6, 0)
        self.assertTrue(res is None)
        self.assertTrue(err is not None)
예제 #9
0
class TestTCPProtocol(BaseTestCase):

    def make_req(self, *args):
        proc = Process(target=self.start_service, args=(self.addr,))
        proc.start()
        self.client = Client(self.addr)
        res, err = self.client.call('divide', *args)
        proc.terminate()
        return res, err

    def test_req_rep_w_success(self):
        res, err = self.make_req(6,2)
        self.assertEqual(3, res)
        self.assertTrue(err is None)

    def test_req_rep_w_error(self):
        res, err = self.make_req(6,0)
        self.assertTrue(res is None)
        self.assertTrue(err is not None)
예제 #10
0
class TestEncodingDecoding(BaseTestCase):
    """ Test the communication between endpoints using various
    various mechanisms """

    def _run_test_with_encoder(self, encoder):
        proc = Process(
            target=self.start_service,
            args=(self.addr, encoder)
        )
        proc.start()
        self.client = Client(self.addr, encoder=encoder)
        res, err = self.client.call('divide', 10, 2)
        proc.terminate()
        expected = 5
        self.assertEqual(expected, res)

    def test_json_encoder(self):
        self._run_test_with_encoder(encoder.JSONEncoder())

    def test_msgpack_encoder(self):
        self._run_test_with_encoder(encoder.MsgPackEncoder())
예제 #11
0
파일: core.py 프로젝트: richwu/oi
 def make(addr):
     c = Client(addr)
     c.sock._set_recv_timeout(timeout)
     return c
예제 #12
0
 def setUp(self):
     addr = 'inproc://test'
     self.client = Client(addr)
     self.service = Service(addr)
     self.service.register('divide', lambda x, y: x / y)
     self.service.register('echo', lambda x: x)
예제 #13
0
# client

from nanoservice import Client

c = Client('ipc:///tmp/service.sock')

res, err = c.call('greet', 'John Doe')
print('Greeting: {}'.format(res))

res, err = c.call('add', 2, 3)
print('Addition: 2 + 3  = {}'.format(res))