Ejemplo n.º 1
0
 /**
  * Constructor.
  *
  * @param string $backend Backend type, currently 'mysql' or 'redshift' is accepted.
  * @param string $token Storage API token.
  * @param string $runId Storage API run Id.
  * @param string $url
  */
 public function __construct($backend, $token, $runId, $url = 'https://syrup.keboola.com/provisioning')
 {
     $this->setBackend($backend);
     $this->setToken($token);
     $this->setRunId($runId);
     $client = new \Guzzle\Http\Client($url);
     $client->getConfig()->set('curl.options', array(CURLOPT_TIMEOUT => $this->timeout));
     $maintenanceBackoff = new BackoffPlugin(new TruncatedBackoffStrategy(10, new MaintenanceBackoffStrategy(array(503), new CurlBackoffStrategy(CurlBackoffStrategy::getDefaultFailureCodes(), new ExponentialBackoffStrategy()))));
     $client->addSubscriber($maintenanceBackoff);
     $this->client = $client;
 }
 public function testRetriesWithExponentialDelay()
 {
     $this->assertNotEmpty(CurlBackoffStrategy::getDefaultFailureCodes());
     $strategy = new CurlBackoffStrategy();
     $this->assertTrue($strategy->makesDecision());
     $request = $this->getMock('Guzzle\\Http\\Message\\Request', array(), array(), '', false);
     $e = new CurlException();
     $e->setError('foo', CURLE_BAD_CALLING_ORDER);
     $this->assertEquals(false, $strategy->getBackoffPeriod(0, $request, null, $e));
     foreach (CurlBackoffStrategy::getDefaultFailureCodes() as $code) {
         $this->assertEquals(0, $strategy->getBackoffPeriod(0, $request, null, $e->setError('foo', $code)));
     }
 }