示例#1
0
    def _queue_task(self, args):
        ''' add transfer to waiting queue if possible
            then notify the background thread to process it '''
        if self._cancel_called:
            raise AsperaTransferQueueError("Cancel already called")
        elif self._wait_called:
            raise AsperaTransferQueueError("Cant queue items during wait")
        elif self.waiting_coordinator_count(
        ) >= self._config.max_submission_queue_size:
            raise AsperaTransferQueueError("Max queued items reached")
        else:
            _coordinator = AsperaTransferCoordinator(args)
            _components = {
                'meta': TransferMeta(args, transfer_id=args.transfer_id),
                'coordinator': _coordinator
            }

            _transfer_future = AsperaTransferFuture(**_components)
            _coordinator.add_subscribers(args.subscribers,
                                         future=_transfer_future)
            _coordinator.add_done_callback(self.remove_aspera_coordinator,
                                           transfer_coordinator=_coordinator)
            self.append_waiting_queue(_coordinator)

            if not self._processing_thread:
                self._processing_thread = threading.Thread(
                    target=self._process_waiting_queue)
                self._processing_thread.daemon = True
                self._processing_thread.start()

            self._wakeup_processing_thread()

        return _transfer_future
 def setUp(self):
     self.subscriber = RecordingSubscriber()
     self.second_subscriber = RecordingSubscriber()
     self.call_args = CallArgs(
         subscribers=[self.subscriber, self.second_subscriber])
     self.transfer_meta = TransferMeta(self.call_args)
     self.transfer_future = TransferFuture(self.transfer_meta)
示例#3
0
class TestTransferMeta(unittest.TestCase):
    def setUp(self):
        self.transfer_meta = TransferMeta()

    def test_size(self):
        self.assertEqual(self.transfer_meta.size, None)
        self.transfer_meta.provide_transfer_size(5)
        self.assertEqual(self.transfer_meta.size, 5)

    def test_call_args(self):
        call_args = object()
        transfer_meta = TransferMeta(call_args)
        # Assert the that call args provided is the same as is returned
        self.assertIs(transfer_meta.call_args, call_args)

    def test_transfer_id(self):
        transfer_meta = TransferMeta(transfer_id=1)
        self.assertEqual(transfer_meta.transfer_id, 1)

    def test_user_context(self):
        self.transfer_meta.user_context['foo'] = 'bar'
        self.assertEqual(self.transfer_meta.user_context, {'foo': 'bar'})
示例#4
0
 def _get_future_with_components(self, call_args):
     transfer_id = self._id_counter
     # Creates a new transfer future along with its components
     transfer_coordinator = TransferCoordinator(transfer_id=transfer_id)
     # Track the transfer coordinator for transfers to manage.
     self._coordinator_controller.add_transfer_coordinator(
         transfer_coordinator)
     # Also make sure that the transfer coordinator is removed once
     # the transfer completes so it does not stick around in memory.
     transfer_coordinator.add_done_callback(
         self._coordinator_controller.remove_transfer_coordinator,
         transfer_coordinator)
     components = {
         'meta': TransferMeta(call_args, transfer_id=transfer_id),
         'coordinator': transfer_coordinator
     }
     transfer_future = TransferFuture(**components)
     return transfer_future, components
示例#5
0
 def setUp(self):
     self.meta = TransferMeta()
     self.coordinator = TransferCoordinator()
     self.future = self._get_transfer_future()
示例#6
0
 def test_transfer_id(self):
     transfer_meta = TransferMeta(transfer_id=1)
     self.assertEqual(transfer_meta.transfer_id, 1)
示例#7
0
 def test_call_args(self):
     call_args = object()
     transfer_meta = TransferMeta(call_args)
     # Assert the that call args provided is the same as is returned
     self.assertIs(transfer_meta.call_args, call_args)
示例#8
0
 def setUp(self):
     self.transfer_meta = TransferMeta()
 def get_transfer_future(self, call_args=None):
     return TransferFuture(meta=TransferMeta(call_args),
                           coordinator=self.transfer_coordinator)