未验证 提交 0b600484 编写于 作者: 张哈希 提交者: GitHub

[ISSUE #2421] Fix SelectMessageQueueByHash in case hashcode is Integer.MIN

上级 872f37d9
......@@ -25,12 +25,10 @@ public class SelectMessageQueueByHash implements MessageQueueSelector {
@Override
public MessageQueue select(List<MessageQueue> mqs, Message msg, Object arg) {
int value = arg.hashCode();
int value = arg.hashCode() % mqs.size();
if (value < 0) {
value = Math.abs(value);
}
value = value % mqs.size();
return mqs.get(value);
}
}
......@@ -44,6 +44,14 @@ public class SelectMessageQueueByHashTest {
String anotherOrderId = "234";
MessageQueue selected = selector.select(messageQueues, message, orderId);
assertThat(selector.select(messageQueues, message, anotherOrderId)).isNotEqualTo(selected);
//No exception is thrown while order Id hashcode is Integer.MIN
anotherOrderId = "polygenelubricants";
selector.select(messageQueues, message, anotherOrderId);
anotherOrderId = "GydZG_";
selector.select(messageQueues, message, anotherOrderId);
anotherOrderId = "DESIGNING WORKHOUSES";
selector.select(messageQueues, message, anotherOrderId);
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册