apache-ignite
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"""
17This module contains basic ignite test.
18"""
19import importlib20from time import monotonic21
22from ducktape.cluster.remoteaccount import RemoteCommandError23from ducktape.tests.test import Test, TestContext24
25from ignitetest.services.utils.ducktests_service import DucktestsService26
27# globals:
28JFR_ENABLED = "jfr_enabled"29IGNITE_TEST_CONTEXT_CLASS_KEY_NAME = "IgniteTestContext"30
31
32class IgniteTestContext(TestContext):33def __init__(self, test_context):34super().__init__()35self.__dict__.update(**test_context.__dict__)36
37@property38def available_cluster_size(self):39return len(self.cluster)40
41def before(self):42pass43
44def after(self, test_result):45return test_result46
47@staticmethod48def resolve(test_context):49if IGNITE_TEST_CONTEXT_CLASS_KEY_NAME in test_context.globals:50fqdn = test_context.globals[IGNITE_TEST_CONTEXT_CLASS_KEY_NAME]51(module, clazz) = fqdn.rsplit('.', 1)52module = importlib.import_module(module)53return getattr(module, clazz)(test_context)54else:55return IgniteTestContext(test_context)56
57
58class IgniteTest(Test):59"""60Basic ignite test.
61"""
62def __init__(self, test_context):63assert isinstance(test_context, IgniteTestContext),\64"any IgniteTest MUST BE decorated with the @ignitetest.utils.cluster decorator"65
66super().__init__(test_context=test_context)67
68@property69def available_cluster_size(self):70# noinspection PyUnresolvedReferences71return self.test_context.available_cluster_size72
73@staticmethod74def monotonic():75"""76monotonic() -> float
77
78:return:
79The value (in fractional seconds) of a monotonic clock, i.e. a clock that cannot go backwards.
80The clock is not affected by system clock updates. The reference point of the returned value is undefined,
81so that only the difference between the results of consecutive calls is valid.
82"""
83return monotonic()84
85def tearDown(self):86# jfr requires graceful shutdown to save the recording.87if not self.test_context.globals.get(JFR_ENABLED, False):88self.logger.debug("Killing all runned services to speed-up the tearing down.")89
90for service in self.test_context.services._services.values():91assert isinstance(service, DucktestsService)92
93try:94service.kill()95except RemoteCommandError:96pass # Process may be already self-killed on segmentation.97
98assert service.stopped99
100self.logger.debug("All runned services killed.")101
102super().tearDown()103
104def _global_param(self, param_name, default=None):105"""Reads global parameter passed to the test suite."""106return self.test_context.globals.get(param_name, default)107
108def _global_int(self, param_name, default: int = None):109"""Reads global parameter passed to the test suite and converts to int."""110return int(self._global_param(param_name, default))111