Search in sources :

Example 1 with HelixTaskExecutor

use of org.apache.helix.messaging.handling.HelixTaskExecutor in project helix by apache.

the class TestHelixTaskHandler method testInvocation.

@Test()
public void testInvocation() throws Exception {
    HelixTaskExecutor executor = new HelixTaskExecutor();
    System.out.println("START TestCMTaskHandler.testInvocation()");
    Message message = new Message(MessageType.STATE_TRANSITION, "Some unique id");
    message.setSrcName("cm-instance-0");
    message.setTgtSessionId("1234");
    message.setFromState("Offline");
    message.setToState("Slave");
    message.setPartitionName("TestDB_0");
    message.setMsgId("Some unique message id");
    message.setResourceName("TestDB");
    message.setTgtName("localhost");
    message.setStateModelDef("MasterSlave");
    message.setStateModelFactoryName(HelixConstants.DEFAULT_STATE_MODEL_FACTORY);
    MockMasterSlaveStateModel stateModel = new MockMasterSlaveStateModel();
    NotificationContext context;
    MockManager manager = new MockManager("clusterName");
    HelixDataAccessor accessor = manager.getHelixDataAccessor();
    StateModelDefinition stateModelDef = new StateModelDefinition(StateModelConfigGenerator.generateConfigForMasterSlave());
    Builder keyBuilder = accessor.keyBuilder();
    accessor.setProperty(keyBuilder.stateModelDef("MasterSlave"), stateModelDef);
    context = new NotificationContext(manager);
    CurrentState currentStateDelta = new CurrentState("TestDB");
    currentStateDelta.setState("TestDB_0", "OFFLINE");
    HelixStateTransitionHandler stHandler = new HelixStateTransitionHandler(null, stateModel, message, context, currentStateDelta);
    HelixTask handler;
    handler = new HelixTask(message, context, stHandler, executor);
    handler.call();
    AssertJUnit.assertTrue(stateModel.stateModelInvoked);
    System.out.println("END TestCMTaskHandler.testInvocation() at " + new Date(System.currentTimeMillis()));
}
Also used : MockMasterSlaveStateModel(org.apache.helix.mock.statemodel.MockMasterSlaveStateModel) Message(org.apache.helix.model.Message) HelixTask(org.apache.helix.messaging.handling.HelixTask) StateModelDefinition(org.apache.helix.model.StateModelDefinition) HelixTaskExecutor(org.apache.helix.messaging.handling.HelixTaskExecutor) Builder(org.apache.helix.PropertyKey.Builder) CurrentState(org.apache.helix.model.CurrentState) MockManager(org.apache.helix.mock.MockManager) HelixStateTransitionHandler(org.apache.helix.messaging.handling.HelixStateTransitionHandler) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 2 with HelixTaskExecutor

use of org.apache.helix.messaging.handling.HelixTaskExecutor in project helix by apache.

the class TestHelixTaskHandler method testInvocationAnnotated.

@Test()
public void testInvocationAnnotated() throws Exception {
    System.out.println("START TestCMTaskHandler.testInvocationAnnotated() at " + new Date(System.currentTimeMillis()));
    HelixTaskExecutor executor = new HelixTaskExecutor();
    Message message = new Message(MessageType.STATE_TRANSITION, "Some unique id");
    message.setSrcName("cm-instance-0");
    message.setTgtSessionId("1234");
    message.setFromState("Offline");
    message.setToState("Slave");
    message.setPartitionName("TestDB_0");
    message.setMsgId("Some unique message id");
    message.setResourceName("TestDB");
    message.setTgtName("localhost");
    message.setStateModelDef("MasterSlave");
    message.setStateModelFactoryName(HelixConstants.DEFAULT_STATE_MODEL_FACTORY);
    MockStateModelAnnotated stateModel = new MockStateModelAnnotated();
    NotificationContext context;
    MockManager manager = new MockManager("clusterName");
    HelixDataAccessor accessor = manager.getHelixDataAccessor();
    StateModelDefinition stateModelDef = new StateModelDefinition(StateModelConfigGenerator.generateConfigForMasterSlave());
    Builder keyBuilder = accessor.keyBuilder();
    accessor.setProperty(keyBuilder.stateModelDef("MasterSlave"), stateModelDef);
    context = new NotificationContext(manager);
    CurrentState currentStateDelta = new CurrentState("TestDB");
    currentStateDelta.setState("TestDB_0", "OFFLINE");
    StateModelFactory<MockStateModelAnnotated> stateModelFactory = new StateModelFactory<MockStateModelAnnotated>() {

        @Override
        public MockStateModelAnnotated createNewStateModel(String resource, String partitionName) {
            // TODO Auto-generated method stub
            return new MockStateModelAnnotated();
        }
    };
    HelixStateTransitionHandler stHandler = new HelixStateTransitionHandler(stateModelFactory, stateModel, message, context, currentStateDelta);
    HelixTask handler = new HelixTask(message, context, stHandler, executor);
    handler.call();
    AssertJUnit.assertTrue(stateModel.stateModelInvoked);
    System.out.println("END TestCMTaskHandler.testInvocationAnnotated() at " + new Date(System.currentTimeMillis()));
}
Also used : Message(org.apache.helix.model.Message) HelixTask(org.apache.helix.messaging.handling.HelixTask) HelixTaskExecutor(org.apache.helix.messaging.handling.HelixTaskExecutor) Builder(org.apache.helix.PropertyKey.Builder) MockStateModelAnnotated(org.apache.helix.mock.statemodel.MockStateModelAnnotated) Date(java.util.Date) StateModelDefinition(org.apache.helix.model.StateModelDefinition) CurrentState(org.apache.helix.model.CurrentState) StateModelFactory(org.apache.helix.participant.statemachine.StateModelFactory) MockManager(org.apache.helix.mock.MockManager) HelixStateTransitionHandler(org.apache.helix.messaging.handling.HelixStateTransitionHandler) Test(org.testng.annotations.Test)

Aggregations

Date (java.util.Date)2 Builder (org.apache.helix.PropertyKey.Builder)2 HelixStateTransitionHandler (org.apache.helix.messaging.handling.HelixStateTransitionHandler)2 HelixTask (org.apache.helix.messaging.handling.HelixTask)2 HelixTaskExecutor (org.apache.helix.messaging.handling.HelixTaskExecutor)2 MockManager (org.apache.helix.mock.MockManager)2 CurrentState (org.apache.helix.model.CurrentState)2 Message (org.apache.helix.model.Message)2 StateModelDefinition (org.apache.helix.model.StateModelDefinition)2 Test (org.testng.annotations.Test)2 MockMasterSlaveStateModel (org.apache.helix.mock.statemodel.MockMasterSlaveStateModel)1 MockStateModelAnnotated (org.apache.helix.mock.statemodel.MockStateModelAnnotated)1 StateModelFactory (org.apache.helix.participant.statemachine.StateModelFactory)1