예제 #1
0
def init():
    global __node
    global _nodes
    port = random.randint(1,1000000)
    ep = "localhost:%d" % port
    server = MockServer(ep, __handler)
    group = Group(server, __registry, __pool)
    group.start()
    _nodes.append(group)
    __node = group
예제 #2
0
def init(registry, pool):
    global __group
    global _nodes
    port = random.randint(1,1000000)
    ep = "localhost:%d" % port

    print ep
    server = MockServer(ep, LockHandler())
    group = Group(server, registry, pool)
    group.start()
    _nodes.append(group)
    __group = group
예제 #3
0
    def setUp(self):
        super(TornadoTransportTestCase, self).setUp()

        self.registry = StaticRegistry('{} Registry'.format(self.__class__.__name__))
        self.groups = []

        for i in xrange(3):
            handler = SimpleKVHandler('{}'.format(i))
            pool = Pool()
            server = Server(handler)
            group = Group(server, self.registry, pool, SimpleKVHandler.hash_key)
            group.start()
            self.groups.append(group)

        self.group = self.groups[0]
예제 #4
0
    def setUp(self):
        super(ZMQTestCase, self).setUp()

        self.registry = StaticRegistry('Test')
        self.context = zmq.Context(1)

        self.groups = []
        for i in xrange(3):
            port = get_unused_port()
            endpoint = '127.0.0.1:{}'.format(port)
            handler = SimpleKVHandler('{}'.format(i))
            pool = Pool(context=self.context, io_loop=self.io_loop)
            server = Server(handler, endpoint, self.context, io_loop=self.io_loop)
            group = Group(server, self.registry, pool, SimpleKVHandler.hash_key)
            group.start()
            self.groups.append(group)
        self.group = self.groups[0]
예제 #5
0
    def call(self, method, *args, **kwargs):
        key = Group.hash_key(method, *args, **kwargs)
        if key in self._futures:
            return self._futures[key]

        future = concurrent.TracebackFuture()

        msg = json.dumps({
            'key': key,
            'method': method,
            'args': list(args),
            'kwargs': kwargs
        }) + '\r\n'
        self._stream.write(msg)
        self._futures[key] = future
        self._ensure_reading()
        return future
예제 #6
0
 def call(self, method, *args, **kwargs):
     key = Group.hash_key(method, *args, **kwargs)
     msg = json.dumps({"key": key, "method": method, "args": args, "kwargs": kwargs}) + "\r\n"
     self._socket.send(msg)
     return self.recv_data()