use of org.apache.helix.tools.ClusterVerifiers.HelixClusterVerifier in project helix by apache.
the class TestDrop method testBasic.
@Test
public void testBasic() throws Exception {
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
final int n = 5;
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
MockParticipantManager[] participants = new MockParticipantManager[n];
// 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
8, // number of nodes
n, // replicas
3, "MasterSlave", // do rebalance
true);
// start controller
ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller");
controller.syncStart();
// start participants
for (int i = 0; i < n; i++) {
String instanceName = "localhost_" + (12918 + i);
participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
participants[i].syncStart();
}
HelixClusterVerifier verifier = new BestPossibleExternalViewVerifier.Builder(clusterName).setZkAddr(ZK_ADDR).build();
Assert.assertTrue(verifier.verify());
// Drop TestDB0
HelixAdmin admin = new ZKHelixAdmin(_gZkClient);
admin.dropResource(clusterName, "TestDB0");
Thread.sleep(1000);
assertEmptyCSandEV(clusterName, "TestDB0", participants);
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
use of org.apache.helix.tools.ClusterVerifiers.HelixClusterVerifier in project helix by apache.
the class TestAlertingRebalancerFailure method testParticipantUnavailable.
@Test(enabled = false)
public void testParticipantUnavailable() {
_setupTool.addResourceToCluster(CLUSTER_NAME, testDb, 5, BuiltInStateModelDefinitions.MasterSlave.name(), RebalanceMode.FULL_AUTO.name());
_setupTool.rebalanceStorageCluster(CLUSTER_NAME, testDb, 3);
HelixClusterVerifier verifier = new BestPossibleExternalViewVerifier.Builder(CLUSTER_NAME).setZkAddr(ZK_ADDR).setResources(new HashSet<>(Collections.singleton(testDb))).build();
Assert.assertTrue(verifier.verify());
// disable then enable the resource to ensure no rebalancing error is generated during this process
_setupTool.dropResourceFromCluster(CLUSTER_NAME, testDb);
_setupTool.addResourceToCluster(CLUSTER_NAME, testDb, 5, BuiltInStateModelDefinitions.MasterSlave.name(), RebalanceMode.FULL_AUTO.name());
_setupTool.rebalanceStorageCluster(CLUSTER_NAME, testDb, 3);
Assert.assertTrue(verifier.verify());
// Verify there is no rebalance error logged
Assert.assertNull(accessor.getProperty(errorNodeKey));
checkRebalanceFailureGauge(false);
// kill nodes, so rebalance cannot be done
for (int i = 0; i < NODE_NR; i++) {
_participants[i].syncStop();
}
// Verify the rebalance error caused by no node available
Assert.assertNotNull(pollForError(accessor, errorNodeKey));
checkRebalanceFailureGauge(true);
// clean up
_setupTool.getClusterManagementTool().dropResource(CLUSTER_NAME, testDb);
for (int i = 0; i < NODE_NR; i++) {
_participants[i] = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, _participants[i].getInstanceName());
_participants[i].syncStart();
}
}
use of org.apache.helix.tools.ClusterVerifiers.HelixClusterVerifier in project helix by apache.
the class TestBucketizedResource method testBucketizedResource.
@Test()
public void testBucketizedResource() {
// Logger.getRootLogger().setLevel(Level.INFO);
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
List<String> instanceNames = Arrays.asList("localhost_12918", "localhost_12919", "localhost_12920", "localhost_12921", "localhost_12922");
int n = instanceNames.size();
String dbName = "TestDB0";
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
MockParticipantManager[] participants = new MockParticipantManager[5];
setupCluster(clusterName, instanceNames, dbName, 3, 10, 1);
ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, _baseAccessor);
ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName);
controller.syncStart();
// start participants
for (int i = 0; i < n; i++) {
participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceNames.get(i));
participants[i].syncStart();
}
PropertyKey evKey = accessor.keyBuilder().externalView(dbName);
boolean result = ClusterStateVerifier.verifyByZkCallback(new MasterNbInExtViewVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(result);
HelixClusterVerifier _clusterVerifier = new BestPossibleExternalViewVerifier.Builder(clusterName).setZkAddr(ZK_ADDR).build();
Assert.assertTrue(_clusterVerifier.verify());
ExternalView ev = accessor.getProperty(evKey);
int v1 = ev.getRecord().getVersion();
// disable the participant
_gSetupTool.getClusterManagementTool().enableInstance(clusterName, participants[0].getInstanceName(), false);
// wait for change in EV
Assert.assertTrue(_clusterVerifier.verify());
// read the version in EV
ev = accessor.getProperty(evKey);
int v2 = ev.getRecord().getVersion();
Assert.assertEquals(v2 > v1, true);
// clean up
controller.syncStop();
for (int i = 0; i < n; i++) {
participants[i].syncStop();
}
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
use of org.apache.helix.tools.ClusterVerifiers.HelixClusterVerifier in project helix by apache.
the class TestBucketizedResource method testListenerOnBucketizedResource.
@Test
public void testListenerOnBucketizedResource() throws Exception {
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
String dbName = "TestDB0";
List<String> instanceNames = Arrays.asList("localhost_0", "localhost_1", "localhost_2", "localhost_3", "localhost_4");
int n = instanceNames.size();
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, _baseAccessor);
PropertyKey.Builder keyBuilder = accessor.keyBuilder();
setupCluster(clusterName, instanceNames, dbName, 3, 10, 2);
// start controller
ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName);
controller.syncStart();
// start participants
MockParticipantManager[] participants = new MockParticipantManager[n];
for (int i = 0; i < n; i++) {
participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceNames.get(i));
participants[i].syncStart();
}
HelixClusterVerifier _clusterVerifier = new BestPossibleExternalViewVerifier.Builder(clusterName).setZkAddr(ZK_ADDR).build();
Assert.assertTrue(_clusterVerifier.verify());
// add an external view listener
TestExternalViewListener listener = new TestExternalViewListener();
controller.addExternalViewChangeListener(listener);
// remove "TestDB0"
_gSetupTool.dropResourceFromCluster(clusterName, dbName);
Assert.assertTrue(_clusterVerifier.verify());
// wait callback to finish
int waitTime = 0;
do {
Thread.sleep(100);
waitTime += 100;
if (waitTime > 30000) {
break;
}
} while (listener.cbCnt == 0);
listener.cbCnt = 0;
// add a new db
String newDbName = "TestDB1";
int r = 3;
ZNRecord idealStateRec = DefaultIdealStateCalculator.calculateIdealState(instanceNames, 10, r - 1, newDbName, "MASTER", "SLAVE");
IdealState idealState = new IdealState(idealStateRec);
idealState.setBucketSize(2);
idealState.setStateModelDefRef("MasterSlave");
idealState.setRebalanceMode(IdealState.RebalanceMode.CUSTOMIZED);
idealState.setReplicas(Integer.toString(r));
accessor.setProperty(keyBuilder.idealStates(newDbName), idealState);
Assert.assertTrue(_clusterVerifier.verify());
Thread.sleep(200);
Assert.assertTrue(listener.cbCnt > 0);
// clean up
controller.syncStop();
for (MockParticipantManager participant : participants) {
participant.syncStop();
}
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
use of org.apache.helix.tools.ClusterVerifiers.HelixClusterVerifier in project helix by apache.
the class TestBucketizedResource method testBounceDisableAndDrop.
@Test
public void testBounceDisableAndDrop() {
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
String dbName = "TestDB0";
List<String> instanceNames = Arrays.asList("localhost_0", "localhost_1", "localhost_2", "localhost_3", "localhost_4");
int n = instanceNames.size();
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, _baseAccessor);
PropertyKey.Builder keyBuilder = accessor.keyBuilder();
setupCluster(clusterName, instanceNames, dbName, 3, 10, 2);
// start controller
ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName);
controller.syncStart();
// start participants
MockParticipantManager[] participants = new MockParticipantManager[n];
for (int i = 0; i < n; i++) {
participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceNames.get(i));
participants[i].syncStart();
}
HelixClusterVerifier _clusterVerifier = new BestPossibleExternalViewVerifier.Builder(clusterName).setZkAddr(ZK_ADDR).build();
Assert.assertTrue(_clusterVerifier.verify());
// bounce
participants[0].syncStop();
participants[0] = new MockParticipantManager(ZK_ADDR, clusterName, instanceNames.get(0));
participants[0].syncStart();
Assert.assertTrue(_clusterVerifier.verify());
// make sure participants[0]'s current state is bucketzied correctly during carryover
String path = keyBuilder.currentState(instanceNames.get(0), participants[0].getSessionId(), dbName).getPath();
ZNRecord record = _baseAccessor.get(path, null, 0);
Assert.assertTrue(record.getMapFields().size() == 0);
// disable the bucketize resource
HelixAdmin admin = new ZKHelixAdmin(_gZkClient);
admin.enableResource(clusterName, dbName, false);
Assert.assertTrue(_clusterVerifier.verify());
// drop the bucketize resource
_gSetupTool.dropResourceFromCluster(clusterName, dbName);
Assert.assertTrue(_clusterVerifier.verify());
// make sure external-view is cleaned up
path = keyBuilder.externalView(dbName).getPath();
boolean result = _baseAccessor.exists(path, 0);
Assert.assertFalse(result);
// clean up
controller.syncStop();
for (MockParticipantManager participant : participants) {
participant.syncStop();
}
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
Aggregations