String controllerName = "controller_0";
DynamicFileHelixManager controller = new DynamicFileHelixManager(clusterName,
controllerName, InstanceType.CONTROLLER, _store);
_mgmtTool.addCluster(clusterName, true);
_mgmtTool.addInstance(clusterName, new InstanceConfig(instanceName));
DynamicFileHelixManager participant = new DynamicFileHelixManager(clusterName,
instanceName, InstanceType.PARTICIPANT, _store);
AssertJUnit.assertEquals(instanceName, participant.getInstanceName());
controller.disconnect();
AssertJUnit.assertFalse(controller.isConnected());
controller.connect();
AssertJUnit.assertTrue(controller.isConnected());
String sessionId = controller.getSessionId();
// AssertJUnit.assertEquals(DynamicFileClusterManager._sessionId,
// sessionId);
AssertJUnit.assertEquals(clusterName, controller.getClusterName());
AssertJUnit.assertEquals(0, controller.getLastNotificationTime());
AssertJUnit.assertEquals(InstanceType.CONTROLLER, controller.getInstanceType());
// AssertJUnit.assertNull(controller.getPropertyStore());
PropertyStore<ZNRecord> propertyStore = controller.getPropertyStore();
AssertJUnit.assertNotNull(propertyStore);
propertyStore.setProperty("testKey", new ZNRecord("testValue"));
ZNRecord record = propertyStore.getProperty("testKey");
Assert.assertEquals(record.getId(), "testValue");
AssertJUnit.assertNull(controller.getHealthReportCollector());
MockListener controllerListener = new MockListener();
controllerListener.reset();
controller.addIdealStateChangeListener(controllerListener);
AssertJUnit.assertTrue(controllerListener.isIdealStateChangeListenerInvoked);
controller.addLiveInstanceChangeListener(controllerListener);
AssertJUnit.assertTrue(controllerListener.isLiveInstanceChangeListenerInvoked);
controller.addCurrentStateChangeListener(controllerListener, controllerName, sessionId);
AssertJUnit.assertTrue(controllerListener.isCurrentStateChangeListenerInvoked);
boolean exceptionCaught = false;
try
{
controller.addConfigChangeListener(controllerListener);
} catch (UnsupportedOperationException e)
{
exceptionCaught = true;
}
AssertJUnit.assertTrue(exceptionCaught);
exceptionCaught = false;
try
{
controller.addExternalViewChangeListener(controllerListener);
} catch (UnsupportedOperationException e)
{
exceptionCaught = true;
}
AssertJUnit.assertTrue(exceptionCaught);
exceptionCaught = false;
try
{
controller.addControllerListener(controllerListener);
} catch (UnsupportedOperationException e)
{
exceptionCaught = true;
}
AssertJUnit.assertTrue(exceptionCaught);
AssertJUnit.assertFalse(controller.removeListener(null, controllerListener));
exceptionCaught = false;
try
{
controller.addIdealStateChangeListener(null);
} catch (HelixException e)
{
exceptionCaught = true;
}
AssertJUnit.assertTrue(exceptionCaught);
// test message service
ClusterMessagingService msgService = controller.getMessagingService();
// test file management tool
HelixAdmin tool = controller.getClusterManagmentTool();
exceptionCaught = false;
try
{
tool.getClusters();
} catch (UnsupportedOperationException e)
{
exceptionCaught = true;
}
AssertJUnit.assertTrue(exceptionCaught);
exceptionCaught = false;
try
{
tool.getResourcesInCluster(clusterName);
} catch (UnsupportedOperationException e)
{
exceptionCaught = true;
}
AssertJUnit.assertTrue(exceptionCaught);
exceptionCaught = false;
try
{
tool.addResource(clusterName, "resource", 10, "MasterSlave",
IdealStateModeProperty.AUTO.toString());
} catch (UnsupportedOperationException e)
{
exceptionCaught = true;
}
AssertJUnit.assertTrue(exceptionCaught);
exceptionCaught = false;
try
{
tool.getStateModelDefs(clusterName);
} catch (UnsupportedOperationException e)
{
exceptionCaught = true;
}
AssertJUnit.assertTrue(exceptionCaught);
exceptionCaught = false;
try
{
tool.getInstanceConfig(clusterName, instanceName);
} catch (UnsupportedOperationException e)
{
exceptionCaught = true;
}
AssertJUnit.assertTrue(exceptionCaught);
exceptionCaught = false;
try
{
tool.getStateModelDef(clusterName, "MasterSlave");
} catch (UnsupportedOperationException e)
{
exceptionCaught = true;
}
AssertJUnit.assertTrue(exceptionCaught);
exceptionCaught = false;
try
{
tool.getResourceExternalView(clusterName, "resource");
} catch (UnsupportedOperationException e)
{
exceptionCaught = true;
}
AssertJUnit.assertTrue(exceptionCaught);
exceptionCaught = false;
try
{
tool.enableInstance(clusterName, "resource", false);
} catch (UnsupportedOperationException e)
{
exceptionCaught = true;
}
AssertJUnit.assertTrue(exceptionCaught);
tool.addCluster(clusterName, true);
tool.addResource(clusterName, "resource", 10, "MasterSlave");
InstanceConfig config = new InstanceConfig("nodeConfig");
tool.addInstance(clusterName, config);
List<String> instances = tool.getInstancesInCluster(clusterName);
AssertJUnit.assertEquals(1, instances.size());
tool.dropInstance(clusterName, config);