use of org.apache.helix.model.Message in project helix by apache.
the class TestHelixTaskExecutor method testCreateHandlerException.
@Test()
public void testCreateHandlerException() throws InterruptedException {
System.out.println("START TestCMTaskExecutor.testCreateHandlerException()");
HelixTaskExecutor executor = new HelixTaskExecutor();
HelixManager manager = new MockClusterManager();
TestMessageHandlerFactory factory = new TestMessageHandlerFactory();
for (String type : factory.getMessageTypes()) {
executor.registerMessageHandlerFactory(type, factory);
}
NotificationContext changeContext = new NotificationContext(manager);
List<Message> msgList = new ArrayList<Message>();
int nMsgs1 = 5;
for (int i = 0; i < nMsgs1; i++) {
Message msg = new Message(factory.getMessageTypes().get(0), UUID.randomUUID().toString());
msg.setTgtSessionId(manager.getSessionId());
msg.setTgtName("Localhost_1123");
msg.setSrcName("127.101.1.23_2234");
msg.setCorrelationId(UUID.randomUUID().toString());
msgList.add(msg);
}
Message exceptionMsg = new Message(factory.getMessageTypes().get(0), UUID.randomUUID().toString());
exceptionMsg.setTgtSessionId(manager.getSessionId());
exceptionMsg.setMsgSubType("EXCEPTION");
exceptionMsg.setTgtName("Localhost_1123");
exceptionMsg.setSrcName("127.101.1.23_2234");
exceptionMsg.setCorrelationId(UUID.randomUUID().toString());
msgList.add(exceptionMsg);
changeContext.setChangeType(HelixConstants.ChangeType.MESSAGE);
executor.onMessage("someInstance", msgList, changeContext);
Thread.sleep(1000);
AssertJUnit.assertTrue(factory._processedMsgIds.size() == nMsgs1);
AssertJUnit.assertTrue(factory._handlersCreated == nMsgs1);
AssertJUnit.assertTrue(exceptionMsg.getMsgState() == MessageState.UNPROCESSABLE);
System.out.println("END TestCMTaskExecutor.testCreateHandlerException()");
}
use of org.apache.helix.model.Message in project helix by apache.
the class TestDefaultControllerMsgHandlerFactory method testDefaultControllerMsgHandlerFactory.
@Test()
public void testDefaultControllerMsgHandlerFactory() {
System.out.println("START TestDefaultControllerMsgHandlerFactory at " + new Date(System.currentTimeMillis()));
DefaultControllerMessageHandlerFactory facotry = new DefaultControllerMessageHandlerFactory();
Message message = new Message(MessageType.NO_OP, "0");
NotificationContext context = new NotificationContext(null);
boolean exceptionCaught = false;
try {
MessageHandler handler = facotry.createHandler(message, context);
} catch (HelixException e) {
exceptionCaught = true;
}
AssertJUnit.assertTrue(exceptionCaught);
message = new Message(MessageType.CONTROLLER_MSG, "1");
exceptionCaught = false;
try {
MessageHandler handler = facotry.createHandler(message, context);
} catch (HelixException e) {
exceptionCaught = true;
}
AssertJUnit.assertFalse(exceptionCaught);
Map<String, String> resultMap = new HashMap<String, String>();
message = new Message(MessageType.NO_OP, "3");
DefaultControllerMessageHandler defaultHandler = new DefaultControllerMessageHandler(message, context);
try {
defaultHandler.handleMessage();
} catch (HelixException e) {
exceptionCaught = true;
} catch (InterruptedException e) {
LOG.error("Interrupted handling message", e);
}
AssertJUnit.assertTrue(exceptionCaught);
message = new Message(MessageType.CONTROLLER_MSG, "4");
defaultHandler = new DefaultControllerMessageHandler(message, context);
exceptionCaught = false;
try {
defaultHandler.handleMessage();
} catch (HelixException e) {
exceptionCaught = true;
} catch (InterruptedException e) {
LOG.error("Interrupted handling message", e);
}
AssertJUnit.assertFalse(exceptionCaught);
System.out.println("END TestDefaultControllerMsgHandlerFactory at " + new Date(System.currentTimeMillis()));
}
use of org.apache.helix.model.Message in project helix by apache.
the class MessagePoster method postTestMessage.
public void postTestMessage(String zkServer, String clusterName, String instanceName) {
String msgSrc = "cm-instance-0";
String msgId = "TestMessageId-2";
Message message = new Message(MessageType.STATE_TRANSITION, msgId);
message.setMsgId(msgId);
message.setSrcName(msgSrc);
message.setTgtName(instanceName);
message.setMsgState(MessageState.NEW);
message.setFromState("Slave");
message.setToState("Master");
message.setPartitionName("EspressoDB.partition-0." + instanceName);
post(zkServer, message, clusterName, instanceName);
}
use of org.apache.helix.model.Message in project helix by apache.
the class MessagePoster method postFaultInjectionMessage.
public void postFaultInjectionMessage(String zkServer, String clusterName, String instanceName, String payloadString, String partition) {
Message message = new Message("FaultInjection", UUID.randomUUID().toString());
if (payloadString != null) {
message.getRecord().setSimpleField("faultType", payloadString);
}
if (partition != null) {
message.setPartitionName(partition);
}
post(zkServer, message, clusterName, instanceName);
}
use of org.apache.helix.model.Message in project helix by apache.
the class TestHelixTaskExecutor method testCMTaskExecutor.
@Test()
public void testCMTaskExecutor() throws Exception {
System.out.println("START TestCMTaskExecutor");
String msgId = "TestMessageId";
Message message = new Message(MessageType.TASK_REPLY, msgId);
message.setMsgId(msgId);
message.setSrcName("cm-instance-0");
message.setTgtName("cm-instance-1");
message.setTgtSessionId("1234");
message.setFromState("Offline");
message.setToState("Slave");
message.setPartitionName("TestDB_0");
message.setResourceName("TestDB");
message.setStateModelDef("MasterSlave");
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);
MockHelixTaskExecutor executor = new MockHelixTaskExecutor();
MockMasterSlaveStateModel stateModel = new MockMasterSlaveStateModel();
executor.registerMessageHandlerFactory(MessageType.TASK_REPLY.name(), new AsyncCallbackService());
NotificationContext context = new NotificationContext(manager);
CurrentState currentStateDelta = new CurrentState("TestDB");
currentStateDelta.setState("TestDB_0", "OFFLINE");
StateModelFactory<MockMasterSlaveStateModel> stateModelFactory = new StateModelFactory<MockMasterSlaveStateModel>() {
@Override
public MockMasterSlaveStateModel createNewStateModel(String resource, String partitionName) {
// TODO Auto-generated method stub
return new MockMasterSlaveStateModel();
}
};
HelixStateTransitionHandler handler = new HelixStateTransitionHandler(stateModelFactory, stateModel, message, context, currentStateDelta);
HelixTask task = new HelixTask(message, context, handler, executor);
executor.scheduleTask(task);
for (int i = 0; i < 10; i++) {
if (!executor.isDone(task.getTaskId())) {
Thread.sleep(500);
}
}
AssertJUnit.assertTrue(stateModel.stateModelInvoked);
System.out.println("END TestCMTaskExecutor");
}
Aggregations