Package org.jclouds.http

Examples of org.jclouds.http.HttpCommand


      invokeHttpMethod.apply(get);
   }

   public void testMethodWithNoTimeoutCallGetDirectly() throws Exception {
      expect(config.getTimeoutNanos(get)).andReturn(Optional.<Long> absent());
      expect(http.invoke(new HttpCommand(getRequest))).andReturn(response);
      replay(http, timeLimiter, fallback, config, future);
      invokeHttpMethod.apply(get);
   }
View Full Code Here


   private HttpResponse fallbackResponse = HttpResponse.builder().statusCode(200).payload("bar").build();

   public void testDirectCallRunsFallbackCreateOrPropagate() throws Exception {
      IllegalStateException exception = new IllegalStateException();
      expect(config.getTimeoutNanos(get)).andReturn(Optional.<Long> absent());
      expect(http.invoke(new HttpCommand(getRequest))).andThrow(exception);
      expect(fallback.createOrPropagate(exception)).andReturn(fallbackResponse);
      replay(http, timeLimiter, fallback, config, future);
      assertEquals(invokeHttpMethod.apply(get), fallbackResponse);
   }
View Full Code Here

      invokeHttpMethod.apply(get);
   }

   public void testMethodWithNoTimeoutCallGetDirectly() throws Exception {
      expect(config.getTimeoutNanos(asyncGet)).andReturn(Optional.<Long> absent());
      expect(http.invoke(new HttpCommand(getRequest))).andReturn(response);
      replay(http, timeLimiter, fallback, config, future);
      invokeHttpMethod.apply(get);
   }
View Full Code Here

      replay(http, timeLimiter, fallback, config, future);
      invokeHttpMethod.apply(get);
   }

   public void testAsyncMethodSubmitsRequest() throws Exception {
      expect(http.submit(new HttpCommand(getRequest))).andReturn(future);
      future.addListener(anyObject(Runnable.class), eq(userThreads));
      replay(http, timeLimiter, fallback, config, future);
      invokeHttpMethod.apply(asyncGet);
   }
View Full Code Here

   private HttpResponse fallbackResponse = HttpResponse.builder().statusCode(200).payload("bar").build();

   public void testDirectCallRunsFallbackCreateOrPropagate() throws Exception {
      IllegalStateException exception = new IllegalStateException();
      expect(config.getTimeoutNanos(asyncGet)).andReturn(Optional.<Long> absent());
      expect(http.invoke(new HttpCommand(getRequest))).andThrow(exception);
      expect(fallback.createOrPropagate(exception)).andReturn(fallbackResponse);
      replay(http, timeLimiter, fallback, config, future);
      assertEquals(invokeHttpMethod.apply(get), fallbackResponse);
   }
View Full Code Here

   }

   @SuppressWarnings("unchecked")
   public void testSubmitRunsFallbackCreateOnGet() throws Exception {
      IllegalStateException exception = new IllegalStateException();
      expect(http.submit(new HttpCommand(getRequest))).andReturn(
            Futures.<HttpResponse> immediateFailedFuture(exception));
      expect(fallback.create(exception)).andReturn(Futures.<HttpResponse> immediateFuture(fallbackResponse));
      // not using the field, as you can see above we are making an immediate
      // failed future instead.
      future = createMock(ListenableFuture.class);
View Full Code Here

   private void assertCodeMakes(String method, URI uri, int statusCode, String message, String contentType,
                                String content, Class<? extends Exception> expected) {

      GoogleComputeEngineErrorHandler function = new GoogleComputeEngineErrorHandler();

      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

   private void assertCodeMakes(String method, URI uri, int statusCode, String message, String contentType,
                                String content, Class<? extends Exception> expected) {

      OAuthErrorHandler function = new OAuthErrorHandler();

      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
   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();

      replay(utils, backoffLimitedRetryHandler, command);

      AtmosServerErrorRetryHandler retry = new AtmosServerErrorRetryHandler(backoffLimitedRetryHandler, utils);
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);
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.