@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); replay(http, timeLimiter, fallback, config, future); assertEquals(ListenableFuture.class.cast(invokeHttpMethod.apply(asyncGet)).get(), fallbackResponse); } }
public void testMethodWithTimeoutRunsTimeLimiter() throws Exception { expect(config.getTimeoutNanos(asyncGet)).andReturn(Optional.of(250000000l)); InvokeAndTransform invoke = invokeHttpMethod.new InvokeAndTransform("ns:get", getCommand); expect(timeLimiter.callWithTimeout(invoke, 250000000, TimeUnit.NANOSECONDS, true)).andReturn(response); replay(http, timeLimiter, fallback, config, future); 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); }
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); }
public void testTimeLimitedRunsFallbackCreateOrPropagate() throws Exception { IllegalStateException exception = new IllegalStateException(); expect(config.getTimeoutNanos(asyncGet)).andReturn(Optional.of(250000000l)); InvokeAndTransform invoke = invokeHttpMethod.new InvokeAndTransform("ns:get", getCommand); expect(timeLimiter.callWithTimeout(invoke, 250000000, TimeUnit.NANOSECONDS, true)).andThrow(exception); expect(fallback.createOrPropagate(exception)).andReturn(fallbackResponse); replay(http, timeLimiter, fallback, config, future); assertEquals(invokeHttpMethod.apply(get), fallbackResponse); }
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); }