Package org.jclouds.http

Examples of org.jclouds.http.HttpCommand


   }

   @Test
   void testClosesInputStream() throws InterruptedException, IOException, SecurityException, NoSuchMethodException {
      HttpCommand command = createCommand();

      HttpResponse response = HttpResponse.builder().statusCode(400).build();

      InputStream inputStream = new InputStream() {
         boolean isOpen = true;
View Full Code Here


  

   private HttpCommand createCommand() throws SecurityException, NoSuchMethodException {
      Invokable<IntegrationTestAsyncClient, String> method = method(IntegrationTestAsyncClient.class, "download", String.class);

      return new HttpCommand(processor.apply(Invocation.create(method, ImmutableList.<Object> of("1"))));
   }
View Full Code Here

      return new HttpCommand(processor.apply(Invocation.create(method, ImmutableList.<Object> of("1"))));
   }

   @Test
   void testIncrementsFailureCount() throws InterruptedException, IOException, SecurityException, NoSuchMethodException {
      HttpCommand command = createCommand();
      HttpResponse response = HttpResponse.builder().statusCode(400).build();

      handler.shouldRetryRequest(command, response);
      assertEquals(command.getFailureCount(), 1);

      handler.shouldRetryRequest(command, response);
      assertEquals(command.getFailureCount(), 2);

      handler.shouldRetryRequest(command, response);
      assertEquals(command.getFailureCount(), 3);
   }
View Full Code Here

   }

   @Test
   void testDisallowsExcessiveRetries() throws InterruptedException, IOException, SecurityException,
            NoSuchMethodException {
      HttpCommand command = createCommand();
      HttpResponse response = HttpResponse.builder().statusCode(400).build();

      assertEquals(handler.shouldRetryRequest(command, response), true); // Failure 1

      assertEquals(handler.shouldRetryRequest(command, response), true); // Failure 2
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, Access> cache = createMock(LoadingCache.class);
      BackoffLimitedRetryHandler backoffHandler = createMock(BackoffLimitedRetryHandler.class);

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

      cache.invalidateAll();
      expectLastCall();

      expect(response.getPayload()).andReturn(Payloads.newStringPayload("")).anyTimes();
View Full Code Here

      verify(cache);
   }

   @Test
   public void test401ShouldRetry4Times() {
      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).anyTimes();
      expect(request.getHeaders()).andStubReturn(null);

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

      verify(command, response, cache);
   }

   @Test
   public void test408ShouldRetry() {
      HttpCommand command = createMock(HttpCommand.class);
      HttpResponse response = createMock(HttpResponse.class);
      @SuppressWarnings("unchecked")
      LoadingCache<Credentials, Access> cache = createMock(LoadingCache.class);
      BackoffLimitedRetryHandler backoffHandler = createMock(BackoffLimitedRetryHandler.class);
View Full Code Here

      }
   }

   public static HttpResponseException returnResponseException(int code) {
      HttpResponse response = HttpResponse.builder().statusCode(code).build();
      return new HttpResponseException(new HttpCommand(HttpRequest.builder().method("GET").endpoint("http://stub")
            .build()), response);
   }
View Full Code Here

    * if a {@code Throwable} is encountered. Parsing and Fallback occur on the
    * {@code userExecutor} thread.
    */
   public ListenableFuture<?> submit(Invocation invocation) {
      String commandName = config.getCommandName(invocation);
      HttpCommand command = toCommand(commandName, invocation);
      Function<HttpResponse, ?> transformer = getTransformer(commandName, command);
      org.jclouds.Fallback<?> fallback = getFallback(commandName, invocation, command);

      logger.debug(">> submitting %s", commandName);
      return withFallback(transform(http.submit(command), transformer, userExecutor), fallback);
View Full Code Here

    * applies a {@link #getFallback(String, Invocation, HttpCommand) fallback}
    * if a {@code Throwable} is encountered.
    */
   public Object invoke(Invocation invocation) {
      String commandName = config.getCommandName(invocation);
      HttpCommand command = toCommand(commandName, invocation);
      Function<HttpResponse, ?> transformer = getTransformer(commandName, command);
      org.jclouds.Fallback<?> fallback = getFallback(commandName, invocation, command);

      logger.debug(">> invoking %s", commandName);
      try {
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.