Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
None
-
Patch
Description
The tests in org.apache.kylin.stream.coordinator.CoordinatorTest#testReassignFailOnStartNew and org.apache.kylin.stream.coordinator.CoordinatorTest#testReassignFailOnStopAndSync will fail when making the following assertions:
assertSame(ClusterStateException.ClusterState.ROLLBACK_FAILED, rune.getClusterState());
assertSame(ClusterStateException.TransactionStep.STOP_AND_SNYC, rune.getTransactionStep());
The failure is reported as follows:
java.lang.Exception: Unexpected exception, expected<org.apache.kylin.stream.coordinator.exception.ClusterStateException>
but was<java.lang.AssertionError>
at org.apache.kylin.stream.coordinator.CoordinatorTest.testReassignFailOnStartNew(CoordinatorTest.java:271)
After my analysis, I find that the root cause is that the variable newAssignMap is a HashMap, which makes no guarantee about the order when iterating in org.apache.kylin.stream.coordinator.Coordinator.doReassign(Coordinator.java:516)
The specification about HashMap says that "this class makes no guarantees as to the order of the map; in particular, it does not guarantee that the order will remain constant over time". The documentation is here for your reference: https://docs.oracle.com/javase/8/docs/api/java/util/HashMap.html
The fix is to use LinkedHashMap instead of HashMap so that the non-deterministic behaviour is eliminated. It will not affect the performance and can make the tests more stable.
Attachments
Issue Links
- links to