18
18
19
19
import com .netflix .zuul .exception .OutboundErrorType ;
20
20
import com .netflix .zuul .netty .connectionpool .OriginConnectException ;
21
+ import io .netty .handler .codec .http2 .DefaultHttp2Connection ;
22
+ import io .netty .handler .codec .http2 .Http2Error ;
23
+ import io .netty .handler .codec .http2 .Http2Exception ;
21
24
import org .junit .jupiter .api .Test ;
22
25
23
26
import javax .net .ssl .SSLHandshakeException ;
26
29
27
30
import static org .junit .jupiter .api .Assertions .assertEquals ;
28
31
import static org .mockito .Mockito .mock ;
32
+ import static org .mockito .Mockito .spy ;
29
33
import static org .mockito .Mockito .when ;
30
34
31
35
public class RequestAttemptTest {
@@ -77,4 +81,38 @@ void originConnectExceptionWithCauseNotUnwrapped() {
77
81
assertEquals ("ORIGIN_CONNECT_ERROR" , attempt .getError ());
78
82
assertEquals ("java.lang.RuntimeException: socket failure" , attempt .getCause ());
79
83
}
84
+
85
+ @ Test
86
+ void h2ExceptionCauseHandled () {
87
+ // mock out a real-ish h2 stream exception
88
+ Exception h2Exception = spy (Http2Exception .streamError (
89
+ 100 ,
90
+ Http2Error .REFUSED_STREAM ,
91
+ "Cannot create stream 100 greater than Last-Stream-ID 99 from GOAWAY." ,
92
+ new Object [] {100 , 99 }));
93
+
94
+ // mock a stacktrace to ensure we don't actually capture it completely
95
+ when (h2Exception .getStackTrace ()).thenReturn (new StackTraceElement [] {
96
+ new StackTraceElement (
97
+ DefaultHttp2Connection .class .getCanonicalName (),
98
+ "createStream" ,
99
+ "DefaultHttp2Connection.java" ,
100
+ 772 ),
101
+ new StackTraceElement (
102
+ DefaultHttp2Connection .class .getCanonicalName (),
103
+ "checkNewStreamAllowed" ,
104
+ "DefaultHttp2Connection.java" ,
105
+ 902 )
106
+ });
107
+
108
+ RequestAttempt attempt = new RequestAttempt (1 , null , null , "target" , "chosen" , 200 , null , null , 0 , 0 , 0 );
109
+ attempt .setException (h2Exception );
110
+
111
+ assertEquals ("Cannot create stream 100 greater than Last-Stream-ID 99 from GOAWAY." , attempt .getError ());
112
+ assertEquals ("StreamException" , attempt .getExceptionType ());
113
+
114
+ assertEquals (
115
+ "io.netty.handler.codec.http2.DefaultHttp2Connection.createStream(DefaultHttp2Connection.java:772)" ,
116
+ attempt .getCause ());
117
+ }
80
118
}
0 commit comments