1717
1818import com .google .mockwebserver .MockResponse ;
1919import com .google .mockwebserver .MockWebServer ;
20+ import com .google .mockwebserver .SocketPolicy ;
2021import dagger .Provides ;
2122import feign .Feign ;
2223import feign .RequestLine ;
@@ -36,7 +37,7 @@ public class RibbonClientTest {
3637 interface TestInterface {
3738 @ RequestLine ("POST /" ) void post ();
3839
39- @ dagger .Module (injects = Feign .class , addsTo = Feign .Defaults .class )
40+ @ dagger .Module (injects = Feign .class , overrides = true , addsTo = Feign .Defaults .class )
4041 static class Module {
4142 @ Provides Decoder defaultDecoder () {
4243 return new Decoder .Default ();
@@ -80,6 +81,33 @@ public void loadBalancingDefaultPolicyRoundRobin() throws IOException, Interrupt
8081 }
8182 }
8283
84+ @ Test
85+ public void ioExceptionRetry () throws IOException , InterruptedException {
86+ String client = "RibbonClientTest-ioExceptionRetry" ;
87+ String serverListKey = client + ".ribbon.listOfServers" ;
88+
89+ MockWebServer server = new MockWebServer ();
90+ server .enqueue (new MockResponse ().setSocketPolicy (SocketPolicy .DISCONNECT_AT_START ));
91+ server .enqueue (new MockResponse ().setBody ("success!" .getBytes (UTF_8 )));
92+ server .play ();
93+
94+ getConfigInstance ().setProperty (serverListKey , hostAndPort (server .getUrl ("" )));
95+
96+ try {
97+
98+ TestInterface api = Feign .create (TestInterface .class , "http://" + client , new TestInterface .Module (), new RibbonModule ());
99+
100+ api .post ();
101+
102+ assertEquals (server .getRequestCount (), 2 );
103+ // TODO: verify ribbon stats match
104+ // assertEquals(target.lb().getLoadBalancerStats().getSingleServerStat())
105+ } finally {
106+ server .shutdown ();
107+ getConfigInstance ().clearProperty (serverListKey );
108+ }
109+ }
110+
83111 static String hostAndPort (URL url ) {
84112 // our build slaves have underscores in their hostnames which aren't permitted by ribbon
85113 return "localhost:" + url .getPort ();
0 commit comments