Package org.jclouds.http

Examples of org.jclouds.http.HttpCommand


public class AWSServerErrorRetryHandlerTest {
   @Test
   public void test500DoesNotRetry() {

      AWSUtils utils = createMock(AWSUtils.class);
      HttpCommand command = createMock(HttpCommand.class);

      replay(utils, command);

      AWSServerErrorRetryHandler retry = new AWSServerErrorRetryHandler(utils,
            ImmutableSet.<String> of());
View Full Code Here


   @Test(dataProvider = "codes")
   public void test503DoesBackoffAndRetryForCode(String code) {

      AWSUtils utils = createMock(AWSUtils.class);
      HttpCommand command = createMock(HttpCommand.class);

      HttpRequest putBucket = HttpRequest.builder().method(PUT)
            .endpoint("https://adriancole-blobstore113.s3.amazonaws.com/").build();

      HttpResponse limitExceeded = HttpResponse.builder().statusCode(SERVICE_UNAVAILABLE.getStatusCode())
            .payload(Payloads.newStringPayload(String.format("<Error><Code>%s</Code></Error>", code))).build();

      expect(command.getCurrentRequest()).andReturn(putBucket);
      final AtomicInteger counter = new AtomicInteger();
      expect(command.incrementFailureCount()).andAnswer(new IAnswer<Integer>() {
         @Override
         public Integer answer() throws Throwable {
            return counter.incrementAndGet();
         }
      }).anyTimes();
      expect(command.isReplayable()).andReturn(true).anyTimes();
      expect(command.getFailureCount()).andAnswer(new IAnswer<Integer>() {
         @Override
         public Integer answer() throws Throwable {
            return counter.get();
         }
      }).anyTimes();
View Full Code Here

   }

   @Test
   public void test504DoesRetry() {
      AWSUtils utils = createMock(AWSUtils.class);
      HttpCommand command = createMock(HttpCommand.class);
      expect(command.getFailureCount()).andReturn(1).anyTimes();
      expect(command.incrementFailureCount()).andReturn(1);
      expect(command.isReplayable()).andReturn(true);

      replay(utils, command);

      AWSServerErrorRetryHandler retry = new AWSServerErrorRetryHandler(utils,
            ImmutableSet.<String> of());
View Full Code Here

            bindConstant().annotatedWith(Names.named(PROPERTY_HEADER_TAG)).to("amz");
         }

      }).getInstance(ParseAWSErrorFromXmlContent.class);

      HttpCommand command = createMock(HttpCommand.class);
      HttpRequest request = HttpRequest.builder().method(method).endpoint(uri).build();
      HttpResponse response = HttpResponse.builder().statusCode(statusCode).message(message).payload(content).build();
      response.getPayload().getContentMetadata().setContentType(contentType);

      expect(command.getCurrentRequest()).andReturn(request).atLeastOnce();
      command.setException(classEq(expected));

      replay(command);

      function.handleError(command, response);
View Full Code Here

*/
@Test(groups = "unit", testName = "RetryOnRenewTest")
public class RetryOnRenewTest {
   @Test
   public void test401ShouldRetry() {
      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();

      expect(response.getPayload()).andReturn(Payloads.newStringPayload("token expired, please renew")).anyTimes();
View Full Code Here

      verify(backoffHandler);
   }

   @Test
   public void test408ShouldRetry() {
      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);
View Full Code Here

      verify(backoffHandler);
   }

   @Test
   public void test404ShouldNotRetry() {
      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);
View Full Code Here

   public void testQueueDeletedRecentlyRetriesWhen59SleepsAndTries() {

      SQSErrorRetryHandler retry = new SQSErrorRetryHandler(createMock(AWSUtils.class),
            createMock(BackoffLimitedRetryHandler.class), ImmutableSet.<String> of(), 60, 100);

      HttpCommand command = createHttpCommandForFailureCount(59);

      Stopwatch watch = new Stopwatch().start();
      assertTrue(retry.shouldRetryRequestOnError(command, response, error));
      assertEquals(command.getFailureCount(), 60);
      // allow for slightly inaccurate system timers
      assertTrue(watch.stop().elapsed(TimeUnit.MILLISECONDS) >= 98);
   }
View Full Code Here

   public void testQueueDeletedRecentlyRetriesWhen60DoesntTry() {

      SQSErrorRetryHandler retry = new SQSErrorRetryHandler(createMock(AWSUtils.class),
            createMock(BackoffLimitedRetryHandler.class), ImmutableSet.<String> of(), 60, 100);

      HttpCommand command = createHttpCommandForFailureCount(60);

      Stopwatch watch = new Stopwatch().start();
      assertFalse(retry.shouldRetryRequestOnError(command, response, error));
      assertEquals(command.getFailureCount(), 61);
      assertTrue(watch.stop().elapsed(TimeUnit.MILLISECONDS) < 100);
   }
View Full Code Here

      assertEquals(command.getFailureCount(), 61);
      assertTrue(watch.stop().elapsed(TimeUnit.MILLISECONDS) < 100);
   }
  
   HttpCommand createHttpCommandForFailureCount(final int failureCount) {
      HttpCommand command = new HttpCommand(HttpRequest.builder().method("GET").endpoint("http://localhost").build());
      while (command.getFailureCount() != failureCount)
         command.incrementFailureCount();
      return command;
   }
View Full Code Here

TOP

Related Classes of org.jclouds.http.HttpCommand

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.