apache-ignite

Форк
0
110 строк · 3.8 Кб
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
This module contains basic ignite test.
18
"""
19
import importlib
20
from time import monotonic
21

22
from ducktape.cluster.remoteaccount import RemoteCommandError
23
from ducktape.tests.test import Test, TestContext
24

25
from ignitetest.services.utils.ducktests_service import DucktestsService
26

27
# globals:
28
JFR_ENABLED = "jfr_enabled"
29
IGNITE_TEST_CONTEXT_CLASS_KEY_NAME = "IgniteTestContext"
30

31

32
class IgniteTestContext(TestContext):
33
    def __init__(self, test_context):
34
        super().__init__()
35
        self.__dict__.update(**test_context.__dict__)
36

37
    @property
38
    def available_cluster_size(self):
39
        return len(self.cluster)
40

41
    def before(self):
42
        pass
43

44
    def after(self, test_result):
45
        return test_result
46

47
    @staticmethod
48
    def resolve(test_context):
49
        if IGNITE_TEST_CONTEXT_CLASS_KEY_NAME in test_context.globals:
50
            fqdn = test_context.globals[IGNITE_TEST_CONTEXT_CLASS_KEY_NAME]
51
            (module, clazz) = fqdn.rsplit('.', 1)
52
            module = importlib.import_module(module)
53
            return getattr(module, clazz)(test_context)
54
        else:
55
            return IgniteTestContext(test_context)
56

57

58
class IgniteTest(Test):
59
    """
60
    Basic ignite test.
61
    """
62
    def __init__(self, test_context):
63
        assert isinstance(test_context, IgniteTestContext),\
64
            "any IgniteTest MUST BE decorated with the @ignitetest.utils.cluster decorator"
65

66
        super().__init__(test_context=test_context)
67

68
    @property
69
    def available_cluster_size(self):
70
        # noinspection PyUnresolvedReferences
71
        return self.test_context.available_cluster_size
72

73
    @staticmethod
74
    def monotonic():
75
        """
76
        monotonic() -> float
77

78
        :return:
79
            The value (in fractional seconds) of a monotonic clock, i.e. a clock that cannot go backwards.
80
            The clock is not affected by system clock updates. The reference point of the returned value is undefined,
81
            so that only the difference between the results of consecutive calls is valid.
82
        """
83
        return monotonic()
84

85
    def tearDown(self):
86
        # jfr requires graceful shutdown to save the recording.
87
        if not self.test_context.globals.get(JFR_ENABLED, False):
88
            self.logger.debug("Killing all runned services to speed-up the tearing down.")
89

90
            for service in self.test_context.services._services.values():
91
                assert isinstance(service, DucktestsService)
92

93
                try:
94
                    service.kill()
95
                except RemoteCommandError:
96
                    pass  # Process may be already self-killed on segmentation.
97

98
                assert service.stopped
99

100
            self.logger.debug("All runned services killed.")
101

102
        super().tearDown()
103

104
    def _global_param(self, param_name, default=None):
105
        """Reads global parameter passed to the test suite."""
106
        return self.test_context.globals.get(param_name, default)
107

108
    def _global_int(self, param_name, default: int = None):
109
        """Reads global parameter passed to the test suite and converts to int."""
110
        return int(self._global_param(param_name, default))
111

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

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

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

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