def test_full_pool(self): def thread_factory(callable): raise exception.ResourceExhausted("Too many tasks", resource="test", current_tasks=0) ctx = FakeContext() request = JsonRpcRequest.decode( '{"jsonrpc":"2.0","method":"Host.stats","params":{},"id":"943"}') server = JsonRpcServer(None, 0, None, threadFactory=thread_factory) server._runRequest(ctx, request) error = ctx.response.toDict().get('error') self.assertEqual(1100, error.get('code')) msg = error.get('message') self.assertTrue(msg.startswith("Not enough resources:")) # not deterministic order in a dict so we need to parse reason = json.loads(msg[22:].replace("'", '"')) self.assertEqual( { "reason": "Too many tasks", "resource": "test", "current_tasks": 0 }, reason)
def constructServer(tp, bridge, ssl=False): server = JsonRpcServer(bridge) with attachedReactor(tp, server, ssl) as clientFactory: try: yield server, clientFactory finally: server.stop()
def __init__(self, bridge, subs, timeout, scheduler): self._executor = executor.Executor(name="jsonrpc.Executor", workers_count=_THREADS, max_tasks=_TASKS, scheduler=scheduler) self._server = JsonRpcServer(bridge, timeout, self._executor.dispatch) self._reactor = StompReactor(subs) self.startReactor()
def __init__(self, bridge, subs, timeout, scheduler, cif): self._executor = executor.Executor(name="jsonrpc", workers_count=_THREADS, max_tasks=_TASKS, scheduler=scheduler) self._bridge = bridge self._server = JsonRpcServer( bridge, timeout, cif, functools.partial(self._executor.dispatch, timeout=_TIMEOUT, discard=False)) self._reactor = StompReactor(subs) self.startReactor()
def __init__(self, bridge, backendConfig, truststore_path=None): reactors = {} self.bridge = bridge self.server = JsonRpcServer(bridge, _simpleThreadFactory) self._cfg = backendConfig for backendType, cfg in backendConfig: if backendType not in reactors: if backendType == "tcp": reactors["tcp"] = self._createTcpReactor(truststore_path) elif backendType == "stomp": reactors["stomp"] = \ self._createStompReactor(truststore_path) elif backendType == "amqp": if ProtonReactor is None: continue reactors["amqp"] = self._createProtonReactor() self._reactors = reactors
def constructServer(tp, bridge): queue = Queue() server = JsonRpcServer(bridge, queue) with constructReactor(tp) as (reactor, clientFactory, laddr): def _accept(listener, client): client.setInbox(queue) reactor.createListener(laddr, _accept) t = threading.Thread(target=server.serve_requests) t.setDaemon(True) t.start() def jsonClientFactory(): return JsonRpcClient(clientFactory()) try: yield server, jsonClientFactory finally: server.stop()
def __init__(self, bridge): self._server = JsonRpcServer(bridge, _simpleThreadFactory) self._reactors = []