Exemple #1
0
def _get_course_in_cache(self, **kwargs):
    """
    Gets the course blocks for the specified course, updating the cache if needed.
    """
    if kwargs.get('with_storage'):
        waffle().override_for_request(STORAGE_BACKING_FOR_CACHE)
    _call_and_retry_if_needed(self, api.get_course_in_cache, **kwargs)
Exemple #2
0
def _get_course_in_cache(self, **kwargs):
    """
    Gets the course blocks for the specified course, updating the cache if needed.
    """
    if kwargs.get('with_storage'):
        waffle().override_for_request(STORAGE_BACKING_FOR_CACHE)
    _call_and_retry_if_needed(self, api.get_course_in_cache, **kwargs)
Exemple #3
0
def _update_course_in_cache(self, **kwargs):
    """
    Updates the course blocks (mongo -> BlockStructure) for the specified course.
    """
    if kwargs.get('with_storage'):
        waffle().override_for_request(STORAGE_BACKING_FOR_CACHE)
    _call_and_retry_if_needed(self, api.update_course_in_cache, **kwargs)
Exemple #4
0
def _update_course_in_cache(self, **kwargs):
    """
    Updates the course blocks (mongo -> BlockStructure) for the specified course.
    """
    if kwargs.get('with_storage'):
        waffle().override_for_request(STORAGE_BACKING_FOR_CACHE)
    _call_and_retry_if_needed(self, api.update_course_in_cache, **kwargs)
    def _generate_course_blocks(self, options, course_keys):
        """
        Generates course blocks for the given course_keys per the given options.
        """
        if options.get('with_storage'):
            waffle().set_request_cache_with_short_name(STORAGE_BACKING_FOR_CACHE, True)

        for course_key in course_keys:
            try:
                self._generate_for_course(options, course_key)
            except Exception as ex:  # pylint: disable=broad-except
                log.exception(
                    u'BlockStructure: An error occurred while generating course blocks for %s: %s',
                    six.text_type(course_key),
                    text_type(ex),
                )
    def _generate_course_blocks(self, options, course_keys):
        """
        Generates course blocks for the given course_keys per the given options.
        """
        if options.get('with_storage'):
            waffle().override_for_request(STORAGE_BACKING_FOR_CACHE)

        for course_key in course_keys:
            try:
                self._generate_for_course(options, course_key)
            except Exception as ex:  # pylint: disable=broad-except
                log.exception(
                    u'BlockStructure: An error occurred while generating course blocks for %s: %s',
                    unicode(course_key),
                    ex.message,
                )
Exemple #7
0
    def test_dump_to_neo4j_published(self, mock_graph_constructor,
                                     mock_selector_class):
        """
        Tests that we only dump those courses that have been published after
        the last time the command was been run.
        """
        mock_graph = MockGraph()
        mock_graph_constructor.return_value = mock_graph
        mock_selector_class.return_value = MockNodeSelector(mock_graph)
        # mocking is thorwing error in kombu serialzier and its not require here any more.
        credentials = {}

        # run once to warm the cache
        submitted, skipped = self.mss.dump_courses_to_neo4j(credentials)
        self.assertEqual(len(submitted), len(self.course_strings))

        # simulate one of the courses being published
        with block_structure_config.waffle().override(
                block_structure_config.STORAGE_BACKING_FOR_CACHE):
            update_block_structure_on_course_publish(None, self.course.id)

        # make sure only the published course was dumped
        submitted, __ = self.mss.dump_courses_to_neo4j(credentials)
        self.assertEqual(len(submitted), 1)
        self.assertEqual(submitted[0], six.text_type(self.course.id))
Exemple #8
0
    def _generate_course_blocks(self, options, course_keys):
        """
        Generates course blocks for the given course_keys per the given options.
        """
        if options.get('with_storage'):
            waffle().override_for_request(STORAGE_BACKING_FOR_CACHE)

        for course_key in course_keys:
            try:
                self._generate_for_course(options, course_key)
            except Exception as ex:  # pylint: disable=broad-except
                log.exception(
                    u'BlockStructure: An error occurred while generating course blocks for %s: %s',
                    unicode(course_key),
                    ex.message,
                )
Exemple #9
0
 def test_query_counts_cached(self, store_type, with_storage_backing):
     with waffle().override(STORAGE_BACKING_FOR_CACHE, active=with_storage_backing):
         course = self._create_course(store_type)
         self._get_blocks(
             course,
             expected_mongo_queries=0,
             expected_sql_queries=6 if with_storage_backing else 5,
         )
 def test_query_counts_cached(self, store_type, with_storage_backing):
     with waffle().override(STORAGE_BACKING_FOR_CACHE, active=with_storage_backing):
         course = self._create_course(store_type)
         self._get_blocks(
             course,
             expected_mongo_queries=0,
             expected_sql_queries=6 if with_storage_backing else 5,
         )
Exemple #11
0
 def test_query_counts_uncached(self, store_type_tuple, with_storage_backing):
     store_type, expected_mongo_queries = store_type_tuple
     with waffle().override(STORAGE_BACKING_FOR_CACHE, active=with_storage_backing):
         course = self._create_course(store_type)
         clear_course_from_cache(course.id)
         self._get_blocks(
             course,
             expected_mongo_queries,
             expected_sql_queries=14 if with_storage_backing else 6,
         )
 def test_query_counts_uncached(self, store_type_tuple, with_storage_backing):
     store_type, expected_mongo_queries = store_type_tuple
     with waffle().override(STORAGE_BACKING_FOR_CACHE, active=with_storage_backing):
         course = self._create_course(store_type)
         clear_course_from_cache(course.id)
         self._get_blocks(
             course,
             expected_mongo_queries,
             expected_sql_queries=14 if with_storage_backing else 6,
         )
    def test_dump_to_neo4j_published(self, mock_graph_constructor, mock_selector_class):
        """
        Tests that we only dump those courses that have been published after
        the last time the command was been run.
        """
        mock_graph = MockGraph()
        mock_graph_constructor.return_value = mock_graph
        mock_selector_class.return_value = MockNodeSelector(mock_graph)
        mock_credentials = mock.Mock()

        # run once to warm the cache
        submitted, skipped = self.mss.dump_courses_to_neo4j(mock_credentials)
        self.assertEqual(len(submitted), len(self.course_strings))

        # simulate one of the courses being published
        with block_structure_config.waffle().override(block_structure_config.STORAGE_BACKING_FOR_CACHE):
            update_block_structure_on_course_publish(None, self.course.id)

        # make sure only the published course was dumped
        submitted, __ = self.mss.dump_courses_to_neo4j(mock_credentials)
        self.assertEqual(len(submitted), 1)
        self.assertEqual(submitted[0], six.text_type(self.course.id))
Exemple #14
0
    def test_query_counts_uncached(self, store_type_tuple, with_storage_backing):
        store_type, expected_mongo_queries = store_type_tuple
        with waffle().override(STORAGE_BACKING_FOR_CACHE, active=with_storage_backing):
            course = self._create_course(store_type)
            clear_course_from_cache(course.id)

            if with_storage_backing:
                # TODO: Remove Django 1.11 upgrade shim
                # SHIM: Django 1.11 results in a few more SAVEPOINTs due to:
                # https://github.com/django/django/commit/d44afd88#diff-5b0dda5eb9a242c15879dc9cd2121379L485
                if django.VERSION >= (1, 11):
                    num_sql_queries = 17
                else:
                    num_sql_queries = 15
            else:
                num_sql_queries = 7

            self._get_blocks(
                course,
                expected_mongo_queries,
                expected_sql_queries=num_sql_queries,
            )
    def test_query_counts_uncached(self, store_type_tuple, with_storage_backing):
        store_type, expected_mongo_queries = store_type_tuple
        with waffle().override(STORAGE_BACKING_FOR_CACHE, active=with_storage_backing):
            course = self._create_course(store_type)
            clear_course_from_cache(course.id)

            if with_storage_backing:
                # TODO: Remove Django 1.11 upgrade shim
                # SHIM: Django 1.11 results in a few more SAVEPOINTs due to:
                # https://github.com/django/django/commit/d44afd88#diff-5b0dda5eb9a242c15879dc9cd2121379L485
                if django.VERSION >= (1, 11):
                    num_sql_queries = 16
                else:
                    num_sql_queries = 14
            else:
                num_sql_queries = 6

            self._get_blocks(
                course,
                expected_mongo_queries,
                expected_sql_queries=num_sql_queries,
            )