use of org.apache.helix.HelixManager in project helix by apache.
the class TestEntropyFreeNodeBounce method createParticipant.
private HelixManager createParticipant(String clusterName, String instanceName) {
HelixManager participant = new ZKHelixManager(clusterName, instanceName, InstanceType.PARTICIPANT, ZK_ADDR);
participant.getStateMachineEngine().registerStateModelFactory("OnlineOffline", new MockStateModelFactory());
return participant;
}
use of org.apache.helix.HelixManager in project helix by apache.
the class TestEntropyFreeNodeBounce method testBounceAll.
@Test
public void testBounceAll() throws Exception {
// pick numbers that don't divide evenly
final int NUM_PARTICIPANTS = 5;
final int NUM_PARTITIONS = 123;
final int NUM_REPLICAS = 1;
final String RESOURCE_PREFIX = "TestDB";
final String RESOURCE_NAME = RESOURCE_PREFIX + "0";
// create a cluster name based on this test name
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
// Set up cluster
// participant port
TestHelper.setupCluster(// participant port
clusterName, // participant port
ZK_ADDR, // participant port
12918, // participant name prefix
"localhost", // resource name prefix
"TestDB", // resources
1, // partitions per resource
NUM_PARTITIONS, // number of nodes
NUM_PARTICIPANTS, // replicas
NUM_REPLICAS, // use FULL_AUTO mode to test node tagging
"OnlineOffline", // use FULL_AUTO mode to test node tagging
RebalanceMode.FULL_AUTO, // do rebalance
true);
// Start the participants
HelixManager[] participants = new HelixManager[NUM_PARTICIPANTS];
for (int i = 0; i < NUM_PARTICIPANTS; i++) {
final String instanceName = "localhost_" + (12918 + i);
participants[i] = createParticipant(clusterName, instanceName);
participants[i].connect();
}
// Start the controller
ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller");
controller.syncStart();
// get an admin and accessor
HelixAdmin helixAdmin = new ZKHelixAdmin(_gZkClient);
BaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, baseAccessor);
PropertyKey.Builder keyBuilder = accessor.keyBuilder();
// do the test
try {
Thread.sleep(1000);
// ensure that the external view coalesces
boolean result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(result);
ExternalView stableExternalView = accessor.getProperty(keyBuilder.externalView(RESOURCE_NAME));
for (HelixManager participant : participants) {
// disable the controller, bounce the node, re-enable the controller, verify assignments
// remained the same
helixAdmin.enableCluster(clusterName, false);
participant.disconnect();
Thread.sleep(1000);
participant = createParticipant(clusterName, participant.getInstanceName());
participant.connect();
Thread.sleep(1000);
helixAdmin.enableCluster(clusterName, true);
Thread.sleep(1000);
result = ClusterStateVerifier.verifyByZkCallback(new MatchingExternalViewVerifier(stableExternalView, clusterName));
Assert.assertTrue(result);
}
} finally {
// clean up
controller.syncStop();
for (HelixManager participant : participants) {
participant.disconnect();
}
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
}
use of org.apache.helix.HelixManager in project helix by apache.
the class TestExternalViewStage method testCachedExternalViews.
@Test
public void testCachedExternalViews() throws Exception {
String clusterName = "CLUSTER_" + TestHelper.getTestMethodName();
HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
HelixManager manager = new DummyClusterManager(clusterName, accessor);
// ideal state: node0 is MASTER, node1 is SLAVE
// replica=2 means 1 master and 1 slave
setupIdealState(clusterName, new int[] { 0, 1 }, new String[] { "TestDB" }, 1, 2);
setupLiveInstances(clusterName, new int[] { 0, 1 });
setupStateModel(clusterName);
ClusterEvent event = new ClusterEvent(ClusterEventType.Unknown);
ClusterDataCache cache = new ClusterDataCache(clusterName);
event.addAttribute(AttributeName.helixmanager.name(), manager);
event.addAttribute(AttributeName.ClusterDataCache.name(), cache);
ExternalViewComputeStage externalViewComputeStage = new ExternalViewComputeStage();
Pipeline dataRefresh = new Pipeline();
dataRefresh.addStage(new ReadClusterDataStage());
runPipeline(event, dataRefresh);
runStage(event, new ResourceComputationStage());
runStage(event, new CurrentStateComputationStage());
runStage(event, externalViewComputeStage);
Assert.assertEquals(cache.getExternalViews().values(), accessor.getChildValues(accessor.keyBuilder().externalViews()));
// Assure there is no external got updated
List<ExternalView> oldExternalViews = accessor.getChildValues(accessor.keyBuilder().externalViews());
runStage(event, externalViewComputeStage);
List<ExternalView> newExternalViews = accessor.getChildValues(accessor.keyBuilder().externalViews());
Assert.assertEquals(oldExternalViews, newExternalViews);
for (int i = 0; i < oldExternalViews.size(); i++) {
Assert.assertEquals(oldExternalViews.get(i).getStat().getVersion(), newExternalViews.get(i).getStat().getVersion());
}
}
use of org.apache.helix.HelixManager in project helix by apache.
the class TestMessageThrottle2 method startController.
void startController() throws Exception {
// start helixController
System.out.println(String.format("Starting Controller{Cluster:%s, Port:%s, Zookeeper:%s}", clusterName, 12000, ZK_ADDR));
HelixManager helixController = HelixControllerMain.startHelixController(ZK_ADDR, clusterName, "localhost_" + 12000, HelixControllerMain.STANDALONE);
StatusPrinter statusPrinter = new StatusPrinter();
statusPrinter.registerWith(helixController);
}
use of org.apache.helix.HelixManager in project helix by apache.
the class TestZeroReplicaAvoidance method test.
@Test
public void test() throws Exception {
HelixManager manager = HelixManagerFactory.getZKHelixManager(CLUSTER_NAME, null, InstanceType.SPECTATOR, ZK_ADDR);
manager.connect();
manager.addExternalViewChangeListener(this);
manager.addIdealStateChangeListener(this);
enablePersistBestPossibleAssignment(_gZkClient, CLUSTER_NAME, true);
// Start half number of nodes.
int i = 0;
for (; i < NUM_NODE / 2; i++) {
_participants.get(i).syncStart();
}
int replica = 3;
int partition = 30;
for (String stateModel : TestStateModels) {
String db = "Test-DB-" + stateModel;
createResourceWithDelayedRebalance(CLUSTER_NAME, db, stateModel, partition, replica, replica, 0);
}
Assert.assertTrue(_clusterVerifier.verify(50000));
_startListen = true;
DelayedTransition.setDelay(50);
// add the other half of nodes.
for (; i < NUM_NODE; i++) {
_participants.get(i).syncStart();
}
Assert.assertTrue(_clusterVerifier.verify(50000));
Assert.assertTrue(_testSuccess);
}
Aggregations