Ejemplo n.º 1
0
 def test_get_cached_and_found(self):
     # DistributionSourcePackageInDatabase.get() returns the DSP if it's
     # found in the database from a good mapping cache entry.
     distribution = self.factory.makeDistribution()
     sourcepackagename = self.factory.makeSourcePackageName()
     dsp = DistributionSourcePackageInDatabase.new(distribution,
                                                   sourcepackagename)
     flush_database_updates()
     with StormStatementRecorder() as recorder:
         dsp_found = DistributionSourcePackageInDatabase.get(
             distribution, sourcepackagename)
         self.assertIs(dsp, dsp_found)
     # Hurrah! This is what we're aiming for: a DSP that is in the mapping
     # cache *and* in Storm's cache.
     self.assertThat(recorder, HasQueryCount(Equals(0)))
 def test_get_cached_and_found(self):
     # DistributionSourcePackageInDatabase.get() returns the DSP if it's
     # found in the database from a good mapping cache entry.
     distribution = self.factory.makeDistribution()
     sourcepackagename = self.factory.makeSourcePackageName()
     dsp = DistributionSourcePackageInDatabase.new(
         distribution, sourcepackagename)
     flush_database_updates()
     with StormStatementRecorder() as recorder:
         dsp_found = DistributionSourcePackageInDatabase.get(
             distribution, sourcepackagename)
         self.assertIs(dsp, dsp_found)
     # Hurrah! This is what we're aiming for: a DSP that is in the mapping
     # cache *and* in Storm's cache.
     self.assertThat(recorder, HasQueryCount(Equals(0)))
Ejemplo n.º 3
0
 def test_getDirect_found(self):
     # DistributionSourcePackageInDatabase.getDirect() returns the
     # DSPInDatabase if one already exists in the database. It also adds
     # the new mapping to the mapping cache.
     distribution = self.factory.makeDistribution()
     sourcepackagename = self.factory.makeSourcePackageName()
     dsp = DistributionSourcePackageInDatabase.new(distribution,
                                                   sourcepackagename)
     flush_database_updates()
     with StormStatementRecorder() as recorder:
         dsp_found = DistributionSourcePackageInDatabase.getDirect(
             dsp.distribution, dsp.sourcepackagename)
         self.assertIs(dsp, dsp_found)
     self.assertThat(recorder, HasQueryCount(Equals(1)))
     self.assertEqual({(distribution.id, sourcepackagename.id): dsp.id},
                      DistributionSourcePackageInDatabase._cache.items())
 def test_getDirect_found(self):
     # DistributionSourcePackageInDatabase.getDirect() returns the
     # DSPInDatabase if one already exists in the database. It also adds
     # the new mapping to the mapping cache.
     distribution = self.factory.makeDistribution()
     sourcepackagename = self.factory.makeSourcePackageName()
     dsp = DistributionSourcePackageInDatabase.new(
         distribution, sourcepackagename)
     flush_database_updates()
     with StormStatementRecorder() as recorder:
         dsp_found = DistributionSourcePackageInDatabase.getDirect(
             dsp.distribution, dsp.sourcepackagename)
         self.assertIs(dsp, dsp_found)
     self.assertThat(recorder, HasQueryCount(Equals(1)))
     self.assertEqual(
         {(distribution.id, sourcepackagename.id): dsp.id},
         DistributionSourcePackageInDatabase._cache.items())
Ejemplo n.º 5
0
 def test_get_not_cached_and_found(self):
     # DistributionSourcePackageInDatabase.get() returns the DSP if it's
     # found in the database even if no mapping cache entry exists for
     # it. It updates the mapping cache with this discovered information.
     distribution = self.factory.makeDistribution()
     sourcepackagename = self.factory.makeSourcePackageName()
     dsp = DistributionSourcePackageInDatabase.new(distribution,
                                                   sourcepackagename)
     # new() updates the mapping cache so we must clear it.
     DistributionSourcePackageInDatabase._cache.clear()
     flush_database_updates()
     with StormStatementRecorder() as recorder:
         dsp_found = DistributionSourcePackageInDatabase.get(
             distribution, sourcepackagename)
         self.assertIs(dsp, dsp_found)
     self.assertThat(recorder, HasQueryCount(Equals(1)))
     self.assertEqual({(distribution.id, sourcepackagename.id): dsp.id},
                      DistributionSourcePackageInDatabase._cache.items())
Ejemplo n.º 6
0
 def test_new(self):
     # DistributionSourcePackageInDatabase.new() creates a new DSP, adds it
     # to the store, and updates the mapping cache.
     distribution = self.factory.makeDistribution()
     sourcepackagename = self.factory.makeSourcePackageName()
     dsp = DistributionSourcePackageInDatabase.new(distribution,
                                                   sourcepackagename)
     self.assertIs(Store.of(distribution), Store.of(dsp))
     self.assertEqual({(distribution.id, sourcepackagename.id): dsp.id},
                      DistributionSourcePackageInDatabase._cache.items())
 def test_get_not_cached_and_found(self):
     # DistributionSourcePackageInDatabase.get() returns the DSP if it's
     # found in the database even if no mapping cache entry exists for
     # it. It updates the mapping cache with this discovered information.
     distribution = self.factory.makeDistribution()
     sourcepackagename = self.factory.makeSourcePackageName()
     dsp = DistributionSourcePackageInDatabase.new(
         distribution, sourcepackagename)
     # new() updates the mapping cache so we must clear it.
     DistributionSourcePackageInDatabase._cache.clear()
     flush_database_updates()
     with StormStatementRecorder() as recorder:
         dsp_found = DistributionSourcePackageInDatabase.get(
             distribution, sourcepackagename)
         self.assertIs(dsp, dsp_found)
     self.assertThat(recorder, HasQueryCount(Equals(1)))
     self.assertEqual(
         {(distribution.id, sourcepackagename.id): dsp.id},
         DistributionSourcePackageInDatabase._cache.items())
 def test_new(self):
     # DistributionSourcePackageInDatabase.new() creates a new DSP, adds it
     # to the store, and updates the mapping cache.
     distribution = self.factory.makeDistribution()
     sourcepackagename = self.factory.makeSourcePackageName()
     dsp = DistributionSourcePackageInDatabase.new(
         distribution, sourcepackagename)
     self.assertIs(Store.of(distribution), Store.of(dsp))
     self.assertEqual(
         {(distribution.id, sourcepackagename.id): dsp.id},
         DistributionSourcePackageInDatabase._cache.items())
Ejemplo n.º 9
0
 def test_get_cached_and_not_found_with_bogus_dsp_in_storm_cache(self):
     # DistributionSourcePackageInDatabase.get() returns None if a DSP does
     # exist in the database for a mapping cache entry, but the DSP
     # discovered does not match the mapping cache key.
     distribution = self.factory.makeDistribution()
     sourcepackagename = self.factory.makeSourcePackageName()
     # Put a bogus entry into the mapping cache.
     bogus_dsp = DistributionSourcePackageInDatabase.new(
         distribution, self.factory.makeSourcePackageName())
     bogus_dsp_cache_key = distribution.id, sourcepackagename.id
     DistributionSourcePackageInDatabase._cache[
         bogus_dsp_cache_key] = bogus_dsp.id
     flush_database_updates()
     with StormStatementRecorder() as recorder:
         dsp = DistributionSourcePackageInDatabase.get(
             distribution, sourcepackagename)
         self.assertIs(None, dsp)
     # A stale mapping means that we ordinarily have to issue two queries:
     # the first gets the bogus DSP from the database, the second gets the
     # correct DSP (or None). However, the bogus DSP is already in Storm's
     # cache, so we issue only one query.
     self.assertThat(recorder, HasQueryCount(Equals(1)))
 def test_get_cached_and_not_found_with_bogus_dsp_in_storm_cache(self):
     # DistributionSourcePackageInDatabase.get() returns None if a DSP does
     # exist in the database for a mapping cache entry, but the DSP
     # discovered does not match the mapping cache key.
     distribution = self.factory.makeDistribution()
     sourcepackagename = self.factory.makeSourcePackageName()
     # Put a bogus entry into the mapping cache.
     bogus_dsp = DistributionSourcePackageInDatabase.new(
         distribution, self.factory.makeSourcePackageName())
     bogus_dsp_cache_key = distribution.id, sourcepackagename.id
     DistributionSourcePackageInDatabase._cache[
         bogus_dsp_cache_key] = bogus_dsp.id
     flush_database_updates()
     with StormStatementRecorder() as recorder:
         dsp = DistributionSourcePackageInDatabase.get(
             distribution, sourcepackagename)
         self.assertIs(None, dsp)
     # A stale mapping means that we ordinarily have to issue two queries:
     # the first gets the bogus DSP from the database, the second gets the
     # correct DSP (or None). However, the bogus DSP is already in Storm's
     # cache, so we issue only one query.
     self.assertThat(recorder, HasQueryCount(Equals(1)))
Ejemplo n.º 11
0
 def test_get_cached_and_not_found_with_bogus_dsp(self):
     # DistributionSourcePackageInDatabase.get() returns None if a DSP does
     # exist in the database for a mapping cache entry, but the DSP
     # discovered does not match the mapping cache key.
     distribution = self.factory.makeDistribution()
     sourcepackagename = self.factory.makeSourcePackageName()
     # Put a bogus entry into the mapping cache.
     bogus_dsp = DistributionSourcePackageInDatabase.new(
         distribution, self.factory.makeSourcePackageName())
     bogus_dsp_cache_key = distribution.id, sourcepackagename.id
     DistributionSourcePackageInDatabase._cache[
         bogus_dsp_cache_key] = bogus_dsp.id
     # Invalidate the bogus DSP from Storm's cache.
     Store.of(bogus_dsp).invalidate(bogus_dsp)
     flush_database_updates()
     with StormStatementRecorder() as recorder:
         dsp = DistributionSourcePackageInDatabase.get(
             distribution, sourcepackagename)
         self.assertIs(None, dsp)
     # A stale mapping means that we have to issue two queries: the first
     # gets the bogus DSP from the database, the second gets the correct
     # DSP (or None).
     self.assertThat(recorder, HasQueryCount(Equals(2)))
Ejemplo n.º 12
0
 def test_get_not_cached_and_not_found(self):
     # DistributionSourcePackageInDatabase.get() returns None if a DSP does
     # not exist in the database and no mapping cache entry exists for
     # it. It does not modify the mapping cache.
     distribution = self.factory.makeDistribution()
     sourcepackagename = self.factory.makeSourcePackageName()
     flush_database_updates()
     with StormStatementRecorder() as recorder:
         dsp = DistributionSourcePackageInDatabase.get(
             distribution, sourcepackagename)
         self.assertIs(None, dsp)
     self.assertThat(recorder, HasQueryCount(Equals(1)))
     self.assertEqual({},
                      DistributionSourcePackageInDatabase._cache.items())
 def test_get_cached_and_not_found_with_bogus_dsp(self):
     # DistributionSourcePackageInDatabase.get() returns None if a DSP does
     # exist in the database for a mapping cache entry, but the DSP
     # discovered does not match the mapping cache key.
     distribution = self.factory.makeDistribution()
     sourcepackagename = self.factory.makeSourcePackageName()
     # Put a bogus entry into the mapping cache.
     bogus_dsp = DistributionSourcePackageInDatabase.new(
         distribution, self.factory.makeSourcePackageName())
     bogus_dsp_cache_key = distribution.id, sourcepackagename.id
     DistributionSourcePackageInDatabase._cache[
         bogus_dsp_cache_key] = bogus_dsp.id
     # Invalidate the bogus DSP from Storm's cache.
     Store.of(bogus_dsp).invalidate(bogus_dsp)
     flush_database_updates()
     with StormStatementRecorder() as recorder:
         dsp = DistributionSourcePackageInDatabase.get(
             distribution, sourcepackagename)
         self.assertIs(None, dsp)
     # A stale mapping means that we have to issue two queries: the first
     # gets the bogus DSP from the database, the second gets the correct
     # DSP (or None).
     self.assertThat(recorder, HasQueryCount(Equals(2)))
 def test_get_not_cached_and_not_found(self):
     # DistributionSourcePackageInDatabase.get() returns None if a DSP does
     # not exist in the database and no mapping cache entry exists for
     # it. It does not modify the mapping cache.
     distribution = self.factory.makeDistribution()
     sourcepackagename = self.factory.makeSourcePackageName()
     flush_database_updates()
     with StormStatementRecorder() as recorder:
         dsp = DistributionSourcePackageInDatabase.get(
             distribution, sourcepackagename)
         self.assertIs(None, dsp)
     self.assertThat(recorder, HasQueryCount(Equals(1)))
     self.assertEqual(
         {}, DistributionSourcePackageInDatabase._cache.items())
Ejemplo n.º 15
0
 def test_get_cached_and_not_found(self):
     # DistributionSourcePackageInDatabase.get() returns None if a DSP does
     # not exist in the database for a stale mapping cache entry.
     distribution = self.factory.makeDistribution()
     sourcepackagename = self.factory.makeSourcePackageName()
     # Enter a stale entry in the mapping cache.
     stale_dsp_cache_key = distribution.id, sourcepackagename.id
     DistributionSourcePackageInDatabase._cache[stale_dsp_cache_key] = -123
     flush_database_updates()
     with StormStatementRecorder() as recorder:
         dsp = DistributionSourcePackageInDatabase.get(
             distribution, sourcepackagename)
         self.assertIs(None, dsp)
     # A stale mapping means that we have to issue two queries: the first
     # queries for the stale DSP from the database, the second gets the
     # correct DSP (or None).
     self.assertThat(recorder, HasQueryCount(Equals(2)))
 def test_get_cached_and_not_found(self):
     # DistributionSourcePackageInDatabase.get() returns None if a DSP does
     # not exist in the database for a stale mapping cache entry.
     distribution = self.factory.makeDistribution()
     sourcepackagename = self.factory.makeSourcePackageName()
     # Enter a stale entry in the mapping cache.
     stale_dsp_cache_key = distribution.id, sourcepackagename.id
     DistributionSourcePackageInDatabase._cache[stale_dsp_cache_key] = -123
     flush_database_updates()
     with StormStatementRecorder() as recorder:
         dsp = DistributionSourcePackageInDatabase.get(
             distribution, sourcepackagename)
         self.assertIs(None, dsp)
     # A stale mapping means that we have to issue two queries: the first
     # queries for the stale DSP from the database, the second gets the
     # correct DSP (or None).
     self.assertThat(recorder, HasQueryCount(Equals(2)))