use of org.apache.helix.mock.MockManager 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");
}
use of org.apache.helix.mock.MockManager in project helix by apache.
the class BaseStageTest method setup.
public void setup() {
_clusterName = "testCluster-" + UUID.randomUUID().toString();
manager = new MockManager(_clusterName);
accessor = manager.getHelixDataAccessor();
ClusterConfig clusterConfig = new ClusterConfig(_clusterName);
setClusterConfig(clusterConfig);
admin = new MockHelixAdmin(manager);
event = new ClusterEvent(ClusterEventType.Unknown);
admin.addCluster(_clusterName);
}
use of org.apache.helix.mock.MockManager in project helix by apache.
the class TestCompatibilityCheckStage method prepare.
private void prepare(String controllerVersion, String participantVersion, String minSupportedParticipantVersion) {
List<String> instances = Arrays.asList("localhost_0", "localhost_1", "localhost_2", "localhost_3", "localhost_4");
int partitions = 10;
int replicas = 1;
// set ideal state
String resourceName = "testResource";
ZNRecord record = DefaultIdealStateCalculator.calculateIdealState(instances, partitions, replicas, resourceName, "MASTER", "SLAVE");
IdealState idealState = new IdealState(record);
idealState.setStateModelDefRef("MasterSlave");
Builder keyBuilder = accessor.keyBuilder();
accessor.setProperty(keyBuilder.idealStates(resourceName), idealState);
// set live instances
record = new ZNRecord("localhost_0");
if (participantVersion != null) {
record.setSimpleField(LiveInstanceProperty.HELIX_VERSION.toString(), participantVersion);
}
LiveInstance liveInstance = new LiveInstance(record);
liveInstance.setSessionId("session_0");
accessor.setProperty(keyBuilder.liveInstance("localhost_0"), liveInstance);
if (controllerVersion != null) {
((MockManager) manager).setVersion(controllerVersion);
}
if (minSupportedParticipantVersion != null) {
manager.getProperties().getProperties().put("minimum_supported_version.participant", minSupportedParticipantVersion);
}
event.addAttribute(AttributeName.helixmanager.name(), manager);
runStage(event, new ReadClusterDataStage());
}
use of org.apache.helix.mock.MockManager 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()));
}
use of org.apache.helix.mock.MockManager 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()));
}
Aggregations