def testDeleteObject_FailFourTimes(self): # max_retrials=3 as set in _DeleteObject means that there can be up to 4 # attempts self.delete_object_mock.side_effect = MakeRepeatMock(5) tasks = self._MakeTestTasks(self._DEFAULT_NUM_TASKS) with self.assertRaises(parallel.MultiError): storage_parallel.DeleteObjects(tasks)
def testProgressBar_NoTasks(self): storage_parallel.DeleteObjects([], num_threads=1, show_progress_bar=True) self.AssertErrEquals( '#============================================================#\n' '#= Deleting 0 objects from Google Cloud Storage =#\n' '#============================================================#\n' ) self.delete_object_mock.assert_not_called()
def _CleanUpBucket(storage_client, bucket_ref): """Removes a bucket and its contents.""" # The bucket must be empty before we can delete it delete_tasks = [] for obj in storage_client.ListBucket(bucket_ref): delete_tasks.append( storage_parallel.ObjectDeleteTask( storage_util.ObjectReference.FromMessage(obj))) storage_parallel.DeleteObjects(delete_tasks) storage_client.DeleteBucket(bucket_ref)
def _RunTestWithGivenParallelism(self, num_threads): tasks = self._MakeTestTasks(self._DEFAULT_NUM_TASKS) storage_parallel.DeleteObjects(tasks, num_threads=num_threads) for n in range(self._DEFAULT_NUM_TASKS): self.delete_object_mock.assert_any_call( storage_util.ObjectReference( self._TEST_BUCKET, 'remote{0}'.format(n))) self.assertEqual(self.delete_object_mock.call_count, self._DEFAULT_NUM_TASKS) self.get_pool_mock.assert_called_once_with(num_threads)
def _RunTestWithSuccessAfterNumTries(self, num_tries): self.delete_object_mock.side_effect = MakeRepeatMock(num_tries) tasks = self._MakeTestTasks(self._DEFAULT_NUM_TASKS) storage_parallel.DeleteObjects(tasks) calls = [] self.assertEqual(self.delete_object_mock.call_count, self._DEFAULT_NUM_TASKS * num_tries) for n in range(self._DEFAULT_NUM_TASKS): for _ in range(num_tries): calls.append(mock.call( storage_util.ObjectReference( self._TEST_BUCKET, 'remote{0}'.format(n)))) self.delete_object_mock.assert_has_calls(calls, any_order=True) self.get_pool_mock.assert_called_once_with(16)
def testProgressBar_OneTask(self): tasks = self._MakeTestTasks(1) self.progress_bar_states = [ ('#============================================================#\n' '#= Deleting 1 object from Google Cloud Storage =#\n' '#'), ] storage_parallel.DeleteObjects(tasks, num_threads=1, show_progress_bar=True) self.assertEqual(self.delete_object_mock.call_count, 1) self.AssertErrEquals( '#============================================================#\n' '#= Deleting 1 object from Google Cloud Storage =#\n' '#============================================================#\n' )
def testDeleteObject_OneFile(self): tasks = self._MakeTestTasks(1) storage_parallel.DeleteObjects(tasks) self.delete_object_mock.assert_called_once_with( storage_util.ObjectReference(self._TEST_BUCKET, 'remote0')) self.get_pool_mock.assert_called_once_with(16)
def testDeleteObject_NoFiles(self): storage_parallel.DeleteObjects([]) self.delete_object_mock.assert_not_called() self.get_pool_mock.assert_called_once_with(16)