<commit_before>#########
# Copyright (c) 2013 GigaSpaces Technologies Ltd. All rights reserved
#
# 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.
from cloudify.context import BootstrapContext
from cloudify.exceptions import NonRecoverableError
from cloudify.mocks import MockCloudifyContext

__author__ = 'elip'


import unittest

from windows_agent_installer import MIN_WORKERS_KEY, \
    MAX_WORKERS_KEY, SERVICE_SUCCESSFUL_CONSECUTVE_STATUS_QUERIES_COUNT_KEY, \
    SERVICE_STATUS_TRANSITION_SLEEP_INTERVAL_KEY, \
    SERVICE_FAILURE_RESET_TIMEOUT_KEY, \
    SERVICE_FAILURE_RESTART_DELAY_KEY, \
    SERVICE_START_TIMEOUT_KEY, \
    SERVICE_STOP_TIMEOUT_KEY, \
    set_service_configuration_parameters, \
    set_autoscale_parameters, \
    set_bootstrap_context_parameters


class InitTest(unittest.TestCase):

    def test_set_service_configuration_parameters_with_empty_service(self):  #NOQA

        # cloudify agent does not contain any service configuration parameters.
        # this means all parameters should be the default ones.
        cloudify_agent = {}
        set_service_configuration_parameters(cloudify_agent)
        self.assertEqual(
            cloudify_agent['service']
            [SERVICE_FAILURE_RESET_TIMEOUT_KEY],
            60)
        self.assertEqual(
            cloudify_agent['service']
            [SERVICE_STATUS_TRANSITION_SLEEP_INTERVAL_KEY],
            5)
        self.assertEqual(
            cloudify_agent['service']
            [SERVICE_SUCCESSFUL_CONSECUTVE_STATUS_QUERIES_COUNT_KEY],
            3)
        self.assertEqual(
            cloudify_agent['service']
            [SERVICE_STOP_TIMEOUT_KEY],
            30)
        self.assertEqual(
            cloudify_agent['service']
            [SERVICE_START_TIMEOUT_KEY],
            30)
        self.assertEqual(
            cloudify_agent['service']
            [SERVICE_FAILURE_RESTART_DELAY_KEY],
            5000)

    def test_set_service_configuration_parameters_with_full_service(self):  #NOQA

        cloudify_agent = {'service': {
            SERVICE_FAILURE_RESET_TIMEOUT_KEY: 1,
            SERVICE_STATUS_TRANSITION_SLEEP_INTERVAL_KEY: 1,
            SERVICE_SUCCESSFUL_CONSECUTVE_STATUS_QUERIES_COUNT_KEY: 1,
            SERVICE_STOP_TIMEOUT_KEY: 1,
            SERVICE_START_TIMEOUT_KEY: 1,
            SERVICE_FAILURE_RESTART_DELAY_KEY: 1
        }}
        set_service_configuration_parameters(cloudify_agent)

        self.assertEqual(
            cloudify_agent['service']
            [SERVICE_FAILURE_RESET_TIMEOUT_KEY],
            1)
        self.assertEqual(
            cloudify_agent['service']
            [SERVICE_STATUS_TRANSITION_SLEEP_INTERVAL_KEY],
            1)
        self.assertEqual(
            cloudify_agent['service']
            [SERVICE_SUCCESSFUL_CONSECUTVE_STATUS_QUERIES_COUNT_KEY],
            1)
        self.assertEqual(
            cloudify_agent['service']
            [SERVICE_STOP_TIMEOUT_KEY],
            1)
        self.assertEqual(
            cloudify_agent['service']
            [SERVICE_START_TIMEOUT_KEY],
            1)
        self.assertEqual(
            cloudify_agent['service']
            [SERVICE_FAILURE_RESTART_DELAY_KEY],
            1)

    def test_set_service_configuration_parameters_digit_validation(self):  # NOQA

        cloudify_agent = {'service': {
            SERVICE_FAILURE_RESET_TIMEOUT_KEY: "Hello"
        }}
        try:
            set_service_configuration_parameters(cloudify_agent)
            self.fail('Expected NonRecoverableError since {0} is not a number'.format(
                SERVICE_FAILURE_RESET_TIMEOUT_KEY))
        except NonRecoverableError:
            pass

    def test_set_autoscale_parameters_with_empty_bootstrap_context_and_no_parameters(self):  # NOQA
<commit_msg>CFY-606 more flake<commit_after>#########
# Copyright (c) 2013 GigaSpaces Technologies Ltd. All rights reserved
#
# 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.
from cloudify.context import BootstrapContext
from cloudify.exceptions import NonRecoverableError
from cloudify.mocks import MockCloudifyContext

__author__ = 'elip'


import unittest

from windows_agent_installer import MIN_WORKERS_KEY, \
    MAX_WORKERS_KEY, SERVICE_SUCCESSFUL_CONSECUTVE_STATUS_QUERIES_COUNT_KEY, \
    SERVICE_STATUS_TRANSITION_SLEEP_INTERVAL_KEY, \
    SERVICE_FAILURE_RESET_TIMEOUT_KEY, \
    SERVICE_FAILURE_RESTART_DELAY_KEY, \
    SERVICE_START_TIMEOUT_KEY, \
    SERVICE_STOP_TIMEOUT_KEY, \
    set_service_configuration_parameters, \
    set_autoscale_parameters, \
    set_bootstrap_context_parameters


class InitTest(unittest.TestCase):

    def test_set_service_configuration_parameters_with_empty_service(self):  # NOQA

        # cloudify agent does not contain any service configuration parameters.
        # this means all parameters should be the default ones.
        cloudify_agent = {}
        set_service_configuration_parameters(cloudify_agent)
        self.assertEqual(
            cloudify_agent['service']
            [SERVICE_FAILURE_RESET_TIMEOUT_KEY],
            60)
        self.assertEqual(
            cloudify_agent['service']
            [SERVICE_STATUS_TRANSITION_SLEEP_INTERVAL_KEY],
            5)
        self.assertEqual(
            cloudify_agent['service']
            [SERVICE_SUCCESSFUL_CONSECUTVE_STATUS_QUERIES_COUNT_KEY],
            3)
        self.assertEqual(
            cloudify_agent['service']
            [SERVICE_STOP_TIMEOUT_KEY],
            30)
        self.assertEqual(
            cloudify_agent['service']
            [SERVICE_START_TIMEOUT_KEY],
            30)
        self.assertEqual(
            cloudify_agent['service']
            [SERVICE_FAILURE_RESTART_DELAY_KEY],
            5000)

    def test_set_service_configuration_parameters_with_full_service(self):  # NOQA

        cloudify_agent = {'service': {
            SERVICE_FAILURE_RESET_TIMEOUT_KEY: 1,
            SERVICE_STATUS_TRANSITION_SLEEP_INTERVAL_KEY: 1,
            SERVICE_SUCCESSFUL_CONSECUTVE_STATUS_QUERIES_COUNT_KEY: 1,
            SERVICE_STOP_TIMEOUT_KEY: 1,
            SERVICE_START_TIMEOUT_KEY: 1,
            SERVICE_FAILURE_RESTART_DELAY_KEY: 1
        }}
        set_service_configuration_parameters(cloudify_agent)

        self.assertEqual(
            cloudify_agent['service']
            [SERVICE_FAILURE_RESET_TIMEOUT_KEY],
            1)
        self.assertEqual(
            cloudify_agent['service']
            [SERVICE_STATUS_TRANSITION_SLEEP_INTERVAL_KEY],
            1)
        self.assertEqual(
            cloudify_agent['service']
            [SERVICE_SUCCESSFUL_CONSECUTVE_STATUS_QUERIES_COUNT_KEY],
            1)
        self.assertEqual(
            cloudify_agent['service']
            [SERVICE_STOP_TIMEOUT_KEY],
            1)
        self.assertEqual(
            cloudify_agent['service']
            [SERVICE_START_TIMEOUT_KEY],
            1)
        self.assertEqual(
            cloudify_agent['service']
            [SERVICE_FAILURE_RESTART_DELAY_KEY],
            1)

    def test_set_service_configuration_parameters_digit_validation(self):  # NOQA

        cloudify_agent = {'service': {
            SERVICE_FAILURE_RESET_TIMEOUT_KEY: "Hello"
        }}
        try:
            set_service_configuration_parameters(cloudify_agent)
            self.fail('Expected NonRecoverableError since {0} is not a number'
                      .format(SERVICE_FAILURE_RESET_TIMEOUT_KEY))
        except NonRecoverableError:
            pass

    def test_set_autoscale_parameters_with_empty_bootstrap_context_and_no_parameters(self):  # NOQA

{'fraction_non_alphanumeric': 0.06409212515993952, 'fraction_numerical': 0.008026055600790973, 'mean_word_length': 2.7382608695652175, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5565472', 'n_tokens_mistral': 2439, 'n_tokens_neox': 2447, 'n_words': 468}