def test_dsl(self): """ The test creates a SocialTraversal and a SocialTraversalSource as part of a DSL. Then calls it's method and checks the results to verify we have the expected results @since @since 1.1.0a1 @jira_ticket PYTHON-790 @expected_result only the vertex corresponding to marko is in the result @test_category dse graph """ class SocialTraversal(GraphTraversal): def knows(self, person_name): return self.out("knows").hasLabel("person").has( "name", person_name).in_() class SocialTraversalSource(GraphTraversalSource): def __init__(self, *args, **kwargs): super(SocialTraversalSource, self).__init__(*args, **kwargs) self.graph_traversal = SocialTraversal def people(self, *names): return self.get_graph_traversal().V().has( "name", P.within(*names)) generate_classic(self.session) g = self.fetch_traversal_source(traversal_class=SocialTraversalSource) traversal = g.people("marko", "albert").knows("vadas") results = self.execute_traversal(traversal) self.assertEqual(len(results), 1) only_vertex = results[0] self._validate_classic_vertex(g, only_vertex)
def test_classic_graph(self): """ Test to validate that basic graph generation, and vertex and edges are surfaced correctly Creates a simple classic tinkerpot graph, and iterates over the the vertices and edges using Tinkerpop's GLV with both explicit and implicit execution ensuring that each one iscorrect. See reference graph here http://www.tinkerpop.com/docs/3.0.0.M1/ @since 1.0.0 @jira_ticket PYTHON-641 @expected_result graph should generate and all vertices and edge results should be @test_category dse graph """ generate_classic(self.session) g = self.fetch_traversal_source() traversal = g.V() vert_list = self.execute_traversal(traversal) for vertex in vert_list: self._validate_classic_vertex(g, vertex) traversal = g.E() edge_list = self.execute_traversal(traversal) for edge in edge_list: self._validate_classic_edge(g, edge)
def test_promise_error_is_propagated(self): generate_classic(self.session) g = DseGraph().traversal_source(self.session, 'wrong_graph', execution_profile=self.ep) traversal_future = g.V().has( 'name', 'marko').out('knows').values('name').promise() with self.assertRaises(Exception): traversal_future.result()
def test_spark_analytic_query(self): generate_classic(self.session) spark_master = find_spark_master(self.session) # Run multipltle times to ensure we don't round robin for i in range(3): to_run = SimpleGraphStatement("g.V().count()") rs = self.session.execute_graph(to_run, execution_profile=EXEC_PROFILE_GRAPH_ANALYTICS_DEFAULT) self.assertEqual(rs[0].value, 6) self.assertEqual(rs.response_future._current_host.address, spark_master)
def test_promise_callback(self): generate_classic(self.session) g = self.fetch_traversal_source() future = Future() def cb(f): future.set_result(f.result()) traversal_future = g.V().has( 'name', 'marko').out('knows').values('name').promise() traversal_future.add_done_callback(cb) self._validate_results(future.result())
def test_graph_profile(self): """ Test verifying various aspects of graph config properties. @since 1.0.0 @jira_ticket PYTHON-570 @test_category dse graph """ hosts = self.cluster.metadata.all_hosts() first_host = hosts[0].address second_hosts = "1.2.3.4" generate_classic(self.session) # Create variou execution policies exec_dif_factory = GraphExecutionProfile(row_factory=single_object_row_factory) exec_dif_factory.graph_options.graph_name = self.graph_name exec_dif_lbp = GraphExecutionProfile(load_balancing_policy=WhiteListRoundRobinPolicy([first_host])) exec_dif_lbp.graph_options.graph_name = self.graph_name exec_bad_lbp = GraphExecutionProfile(load_balancing_policy=WhiteListRoundRobinPolicy([second_hosts])) exec_dif_lbp.graph_options.graph_name = self.graph_name exec_short_timeout = GraphExecutionProfile(request_timeout=1, load_balancing_policy=WhiteListRoundRobinPolicy([first_host])) exec_short_timeout.graph_options.graph_name = self.graph_name # Add a single exection policy on cluster creation local_cluster = Cluster(protocol_version=PROTOCOL_VERSION, execution_profiles={"exec_dif_factory": exec_dif_factory}) local_session = local_cluster.connect() rs1 = self.session.execute_graph('g.V()') rs2 = local_session.execute_graph('g.V()', execution_profile='exec_dif_factory') # Verify default and non default policy works self.assertFalse(isinstance(rs2[0], Vertex)) self.assertTrue(isinstance(rs1[0], Vertex)) # Add other policies validate that lbp are honored local_cluster.add_execution_profile("exec_dif_ldp", exec_dif_lbp) local_session.execute_graph('g.V()', execution_profile="exec_dif_ldp") local_cluster.add_execution_profile("exec_bad_lbp", exec_bad_lbp) with self.assertRaises(NoHostAvailable): local_session.execute_graph('g.V()', execution_profile="exec_bad_lbp") # Try with missing EP with self.assertRaises(ValueError): local_session.execute_graph('g.V()', execution_profile='bad_exec_profile') # Validate that timeout is honored local_cluster.add_execution_profile("exec_short_timeout", exec_short_timeout) with self.assertRaises(Exception) as e: self.assertTrue(isinstance(e, InvalidRequest) or isinstance(e, OperationTimedOut)) local_session.execute_graph('java.util.concurrent.TimeUnit.MILLISECONDS.sleep(2000L);', execution_profile='exec_short_timeout')
def test_promise_callback_on_error(self): generate_classic(self.session) g = DseGraph().traversal_source(self.session, 'wrong_graph', execution_profile=self.ep) future = Future() def cb(f): try: f.result() except Exception as e: future.set_exception(e) traversal_future = g.V().has( 'name', 'marko').out('knows').values('name').promise() traversal_future.add_done_callback(cb) with self.assertRaises(Exception): future.result()
def test_edge_properties_with_graphson2(self): """ Test that the edge property deserializer return a dict, and not a set. @since 3.20 @jira_ticket PYTHON-1033 @expected_result the properties are stored in a dict @test_category dse graph """ generate_classic(self.session) epg2 = self.session.execution_profile_clone_update( EXEC_PROFILE_GRAPH_DEFAULT) epg2.graph_options.graph_protocol = GraphProtocol.GRAPHSON_2_0 epg2.row_factory = graph_graphson2_row_factory rs = self.session.execute_graph('g.E()', execution_profile=epg2) for edge in rs: validate_classic_edge(self, edge)
def test_bulked_results(self): """ Send a query expecting a bulked result and the driver "undoes" the bulk and returns the expected list @since 1.1.0a1 @jira_ticket PYTHON-771 @expected_result the expanded list @test_category dse graph """ generate_classic(self.session) g = self.fetch_traversal_source() barrier_traversal = g.E().label().barrier() results = self.execute_traversal(barrier_traversal) self.assertEqual( ["created", "created", "created", "created", "knows", "knows"], results)
def test_graph_classic_path(self): """ Test to validate that the path version of the result type is generated correctly. It also tests basic path results as that is not covered elsewhere @since 1.0.0 @jira_ticket PYTHON-479 @expected_result path object should be unpacked correctly including all nested edges and verticies @test_category dse graph """ generate_classic(self.session) rs = self.session.execute_graph("g.V().hasLabel('person').has('name', 'marko').as('a').outE('knows').inV().as('c', 'd').outE('created').as('e', 'f', 'g').inV().path()") rs_list = list(rs) self.assertEqual(len(rs_list), 2) for result in rs_list: path = result.as_path() validate_path_result_type(self, path)
def test_graph_classic_path(self): """ Test to validate that the path version of the result type is generated correctly. It also tests basic path results as that is not covered elsewhere @since 1.0.0 @jira_ticket PYTHON-641 @expected_result path object should be unpacked correctly including all nested edges and verticies @test_category dse graph """ generate_classic(self.session) g = self.fetch_traversal_source() traversal = g.V().hasLabel('person').has( 'name', 'marko').as_('a').outE('knows').inV().as_( 'c', 'd').outE('created').as_('e', 'f', 'g').inV().path() path_list = self.execute_traversal(traversal) self.assertEqual(len(path_list), 2) for path in path_list: self._validate_path_result_type(g, path)
def test_classic_graph(self): """ Test to validate that basic graph generation, and vertex and edges are surfaced correctly Creates a simple classic tinkerpot graph, and iterates over the the vertices and edges ensureing that each one is correct. See reference graph here http://www.tinkerpop.com/docs/3.0.0.M1/ @since 1.0.0 @jira_ticket PYTHON-457 @expected_result graph should generate and all vertices and edge results should be @test_category dse graph """ generate_classic(self.session) rs = self.session.execute_graph('g.V()') for vertex in rs: validate_classic_vertex(self, vertex) rs = self.session.execute_graph('g.E()') for edge in rs: validate_classic_edge(self, edge)
def test_connect_with_kerberos_and_graph(self): """ This tests will attempt to authenticate with a user and execute a graph query @since 1.0.0 @jira_ticket PYTHON-457 @test_category dse auth @expected_result Client should be able to connect and run a basic graph query with authentication """ self.refresh_kerberos_tickets(self.cassandra_keytab, "*****@*****.**", self.krb_conf) auth_provider = DSEGSSAPIAuthProvider(service='dse', qops=["auth"]) rs = self.connect_and_query(auth_provider) self.assertIsNotNone(rs) reset_graph(self.session, self._testMethodName.lower()) profiles = self.cluster.profile_manager.profiles profiles[EXEC_PROFILE_GRAPH_DEFAULT].graph_options.graph_name = self._testMethodName.lower() generate_classic(self.session) rs = self.session.execute_graph('g.V()') self.assertIsNotNone(rs)
def test_result_forms(self): """ Test to validate that geometric types function correctly Creates a very simple graph, and tries to insert a simple point type @since 1.0.0 @jira_ticket DSP-8087 @expected_result json types assoicated with insert is parsed correctly @test_category dse graph """ generate_classic(self.session) rs = list(self.session.execute_graph('g.V()')) self.assertGreater(len(rs), 0, "Result set was empty this was not expected") for v in rs: validate_classic_vertex(self, v) rs = list(self.session.execute_graph('g.E()')) self.assertGreater(len(rs), 0, "Result set was empty this was not expected") for e in rs: validate_classic_edge(self, e)
def test_basic_query(self): """ Test to validate that basic graph query results can be executed with a sane result set. Creates a simple classic tinkerpot graph, and attempts to find all vertices related the vertex marco, that have a label of knows. See reference graph here http://www.tinkerpop.com/docs/3.0.0.M1/ @since 1.0.0 @jira_ticket PYTHON-457 @expected_result graph should find two vertices related to marco via 'knows' edges. @test_category dse graph """ generate_classic(self.session) rs = self.session.execute_graph('''g.V().has('name','marko').out('knows').values('name')''') self.assertFalse(rs.has_more_pages) results_list = [result.value for result in rs.current_rows] self.assertEqual(len(results_list), 2) self.assertIn('vadas', results_list) self.assertIn('josh', results_list)
def test_basic_query(self): """ Test to validate that basic graph queries works Creates a simple classic tinkerpot graph, and attempts to preform a basic query using Tinkerpop's GLV with both explicit and implicit execution ensuring that each one is correct. See reference graph here http://www.tinkerpop.com/docs/3.0.0.M1/ @since 1.0.0 @jira_ticket PYTHON-641 @expected_result graph should generate and all vertices and edge results should be @test_category dse graph """ g = self.fetch_traversal_source() generate_classic(self.session) traversal = g.V().has('name', 'marko').out('knows').values('name') results_list = self.execute_traversal(traversal) self.assertEqual(len(results_list), 2) self.assertIn('vadas', results_list) self.assertIn('josh', results_list)
def test_promise(self): generate_classic(self.session) g = self.fetch_traversal_source() traversal_future = g.V().has( 'name', 'marko').out('knows').values('name').promise() self._validate_results(traversal_future.result())