def test_do_sparql_cancel_non_str_query_id(self):
     with self.assertRaises(ValueError):
         query_id = 42
         request_generator = create_request_generator(
             AuthModeEnum.IAM, IAMAuthCredentialsProvider.ENV)
         do_sparql_cancel(self.host, self.port, self.ssl, request_generator,
                          query_id, False)
 def setUp(self) -> None:
     request_generator = create_request_generator(
         AuthModeEnum.IAM, IAMAuthCredentialsProvider.ENV)
     res = do_sparql_status(self.host, self.port, self.ssl,
                            request_generator)
     for q in res['queries']:
         do_sparql_cancel(self.host, self.port, self.ssl, request_generator,
                          q['queryId'], False)
    def test_do_sparql_status_and_cancel_silently(self):
        query = "SELECT * WHERE { ?s ?p ?o . ?s2 ?p2 ?o2 .?s3 ?p3 ?o3 .} ORDER BY DESC(?s) LIMIT 100"
        query_res = {}
        sparql_query_thread = threading.Thread(target=self.do_sparql_query_save_result, args=(query, query_res,))
        sparql_query_thread.start()
        time.sleep(3)

        query_id = ''
        request_generator = create_request_generator(AuthModeEnum.DEFAULT)
        status_res = do_sparql_status(self.host, self.port, self.ssl, request_generator, query_id)
        self.assertEqual(type(status_res), dict)
        self.assertTrue('acceptedQueryCount' in status_res)
        self.assertTrue('runningQueryCount' in status_res)
        self.assertEqual(1, status_res['runningQueryCount'])
        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_sparql_cancel(self.host, self.port, self.ssl, request_generator, query_id, True)
        self.assertEqual(type(cancel_res), dict)
        self.assertTrue('acceptedQueryCount' in cancel_res)
        self.assertTrue('runningQueryCount' in cancel_res)
        self.assertTrue('queries' in cancel_res)

        sparql_query_thread.join()
        self.assertEqual(type(query_res['result']), dict)
        self.assertTrue('s3' in query_res['result']['head']['vars'])
        self.assertTrue('p3' in query_res['result']['head']['vars'])
        self.assertTrue('o3' in query_res['result']['head']['vars'])
        self.assertEqual([], query_res['result']['results']['bindings'])
Exemple #4
0
    def sparql_status(self, line='', local_ns: dict = None):
        parser = argparse.ArgumentParser()
        parser.add_argument('-q', '--queryId', default='',
                            help='The ID of a running SPARQL query. Only displays the status of the specified query.')
        parser.add_argument('-c', '--cancelQuery', action='store_true',
                            help='Tells the status command to cancel a query. This parameter does not take a value')
        parser.add_argument('-s', '--silent', action='store_true',
                            help='If silent=true then the running query is cancelled and the HTTP response code is 200. If silent is not present or silent=false, the query is cancelled with an HTTP 500 status code.')
        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_sparql_status(self.graph_notebook_config.host, self.graph_notebook_config.port,
                                   self.graph_notebook_config.ssl, request_generator, args.queryId)

        else:
            if args.queryId == '':
                print(SPARQL_CANCEL_HINT_MSG)
                return
            else:
                res = do_sparql_cancel(self.graph_notebook_config.host, self.graph_notebook_config.port,
                                       self.graph_notebook_config.ssl, request_generator, args.queryId, args.silent)

        store_to_ns(args.store_to, res, local_ns)
        print(json.dumps(res, indent=2))
 def test_do_sparql_cancel_nonexistent(self):
     query_id = "ac7d5a03-00cf-4280-b464-edbcbf51ffce"
     request_generator = create_request_generator(AuthModeEnum.DEFAULT)
     res = do_sparql_cancel(self.host, self.port, self.ssl, request_generator, query_id, False)
     self.assertEqual(type(res), dict)
     self.assertTrue('acceptedQueryCount' in res)
     self.assertTrue('runningQueryCount' in res)
     self.assertTrue('queries' in res)
    def test_do_sparql_status_and_cancel(self):
        query = "SELECT * WHERE { ?s ?p ?o . ?s2 ?p2 ?o2 .?s3 ?p3 ?o3 .} ORDER BY DESC(?s) LIMIT 100"
        query_res = {}
        sparql_query_thread = threading.Thread(
            target=self.do_sparql_query_save_result, args=(
                query,
                query_res,
            ))
        sparql_query_thread.start()
        time.sleep(1)

        query_id = ''
        request_generator = create_request_generator(
            AuthModeEnum.IAM, IAMAuthCredentialsProvider.ENV)
        status_res = do_sparql_status(self.host, self.port, self.ssl,
                                      self.request_generator, query_id)
        self.assertEqual(type(status_res), dict)
        self.assertTrue('acceptedQueryCount' in status_res)
        self.assertTrue('runningQueryCount' in status_res)
        self.assertTrue('queries' in status_res)

        time.sleep(1)

        query_id = ''
        for q in status_res['queries']:
            if query in q['queryString']:
                query_id = q['queryId']

        self.assertNotEqual(query_id, '')

        cancel_res = do_sparql_cancel(self.host, self.port, self.ssl,
                                      request_generator, query_id, False)
        self.assertEqual(type(cancel_res), dict)
        self.assertTrue('acceptedQueryCount' in cancel_res)
        self.assertTrue('runningQueryCount' in cancel_res)
        self.assertTrue('queries' in cancel_res)

        sparql_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.assertEqual('CancelledByUserException',
                         query_res['error']['code'])
 def test_do_sparql_cancel_non_str_query_id(self):
     with self.assertRaises(ValueError):
         query_id = 42
         request_generator = create_request_generator(AuthModeEnum.DEFAULT)
         do_sparql_cancel(query_id, False, self.host, self.port, self.ssl, request_generator)
 def setUp(self) -> None:
     request_generator = create_request_generator(AuthModeEnum.DEFAULT)
     res = do_sparql_status(self.host, self.port, self.ssl, request_generator)
     for q in res['queries']:
         do_sparql_cancel(self.host, self.port, self.ssl, request_generator, q['queryId'], False)