protected function createStorageInstance() { $storageClient = null; if (TESTS_SESSIONHANDLER_RUNONPROD) { $storageClient = new Microsoft_WindowsAzure_Storage_Blob(TESTS_BLOB_HOST_PROD, TESTS_STORAGE_ACCOUNT_PROD, TESTS_STORAGE_KEY_PROD, false, Microsoft_WindowsAzure_RetryPolicy_RetryPolicyAbstract::retryN(10, 250)); } else { $storageClient = new Microsoft_WindowsAzure_Storage_Blob(TESTS_BLOB_HOST_DEV, TESTS_STORAGE_ACCOUNT_DEV, TESTS_STORAGE_KEY_DEV, true, Microsoft_WindowsAzure_RetryPolicy_RetryPolicyAbstract::retryN(10, 250)); } if (TESTS_STORAGE_USEPROXY) { $storageClient->setProxy(TESTS_STORAGE_USEPROXY, TESTS_STORAGE_PROXY, TESTS_STORAGE_PROXY_PORT, TESTS_STORAGE_PROXY_CREDENTIALS); } return $storageClient; }
/** * Inits storage client object * * @param string $error * @return boolean */ function _init(&$error) { if (empty($this->_config['user'])) { $error = 'Empty account name.'; return false; } if (empty($this->_config['key'])) { $error = 'Empty account key.'; return false; } if (empty($this->_config['container'])) { $error = 'Empty container name.'; return false; } set_include_path(get_include_path() . PATH_SEPARATOR . W3TC_LIB_DIR); require_once 'Microsoft/WindowsAzure/Storage/Blob.php'; $this->_client = new Microsoft_WindowsAzure_Storage_Blob(Microsoft_WindowsAzure_Storage::URL_CLOUD_BLOB, $this->_config['user'], $this->_config['key'], false, Microsoft_WindowsAzure_RetryPolicy_RetryPolicyAbstract::noRetry()); return true; }
/** * Perform request using Microsoft_Http_Client channel * * @param string $path Path * @param string $queryString Query string * @param string $httpVerb HTTP verb the request will use * @param array $headers x-ms headers to add * @param boolean $forTableStorage Is the request for table storage? * @param mixed $rawData Optional RAW HTTP data to be sent over the wire * @param string $resourceType Resource type * @param string $requiredPermission Required permission * @return Microsoft_Http_Response */ protected function _performRequest($path = '/', $queryString = '', $httpVerb = Microsoft_Http_Client::GET, $headers = array(), $forTableStorage = false, $rawData = null, $resourceType = Microsoft_WindowsAzure_Storage::RESOURCE_UNKNOWN, $requiredPermission = Microsoft_WindowsAzure_Credentials_CredentialsAbstract::PERMISSION_READ) { // Clean path if (strpos($path, '/') !== 0) { $path = '/' . $path; } // Clean headers if (is_null($headers)) { $headers = array(); } // Ensure cUrl will also work correctly: // - disable Content-Type if required // - disable Expect: 100 Continue if (!isset($headers["Content-Type"])) { $headers["Content-Type"] = ''; } $headers["Expect"] = ''; // Add version header $headers['x-ms-version'] = $this->_apiVersion; // URL encoding $path = self::urlencode($path); $queryString = self::urlencode($queryString); // Generate URL and sign request $requestUrl = $this->_credentials->signRequestUrl($this->getBaseUrl() . $path . $queryString, $resourceType, $requiredPermission); $requestHeaders = $this->_credentials->signRequestHeaders($httpVerb, $path, $queryString, $headers, $forTableStorage, $resourceType, $requiredPermission, $rawData); // Prepare request $this->_httpClientChannel->resetParameters(true); $this->_httpClientChannel->setUri($requestUrl); $this->_httpClientChannel->setHeaders($requestHeaders); $this->_httpClientChannel->setRawData($rawData); // Execute request $response = $this->_retryPolicy->execute(array($this->_httpClientChannel, 'request'), array($httpVerb)); return $response; }
/** * Perform request using Microsoft_Http_Client channel * * @param string $path Path * @param array $query Query parameters * @param string $httpVerb HTTP verb the request will use * @param array $headers x-ms headers to add * @param mixed $rawData Optional RAW HTTP data to be sent over the wire * @return Microsoft_Http_Response */ protected function _performRequest($path = '/', $query = array(), $httpVerb = Microsoft_Http_Client::GET, $headers = array(), $rawData = null) { // Clean path if (strpos($path, '/') !== 0) { $path = '/' . $path; } // Clean headers if (is_null($headers)) { $headers = array(); } // Ensure cUrl will also work correctly: // - disable Content-Type if required // - disable Expect: 100 Continue if (!isset($headers["Content-Type"])) { $headers["Content-Type"] = ''; } //$headers["Expect"] = ''; // Add version header $headers['x-ms-version'] = $this->_apiVersion; // Generate URL and sign request $requestUrl = $this->getBaseUrl() . rawurlencode($path); $requestHeaders = $headers; if (count($query) > 0) { $queryString = ''; foreach ($query as $key => $value) { $queryString .= ($queryString ? '&' : '?') . rawurlencode($key) . '=' . rawurlencode($value); } $requestUrl .= $queryString; } // Prepare request $this->_httpClientChannel->resetParameters(true); $this->_httpClientChannel->setUri($requestUrl); $this->_httpClientChannel->setHeaders($requestHeaders); $this->_httpClientChannel->setRawData($rawData); // Execute request $response = $this->_retryPolicy->execute(array($this->_httpClientChannel, 'request'), array($httpVerb)); // Store request id $this->_lastRequestId = $response->getHeader('x-ms-request-id'); return $response; }
/** * Test retry policy - retryN */ public function testRetryN() { $this->_executedRetries = 0; $this->_exceptionCount = 9; $policy = Microsoft_WindowsAzure_RetryPolicy_RetryPolicyAbstract::retryN(10, 100); $retries = $policy->execute( array($this, '_countRetriesAndThrowExceptions') ); $this->assertEquals(10, $retries); }
protected function createStorageInstance() { return new Microsoft_WindowsAzure_Storage_Blob(TESTS_BLOB_HOST_PROD, TESTS_STORAGE_ACCOUNT_PROD, TESTS_STORAGE_KEY_PROD, false, Microsoft_WindowsAzure_RetryPolicy_RetryPolicyAbstract::retryN(10, 250)); }