Exemplo n.º 1
0
  def test_AppendComponentTrackerToParallelUploadTrackerFile(self):
    """Tests the _CreateParallelUploadTrackerFile function with append."""
    tracker_file = self.CreateTempFile(file_name='foo', contents='asdf')
    tracker_file_lock = CreateLock()
    random_prefix = '123'
    objects = ['obj1', '42', 'obj2', '314159']
    expected_contents = [random_prefix] + objects
    objects = [ObjectFromTracker(objects[2 * i], objects[2 * i + 1])
               for i in range(0, len(objects) / 2)]
    _CreateParallelUploadTrackerFile(tracker_file, random_prefix, objects,
                                     tracker_file_lock)

    new_object = ['obj2', '1234']
    expected_contents += new_object
    new_object = ObjectFromTracker(new_object[0], new_object[1])
    _AppendComponentTrackerToParallelUploadTrackerFile(tracker_file, new_object,
                                                       tracker_file_lock)
    with open(tracker_file, 'rb') as f:
      lines = f.read().splitlines()
    self.assertEqual(expected_contents, lines)
Exemplo n.º 2
0
    def test_AppendComponentTrackerToParallelUploadTrackerFile(self):
        """Tests the _CreateParallelUploadTrackerFile function with append."""
        tracker_file = self.CreateTempFile(file_name='foo', contents='asdf')
        tracker_file_lock = CreateLock()
        random_prefix = '123'
        objects = ['obj1', '42', 'obj2', '314159']
        expected_contents = [random_prefix] + objects
        objects = [
            ObjectFromTracker(objects[2 * i], objects[2 * i + 1])
            for i in range(0,
                           len(objects) / 2)
        ]
        _CreateParallelUploadTrackerFile(tracker_file, random_prefix, objects,
                                         tracker_file_lock)

        new_object = ['obj2', '1234']
        expected_contents += new_object
        new_object = ObjectFromTracker(new_object[0], new_object[1])
        _AppendComponentTrackerToParallelUploadTrackerFile(
            tracker_file, new_object, tracker_file_lock)
        with open(tracker_file, 'rb') as f:
            lines = f.read().splitlines()
        self.assertEqual(expected_contents, lines)