def test_does_not_run_deleter_if_aliased(self, es, deleter): """If dealing with an alias, do not run the deleter.""" es.get_aliased_index.return_value = 'foobar' index.reindex(mock.sentinel.session, es, mock.sentinel.request) deleter.delete_all.assert_not_called()
def test_it_removes_all_deleted_annotations(self, BatchDeleter): index.reindex(mock.sentinel.session, mock.sentinel.es, mock.sentinel.request) BatchDeleter.assert_called_once_with(mock.sentinel.session, mock.sentinel.es) assert BatchDeleter.return_value.delete_all.called
def test_updates_alias_when_reindexed_if_aliased(self, es, matchers): """Call update_aliased_index on the client with the new index name.""" es.get_aliased_index.return_value = 'foobar' index.reindex(mock.sentinel.session, es, mock.sentinel.request) es.update_aliased_index.assert_called_once_with(matchers.regex('hypothesis-[0-9a-f]{8}'))
def test_creates_new_index_if_aliased(self, es, configure_index, matchers): """If the current index isn't concrete, then create a new target index.""" es.get_aliased_index.return_value = 'foobar' index.reindex(mock.sentinel.session, es, mock.sentinel.request) configure_index.assert_called_once_with(es, matchers.regex('hypothesis-[0-9a-f]{8}'))
def test_passes_new_index_to_indexer_if_aliased(self, es, matchers, BatchIndexer): """Pass the name of any new index as target_index to indexer.""" es.get_aliased_index.return_value = 'foobar' index.reindex(mock.sentinel.session, es, mock.sentinel.request) _, kwargs = BatchIndexer.call_args assert kwargs['target_index'] == matchers.regex('hypothesis-[0-9a-f]{8}')
def test_it_indexes_all_annotations(self, BatchIndexer): index.reindex(mock.sentinel.session, mock.sentinel.es, mock.sentinel.request) BatchIndexer.assert_called_once_with(mock.sentinel.session, mock.sentinel.es, mock.sentinel.request) assert BatchIndexer.return_value.index_all.called
def reindex(ctx): """ Reindex all annotations from the PostgreSQL database to the Elasticsearch index. """ request = ctx.obj['bootstrap']() index.reindex(request.db, request.es, request)
def test_retries_failed_annotations(self, es, indexer): """Should call .index() a second time with any failed annotation IDs.""" indexer.index.return_value = ['abc123', 'def456'] index.reindex(mock.sentinel.session, es, mock.sentinel.request) assert indexer.index.mock_calls == [ mock.call(), mock.call(['abc123', 'def456']), ]
def test_does_not_update_alias_if_indexing_fails(self, es, indexer): """Don't call update_aliased_index if index() fails...""" es.get_aliased_index.return_value = 'foobar' indexer.index.side_effect = RuntimeError('fail') try: index.reindex(mock.sentinel.session, es, mock.sentinel.request) except RuntimeError: pass es.update_aliased_index.assert_not_called()
def test_indexes_annotations(self, es, indexer): """Should call .index() on the batch indexer instance.""" index.reindex(mock.sentinel.session, es, mock.sentinel.request) indexer.index.assert_called_once_with()
def test_runs_deleter_if_not_aliased(self, es, deleter): """If dealing with a concrete index, run the deleter.""" index.reindex(mock.sentinel.session, es, mock.sentinel.request) deleter.delete_all.assert_called_once_with()
def reindex_annotations(): reindex(celery.request.db, celery.request.es, celery.request)