def setUp(self): super(AbstractSearchTest, self).setUp() self.ep_graphson2 = DseGraph().create_execution_profile(self.graph_name, graph_protocol=GraphProtocol.GRAPHSON_2_0) self.ep_graphson3 = DseGraph().create_execution_profile(self.graph_name, graph_protocol=GraphProtocol.GRAPHSON_3_0) self.cluster.add_execution_profile('traversal_graphson2', self.ep_graphson2) self.cluster.add_execution_profile('traversal_graphson3', self.ep_graphson3)
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 create_traversal_profiles(cluster, graph_name): ep_graphson2 = DseGraph().create_execution_profile( graph_name, graph_protocol=GraphProtocol.GRAPHSON_2_0) ep_graphson3 = DseGraph().create_execution_profile( graph_name, graph_protocol=GraphProtocol.GRAPHSON_3_0) cluster.add_execution_profile('traversal_graphson2', ep_graphson2) cluster.add_execution_profile('traversal_graphson3', ep_graphson3) return ep_graphson2, ep_graphson3
def _test_promise_callback_on_error(self, schema, graphson): self.execute_graph(schema.fixtures.classic(), graphson) 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 setUpClass(self): super(ExplicitSearchTest, self).setUpClass() if DSE_VERSION: self.ep = DseGraph().create_execution_profile(self.graph_name) self.cluster.add_execution_profile(self.graph_name, self.ep) generate_address_book_graph(self.session, 0) time.sleep(20)
def test_only_graph_traversals_are_accepted(self): """ Verifies that ValueError is risen if the parameter add is not a traversal @since 1.1.0 @jira_ticket PYTHON-789 @expected_result ValueError is arisen @test_category dse graph """ batch = DseGraph.batch() self.assertRaises(ValueError, batch.add, '{"@value":{"step":[["addV","poc_int"],' '["property","bigint1value",{"@value":12,"@type":"g:Int32"}]]},' '"@type":"g:Bytecode"}') another_batch = DseGraph.batch() self.assertRaises(ValueError, batch.add, another_batch)
def setUp(self): super(BatchStatementTests, self).setUp() self.g = self.fetch_traversal_source() if hasattr(self, "batch"): self.batch.clear() else: self.batch = DseGraph.batch(session=self.session, execution_profile=self.ep)
def execute_traversal(self, traversal, graphson): ep = self.get_execution_profile(graphson, traversal=True) ep = self.session.get_execution_profile(ep) context = None if graphson == GraphProtocol.GRAPHSON_3_0: context = { 'cluster': self.cluster, 'graph_name': ep.graph_options.graph_name.decode('utf-8') if ep.graph_options.graph_name else None } query = DseGraph.query_from_traversal(traversal, graphson, context=context) result_set = self.execute_graph(query, graphson, traversal=True) return list(result_set)
def execute_traversal(self, traversal, graphson): ep = self.get_execution_profile(graphson, traversal=True) ep = self.session.get_execution_profile(ep) context = None if graphson == GraphProtocol.GRAPHSON_3_0: context = { 'cluster': self.cluster, 'graph_name': ep.graph_options.graph_name.decode('utf-8') if ep.graph_options.graph_name else None } query = DseGraph.query_from_traversal(traversal, graphson, context=context) #Use an ep that is configured with the correct row factory, and bytecode-json language flat set result_set = self.execute_graph(query, graphson, traversal=True) return list(result_set)
def _send_batch_and_read_results(self, schema, graphson, add_all=False, use_schema=True): traversals = [] datatypes = schema.fixtures.datatypes() values = {} g = self.fetch_traversal_source(graphson) ep = self.get_execution_profile(graphson) batch = DseGraph.batch(session=self.session, execution_profile=self.get_execution_profile( graphson, traversal=True)) for data in six.itervalues(datatypes): typ, value, deserializer = data vertex_label = VertexLabel([typ]) property_name = next(six.iterkeys(vertex_label.non_pk_properties)) values[property_name] = value if use_schema or schema is CoreGraphSchema: schema.create_vertex_label(self.session, vertex_label, execution_profile=ep) traversal = g.addV(str(vertex_label.label)).property( 'pkid', vertex_label.id).property(property_name, value) if not add_all: batch.add(traversal) traversals.append(traversal) if add_all: batch.add_all(traversals) self.assertEqual(len(datatypes), len(batch)) batch.execute() vertices = self.execute_traversal(g.V(), graphson) self.assertEqual(len(vertices), len(datatypes), "g.V() returned {}".format(vertices)) # Iterate over all the vertices and check that they match the original input for vertex in vertices: schema.ensure_properties(self.session, vertex, execution_profile=ep) key = [k for k in list(vertex.properties.keys()) if k != 'pkid'][0].replace("value", "") original = values[key] self._check_equality(original, vertex)
def _test_cont_paging_with_custom_options(self, schema, graphson): """ Test that we can specify custom paging options. @jira_ticket PYTHON-1045 @expected_result we get only the desired number of results @test_category dse graph """ ep = self.get_execution_profile(graphson, traversal=True) ep = self.session.execution_profile_clone_update(ep, continuous_paging_options=ContinuousPagingOptions(max_pages=1)) self._setup_data(schema, graphson) self.session.default_fetch_size = 10 g = DseGraph.traversal_source(self.session, execution_profile=ep) results = g.V().toList() self.assertEqual(len(results), 10) # only 10 results since paging is disabled
def _test_cont_paging_is_enabled_by_default(self, schema, graphson): """ Test that graph paging is automatically enabled with a >=6.8 cluster. @jira_ticket PYTHON-1045 @expected_result the default continuous paging options are used @test_category dse graph """ # with traversals... I don't have access to the response future... so this is a hack to ensure paging is on cluster.ContinuousPagingOptions = ContinuousPagingOptionsForTests ep = self.get_execution_profile(graphson, traversal=True) self._setup_data(schema, graphson) self.session.default_fetch_size = 10 g = DseGraph.traversal_source(self.session, execution_profile=ep) results = g.V().toList() self.assertEqual(len(results), 10) # only 10 results due to our hack
def _test_cont_paging_can_be_disabled(self, schema, graphson): """ Test that graph paging can be disabled. @jira_ticket PYTHON-1045 @expected_result the default continuous paging options are not used @test_category dse graph """ # with traversals... I don't have access to the response future... so this is a hack to ensure paging is on cluster.ContinuousPagingOptions = ContinuousPagingOptionsForTests ep = self.get_execution_profile(graphson, traversal=True) ep = self.session.execution_profile_clone_update(ep, continuous_paging_options=None) self._setup_data(schema, graphson) self.session.default_fetch_size = 10 g = DseGraph.traversal_source(self.session, execution_profile=ep) results = g.V().toList() self.assertEqual(len(results), 100) # 100 results since paging is disabled
def fetch_traversal_source(self, **kwargs): return DseGraph().traversal_source(self.session, self.graph_name, **kwargs)
def setUp(self): super(BaseCqlCollectionPredicatesTest, self).setUp() self.ep_graphson3 = DseGraph().create_execution_profile(self.graph_name, graph_protocol=GraphProtocol.GRAPHSON_3_0) self.cluster.add_execution_profile('traversal_graphson3', self.ep_graphson3)
def fetch_traversal_source(self, graphson, **kwargs): ep = self.get_execution_profile(graphson, traversal=True) return DseGraph().traversal_source(self.session, self.graph_name, execution_profile=ep, **kwargs)
def setUp(self): super(BaseImplicitExecutionTest, self).setUp() if DSE_VERSION: self.ep = DseGraph().create_execution_profile(self.graph_name) self.cluster.add_execution_profile(self.graph_name, self.ep)
def fetch_traversal_source(self, **kwargs): return DseGraph().traversal_source(self.session, self.graph_name, execution_profile=self.ep, **kwargs)
def execute_traversal(self, traversal): query = DseGraph.query_from_traversal(traversal) #Use an ep that is configured with the correct row factory, and bytecode-json language flat set result_set = self.session.execute_graph(query, execution_profile=self.ep) return list(result_set)