@@ -0,0 +1,3243 @@
+package com.linkedin.helix.integration;%0A%0Aimport java.util.Map;%0Aimport java.util.Random;%0Aimport java.util.UUID;%0A%0Aimport org.testng.Assert;%0Aimport org.testng.annotations.Test;%0A%0Aimport com.linkedin.helix.HelixDataAccessor;%0Aimport com.linkedin.helix.HelixManager;%0Aimport com.linkedin.helix.PropertyKey.Builder;%0Aimport com.linkedin.helix.model.ExternalView;%0Aimport com.linkedin.helix.model.LiveInstance;%0Aimport com.linkedin.helix.model.Message;%0Aimport com.linkedin.helix.model.Message.MessageState;%0Aimport com.linkedin.helix.model.Message.MessageType;%0A%0Apublic class TestMessagePartitionStateMismatch extends ZkStandAloneCMTestBase%0A%7B%0A  @Test%0A  public void testStateMismatch() throws InterruptedException%0A  %7B%0A    String controllerName = CONTROLLER_PREFIX + %22_0%22;%0A    %0A    HelixManager manager = _startCMResultMap.get(controllerName)._manager;%0A    HelixDataAccessor accessor = manager.getHelixDataAccessor();%0A    Builder kb = accessor.keyBuilder();%0A    ExternalView ev = accessor.getProperty(kb.externalView(TEST_DB));%0A    Map%3CString, LiveInstance%3E liveinstanceMap = accessor.getChildValuesMap(accessor.keyBuilder().liveInstances());%0A    %0A    for(String instanceName : liveinstanceMap.keySet())%0A    %7B%0A      String sessionid = liveinstanceMap.get(instanceName).getSessionId();%0A      for(String partition : ev.getPartitionSet())%0A      %7B%0A        if(ev.getStateMap(partition).containsKey(instanceName))%0A        %7B%0A          String uuid = UUID.randomUUID().toString();%0A          Message message = new Message(MessageType.STATE_TRANSITION, uuid);%0A          boolean rand = new Random().nextInt(10) %3E 5;%0A          if(ev.getStateMap(partition).get(instanceName).equals(%22MASTER%22))%0A          %7B%0A            message.setSrcName(manager.getInstanceName());%0A            message.setTgtName(instanceName);%0A            message.setMsgState(MessageState.NEW);%0A            message.setPartitionName(partition);%0A            message.setResourceName(TEST_DB);%0A            message.setFromState(rand ? %22SLAVE%22 : %22OFFLINE%22);%0A            message.setToState(rand ? %22MASTER%22 : %22SLAVE%22);%0A            message.setTgtSessionId(sessionid);%0A            message.setSrcSessionId(manager.getSessionId());%0A            message.setStateModelDef(%22MasterSlave%22);%0A            message.setStateModelFactoryName(%22DEFAULT%22); %0A          %7D%0A          else if (ev.getStateMap(partition).get(instanceName).equals(%22SLAVE%22))%0A          %7B%0A            message.setSrcName(manager.getInstanceName());%0A            message.setTgtName(instanceName);%0A            message.setMsgState(MessageState.NEW);%0A            message.setPartitionName(partition);%0A            message.setResourceName(TEST_DB);%0A            message.setFromState(rand ? %22MASTER%22 : %22OFFLINE%22);%0A            message.setToState(rand ? %22SLAVE%22 : %22SLAVE%22);%0A            message.setTgtSessionId(sessionid);%0A            message.setSrcSessionId(manager.getSessionId());%0A            message.setStateModelDef(%22MasterSlave%22);%0A            message.setStateModelFactoryName(%22DEFAULT%22);%0A          %7D%0A          accessor.setProperty(accessor.keyBuilder().message(instanceName, message.getMsgId()), message);%0A        %7D%0A      %7D%0A    %7D%0A    Thread.sleep(3000);%0A    ExternalView ev2 = accessor.getProperty(kb.externalView(TEST_DB));%0A    Assert.assertTrue(ev.equals(ev2));%0A  %7D%0A%7D%0A

Add testcase for message from state does not match with current state of a partition