|
29 | 29 | import com.tencent.trpc.core.rpc.RpcInvocation; |
30 | 30 | import com.tencent.trpc.core.rpc.common.RpcMethodInfo; |
31 | 31 | import com.tencent.trpc.core.rpc.common.RpcMethodInfoAndInvoker; |
| 32 | +import com.tencent.trpc.core.rpc.def.DefRequest; |
32 | 33 | import com.tencent.trpc.core.worker.spi.WorkerPool; |
33 | 34 | import com.tencent.trpc.core.worker.spi.WorkerPool.Task; |
| 35 | +import com.tencent.trpc.proto.http.common.HttpCodec; |
34 | 36 | import com.tencent.trpc.proto.http.common.HttpConstants; |
35 | 37 | import java.util.concurrent.CompletableFuture; |
36 | 38 | import javax.servlet.http.HttpServletRequest; |
@@ -93,10 +95,15 @@ public void execute_shouldHandleTimeoutException() throws Exception { |
93 | 95 | when(abstractHttpExecutor, "execute", request, response, methodInfoAndInvoker).thenCallRealMethod(); |
94 | 96 | doCallRealMethod().when(abstractHttpExecutor, "doErrorReply", any(), any(), any()); |
95 | 97 | doCallRealMethod().when(abstractHttpExecutor, "httpErrorReply", any(), any(), any()); |
| 98 | + DefRequest defRequest = new DefRequest(); |
| 99 | + doReturn(defRequest).when(abstractHttpExecutor, "buildDefRequest", any(), any(), any()); |
| 100 | + HttpCodec httpCodec = mock(HttpCodec.class); |
| 101 | + Whitebox.setInternalState(abstractHttpExecutor, "httpCodec", httpCodec); |
| 102 | + when(abstractHttpExecutor, "invokeRpcRequest", any(), any(), any(), any()).thenCallRealMethod(); |
96 | 103 |
|
97 | 104 | Whitebox.invokeMethod(abstractHttpExecutor, "execute", request, response, methodInfoAndInvoker); |
98 | 105 |
|
99 | | - verify(response).setStatus(HttpStatus.SC_SERVICE_UNAVAILABLE); |
| 106 | + verify(response).setStatus(HttpStatus.SC_REQUEST_TIMEOUT); |
100 | 107 | } |
101 | 108 |
|
102 | 109 | @Test |
@@ -137,10 +144,15 @@ public void execute_shouldHandleInvokeException() throws Exception { |
137 | 144 | when(abstractHttpExecutor, "execute", request, response, methodInfoAndInvoker).thenCallRealMethod(); |
138 | 145 | doCallRealMethod().when(abstractHttpExecutor, "doErrorReply", any(), any(), any()); |
139 | 146 | doCallRealMethod().when(abstractHttpExecutor, "httpErrorReply", any(), any(), any()); |
| 147 | + DefRequest defRequest = new DefRequest(); |
| 148 | + doReturn(defRequest).when(abstractHttpExecutor, "buildDefRequest", any(), any(), any()); |
| 149 | + HttpCodec httpCodec = mock(HttpCodec.class); |
| 150 | + Whitebox.setInternalState(abstractHttpExecutor, "httpCodec", httpCodec); |
| 151 | + when(abstractHttpExecutor, "invokeRpcRequest", any(), any(), any(), any()).thenCallRealMethod(); |
140 | 152 |
|
141 | 153 | Whitebox.invokeMethod(abstractHttpExecutor, "execute", request, response, methodInfoAndInvoker); |
142 | 154 |
|
143 | | - verify(response).setStatus(HttpStatus.SC_SERVICE_UNAVAILABLE); |
| 155 | + verify(response).setStatus(HttpStatus.SC_REQUEST_TIMEOUT); |
144 | 156 | } |
145 | 157 |
|
146 | 158 | @Test |
@@ -183,9 +195,14 @@ public void execute_shouldHandleResponseException() throws Exception { |
183 | 195 | when(abstractHttpExecutor, "execute", request, response, methodInfoAndInvoker).thenCallRealMethod(); |
184 | 196 | doCallRealMethod().when(abstractHttpExecutor, "doErrorReply", any(), any(), any()); |
185 | 197 | doCallRealMethod().when(abstractHttpExecutor, "httpErrorReply", any(), any(), any()); |
| 198 | + DefRequest defRequest = new DefRequest(); |
| 199 | + doReturn(defRequest).when(abstractHttpExecutor, "buildDefRequest", any(), any(), any()); |
| 200 | + HttpCodec httpCodec = mock(HttpCodec.class); |
| 201 | + Whitebox.setInternalState(abstractHttpExecutor, "httpCodec", httpCodec); |
| 202 | + when(abstractHttpExecutor, "invokeRpcRequest", any(), any(), any(), any()).thenCallRealMethod(); |
186 | 203 |
|
187 | 204 | Whitebox.invokeMethod(abstractHttpExecutor, "execute", request, response, methodInfoAndInvoker); |
188 | 205 |
|
189 | | - verify(response).setStatus(HttpStatus.SC_SERVICE_UNAVAILABLE); |
| 206 | + verify(response).setStatus(HttpStatus.SC_REQUEST_TIMEOUT); |
190 | 207 | } |
191 | 208 | } |
0 commit comments