<commit_before># -*- coding: utf-8 -*-
"""
"""
import time
import logging

from testing.aid.dockerbase import DockerBase


def get_log(e=None):
    return logging.getLogger("{0}.{1}".format(__name__, e) if e else __name__)


class DKElasticSearch(DockerBase):
    """This overrides implements the waitForReady needed to make sure
    elasticsearch is ready for use.

    """
    def __init__(self, cfg):
        """Recover our set up from the influxdb container section.
        """
        super(DKElasticSearch, self).__init__(cfg, 'elasticsearch')

    def waitForReady(self):
        """Wait for the client socker to be available then attempt to create
        and destroy a dummy database.

        """
        log = get_log("DKElasticSearch.waitForReady")

        log.info("Testing container is ready for use.")

        # wait for the first port to respond to connections:
        interface = self.settings['interface']
        name = self.settings['export']['wait_for_port']
        ports = self.settings['export']['ports']
        port = [p['export_port'] for p in ports if p['name'] == name]
        port = port[0]

        # Create a database then drop it which should test influxdb is running
        # and ready. This may fail with ConnectionError as the container is
        # still in the process of starting influxdb.
        import socket
        from pyelasticsearch import ElasticSearch

        count_down = self.retries
        while True:
            try:
                base_uri = 'http://{}:{}'.format(interface, port)
                log.info("ElasticSearch base_uri: '{}'".format(base_uri))
                conn = ElasticSearch(base_uri)
                #conn.delete_all_indexes()
                break

            except socket.error:
                log.warn("Connection to DB failed. Retrying...")
                time.sleep(self.sleep_period)<commit_msg>waitForReady() now works with elastic search container. I've had to bump up the retries for this to 20 (20x2sec) to allow it to start in time. It could just be the dockerfile/elasticsearch container I'm using in config.<commit_after># -*- coding: utf-8 -*-
"""
"""
import time
import uuid
import logging

from testing.aid.dockerbase import DockerBase


def get_log(e=None):
    return logging.getLogger("{0}.{1}".format(__name__, e) if e else __name__)


class DKElasticSearch(DockerBase):
    """This overrides implements the waitForReady needed to make sure
    elasticsearch is ready for use.

    """
    def __init__(self, cfg):
        """Recover our set up from the influxdb container section.
        """
        super(DKElasticSearch, self).__init__(cfg, 'elasticsearch', retries=20)

    def waitForReady(self):
        """Wait for the client socker to be available then attempt to create
        and destroy a dummy database.

        """
        log = get_log("DKElasticSearch.waitForReady")

        log.info("Testing container is ready for use.")

        # wait for the first port to respond to connections:
        interface = self.settings['interface']
        name = self.settings['export']['wait_for_port']
        ports = self.settings['export']['ports']
        port = [p['export_port'] for p in ports if p['name'] == name]
        port = port[0]

        # Connect and then try to create and delete an index. If this works
        # we are ready to roll.
        from elasticsearch import ConnectionError
        from elasticsearch import Elasticsearch as ElasticSearch

        count_down = self.retries
        while True:
            try:
                base_uri = 'http://{}:{}/'.format(interface, port)
                log.info("ElasticSearch base_uri: '{}'".format(base_uri))
                es = ElasticSearch([base_uri])
                idx = "testreadytorolldb_{}".format(uuid.uuid4().hex)
                es.indices.create(index=idx, ignore=400)
                es.indices.delete(index=idx, ignore=[400, 404])
                break

            except ConnectionError:
                log.warn("Connection to DB failed. Retrying...")
                time.sleep(self.sleep_period)
{'fraction_non_alphanumeric': 0.10343986338131252, 'fraction_numerical': 0.006099048548426446, 'mean_word_length': 2.4338358458961475, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3287666', 'n_tokens_mistral': 1137, 'n_tokens_neox': 1085, 'n_words': 362}