def test_do_gremlin_cancel_nonexistent(self): with self.assertRaises(requests.HTTPError): query_id = "some-guid-here" request_generator = create_request_generator(AuthModeEnum.IAM, IAMAuthCredentialsProvider.ENV) try: do_gremlin_cancel(self.host, self.port, self.ssl, AuthModeEnum.IAM, request_generator, query_id) except requests.HTTPError as exception: content = exception.response.json() self.assertTrue('requestId' in content) self.assertTrue('code' in content) self.assertTrue('detailedMessage' in content) self.assertEqual('InvalidParameterException', content['code']) raise exception
def test_do_gremlin_cancel_nonexistent(self): with self.assertRaises(requests.HTTPError): query_id = "ac7d5a03-00cf-4280-b464-edbcbf51ffce" request_generator = create_request_generator(AuthModeEnum.DEFAULT) try: do_gremlin_cancel(self.host, self.port, self.ssl, self.auth_mode, request_generator, query_id) except requests.HTTPError as exception: content = exception.response.json() self.assertTrue('requestId' in content) self.assertTrue('code' in content) self.assertTrue('detailedMessage' in content) self.assertEqual('InvalidParameterException', content['code']) raise exception
def gremlin_status(self, line='', local_ns: dict = None): parser = argparse.ArgumentParser() parser.add_argument('-q', '--queryId', default='', help='The ID of a running Gremlin query. Only displays the status of the specified query.') parser.add_argument('-c', '--cancelQuery', action='store_true', help='Required for cancellation. Parameter has no corresponding value.') parser.add_argument('-w', '--includeWaiting', action='store_true', help='(Optional) Normally, only running queries are included in the response. When the includeWaiting parameter is specified, the status of all waiting queries is also returned.') parser.add_argument('--store-to', type=str, default='', help='store query result to this variable') args = parser.parse_args(line.split()) request_generator = create_request_generator(self.graph_notebook_config.auth_mode, self.graph_notebook_config.iam_credentials_provider_type) if not args.cancelQuery: res = do_gremlin_status(self.graph_notebook_config.host, self.graph_notebook_config.port, self.graph_notebook_config.ssl, self.graph_notebook_config.auth_mode, request_generator, args.queryId, args.includeWaiting) else: if args.queryId == '': print(GREMLIN_CANCEL_HINT_MSG) return else: res = do_gremlin_cancel(self.graph_notebook_config.host, self.graph_notebook_config.port, self.graph_notebook_config.ssl, self.graph_notebook_config.auth_mode, request_generator, args.queryId) print(json.dumps(res, indent=2)) store_to_ns(args.store_to, res, local_ns)
def test_do_gremlin_status_and_cancel(self): query = "g.V().out().out().out().out()" query_res = {} gremlin_query_thread = threading.Thread( target=self.do_gremlin_query_save_results, args=( query, query_res, )) gremlin_query_thread.start() time.sleep(3) query_id = '' request_generator = create_request_generator(AuthModeEnum.DEFAULT) status_res = do_gremlin_status(self.host, self.port, self.ssl, self.auth_mode, request_generator, query_id, False) self.assertEqual(type(status_res), dict) self.assertTrue('acceptedQueryCount' in status_res) self.assertTrue('runningQueryCount' in status_res) self.assertTrue(status_res['runningQueryCount'] == 1) self.assertTrue('queries' in status_res) query_id = '' for q in status_res['queries']: if query in q['queryString']: query_id = q['queryId'] self.assertNotEqual(query_id, '') cancel_res = do_gremlin_cancel(self.host, self.port, self.ssl, self.auth_mode, request_generator, query_id) self.assertEqual(type(cancel_res), dict) self.assertTrue('status' in cancel_res) self.assertTrue('payload' in cancel_res) self.assertEqual('200 OK', cancel_res['status']) gremlin_query_thread.join() self.assertFalse('result' in query_res) self.assertTrue('error' in query_res) self.assertTrue('code' in query_res['error']) self.assertTrue('requestId' in query_res['error']) self.assertTrue('detailedMessage' in query_res['error']) self.assertTrue('TimeLimitExceededException' in query_res['error'])
def test_do_gremlin_cancel_non_str_query_id(self): with self.assertRaises(ValueError): query_id = 42 request_generator = create_request_generator(AuthModeEnum.IAM, IAMAuthCredentialsProvider.ENV) do_gremlin_cancel(self.host, self.port, self.ssl, AuthModeEnum.IAM, request_generator, query_id)
def test_do_gremlin_cancel_non_str_query_id(self): with self.assertRaises(ValueError): query_id = 42 request_generator = create_request_generator(AuthModeEnum.DEFAULT) do_gremlin_cancel(self.host, self.port, self.ssl, self.auth_mode, request_generator, query_id)