def setUp(self):
        super(StorageTableBatchTest, self).setUp()

        self.ts = self._create_storage_service(TableService, self.settings)
        self.ts.retry = LinearRetry(backoff=1, max_attempts=2).retry
        self.test_tables = []
        self.table_name = self._get_table_reference()

        if not self.is_playback():
            self.ts.create_table(self.table_name)
    def test_queue_service_stats_when_unavailable(self):
        # Arrange
        qs = self._create_storage_service(QueueService, self.settings)
        qs.response_callback = self.override_response_body_with_unavailable_status
        qs.retry = LinearRetry(backoff=1).retry

        # Act
        stats = qs.get_queue_service_stats()

        # Assert
        self._assert_stats_unavailable(stats)
    def test_blob_service_stats_when_unavailable(self):
        # Arrange
        bs = self._create_storage_service(BlockBlobService, self.settings)
        bs.response_callback = self.override_response_body_with_unavailable_status
        bs.retry = LinearRetry(backoff=1).retry

        # Act
        stats = bs.get_blob_service_stats()

        # Assert
        self._assert_stats_unavailable(stats)
    def retries(self):
        # By default, retries are performed with an exponential backoff.
        # Any custom retry logic may be used by simply defining a retry function,
        # but several easy pre-written options are available with modifiable settings.
        client = BlockBlobService(account_name='<account_name>',
                                  account_key='<account_key>')

        # Use an exponential retry, but modify the backoff settings
        # Here, we increase the initial back off, increase the number of retry attempts
        # and decrease the base of the exponential backoff.
        client.retry = ExponentialRetry(initial_backoff=30,
                                        increment_power=2,
                                        max_attempts=5).retry

        # Use a default linear retry policy instead
        client.retry = LinearRetry().retry

        # Turn off retries
        client.retry = no_retry
Example #5
0
    def test_linear_retry(self):
        # Arrange
        container_name = self.get_resource_name()
        service = self._create_storage_service(BlockBlobService, self.settings)
        service.retry = LinearRetry(backoff=1).retry

        # Force the create call to 'timeout' with a 408
        service.response_callback = ResponseCallback(
            status=201, new_status=408).override_status

        # Act
        try:
            created = service.create_container(container_name)
        finally:
            service.delete_container(container_name)

        # Assert
        # The initial create will return 201, but we overwrite it and retry.
        # The retry will then get a 409 and return false.
        self.assertFalse(created)
Example #6
0
    def test_retry_on_socket_timeout(self):
        # Arrange
        container_name = self.get_resource_name()
        service = self._create_storage_service(BlockBlobService, self.settings)
        service.retry = LinearRetry(backoff=1).retry

        # make the connect timeout reasonable, but packet timeout truly small, to make sure the request always times out
        service.socket_timeout = (11, 0.000000000001)

        # Act
        try:
            service.create_container(container_name)
        except AzureException as e:
            # Assert
            # This call should succeed on the server side, but fail on the client side due to socket timeout
            self.assertTrue(
                'read timeout' in str(e),
                'Expected socket timeout but got different exception.')
            pass
        finally:
            # we must make the timeout normal again to let the delete operation succeed
            service.socket_timeout = (11, 11)
            service.delete_container(container_name)