Search in sources :

Example 6 with MockManager

use of org.apache.helix.mock.MockManager in project helix by apache.

the class TestRoutingTable method setup.

@BeforeClass()
public synchronized void setup() {
    final String[] array = new String[] { "localhost_8900", "localhost_8901" };
    HelixManager manager = new MockManager() {

        private MockAccessor _mockAccessor;

        @Override
        public // public DataAccessor getDataAccessor()
        HelixDataAccessor getHelixDataAccessor() {
            if (_mockAccessor == null) {
                _mockAccessor = new MockAccessor() {

                    @SuppressWarnings("unchecked")
                    @Override
                    public <T extends HelixProperty> List<T> getChildValues(PropertyKey key) {
                        PropertyType type = key.getType();
                        String[] keys = key.getParams();
                        if (type == PropertyType.CONFIGS && keys != null && keys.length > 1 && keys[1].equalsIgnoreCase(ConfigScopeProperty.PARTICIPANT.toString())) {
                            List<InstanceConfig> configs = new ArrayList<InstanceConfig>();
                            for (String instanceName : array) {
                                InstanceConfig config = new InstanceConfig(instanceName);
                                String[] splits = instanceName.split("_");
                                config.setHostName(splits[0]);
                                config.setPort(splits[1]);
                                configs.add(config);
                            }
                            return (List<T>) configs;
                        }
                        return Collections.emptyList();
                    }
                };
            }
            return _mockAccessor;
        }
    };
    changeContext = new NotificationContext(manager);
}
Also used : InstanceConfig(org.apache.helix.model.InstanceConfig) ArrayList(java.util.ArrayList) List(java.util.List) MockManager(org.apache.helix.mock.MockManager) BeforeClass(org.testng.annotations.BeforeClass)

Example 7 with MockManager

use of org.apache.helix.mock.MockManager in project helix by apache.

the class TestDefaultMessagingService method testMultipleMessageTypeRegisteration.

@Test
public void testMultipleMessageTypeRegisteration() {
    HelixManager manager = new MockManager();
    MockDefaultMessagingService svc = new MockDefaultMessagingService(manager);
    TestStateTransitionHandlerFactory factory = new TestStateTransitionHandlerFactory();
    svc.registerMessageHandlerFactory(factory.getMessageTypes(), factory);
    Assert.assertTrue(svc.getMessageHandlerFactoryMap().containsKey(Message.MessageType.STATE_TRANSITION.name()));
    Assert.assertTrue(svc.getMessageHandlerFactoryMap().containsKey(Message.MessageType.STATE_TRANSITION_CANCELLATION.name()));
    Assert.assertTrue(svc.getMessageHandlerFactoryMap().containsKey(Message.MessageType.CONTROLLER_MSG.name()));
}
Also used : HelixManager(org.apache.helix.HelixManager) MockManager(org.apache.helix.mock.MockManager) Test(org.testng.annotations.Test)

Aggregations

MockManager (org.apache.helix.mock.MockManager)7 Builder (org.apache.helix.PropertyKey.Builder)4 Test (org.testng.annotations.Test)4 HelixStateTransitionHandler (org.apache.helix.messaging.handling.HelixStateTransitionHandler)3 HelixTask (org.apache.helix.messaging.handling.HelixTask)3 CurrentState (org.apache.helix.model.CurrentState)3 Message (org.apache.helix.model.Message)3 StateModelDefinition (org.apache.helix.model.StateModelDefinition)3 Date (java.util.Date)2 HelixTaskExecutor (org.apache.helix.messaging.handling.HelixTaskExecutor)2 MockMasterSlaveStateModel (org.apache.helix.mock.statemodel.MockMasterSlaveStateModel)2 StateModelFactory (org.apache.helix.participant.statemachine.StateModelFactory)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 HelixManager (org.apache.helix.HelixManager)1 ZNRecord (org.apache.helix.ZNRecord)1 AsyncCallbackService (org.apache.helix.messaging.handling.AsyncCallbackService)1 MockHelixAdmin (org.apache.helix.mock.MockHelixAdmin)1 MockHelixTaskExecutor (org.apache.helix.mock.participant.MockHelixTaskExecutor)1 MockStateModelAnnotated (org.apache.helix.mock.statemodel.MockStateModelAnnotated)1