public void testTimeLimitedRunsFallbackCreateOrPropagate() throws Exception { IllegalStateException exception = new IllegalStateException(); expect(config.getTimeoutNanos(get)).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); } }
@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 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 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); }
/** * invokes the {@linkplain HttpCommand} associated with {@code invocation}, * {@link #getTransformer(String, HttpCommand) parses its response}, and * 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 { return transformer.apply(http.invoke(command)); } catch (Throwable t) { try { return fallback.createOrPropagate(t); } catch (Exception e) { throw propagate(e); } } }
public void testTimeLimitedRunsFallbackCreateOrPropagate() throws Exception { IllegalStateException exception = new IllegalStateException(); expect(config.getTimeoutNanos(get)).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); assertEquals(invokeHttpMethod.apply(get), fallbackResponse); } }
/** * invokes the {@linkplain HttpCommand} associated with {@code invocation}, * {@link #getTransformer(String, HttpCommand) parses its response}, and * 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 { return transformer.apply(http.invoke(command)); } catch (Throwable t) { try { return fallback.createOrPropagate(t); } catch (Exception e) { throw propagate(e); } } }
/** * invokes the {@linkplain HttpCommand} associated with {@code invocation}, * {@link #getTransformer(String, HttpCommand) parses its response}, and * 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 { return transformer.apply(http.invoke(command)); } catch (Throwable t) { try { return fallback.createOrPropagate(t); } catch (Exception e) { throw propagate(e); } } }
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); assertEquals(invokeHttpMethod.apply(get), fallbackResponse); }
/** * invokes the {@linkplain HttpCommand} associated with {@code invocation}, * {@link #getTransformer(String, HttpCommand) parses its response}, and * 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 { return transformer.apply(http.invoke(command)); } catch (Throwable t) { try { return fallback.createOrPropagate(t); } catch (Exception e) { throw propagate(e); } } }
/** * invokes the {@linkplain HttpCommand} associated with {@code invocation}, * {@link #getTransformer(String, HttpCommand) parses its response}, and * 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 { return transformer.apply(http.invoke(command)); } catch (Throwable t) { try { return fallback.createOrPropagate(t); } catch (Exception e) { throw propagate(e); } } }
/** * invokes the {@linkplain HttpCommand} associated with {@code invocation}, * {@link #getTransformer(String, HttpCommand) parses its response}, and * 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 { return transformer.apply(http.invoke(command)); } catch (Throwable t) { try { return fallback.createOrPropagate(t); } catch (Exception e) { throw propagate(e); } } }
/** * invokes the {@linkplain HttpCommand} associated with {@code invocation}, * {@link #getTransformer(String, HttpCommand) parses its response}, and * 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 { return transformer.apply(http.invoke(command)); } catch (Throwable t) { try { return fallback.createOrPropagate(t); } catch (Exception e) { throw propagate(e); } } }
/** * invokes the {@linkplain HttpCommand} associated with {@code invocation}, * {@link #getTransformer(String, HttpCommand) parses its response}, and * 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 { return transformer.apply(http.invoke(command)); } catch (Throwable t) { try { return fallback.createOrPropagate(t); } catch (Exception e) { throw propagate(e); } } }
/** * invokes the {@linkplain HttpCommand} associated with {@code invocation}, * {@link #getTransformer(String, HttpCommand) parses its response}, and * 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 { return transformer.apply(http.invoke(command)); } catch (Throwable t) { try { return fallback.createOrPropagate(t); } catch (Exception e) { throw propagate(e); } } }
} catch (Throwable t) { try { return fallback.createOrPropagate(t); } catch (Exception e) { throw propagate(e);
} catch (Throwable t) { try { return fallback.createOrPropagate(t); } catch (Exception e) { throw propagate(e);
} catch (Throwable t) { try { return fallback.createOrPropagate(t); } catch (Exception e) { throw propagate(e);
} catch (Throwable t) { try { return fallback.createOrPropagate(t); } catch (Exception e) { throw propagate(e);