@Test @Ignore public void testCommandWithMetaData() throws IOException, InterruptedException, ExecutionException { MockWebServer server = new MockWebServer(); String content = "Hello world"; for (int i = 0; i < 6; i++) { server.enqueue(new MockResponse() .setResponseCode(200) .setHeader("Content-type", "text/plain") .setBody(content)); } server.play(); HttpResourceGroup group = Ribbon.createHttpResourceGroup("myclient", ClientOptions.create() .withConfigurationBasedServerList("localhost:" + server.getPort()) .withMaxAutoRetriesNextServer(3)); HttpRequestTemplate<ByteBuf> template = group.newTemplateBuilder("test") .withUriTemplate("/") .withMethod("GET") .withCacheProvider("somekey", new CacheProvider<ByteBuf>(){ @Override public Observable<ByteBuf> get(String key, Map<String, Object> vars) { return Observable.error(new Exception("Cache miss")); } }).build(); RibbonRequest<ByteBuf> request = template .requestBuilder().build(); final AtomicBoolean success = new AtomicBoolean(false); RequestWithMetaData<ByteBuf> metaRequest = request.withMetadata(); Observable<String> result = metaRequest.toObservable().flatMap(new Func1<RibbonResponse<Observable<ByteBuf>>, Observable<String>>(){ @Override public Observable<String> call( final RibbonResponse<Observable<ByteBuf>> response) { success.set(response.getHystrixInfo().isSuccessfulExecution()); return response.content().map(new Func1<ByteBuf, String>(){ @Override public String call(ByteBuf t1) { return t1.toString(Charset.defaultCharset()); } }); } }); String s = result.toBlocking().single(); assertEquals(content, s); assertTrue(success.get()); Future<RibbonResponse<ByteBuf>> future = metaRequest.queue(); RibbonResponse<ByteBuf> response = future.get(); assertTrue(future.isDone()); assertEquals(content, response.content().toString(Charset.defaultCharset())); assertTrue(response.getHystrixInfo().isSuccessfulExecution()); RibbonResponse<ByteBuf> result1 = metaRequest.execute(); assertEquals(content, result1.content().toString(Charset.defaultCharset())); assertTrue(result1.getHystrixInfo().isSuccessfulExecution()); }
public static HttpResourceGroup createHttpResourceGroup(String name) { return factory.createHttpResourceGroup(name); }
Ribbon { public static HttpResourceGroup createHttpResourceGroup(String name) { return factory.createHttpResourceGroup(name); } }
Ribbon { public static HttpResourceGroup createHttpResourceGroup(String name) { return factory.createHttpResourceGroup(name); } private  Ribbon(); }
Ribbon { public static HttpResourceGroup createHttpResourceGroup(String name) { return factory.createHttpResourceGroup(name); } private  Ribbon(); static Builder createHttpResourceGroupBuilder(String name); static HttpResourceGroup createHttpResourceGroup(String name); static HttpResourceGroup createHttpResourceGroup(String name, ClientOptions options); static T from(Class<T> contract); }
Ribbon { public static HttpResourceGroup createHttpResourceGroup(String name) { return factory.createHttpResourceGroup(name); } private  Ribbon(); static Builder createHttpResourceGroupBuilder(String name); static HttpResourceGroup createHttpResourceGroup(String name); static HttpResourceGroup createHttpResourceGroup(String name, ClientOptions options); static T from(Class<T> contract);  }