示例#1
0
    def setUp(self):
        self.progress_manager = InMemoryProgressManager(
            Mock(spec=LocalDirectoryWorkingContext))
        self.workunit_provider = Mock(spec=WorkUnitProvider)

        self.workunit1 = MagicMock(spec=WorkUnit)
        self.file1 = "file1"
        self.workunit1.get_filename.return_value = self.file1

        self.workunit2 = MagicMock(spec=WorkUnit)
        self.file2 = "file2"
        self.workunit2.get_filename.return_value = self.file2

        workunits = [self.workunit1, self.workunit2]

        def get_workunit(index):
            workunit = workunits[index]
            self.progress_manager.lock(workunit.get_filename())
            return workunit

        self.workunit_provider.get_workunit.side_effect = (
            get_workunit(index) for index in range(2))
        image_manager = Mock(spec=ImageManager)

        self.undertest = ValidationModel(self.workunit_provider, image_manager,
                                         None)
        self.undertest.start_work()
示例#2
0
class WorkloadManagementTest(unittest.TestCase):
    def setUp(self):
        self.progress_manager = InMemoryProgressManager(Mock(spec=LocalDirectoryWorkingContext))
        self.workunit_provider = Mock(spec=WorkUnitProvider)

        self.workunit1 = MagicMock(spec=WorkUnit)
        self.file1 = "file1"
        self.workunit1.get_filename.return_value = self.file1

        self.workunit2 = MagicMock(spec=WorkUnit)
        self.file2 = "file2"
        self.workunit2.get_filename.return_value = self.file2

        workunits = [self.workunit1, self.workunit2]

        def get_workunit(index):
            workunit = workunits[index]
            self.progress_manager.lock(workunit.get_filename())
            return workunit

        self.workunit_provider.get_workunit.side_effect = (get_workunit(index) for index in xrange(2))
        image_manager = Mock(spec=ImageManager)

        self.undertest = ValidationModel(self.workunit_provider, image_manager, None)
        self.undertest.start_work()

    def test_workunits_on_demand(self):
        assert_that(self.undertest.get_current_workunit(), equal_to(self.workunit1))
        assert_that(self.workunit_provider.get_workunit.call_count, equal_to(1))

        self.undertest.next_workunit()
        assert_that(self.undertest.get_current_workunit(), equal_to(self.workunit2))
        assert_that(self.workunit_provider.get_workunit.call_count, equal_to(2))

    def test_shift_locks(self):
        assert_that(self.undertest.get_current_workunit(), equal_to(self.workunit1))
        assert_that(self.progress_manager.owns_lock(self.file1), equal_to(True))
        assert_that(self.progress_manager.owns_lock(self.file2), equal_to(False))

        self.undertest.next_workunit()
        assert_that(self.undertest.get_current_workunit(), equal_to(self.workunit2))

        # Note we don't give up lock just by going to next workunit.  It is
        # released once it is done processing.
        assert_that(self.progress_manager.owns_lock(self.file1), equal_to(True))
        assert_that(self.progress_manager.owns_lock(self.file2), equal_to(True))
示例#3
0
 def setUp(self):
     working_directory = self.get_directory_to_clean()
     context = LocalDirectoryWorkingContext(working_directory)
     progress_manager = InMemoryProgressManager(context)
     parser = AstromParser()
     builder = RealsWorkUnitBuilder(parser, context, context,
                                    progress_manager)
     undertest = WorkUnitProvider(tasks.get_suffix(tasks.REALS_TASK),
                                  context, progress_manager, builder)
     self.progress_manager = progress_manager
     self.undertest = undertest
示例#4
0
    def setUp(self):
        self.taskid = "id"
        self.file1 = "file1"
        self.file2 = "file2"
        self.file3 = "file3"
        self.file4 = "file4"
        self.test_files = [self.file1, self.file2]

        directory_manager = TestDirectoryManager()
        progress_manager = InMemoryProgressManager(directory_manager)
        builder = TestWorkUnitBuilder()

        self.undertest = WorkUnitProvider(self.taskid, directory_manager,
                                          progress_manager, builder)
        self.directory_manager = directory_manager
        self.progress_manager = progress_manager
        self.directory_manager.set_listing(self.taskid, self.test_files)
示例#5
0
    def setUp(self):
        self.progress_manager = InMemoryProgressManager(Mock(spec=LocalDirectoryWorkingContext))
        self.workunit_provider = Mock(spec=WorkUnitProvider)

        self.workunit1 = MagicMock(spec=WorkUnit)
        self.file1 = "file1"
        self.workunit1.get_filename.return_value = self.file1

        self.workunit2 = MagicMock(spec=WorkUnit)
        self.file2 = "file2"
        self.workunit2.get_filename.return_value = self.file2

        workunits = [self.workunit1, self.workunit2]

        def get_workunit(index):
            workunit = workunits[index]
            self.progress_manager.lock(workunit.get_filename())
            return workunit

        self.workunit_provider.get_workunit.side_effect = (get_workunit(index) for index in xrange(2))
        image_manager = Mock(spec=ImageManager)

        self.undertest = ValidationModel(self.workunit_provider, image_manager, None)
        self.undertest.start_work()
示例#6
0
    def setUp(self):
        self.file1 = "file1"
        self.file2 = "file2"

        directory_manager = Mock(spec=LocalDirectoryWorkingContext)
        self.undertest = InMemoryProgressManager(directory_manager)
示例#7
0
class InMemoryProgressManagerTest(unittest.TestCase):
    def setUp(self):
        self.file1 = "file1"
        self.file2 = "file2"

        directory_manager = Mock(spec=LocalDirectoryWorkingContext)
        self.undertest = InMemoryProgressManager(directory_manager)

    def test_done(self):
        assert_that(self.undertest.is_done(self.file1), equal_to(False))
        assert_that(self.undertest.is_done(self.file2), equal_to(False))

        self.undertest.lock(self.file2)
        self.undertest.record_done(self.file2)
        self.undertest.unlock(self.file2)

        assert_that(self.undertest.is_done(self.file1), equal_to(False))
        assert_that(self.undertest.is_done(self.file2), equal_to(True))

        self.undertest.lock(self.file1)
        self.undertest.record_done(self.file1)
        self.undertest.unlock(self.file1)

        assert_that(self.undertest.is_done(self.file1), equal_to(True))
        assert_that(self.undertest.is_done(self.file2), equal_to(True))

    def test_processed_indices(self):
        assert_that(self.undertest.get_processed_indices(self.file1),
                    has_length(0))
        self.undertest.lock(self.file1)
        self.undertest.record_index(self.file1, 1)
        assert_that(self.undertest.get_processed_indices(self.file1),
                    contains_inanyorder(1))

        self.undertest.record_index(self.file1, 2)
        assert_that(self.undertest.get_processed_indices(self.file1),
                    contains_inanyorder(1, 2))

        assert_that(self.undertest.get_processed_indices(self.file2),
                    has_length(0))

    def test_locking(self):
        assert_that(self.undertest.owns_lock(self.file1), equal_to(False))
        assert_that(self.undertest.owns_lock(self.file2), equal_to(False))

        self.undertest.lock(self.file1)

        assert_that(self.undertest.owns_lock(self.file1), equal_to(True))
        assert_that(self.undertest.owns_lock(self.file2), equal_to(False))

        self.assertRaises(RequiresLockException, self.undertest.record_done, self.file2)
        self.assertRaises(RequiresLockException, self.undertest.record_index, self.file2, 1)

    def test_external_locks(self):
        self.undertest.add_external_lock(self.file1)

        assert_that(self.undertest.owns_lock(self.file1), equal_to(False))
        self.assertRaises(FileLockedException, self.undertest.lock, self.file1)
        self.assertRaises(FileLockedException, self.undertest.unlock, self.file1)

        self.undertest.lock(self.file2)
        assert_that(self.undertest.owns_lock(self.file2), equal_to(True))
示例#8
0
    def setUp(self):
        self.file1 = "file1"
        self.file2 = "file2"

        directory_manager = Mock(spec=LocalDirectoryWorkingContext)
        self.undertest = InMemoryProgressManager(directory_manager)
示例#9
0
class InMemoryProgressManagerTest(unittest.TestCase):
    def setUp(self):
        self.file1 = "file1"
        self.file2 = "file2"

        directory_manager = Mock(spec=LocalDirectoryWorkingContext)
        self.undertest = InMemoryProgressManager(directory_manager)

    def test_done(self):
        assert_that(self.undertest.is_done(self.file1), equal_to(False))
        assert_that(self.undertest.is_done(self.file2), equal_to(False))

        self.undertest.lock(self.file2)
        self.undertest.record_done(self.file2)
        self.undertest.unlock(self.file2)

        assert_that(self.undertest.is_done(self.file1), equal_to(False))
        assert_that(self.undertest.is_done(self.file2), equal_to(True))

        self.undertest.lock(self.file1)
        self.undertest.record_done(self.file1)
        self.undertest.unlock(self.file1)

        assert_that(self.undertest.is_done(self.file1), equal_to(True))
        assert_that(self.undertest.is_done(self.file2), equal_to(True))

    def test_processed_indices(self):
        assert_that(self.undertest.get_processed_indices(self.file1),
                    has_length(0))
        self.undertest.lock(self.file1)
        self.undertest.record_index(self.file1, 1)
        assert_that(self.undertest.get_processed_indices(self.file1),
                    contains_inanyorder(1))

        self.undertest.record_index(self.file1, 2)
        assert_that(self.undertest.get_processed_indices(self.file1),
                    contains_inanyorder(1, 2))

        assert_that(self.undertest.get_processed_indices(self.file2),
                    has_length(0))

    def test_locking(self):
        assert_that(self.undertest.owns_lock(self.file1), equal_to(False))
        assert_that(self.undertest.owns_lock(self.file2), equal_to(False))

        self.undertest.lock(self.file1)

        assert_that(self.undertest.owns_lock(self.file1), equal_to(True))
        assert_that(self.undertest.owns_lock(self.file2), equal_to(False))

        self.assertRaises(RequiresLockException, self.undertest.record_done,
                          self.file2)
        self.assertRaises(RequiresLockException, self.undertest.record_index,
                          self.file2, 1)

    def test_external_locks(self):
        self.undertest.add_external_lock(self.file1)

        assert_that(self.undertest.owns_lock(self.file1), equal_to(False))
        self.assertRaises(FileLockedException, self.undertest.lock, self.file1)
        self.assertRaises(FileLockedException, self.undertest.unlock,
                          self.file1)

        self.undertest.lock(self.file2)
        assert_that(self.undertest.owns_lock(self.file2), equal_to(True))