Package org.jclouds.http.handlers

Examples of org.jclouds.http.handlers.BackoffLimitedRetryHandler


   @Test
   public void test401DoesNotRetry() {

      HttpCommand command = createMock(HttpCommand.class);
      HttpResponse response = createMock(HttpResponse.class);
      BackoffLimitedRetryHandler retry = createMock(BackoffLimitedRetryHandler.class);

      expect(command.getFailureCount()).andReturn(0);
      expect(response.getStatusCode()).andReturn(401).atLeastOnce();

      replay(response);
View Full Code Here


   @Test
   public void test400DoesNotRetry() {

      HttpCommand command = createMock(HttpCommand.class);
      HttpResponse response = createMock(HttpResponse.class);
      BackoffLimitedRetryHandler retry = createMock(BackoffLimitedRetryHandler.class);

      expect(command.getFailureCount()).andReturn(0);
      expect(response.getStatusCode()).andReturn(401).atLeastOnce();

      replay(response);
View Full Code Here

   @Test
   public void testRetryOn400PutSandbox() {

      HttpCommand command = createMock(HttpCommand.class);
      BackoffLimitedRetryHandler retry = createMock(BackoffLimitedRetryHandler.class);

      HttpRequest request = HttpRequest.builder().method("PUT")
            .endpoint("https://api.opscode.com/organizations/jclouds/sandboxes/bfd68d4052f44053b2e593a33b5e1cd5")
            .build();
      HttpResponse response = HttpResponse
            .builder()
            .statusCode(400)
            .message("400 Bad Request")
            .payload(
                  "{\"error\":[\"Cannot update sandbox bfd68d4052f44053b2e593a33b5e1cd5: checksum 9b7c23369f4b576451216c39f214af6c was not uploaded\"]}")
            .build();

      expect(command.getFailureCount()).andReturn(0);
      expect(command.getCurrentRequest()).andReturn(request).atLeastOnce();
      expect(retry.shouldRetryRequest(command, response)).andReturn(true);

      replay(retry);
      replay(command);

      ChefApiErrorRetryHandler handler = new ChefApiErrorRetryHandler(retry);
View Full Code Here

         "</Error>\n";

   @Test
   public void testGet500WithoutError() {
      AtmosUtils utils = createMock(AtmosUtils.class);
      BackoffLimitedRetryHandler backoffLimitedRetryHandler = createMock(BackoffLimitedRetryHandler.class);
      HttpCommand command = createMock(HttpCommand.class);

      expect(command.getFailureCount()).andReturn(0).once();
      expect(command.incrementFailureCount()).andReturn(1).once();
View Full Code Here

   }

   @Test
   public void testGet500WithError1040() {
      AtmosUtils utils = createMock(AtmosUtils.class);
      BackoffLimitedRetryHandler backoffLimitedRetryHandler = createMock(BackoffLimitedRetryHandler.class);
      HttpCommand command = createMock(HttpCommand.class);
      String content = String.format(HTTP_MESSAGE_FORMAT, 1040, "The server is busy. Please try again");
      HttpResponse response = HttpResponse.builder().statusCode(500).payload(content).build();

      expect(command.getFailureCount()).andReturn(0).once();
      expect(utils.parseAtmosErrorFromContent(command, response, content)).andReturn(new AtmosError(1040, "The server is busy. Please try again")).once();
      expect(backoffLimitedRetryHandler.shouldRetryRequest(command, response)).andReturn(true).once();

      replay(utils, backoffLimitedRetryHandler, command);

      AtmosServerErrorRetryHandler retry = new AtmosServerErrorRetryHandler(backoffLimitedRetryHandler, utils);
View Full Code Here

      HttpCommand command = createMock(HttpCommand.class);
      HttpRequest request = createMock(HttpRequest.class);
      HttpResponse response = createMock(HttpResponse.class);
      @SuppressWarnings("unchecked")
      LoadingCache<Credentials, Auth> cache = createMock(LoadingCache.class);
      BackoffLimitedRetryHandler backoffHandler = createMock(BackoffLimitedRetryHandler.class);

      expect(command.getCurrentRequest()).andReturn(request);

      cache.invalidateAll();
      expectLastCall();
View Full Code Here

      HttpCommand command = createMock(HttpCommand.class);
      HttpRequest request = createMock(HttpRequest.class);
      HttpResponse response = createMock(HttpResponse.class);
      @SuppressWarnings("unchecked")
      LoadingCache<Credentials, Auth> cache = createMock(LoadingCache.class);
      BackoffLimitedRetryHandler backoffHandler = createMock(BackoffLimitedRetryHandler.class);

      expect(response.getPayload()).andReturn(Payloads.newStringPayload(
                  "The server has waited too long for the request to be sent by the client.")).times(2);
      expect(backoffHandler.shouldRetryRequest(command, response)).andReturn(true).once();
      expect(response.getStatusCode()).andReturn(408).once();

      replay(command);
      replay(response);
      replay(cache);
View Full Code Here

      HttpCommand command = createMock(HttpCommand.class);
      HttpRequest request = createMock(HttpRequest.class);
      HttpResponse response = createMock(HttpResponse.class);
      @SuppressWarnings("unchecked")
      LoadingCache<Credentials, Auth> cache = createMock(LoadingCache.class);
      BackoffLimitedRetryHandler backoffHandler = createMock(BackoffLimitedRetryHandler.class);

      expect(response.getPayload()).andReturn(Payloads.newStringPayload("")).times(2);
      expect(response.getStatusCode()).andReturn(404).once();

      replay(command);
View Full Code Here

      HttpCommand command = createMock(HttpCommand.class);
      HttpRequest request = createMock(HttpRequest.class);
      HttpResponse response = createMock(HttpResponse.class);
      @SuppressWarnings("unchecked")
      LoadingCache<Credentials, Access> cache = createMock(LoadingCache.class);
      BackoffLimitedRetryHandler backoffHandler = createMock(BackoffLimitedRetryHandler.class);

      expect(command.getCurrentRequest()).andReturn(request);

      cache.invalidateAll();
      expectLastCall();
View Full Code Here

      HttpRequest request = createMock(HttpRequest.class);
      HttpResponse response = createMock(HttpResponse.class);

      @SuppressWarnings("unchecked")
      LoadingCache<Credentials, Access> cache = createMock(LoadingCache.class);
      BackoffLimitedRetryHandler backoffHandler = createMock(BackoffLimitedRetryHandler.class);

      expect(command.getCurrentRequest()).andReturn(request).anyTimes();
      expect(request.getHeaders()).andStubReturn(null);

      cache.invalidateAll();
View Full Code Here

TOP

Related Classes of org.jclouds.http.handlers.BackoffLimitedRetryHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.