Esempio n. 1
0
    def test_process_changes_chunk(self):
        processor = BulkElasticProcessor(self.es, TEST_INDEX_INFO)

        changes = self._changes_from_ids(self.case_ids)

        retry, errors = processor.process_changes_chunk(changes)
        self.assertEqual([], retry)
        self.assertEqual([], errors)

        es_docs = self.es_interface.get_bulk_docs(
            index=self.index,
            doc_type=TEST_INDEX_INFO.type,
            doc_ids=self.case_ids)
        ids_in_es = {doc['_id'] for doc in es_docs}
        self.assertEqual(set(self.case_ids), ids_in_es)
Esempio n. 2
0
    def test_process_changes_chunk_ignore_couch(self):
        processor = BulkElasticProcessor(
            self.es,
            TEST_INDEX_INFO,
            change_filter_fn=is_couch_change_for_sql_domain)

        changes = self._changes_from_ids(self.case_ids)

        retry, errors = processor.process_changes_chunk(changes)
        self.assertEqual([], retry)
        self.assertEqual([], errors)

        es_docs = self.es_interface.get_bulk_docs(
            self.es_alias,
            doc_type=TEST_INDEX_INFO.type,
            doc_ids=self.case_ids)
        self.assertEqual([], es_docs)
Esempio n. 3
0
    def test_process_changes_chunk_with_errors(self):
        mock_response = (5, [{'index': {'_id': self.case_ids[0], 'error': 'DateParseError'}}])
        processor = BulkElasticProcessor(Mock(), TEST_INDEX_INFO)

        missing_case_ids = [uuid.uuid4().hex, uuid.uuid4().hex]
        changes = self._changes_from_ids(self.case_ids + missing_case_ids)

        with patch.object(ElasticsearchInterface, 'bulk_ops', return_value=mock_response):
            retry, errors = processor.process_changes_chunk(changes)
        self.assertEqual(
            set(missing_case_ids),
            set([change.id for change in retry])
        )
        self.assertEqual(
            [self.case_ids[0]],
            [error[0].id for error in errors]
        )