Skip to content

Commit c66f370

Browse files
committed
提高单测覆盖率
1 parent 9b3740e commit c66f370

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

trpc-proto/trpc-proto-http/src/test/java/com/tencent/trpc/proto/http/server/AbstractHttpExecutorTest.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@
2929
import com.tencent.trpc.core.rpc.RpcInvocation;
3030
import com.tencent.trpc.core.rpc.common.RpcMethodInfo;
3131
import com.tencent.trpc.core.rpc.common.RpcMethodInfoAndInvoker;
32+
import com.tencent.trpc.core.rpc.def.DefRequest;
3233
import com.tencent.trpc.core.worker.spi.WorkerPool;
3334
import com.tencent.trpc.core.worker.spi.WorkerPool.Task;
35+
import com.tencent.trpc.proto.http.common.HttpCodec;
3436
import com.tencent.trpc.proto.http.common.HttpConstants;
3537
import java.util.concurrent.CompletableFuture;
3638
import javax.servlet.http.HttpServletRequest;
@@ -93,10 +95,15 @@ public void execute_shouldHandleTimeoutException() throws Exception {
9395
when(abstractHttpExecutor, "execute", request, response, methodInfoAndInvoker).thenCallRealMethod();
9496
doCallRealMethod().when(abstractHttpExecutor, "doErrorReply", any(), any(), any());
9597
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();
96103

97104
Whitebox.invokeMethod(abstractHttpExecutor, "execute", request, response, methodInfoAndInvoker);
98105

99-
verify(response).setStatus(HttpStatus.SC_SERVICE_UNAVAILABLE);
106+
verify(response).setStatus(HttpStatus.SC_REQUEST_TIMEOUT);
100107
}
101108

102109
@Test
@@ -137,10 +144,15 @@ public void execute_shouldHandleInvokeException() throws Exception {
137144
when(abstractHttpExecutor, "execute", request, response, methodInfoAndInvoker).thenCallRealMethod();
138145
doCallRealMethod().when(abstractHttpExecutor, "doErrorReply", any(), any(), any());
139146
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();
140152

141153
Whitebox.invokeMethod(abstractHttpExecutor, "execute", request, response, methodInfoAndInvoker);
142154

143-
verify(response).setStatus(HttpStatus.SC_SERVICE_UNAVAILABLE);
155+
verify(response).setStatus(HttpStatus.SC_REQUEST_TIMEOUT);
144156
}
145157

146158
@Test
@@ -183,9 +195,14 @@ public void execute_shouldHandleResponseException() throws Exception {
183195
when(abstractHttpExecutor, "execute", request, response, methodInfoAndInvoker).thenCallRealMethod();
184196
doCallRealMethod().when(abstractHttpExecutor, "doErrorReply", any(), any(), any());
185197
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();
186203

187204
Whitebox.invokeMethod(abstractHttpExecutor, "execute", request, response, methodInfoAndInvoker);
188205

189-
verify(response).setStatus(HttpStatus.SC_SERVICE_UNAVAILABLE);
206+
verify(response).setStatus(HttpStatus.SC_REQUEST_TIMEOUT);
190207
}
191208
}

0 commit comments

Comments
 (0)