File: test_spark.py

package info (click to toggle)
python-cassandra-driver 3.29.2-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,144 kB
  • sloc: python: 51,532; ansic: 768; makefile: 138; sh: 13
file content (50 lines) | stat: -rw-r--r-- 2,046 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# Copyright DataStax, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import logging

from cassandra.cluster import EXEC_PROFILE_GRAPH_ANALYTICS_DEFAULT
from cassandra.graph import SimpleGraphStatement
from tests.integration import DSE_VERSION, requiredse
from tests.integration.advanced import use_singledc_wth_graph_and_spark, find_spark_master
from tests.integration.advanced.graph import BasicGraphUnitTestCase, ClassicGraphFixtures
log = logging.getLogger(__name__)


def setup_module():
    if DSE_VERSION:
        use_singledc_wth_graph_and_spark()


@requiredse
class SparkLBTests(BasicGraphUnitTestCase):
    """
    Test to validate that analtics query can run in a multi-node enviroment. Also check to to ensure
    that the master spark node is correctly targeted when OLAP queries are run

    @since 3.20
    @jira_ticket PYTHON-510
    @expected_result OLAP results should come back correctly, master spark coordinator should always be picked.
    @test_category dse graph
    """
    def test_spark_analytic_query(self):
        self.session.execute_graph(ClassicGraphFixtures.classic())
        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, 7)
            self.assertEqual(rs.response_future._current_host.address, spark_master)