Github user dongeforever commented on a diff in the pull request:
https://github.com/apache/incubator-rocketmq/pull/146#discussion_r134941603
--- Diff:
store/src/test/java/org/apache/rocketmq/store/ConsumeQueueTest.java ---
@@ -148,6 +148,52 @@ protected void deleteFile(File file) {
}
@Test
+ public void
test_putMessagePositionInfo_build_consume_queue_idempotent() {
+ DefaultMessageStore messageStore = null;
+ try {
+
+ messageStore = gen();
+
+ int totalMessages = 10;
+
+ for (int i = 0; i < totalMessages; i++) {
+ putMsg(messageStore);
+ }
+ Thread.sleep(5);
+
+ ConsumeQueue cq =
messageStore.getConsumeQueueTable().get(topic).get(queueId);
+ Method method =
cq.getClass().getDeclaredMethod("putMessagePositionInfo", long.class,
int.class, long.class, long.class);
+
+ assertThat(method).isNotNull();
+
+ method.setAccessible(true);
+
+ SelectMappedBufferResult result =
messageStore.getCommitLog().getData(0);
+ assertThat(result != null).isTrue();
+
+ DispatchRequest dispatchRequest =
messageStore.getCommitLog().checkMessageAndReturnSize(result.getByteBuffer(),
false, false);
+
+ assertThat(cq).isNotNull();
+
+ Object dispatchResult = method.invoke(cq,
dispatchRequest.getCommitLogOffset(),
+ dispatchRequest.getMsgSize(),
dispatchRequest.getTagsCode(), dispatchRequest.getConsumeQueueOffset());
+
+
assertThat(Boolean.parseBoolean(dispatchResult.toString())).isTrue();
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ assertThat(Boolean.FALSE).isTrue();
--- End diff --
It is better to remove try....catch from unit test, let the test framework
handle it.
Another suggestion:
Use a list to hold all the generated MessageStores, and release them
inside "@After" function. This will make the test more clear and look simple
without the finally block.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---