apache-ignite

Форк
0
105 строк · 3.7 Кб
1
# Licensed to the Apache Software Foundation (ASF) under one or more
2
# contributor license agreements.  See the NOTICE file distributed with
3
# this work for additional information regarding copyright ownership.
4
# The ASF licenses this file to You under the Apache License, Version 2.0
5
# (the "License"); you may not use this file except in compliance with
6
# the License.  You may obtain a copy of the License at
7
#
8
#    http://www.apache.org/licenses/LICENSE-2.0
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
15

16
"""
17
Checks custom cluster metadata decorator.
18
"""
19

20
from unittest.mock import Mock
21

22
import pytest
23
from ducktape.cluster.cluster_spec import ClusterSpec, LINUX
24
from ducktape.mark.mark_expander import MarkedFunctionExpander
25

26
from ignitetest.utils._mark import cluster, ParametrizableClusterMetadata, CLUSTER_SIZE_KEYWORD, CLUSTER_SPEC_KEYWORD
27

28

29
def expand_function(*, func, sess_ctx):
30
    """
31
    Inject parameters into function and generate context list.
32
    """
33
    assert hasattr(func, "marks")
34
    assert next(filter(lambda x: isinstance(x, ParametrizableClusterMetadata), func.marks), None)
35

36
    return MarkedFunctionExpander(session_context=sess_ctx, function=func).expand()
37

38

39
def mock_session_ctx(*, cluster_size=None):
40
    """
41
    Create mock of session context.
42
    """
43
    sess_ctx = Mock()
44
    sess_ctx.globals = {"cluster_size": cluster_size} if cluster_size is not None else {}
45

46
    return sess_ctx
47

48

49
class CheckClusterParametrization:
50
    """
51
    Checks custom @cluster parametrization.
52
    """
53
    def check_num_nodes(self):
54
        """"
55
        Check num_nodes.
56
        """
57
        @cluster(num_nodes=10)
58
        def function():
59
            return 0
60

61
        test_context_list = expand_function(func=function, sess_ctx=mock_session_ctx())
62
        assert len(test_context_list) == 1
63
        assert test_context_list[0].cluster_use_metadata[CLUSTER_SIZE_KEYWORD] == 10
64

65
        test_context_list = expand_function(func=function,
66
                                            sess_ctx=mock_session_ctx(cluster_size="100"))
67
        assert len(test_context_list) == 1
68
        assert test_context_list[0].cluster_use_metadata[CLUSTER_SIZE_KEYWORD] == 100
69

70
    def check_cluster_spec(self):
71
        """"
72
        Check cluster_spec.
73
        """
74
        @cluster(cluster_spec=ClusterSpec.simple_linux(10))
75
        def function():
76
            return 0
77

78
        test_context_list = expand_function(func=function, sess_ctx=mock_session_ctx())
79
        assert len(test_context_list) == 1
80
        inserted_spec = test_context_list[0].cluster_use_metadata[CLUSTER_SPEC_KEYWORD]
81

82
        assert inserted_spec.size() == 10
83
        for node in inserted_spec.nodes:
84
            assert node.operating_system == LINUX
85

86
        test_context_list = expand_function(func=function,
87
                                            sess_ctx=mock_session_ctx(cluster_size="100"))
88
        assert len(test_context_list) == 1
89
        inserted_spec = test_context_list[0].cluster_use_metadata[CLUSTER_SPEC_KEYWORD]
90

91
        assert inserted_spec.size() == 100
92
        for node in inserted_spec.nodes:
93
            assert node.operating_system == LINUX
94

95
    def check_invalid_global_param(self):
96
        """Check handle of invalid params."""
97
        @cluster(num_nodes=10)
98
        def function():
99
            return 0
100

101
        invalid_vals = ["abc", "-10", "1.5", "0", 1.6, -7, 0]
102

103
        for val in invalid_vals:
104
            with pytest.raises(Exception):
105
                expand_function(func=function, sess_ctx=mock_session_ctx(cluster_size=val))
106

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.