This is an automated email from the ASF dual-hosted git repository. jiajunwang pushed a commit to branch helix-0.9.x in repository https://gitbox.apache.org/repos/asf/helix.git
commit c80fdb3f8ede319ed54982b3ad42a6379d2947ea Author: zhangmeng916 <[email protected]> AuthorDate: Wed Feb 26 10:05:41 2020 -0800 add one more test for auto registration (#806) Add a test case for participant auto registers to cluster in cloud environment. Note that the final step is expected to fail as the test is not running in a cloud environment. --- .../paticipant/TestInstanceAutoJoin.java | 62 +++++++++++++++++++--- 1 file changed, 54 insertions(+), 8 deletions(-) diff --git a/helix-core/src/test/java/org/apache/helix/integration/paticipant/TestInstanceAutoJoin.java b/helix-core/src/test/java/org/apache/helix/integration/paticipant/TestInstanceAutoJoin.java index f0ffc63..5d5ec46 100644 --- a/helix-core/src/test/java/org/apache/helix/integration/paticipant/TestInstanceAutoJoin.java +++ b/helix-core/src/test/java/org/apache/helix/integration/paticipant/TestInstanceAutoJoin.java @@ -1,16 +1,22 @@ package org.apache.helix.integration.paticipant; import org.apache.helix.HelixDataAccessor; +import org.apache.helix.HelixException; import org.apache.helix.HelixManager; +import org.apache.helix.PropertyKey; +import org.apache.helix.cloud.constants.CloudProvider; import org.apache.helix.integration.common.ZkStandAloneCMTestBase; import org.apache.helix.integration.manager.MockParticipantManager; import org.apache.helix.manager.zk.ZKHelixManager; +import org.apache.helix.model.CloudConfig; import org.apache.helix.model.ConfigScope; import org.apache.helix.model.IdealState.RebalanceMode; import org.apache.helix.model.builder.ConfigScopeBuilder; import org.testng.Assert; import org.testng.annotations.Test; +import static org.testng.Assert.*; + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -32,14 +38,15 @@ import org.testng.annotations.Test; public class TestInstanceAutoJoin extends ZkStandAloneCMTestBase { String db2 = TEST_DB + "2"; + String db3 = TEST_DB + "3"; @Test public void testInstanceAutoJoin() throws Exception { HelixManager manager = _participants[0]; HelixDataAccessor accessor = manager.getHelixDataAccessor(); - _gSetupTool.addResourceToCluster(CLUSTER_NAME, db2, 60, "OnlineOffline", RebalanceMode.FULL_AUTO - + ""); + _gSetupTool.addResourceToCluster(CLUSTER_NAME, db2, 60, "OnlineOffline", + RebalanceMode.FULL_AUTO + ""); _gSetupTool.rebalanceStorageCluster(CLUSTER_NAME, db2, 1); String instance2 = "localhost_279699"; @@ -50,8 +57,8 @@ public class TestInstanceAutoJoin extends ZkStandAloneCMTestBase { Thread.sleep(500); // Assert.assertFalse(result._thread.isAlive()); - Assert.assertTrue(null == manager.getHelixDataAccessor().getProperty( - accessor.keyBuilder().liveInstance(instance2))); + Assert.assertTrue(null == manager.getHelixDataAccessor() + .getProperty(accessor.keyBuilder().liveInstance(instance2))); ConfigScope scope = new ConfigScopeBuilder().forCluster(CLUSTER_NAME).build(); @@ -63,15 +70,54 @@ public class TestInstanceAutoJoin extends ZkStandAloneCMTestBase { Thread.sleep(500); // Assert.assertTrue(result._thread.isAlive() || result2._thread.isAlive()); for (int i = 0; i < 20; i++) { - if (null == manager.getHelixDataAccessor().getProperty( - accessor.keyBuilder().liveInstance(instance2))) { + if (null == manager.getHelixDataAccessor() + .getProperty(accessor.keyBuilder().liveInstance(instance2))) { Thread.sleep(100); } else break; } - Assert.assertTrue(null != manager.getHelixDataAccessor().getProperty( - accessor.keyBuilder().liveInstance(instance2))); + Assert.assertTrue(null != manager.getHelixDataAccessor() + .getProperty(accessor.keyBuilder().liveInstance(instance2))); newParticipant.syncStop(); } + + @Test(dependsOnMethods = "testInstanceAutoJoin") + public void testAutoRegistrationShouldFailWhenWaitingResponse() throws Exception { + // Create CloudConfig object and add to config + CloudConfig.Builder cloudConfigBuilder = new CloudConfig.Builder(); + cloudConfigBuilder.setCloudEnabled(true); + cloudConfigBuilder.setCloudProvider(CloudProvider.AZURE); + cloudConfigBuilder.setCloudID("TestID"); + CloudConfig cloudConfig = cloudConfigBuilder.build(); + + HelixManager manager = _participants[0]; + HelixDataAccessor accessor = manager.getHelixDataAccessor(); + + _gSetupTool.addResourceToCluster(CLUSTER_NAME, db3, 60, "OnlineOffline", + RebalanceMode.FULL_AUTO + ""); + _gSetupTool.rebalanceStorageCluster(CLUSTER_NAME, db3, 1); + String instance3 = "localhost_279700"; + + ConfigScope scope = new ConfigScopeBuilder().forCluster(CLUSTER_NAME).build(); + + manager.getConfigAccessor().set(scope, ZKHelixManager.ALLOW_PARTICIPANT_AUTO_JOIN, "true"); + // Write the CloudConfig to Zookeeper + PropertyKey.Builder keyBuilder = accessor.keyBuilder(); + accessor.setProperty(keyBuilder.cloudConfig(), cloudConfig); + + MockParticipantManager autoParticipant = + new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instance3); + autoParticipant.syncStart(); + + Assert.assertTrue(null == manager.getHelixDataAccessor() + .getProperty(accessor.keyBuilder().liveInstance(instance3))); + try { + manager.getConfigAccessor().getInstanceConfig(CLUSTER_NAME, instance3); + fail( + "Exception should be thrown because the instance cannot be added to the cluster due to the disconnection with Azure endpoint"); + } catch (HelixException e) { + + } + } }
