コード例 #1
0
 def setUp(self):
     self._datetime = FakeDateTime()
     self._test_patcher = TestPatcher(_TEST_PATCH_VERSION,
                                      _TEST_PATCH_FILES, _TEST_PATCH_DATA)
     self._patcher = CachingRietveldPatcher(
         self._test_patcher, ObjectStoreCreator(start_empty=False),
         self._datetime)
コード例 #2
0
 def setUp(self):
     self._datetime = FakeDateTime()
     # CachingRietveldPatcher should always call Apply with binary=True.
     self._test_patcher = TestPatcher(_TEST_PATCH_VERSION,
                                      _TEST_PATCH_FILES,
                                      _TEST_PATCH_DATA,
                                      assert_binary=True)
     self._patcher = CachingRietveldPatcher(
         self._test_patcher, ObjectStoreCreator('test', start_empty=False),
         self._datetime)
コード例 #3
0
    def CreateServerInstance(self):
        # start_empty=False because a patch can rely on files that are already in
        # SVN repository but not yet pulled into data store by cron jobs (a typical
        # example is to add documentation for an existing API).
        object_store_creator = ObjectStoreCreator(start_empty=False)

        unpatched_file_system = self._delegate.CreateHostFileSystemProvider(
            object_store_creator).GetTrunk()

        rietveld_patcher = CachingRietveldPatcher(
            RietveldPatcher(
                self._issue,
                AppEngineUrlFetcher(url_constants.CODEREVIEW_SERVER)),
            object_store_creator)

        patched_file_system = PatchedFileSystem(unpatched_file_system,
                                                rietveld_patcher)

        patched_host_file_system_provider = (
            self._delegate.CreateHostFileSystemProvider(
                object_store_creator,
                # The patched file system needs to be online otherwise it'd be
                # impossible to add files in the patches.
                offline=False,
                # The trunk file system for this creator should be the patched one.
                default_trunk_instance=patched_file_system))

        combined_compiled_fs_factory = ChainedCompiledFileSystem.Factory(
            [unpatched_file_system], object_store_creator)

        branch_utility = self._delegate.CreateBranchUtility(
            object_store_creator)

        server_instance = ServerInstance(
            object_store_creator,
            combined_compiled_fs_factory,
            branch_utility,
            patched_host_file_system_provider,
            self._delegate.CreateGithubFileSystemProvider(
                object_store_creator),
            CloudStorageFileSystemProvider(object_store_creator),
            base_path='/_patch/%s/' % self._issue)

        # HACK: if content_providers.json changes in this patch then the cron needs
        # to be re-run to pull in the new configuration.
        _, _, modified = rietveld_patcher.GetPatchedFiles()
        if CONTENT_PROVIDERS in modified:
            server_instance.content_providers.Cron().Get()

        return server_instance
コード例 #4
0
ファイル: patch_servlet.py プロジェクト: hujiajie/pa-chromium
    def CreateServerInstanceForChannel(self, channel):
        base_object_store_creator = ObjectStoreCreator(channel,
                                                       start_empty=False)
        # TODO(fj): Use OfflineFileSystem here once all json/idl files in api/
        # are pulled into data store by cron jobs.
        base_file_system = CachingFileSystem(
            self._delegate.CreateHostFileSystemForBranch(channel),
            base_object_store_creator)
        base_compiled_fs_factory = CompiledFileSystem.Factory(
            base_file_system, base_object_store_creator)

        object_store_creator = ObjectStoreCreator('trunk@%s' % self._issue,
                                                  start_empty=False)
        rietveld_patcher = CachingRietveldPatcher(
            RietveldPatcher(
                svn_constants.EXTENSIONS_PATH, self._issue,
                AppEngineUrlFetcher(url_constants.CODEREVIEW_SERVER)),
            object_store_creator)
        patched_file_system = PatchedFileSystem(base_file_system,
                                                rietveld_patcher)
        patched_compiled_fs_factory = CompiledFileSystem.Factory(
            patched_file_system, object_store_creator)

        compiled_fs_factory = ChainedCompiledFileSystem.Factory([
            (patched_compiled_fs_factory, patched_file_system),
            (base_compiled_fs_factory, base_file_system)
        ])
        return ServerInstance(
            channel, object_store_creator, patched_file_system,
            self._delegate.CreateAppSamplesFileSystem(
                base_object_store_creator), '/_patch/%s' % self._issue,
            compiled_fs_factory)
コード例 #5
0
    def CreateServerInstance(self):
        object_store_creator = ObjectStoreCreator(start_empty=False)
        branch_utility = self._delegate.CreateBranchUtility(
            object_store_creator)
        host_file_system_creator = self._delegate.CreateHostFileSystemCreator(
            object_store_creator)
        # offline=False because a patch can rely on files that are already in SVN
        # repository but not yet pulled into data store by cron jobs (a typical
        # example is to add documentation for an existing API).
        base_file_system = CachingFileSystem(
            host_file_system_creator.Create(offline=False),
            object_store_creator)
        base_compiled_fs_factory = CompiledFileSystem.Factory(
            base_file_system, object_store_creator)

        rietveld_patcher = CachingRietveldPatcher(
            RietveldPatcher(
                svn_constants.EXTENSIONS_PATH, self._issue,
                AppEngineUrlFetcher(url_constants.CODEREVIEW_SERVER)),
            object_store_creator)
        patched_file_system = PatchedFileSystem(base_file_system,
                                                rietveld_patcher)
        patched_compiled_fs_factory = CompiledFileSystem.Factory(
            patched_file_system, object_store_creator)

        compiled_fs_factory = ChainedCompiledFileSystem.Factory([
            (patched_compiled_fs_factory, patched_file_system),
            (base_compiled_fs_factory, base_file_system)
        ])

        return ServerInstance(
            object_store_creator, patched_file_system,
            self._delegate.CreateAppSamplesFileSystem(object_store_creator),
            '/_patch/%s' % self._issue, compiled_fs_factory, branch_utility,
            host_file_system_creator)
コード例 #6
0
class CachingRietveldPatcherTest(unittest.TestCase):
    def setUp(self):
        self._datetime = FakeDateTime()
        # CachingRietveldPatcher should always call Apply with binary=True.
        self._test_patcher = TestPatcher(_TEST_PATCH_VERSION,
                                         _TEST_PATCH_FILES,
                                         _TEST_PATCH_DATA,
                                         assert_binary=True)
        self._patcher = CachingRietveldPatcher(
            self._test_patcher, ObjectStoreCreator('test', start_empty=False),
            self._datetime)

    def testGetVersion(self):
        # Invalidate cache.
        self._datetime.time += _VERSION_CACHE_MAXAGE
        # Fill cache.
        self._patcher.GetVersion()
        count = self._test_patcher.get_version_count
        # Should read from cache.
        self._patcher.GetVersion()
        self.assertEqual(count, self._test_patcher.get_version_count)
        # Invalidate cache.
        self._datetime.time += _VERSION_CACHE_MAXAGE
        # Should fetch version.
        self._patcher.GetVersion()
        self.assertEqual(count + 1, self._test_patcher.get_version_count)

    def testGetPatchedFiles(self):
        # Fill cache.
        self._patcher.GetPatchedFiles()
        count = self._test_patcher.get_patched_files_count
        # Should read from cache.
        self._patcher.GetPatchedFiles()
        self.assertEqual(count, self._test_patcher.get_patched_files_count)

    def testApply(self):
        # Fill cache.
        self._patcher.Apply(['add.txt'], None).Get()
        count = self._test_patcher.apply_count
        # Should read from cache even though it's reading another file.
        self._patcher.Apply(['modify.txt'], None).Get()
        self.assertEqual(count, self._test_patcher.apply_count)

        # Make sure RietveldPatcher handles |binary| correctly.
        self.assertTrue(
            isinstance(
                self._patcher.Apply(['add.txt'], None, True).Get()['add.txt'],
                str), 'Expected result is binary. It was text.')
        self.assertTrue(
            isinstance(
                self._patcher.Apply(['add.txt'], None).Get()['add.txt'],
                unicode), 'Expected result is text. It was binary.')
コード例 #7
0
class CachingRietveldPatcherTest(unittest.TestCase):
    def setUp(self):
        self._datetime = FakeDateTime()
        self._test_patcher = TestPatcher(_TEST_PATCH_VERSION,
                                         _TEST_PATCH_FILES, _TEST_PATCH_DATA)
        self._patcher = CachingRietveldPatcher(
            self._test_patcher, ObjectStoreCreator(start_empty=False),
            self._datetime)

    def testGetVersion(self):
        # Invalidate cache.
        self._datetime.time += _VERSION_CACHE_MAXAGE
        # Fill cache.
        self._patcher.GetVersion()
        count = self._test_patcher.get_version_count
        # Should read from cache.
        self._patcher.GetVersion()
        self.assertEqual(count, self._test_patcher.get_version_count)
        # Invalidate cache.
        self._datetime.time += _VERSION_CACHE_MAXAGE
        # Should fetch version.
        self._patcher.GetVersion()
        self.assertEqual(count + 1, self._test_patcher.get_version_count)

    def testGetPatchedFiles(self):
        # Fill cache.
        self._patcher.GetPatchedFiles()
        count = self._test_patcher.get_patched_files_count
        # Should read from cache.
        self._patcher.GetPatchedFiles()
        self.assertEqual(count, self._test_patcher.get_patched_files_count)

    def testApply(self):
        # Fill cache.
        self._patcher.Apply(['add.txt'], None).Get()
        count = self._test_patcher.apply_count
        # Should read from cache even though it's reading another file.
        self._patcher.Apply(['modify.txt'], None).Get()
        self.assertEqual(count, self._test_patcher.apply_count)