Ejemplo n.º 1
0
 def refresh(self, timesleep=0):
     index = get_index()
     # Any time we're doing a refresh, we're making sure that the
     # index is ready to be queried.  Given that, it's almost
     # always the case that we want to run all the generated tasks,
     # then refresh.
     get_indexing_es().refresh(index)
     if timesleep > 0:
         time.sleep(timesleep)
Ejemplo n.º 2
0
 def refresh(self, timesleep=0):
     index = get_index()
     # Any time we're doing a refresh, we're making sure that the
     # index is ready to be queried.  Given that, it's almost
     # always the case that we want to run all the generated tasks,
     # then refresh.
     get_indexing_es().indices.refresh(index=index)
     if timesleep > 0:
         time.sleep(timesleep)
Ejemplo n.º 3
0
    def refresh(self, timesleep=0):
        index = get_index()

        # Any time we're doing a refresh, we're making sure that the
        # index is ready to be queried.  Given that, it's almost
        # always the case that we want to run all the generated tasks,
        # then refresh.
        # TODO: uncomment this when we have live indexing.
        # generate_tasks()

        get_indexing_es().refresh(index)
        if timesleep > 0:
            time.sleep(timesleep)
Ejemplo n.º 4
0
    def setup_indexes(self, empty=False, wait=True):
        """(Re-)create ES indexes."""
        from search.index import es_reindex_cmd

        if empty:
            # Removes the index and creates a new one with nothing in
            # it (by abusing the percent argument).
            es_reindex_cmd(percent=0)
        else:
            # Removes the index, creates a new one, and indexes
            # existing data into it.
            es_reindex_cmd()

        self.refresh()
        if wait:
            get_indexing_es().health(wait_for_status='yellow')
Ejemplo n.º 5
0
    def setup_indexes(self, empty=False, wait=True):
        """(Re-)create ES indexes."""
        from search.index import es_reindex_cmd

        if empty:
            # Removes the index and creates a new one with nothing in
            # it (by abusing the percent argument).
            es_reindex_cmd(percent=0)
        else:
            # Removes the index, creates a new one, and indexes
            # existing data into it.
            es_reindex_cmd()

        self.refresh()
        if wait:
            get_indexing_es().health(wait_for_status='yellow')
Ejemplo n.º 6
0
 def teardown_indexes(self):
     es = get_indexing_es()
     try:
         es.delete_index(get_index())
     except ElasticHttpNotFoundError:
         # If we get this error, it means the index didn't exist
         # so there's nothing to delete.
         pass
Ejemplo n.º 7
0
 def teardown_indexes(self):
     es = get_indexing_es()
     try:
         es.delete_index(get_index())
     except ElasticHttpNotFoundError:
         # If we get this error, it means the index didn't exist
         # so there's nothing to delete.
         pass
Ejemplo n.º 8
0
    def setUpClass(cls):
        try:
            super(ElasticTestCase, cls).setUpClass()
        except AttributeError:
            # python 2.6 has no setUpClass, but that's okay
            pass

        if not getattr(settings, 'ES_URLS', None):
            cls.skipme = True
            return

        # try to connect to ES and if it fails, skip ElasticTestCases.
        try:
            get_indexing_es().health()
        except (Timeout, ConnectionError):
            cls.skipme = True
            return

        cls._old_es_index_prefix = settings.ES_INDEX_PREFIX
        settings.ES_INDEX_PREFIX = settings.ES_INDEX_PREFIX + 'test'
        # TODO: cleanup after upgarding test-utils (also in tearDownClass)
        cls._old_es_live_index = settings.__dict__['ES_LIVE_INDEX']
        settings.__dict__['ES_LIVE_INDEX'] = True
Ejemplo n.º 9
0
    def setUpClass(cls):
        try:
            super(ElasticTestCase, cls).setUpClass()
        except AttributeError:
            # python 2.6 has no setUpClass, but that's okay
            pass

        if not getattr(settings, 'ES_URLS', None):
            cls.skipme = True
            return

        # try to connect to ES and if it fails, skip ElasticTestCases.
        try:
            get_indexing_es().health()
        except (Timeout, ConnectionError):
            cls.skipme = True
            return

        cls._old_es_index_prefix = settings.ES_INDEX_PREFIX
        settings.ES_INDEX_PREFIX = settings.ES_INDEX_PREFIX + 'test'
        # TODO: cleanup after upgarding test-utils (also in tearDownClass)
        cls._old_es_live_index = settings.ES_LIVE_INDEX
        settings.ES_LIVE_INDEX = True
Ejemplo n.º 10
0
    def test_delete_index(self):
        # first create and populate the index
        index = Index.objects.create()
        index.populate()

        # then create it again and see if it blows up
        es = get_indexing_es()

        self.assertRaises(RequestError, es.indices.create, index.prefixed_name)

        # then delete it and check if recreating works without blowing up
        index.delete()
        try:
            es.indices.create(index.prefixed_name)
        except RequestError:
            assert False
        es.indices.delete(index.prefixed_name)
Ejemplo n.º 11
0
    def test_delete_index(self):
        # first create and populate the index
        index = Index.objects.create()
        index.populate()

        # then create it again and see if it blows up
        es = get_indexing_es()

        try:
            es.create_index(index.prefixed_name)
        except IndexAlreadyExistsError:
            pass
        else:
            assert False

        # then delete it and check if recreating works without blowing up
        index.delete()
        try:
            es.create_index(index.prefixed_name)
        except IndexAlreadyExistsError:
            assert False
        es.delete_index(index.prefixed_name)
Ejemplo n.º 12
0
    def test_delete_index(self):
        # first create and populate the index
        index = Index.objects.create()
        index.populate()

        # then create it again and see if it blows up
        es = get_indexing_es()

        try:
            es.indices.create(index.prefixed_name)
        except RequestError:
            pass
        else:
            assert False

        # then delete it and check if recreating works without blowing up
        index.delete()
        try:
            es.indices.create(index.prefixed_name)
        except RequestError:
            assert False
        es.indices.delete(index.prefixed_name)