pandaapo commented on code in PR #4480:
URL: https://github.com/apache/eventmesh/pull/4480#discussion_r1352304518
##########
eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/impl/SubClientImpl.java:
##########
@@ -171,35 +167,31 @@ public Package dispatcher(Package request, long timeout)
throws Exception {
Package response = super.io(request, timeout);
switch (request.getHeader().getCommand()) {
case HELLO_REQUEST:
- Assertions.assertEquals(response.getHeader().getCommand(),
Command.HELLO_RESPONSE);
+ Assertions.assertEquals(Command.HELLO_RESPONSE,
response.getHeader().getCommand());
break;
case HEARTBEAT_REQUEST:
- Assertions.assertEquals(response.getHeader().getCommand(),
Command.HEARTBEAT_RESPONSE);
+ Assertions.assertEquals(Command.HEARTBEAT_RESPONSE,
response.getHeader().getCommand());
break;
case LISTEN_REQUEST:
- Assertions.assertEquals(response.getHeader().getCommand(),
Command.LISTEN_RESPONSE);
+ Assertions.assertEquals(Command.LISTEN_RESPONSE,
response.getHeader().getCommand());
break;
case CLIENT_GOODBYE_REQUEST:
- Assertions.assertEquals(response.getHeader().getCommand(),
Command.CLIENT_GOODBYE_RESPONSE);
+ Assertions.assertEquals(Command.CLIENT_GOODBYE_RESPONSE,
response.getHeader().getCommand());
break;
case SUBSCRIBE_REQUEST:
- Assertions.assertEquals(response.getHeader().getCommand(),
Command.SUBSCRIBE_RESPONSE);
+ Assertions.assertEquals(Command.SUBSCRIBE_RESPONSE,
response.getHeader().getCommand());
break;
case UNSUBSCRIBE_REQUEST:
- Assertions.assertEquals(response.getHeader().getCommand(),
Command.UNSUBSCRIBE_RESPONSE);
+ Assertions.assertEquals(Command.UNSUBSCRIBE_RESPONSE,
response.getHeader().getCommand());
break;
case SYS_LOG_TO_LOGSERVER:
- Assertions.assertNull(response);
- break;
case TRACE_LOG_TO_LOGSERVER:
Assertions.assertNull(response);
break;
default:
break;
}
- if (response != null) {
- assert response.getHeader().getCode() ==
OPStatus.SUCCESS.getCode();
- }
+ assert response == null || response.getHeader().getCode() ==
OPStatus.SUCCESS.getCode();
Review Comment:
My point is that `response == (!=) null` seems to lack the significance of
an assertion. It is just a logical condition. This reduces the number of lines
of assertion code, but also reduces readability.
Also, if you change it to `assert response != null &&
response.getHeader().getCode() == OPStatus.SUCCESS.getCode()` in new commit,
previously there would be no error if response was null, but now there will be
an error.
---
我的意思是 `response == (!=) null`好像没有断言的意义。它只是个逻辑条件。这样断言代码行数少了,但可读性差了。
另外你在新的commit中改成`assert response != null && response.getHeader().getCode() ==
OPStatus.SUCCESS.getCode()`这样以后,本来response为null没有错误,现在会报错。
##########
eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/impl/SubClientImpl.java:
##########
@@ -171,35 +167,31 @@ public Package dispatcher(Package request, long timeout)
throws Exception {
Package response = super.io(request, timeout);
switch (request.getHeader().getCommand()) {
case HELLO_REQUEST:
- Assertions.assertEquals(response.getHeader().getCommand(),
Command.HELLO_RESPONSE);
+ Assertions.assertEquals(Command.HELLO_RESPONSE,
response.getHeader().getCommand());
break;
case HEARTBEAT_REQUEST:
- Assertions.assertEquals(response.getHeader().getCommand(),
Command.HEARTBEAT_RESPONSE);
+ Assertions.assertEquals(Command.HEARTBEAT_RESPONSE,
response.getHeader().getCommand());
break;
case LISTEN_REQUEST:
- Assertions.assertEquals(response.getHeader().getCommand(),
Command.LISTEN_RESPONSE);
+ Assertions.assertEquals(Command.LISTEN_RESPONSE,
response.getHeader().getCommand());
break;
case CLIENT_GOODBYE_REQUEST:
- Assertions.assertEquals(response.getHeader().getCommand(),
Command.CLIENT_GOODBYE_RESPONSE);
+ Assertions.assertEquals(Command.CLIENT_GOODBYE_RESPONSE,
response.getHeader().getCommand());
break;
case SUBSCRIBE_REQUEST:
- Assertions.assertEquals(response.getHeader().getCommand(),
Command.SUBSCRIBE_RESPONSE);
+ Assertions.assertEquals(Command.SUBSCRIBE_RESPONSE,
response.getHeader().getCommand());
break;
case UNSUBSCRIBE_REQUEST:
- Assertions.assertEquals(response.getHeader().getCommand(),
Command.UNSUBSCRIBE_RESPONSE);
+ Assertions.assertEquals(Command.UNSUBSCRIBE_RESPONSE,
response.getHeader().getCommand());
break;
case SYS_LOG_TO_LOGSERVER:
- Assertions.assertNull(response);
- break;
case TRACE_LOG_TO_LOGSERVER:
Assertions.assertNull(response);
break;
default:
break;
}
- if (response != null) {
- assert response.getHeader().getCode() ==
OPStatus.SUCCESS.getCode();
- }
+ assert response == null || response.getHeader().getCode() ==
OPStatus.SUCCESS.getCode();
Review Comment:
My point is that `response == (!=) null` seems to lack the significance of
an assertion. It is just a logical condition. This reduces the number of lines
of assertion code, but also reduces readability.
Also, if you change it to `assert response != null &&
response.getHeader().getCode() == OPStatus.SUCCESS.getCode()` in new commit,
previously there would be no error if response was null, but now there will be
an error.
---
我的意思是 `response == (!=) null`好像没有断言的意义。它只是个逻辑条件。这样断言代码行数少了,但可读性差了。
另外你在新的commit中改成`assert response != null && response.getHeader().getCode() ==
OPStatus.SUCCESS.getCode()`这样以后,本来response为null没有错误,现在会报错。
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]