<commit_before>#!/usr/bin/python
#-*- coding: utf-8 -*-

# ======================================================================
# Copyright 2016 <NAME>
# 
# 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 random

from supervisor.states import RUNNING_STATES, STOPPED_STATES


class DummyLogger:
    """ Simple logger that stores log traces. """

    def __init__(self):
        self.messages = []

    def critical(self, message):
        self.messages.append(('critical', message))

    def error(self, message):
        self.messages.append(('error', message))

    def warn(self, message):
        self.messages.append(('warn', message))

    def info(self, message):
        self.messages.append(('info', message))

    def debug(self, message):
        self.messages.append(('debug', message))

    def trace(self, message):
        self.messages.append(('trace', message))

    def blather(self, message):
        self.messages.append(('blather', message))


class DummyAddressMapper:
    """ Simple address mapper with an empty addresses list. """

    def __init__(self):
        self.addresses = ['127.0.0.1', '10.0.0.1', '10.0.0.2', '10.0.0.3', '10.0.0.4', '10.0.0.5']
        self.local_address = '127.0.0.1'


class DummyAddressStatus:
    """ Simple address status with name, state and loading. """

    def __init__(self, name, state, load):
        self.name = name
        self.state = state
        self.load = load

    def state_string(self):
        return ""

    def loading(self):
        return self.load


class DummyApplicationStatus:
    """ Simple ApplicationStatus. """

    def sequence_deployment(self):
        pass

    def update_status(self):
        pass


class DummyContext:
    """ Simple context with an empty list of AddressStatus. """

    def __init__(self):
        self.addresses = {}
        self.applications = {}
        self.master_address = ''
        self.master = True

    # TODO: implement running_addresses, unknown_addresses, conflicting, conflicts, marked_processes,
    #                 on_timer_event, handle_isolation, on_tick_event, on_process_event

# TEMP
def read_string(self, s):
    from StringIO import StringIO
    s = StringIO(s)
    return self.readfp(s)


class DummyInfoSource:
    """ Simple info source with dummy methods. """

    def autorestart(self, namespec):
        return namespec == "test_autorestart"


class DummyOptions:
    """ Simple options with dummy attributes. """

    def __init__(self):
        self.internal_port = 65100
        self.event_port = 65200
        self.synchro_timeout = 10
        self.deployment_strategy = 0
        self.conciliation_strategy = 0
        self.stats_periods = 5, 15, 60
        self.stats_histo = 10


class DummySupvisors:
    """ Simple supvisors with all dummies. """

    def __init__(self):
        class DummyClass:
            pass
        self.address_mapper = DummyAddressMapper()
        self.context = DummyContext()
        self.deployer = DummyClass()
        self.fsm = DummyClass()
        self.info_source = DummyInfoSource()
        self.logger = DummyLogger()
        self.options = DummyOptions()
        self.pool = DummyClass()
        self.requester = DummyClass()
        self.statistician = DummyClass()
        # TODO: DummyDeployer with deploy_applications, check_deployment, in_progress, deploy_on_event, deploy_marked_processes
        # TODO: DummyPublisher with send_supvisors_status


class DummySupervisor:
    """ Simple supervisor with simple supvisors attribute. """

    def __init__(self):
        self.supvisors = DummySupvisors()


# note that all dates ('now') are different
ProcessInfoDatabase = [
    {'description': '', 'pid': 80886, 'stderr_logfile': '', 'stop': 1473888084,
        'logfile': './log/late_segv_cliche01.log', 'exitstatus': 0, 'spawnerr': '', 'now': 1473888091,
        'group': 'crash', 'name': 'late_segv', 'statename': 'STARTING', 'start': 1473888089, 'state': 10,
        'stdout_logfile': './log/late_segv_cliche01.log'},
    {'description': 'Exited too quickly (process log may have details)', 'pid': 0, 'stderr_logfile': '',
        'stop': 1473888156, 'logfile': './log/segv_cliche01.log', 'exitstatus': 0,
        'spawnerr': 'Exited too quickly (process log may have details)', 'now': 1473888156,
        'group': 'crash', 'name': 'segv', 'statename': 'BACKOFF', 'start': 1473888155, 'state': 30,
        'stdout_logfile': './log/segv_cliche01.log'}, <commit_msg>add server_config to DummySupervisor<commit_after>#!/usr/bin/python
#-*- coding: utf-8 -*-

# ======================================================================
# Copyright 2016 <NAME>
# 
# 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 random

from supervisor.states import RUNNING_STATES, STOPPED_STATES


class DummyClass:
    """ Temporary empty class. """


class DummyLogger:
    """ Simple logger that stores log traces. """

    def __init__(self):
        self.messages = []

    def critical(self, message):
        self.messages.append(('critical', message))

    def error(self, message):
        self.messages.append(('error', message))

    def warn(self, message):
        self.messages.append(('warn', message))

    def info(self, message):
        self.messages.append(('info', message))

    def debug(self, message):
        self.messages.append(('debug', message))

    def trace(self, message):
        self.messages.append(('trace', message))

    def blather(self, message):
        self.messages.append(('blather', message))


class DummyAddressMapper:
    """ Simple address mapper with an empty addresses list. """

    def __init__(self):
        self.addresses = ['127.0.0.1', '10.0.0.1', '10.0.0.2', '10.0.0.3', '10.0.0.4', '10.0.0.5']
        self.local_address = '127.0.0.1'


class DummyAddressStatus:
    """ Simple address status with name, state and loading. """

    def __init__(self, name, state, load):
        self.name = name
        self.state = state
        self.load = load

    def state_string(self):
        return ""

    def loading(self):
        return self.load


class DummyApplicationStatus:
    """ Simple ApplicationStatus. """

    def sequence_deployment(self):
        pass

    def update_status(self):
        pass


class DummyContext:
    """ Simple context with an empty list of AddressStatus. """

    def __init__(self):
        self.addresses = {}
        self.applications = {}
        self.master_address = ''
        self.master = True

    # TODO: implement running_addresses, unknown_addresses, conflicting, conflicts, marked_processes,
    #                 on_timer_event, handle_isolation, on_tick_event, on_process_event

# TEMP
def read_string(self, s):
    from StringIO import StringIO
    s = StringIO(s)
    return self.readfp(s)


class DummyInfoSource:
    """ Simple info source with dummy methods. """

    def autorestart(self, namespec):
        return namespec == "test_autorestart"


class DummyOptions:
    """ Simple options with dummy attributes. """

    def __init__(self):
        self.internal_port = 65100
        self.event_port = 65200
        self.synchro_timeout = 10
        self.deployment_strategy = 0
        self.conciliation_strategy = 0
        self.stats_periods = 5, 15, 60
        self.stats_histo = 10


class DummySupvisors:
    """ Simple supvisors with all dummies. """

    def __init__(self):
        self.address_mapper = DummyAddressMapper()
        self.context = DummyContext()
        self.deployer = DummyClass()
        self.fsm = DummyClass()
        self.info_source = DummyInfoSource()
        self.logger = DummyLogger()
        self.options = DummyOptions()
        self.pool = DummyClass()
        self.requester = DummyClass()
        self.statistician = DummyClass()
        # TODO: DummyDeployer with deploy_applications, check_deployment, in_progress, deploy_on_event, deploy_marked_processes
        # TODO: DummyPublisher with send_supvisors_status


class DummySupervisor:
    """ Simple supervisor instance with simple supvisors attribute. """

    def __init__(self):
        self.supvisors = DummySupvisors()
        self.options = DummyClass()
        self.options.server_configs = [{'section': 'inet_http_server'}]


# note that all dates ('now') are different
ProcessInfoDatabase = [
    {'description': '', 'pid': 80886, 'stderr_logfile': '', 'stop': 1473888084,
        'logfile': './log/late_segv_cliche01.log', 'exitstatus': 0, 'spawnerr': '', 'now': 1473888091,
        'group': 'crash', 'name': 'late_segv', 'statename': 'STARTING', 'start': 1473888089, 'state': 10,
        'stdout_logfile': './log/late_segv_cliche01.log'},
    {'description': 'Exited too quickly (process log may have details)', 'pid': 0, 'stderr_logfile': '',
        'stop': 1473888156, 'logfile': './log/segv_cliche01.log', 'exitstatus': 0,
        'spawnerr': 'Exited too quickly (process log may have details)', 'now': 1473888156,
        'group': 'crash', 'name': 'segv', 'statename': 'BACKOFF', 'start': 1473888155, 'state': 30,
        'stdout_logfile': './log/segv_cliche01.log'}, 
{'fraction_non_alphanumeric': 0.1482313855774868, 'fraction_numerical': 0.028727770177838577, 'mean_word_length': 3.160569105691057, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 14, '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': '736824', 'n_tokens_mistral': 3251, 'n_tokens_neox': 2957, 'n_words': 821}