def run(self): params = self.args.get('<params>') if params == '-': params = sys.stdin.read() body = json.loads(params) try: timeout = float(self.args.get('--timeout')) except ValueError: print("--timeout requires a number (e.g. --timeout=0.42)") return 1 subject, version = parse_versioned_name(self.args['<subject>']) address = self.args.get('--address') if not address: address = subject.rsplit('.', 1)[0] client = Client.from_config(self.config) def request(): trace.set_id(self.args.get('--trace-id')) return client.request(address, subject, body, timeout=timeout, version=version) N, C = int(self.args['-N']), int(self.args['-C']) if N == 1: return self._run_one_request(request) else: return self._run_many_requests(request, N, C)
def generate(cls, name): name, version = parse_versioned_name(name) return Schema({ name: { str(version or ''): { 'methods': _get_rpc_methods(cls), }, } })
def build_service(self, name): name, version = parse_versioned_name(name) if version: version = self._get_best_match(name, version) version = str(version) if version else '' try: methods = self.__raw[name][version]['methods'] except KeyError: raise ValueError("unknown service or version") return Service(name, version, methods)
def setUp(self): super(MultiServiceRPCTestCase, self).setUp() self.network = MockServiceNetwork() for interfaces in self.containers: container = self.network.add_service() for name, config in interfaces.items(): cls = config.pop("class") name, version = parse_versioned_name(name) interface = container.install_interface(cls, name=name, version=version) interface.apply_config(config) self.client = self.network.add_service().install_interface(ClientInterface) self.network.start()
def setUp(self): super(MultiServiceRPCTestCase, self).setUp() self.network = MockServiceNetwork() for interfaces in self.containers: container = self.network.add_service() for name, config in interfaces.items(): cls = config.pop('class') name, version = parse_versioned_name(name) interface = container.install_interface(cls, name=name, version=version) interface.apply_config(config) self.client = self.network.add_service().install_interface( ClientInterface) self.network.start()
def install_interfaces(container, interfaces): for name_and_version, instance_config in six.iteritems(interfaces): name, version = parse_versioned_name(name_and_version) try: cls_name = instance_config['class'] except KeyError: print("no instance class for '%s'" % name_and_version) sys.exit(1) cls = import_object(cls_name) try: interface = container.install_interface(cls, name=name, version=version) except InterfaceSkipped as e: logger.info("skipping interface %s: %s", name, e) continue interface.apply_config(instance_config)