Skip to content

Commit

Permalink
[ISSUE #2421] Fix SelectMessageQueueByHash in case hashcode is Intege…
Browse files Browse the repository at this point in the history
…r.MIN
  • Loading branch information
HashJang committed Nov 12, 2020
1 parent 872f37d commit 0b60048
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ public void testSelect() throws Exception {
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);
}

}

0 comments on commit 0b60048

Please sign in to comment.