You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@helix.apache.org by jx...@apache.org on 2020/08/13 23:11:03 UTC
[helix] branch master updated: Change TestInstanceAutoJoin to adapt
to cloud environment (#1265)
This is an automated email from the ASF dual-hosted git repository.
jxue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/helix.git
The following commit(s) were added to refs/heads/master by this push:
new cb66bcc Change TestInstanceAutoJoin to adapt to cloud environment (#1265)
cb66bcc is described below
commit cb66bcc0889df1a8214f56fb2d2883a973b9b87c
Author: Meng Zhang <mn...@linkedin.com>
AuthorDate: Thu Aug 13 16:10:54 2020 -0700
Change TestInstanceAutoJoin to adapt to cloud environment (#1265)
Change TestInstanceAutoJoin to adapt to cloud environment
---
.../AzureCloudInstanceInformationProcessor.java | 6 +++---
.../paticipant/TestInstanceAutoJoin.java | 25 ++++++++++++++--------
2 files changed, 19 insertions(+), 12 deletions(-)
diff --git a/helix-core/src/main/java/org/apache/helix/cloud/azure/AzureCloudInstanceInformationProcessor.java b/helix-core/src/main/java/org/apache/helix/cloud/azure/AzureCloudInstanceInformationProcessor.java
index f0f75f7..c943664 100644
--- a/helix-core/src/main/java/org/apache/helix/cloud/azure/AzureCloudInstanceInformationProcessor.java
+++ b/helix-core/src/main/java/org/apache/helix/cloud/azure/AzureCloudInstanceInformationProcessor.java
@@ -109,7 +109,7 @@ public class AzureCloudInstanceInformationProcessor
CloseableHttpResponse response = _closeableHttpClient.execute(httpGet);
if (response == null || response.getStatusLine().getStatusCode() != 200) {
String errorMsg = String.format(
- "Failed to get an HTTP Response for the request. Response: {}. Status code: {}",
+ "Failed to get an HTTP Response for the request. Response: %s. Status code: %s",
(response == null ? "NULL" : response.getStatusLine().getReasonPhrase()),
response.getStatusLine().getStatusCode());
throw new HelixException(errorMsg);
@@ -119,7 +119,7 @@ public class AzureCloudInstanceInformationProcessor
return responseString;
} catch (IOException e) {
throw new HelixException(
- String.format("Failed to get Azure cloud instance information from url {}", url), e);
+ String.format("Failed to get Azure cloud instance information from url %s", url), e);
}
}
@@ -153,7 +153,7 @@ public class AzureCloudInstanceInformationProcessor
}
} catch (IOException e) {
throw new HelixException(
- String.format("Error in parsing cloud instance information: {}", response, e));
+ String.format("Error in parsing cloud instance information: %s", response, e));
}
return azureCloudInstanceInformation;
}
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 3a48f53..d0a72e4 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
@@ -4,6 +4,7 @@ import org.apache.helix.HelixDataAccessor;
import org.apache.helix.HelixException;
import org.apache.helix.HelixManager;
import org.apache.helix.PropertyKey;
+import org.apache.helix.TestHelper;
import org.apache.helix.cloud.constants.CloudProvider;
import org.apache.helix.integration.common.ZkStandAloneCMTestBase;
import org.apache.helix.integration.manager.MockParticipantManager;
@@ -15,8 +16,6 @@ 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
@@ -83,12 +82,11 @@ public class TestInstanceAutoJoin extends ZkStandAloneCMTestBase {
}
@Test(dependsOnMethods = "testInstanceAutoJoin")
- public void testAutoRegistrationShouldFailWhenWaitingResponse() throws Exception {
+ public void testAutoRegistration() 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];
@@ -110,14 +108,23 @@ public class TestInstanceAutoJoin extends ZkStandAloneCMTestBase {
new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instance3);
autoParticipant.syncStart();
- Assert.assertTrue(null == manager.getHelixDataAccessor()
- .getProperty(accessor.keyBuilder().liveInstance(instance3)));
+ // if the test is run in cloud environment, auto registration will succeed and live instance
+ // will be added, otherwise, auto registration will fail and instance config will not be
+ // populated. An exception will be thrown.
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");
+ Assert.assertTrue(TestHelper.verify(() -> {
+ if (null == manager.getHelixDataAccessor()
+ .getProperty(accessor.keyBuilder().liveInstance(instance3))) {
+ return false;
+ }
+ return true;
+ }, 2000));
} catch (HelixException e) {
-
+ Assert.assertTrue(null == manager.getHelixDataAccessor()
+ .getProperty(accessor.keyBuilder().liveInstance(instance3)));
}
+
+ autoParticipant.syncStop();
}
}