xyuanlu commented on a change in pull request #1129:
URL: https://github.com/apache/helix/pull/1129#discussion_r447263950



##########
File path: 
helix-rest/src/test/java/org/apache/helix/rest/server/TestPerInstanceAccessor.java
##########
@@ -463,5 +464,53 @@ public void testValidateWeightForInstance()
     // Must have the results saying they are all valid (true) because capacity 
keys are set
     // in ClusterConfig
     node.iterator().forEachRemaining(child -> 
Assert.assertTrue(child.getBooleanValue()));
+    System.out.println("End test :" + TestHelper.getTestMethodName());
+  }
+
+  @Test(dependsOnMethods = "testValidateWeightForInstance")
+  public void testValidateDeltaInstanceConfigForUpdate() throws IOException {
+    System.out.println("Start test :" + TestHelper.getTestMethodName());
+    // Enable Topology aware for the cluster
+    ClusterConfig clusterConfig = 
_configAccessor.getClusterConfig(CLUSTER_NAME);
+    clusterConfig.getRecord()
+        
.setListField(ClusterConfig.ClusterConfigProperty.INSTANCE_CAPACITY_KEYS.name(),
+            new ArrayList<>());
+    clusterConfig.setTopologyAwareEnabled(true);
+    clusterConfig.setTopology("/Rack/Sub-Rack/Host/Instance");
+    clusterConfig.setFaultZoneType("Host");
+    _configAccessor.setClusterConfig(CLUSTER_NAME, clusterConfig);
+
+    String instanceName = CLUSTER_NAME + "localhost_12918";
+    InstanceConfig instanceConfig = 
_configAccessor.getInstanceConfig(CLUSTER_NAME, instanceName);
+
+    // Update InstanceConfig with Topology Info
+    String domain = "Rack=rack1, Sub-Rack=Sub-Rack1, Host=Host-1";
+    ZNRecord record = instanceConfig.getRecord();
+    
record.getSimpleFields().put(InstanceConfig.InstanceConfigProperty.DOMAIN.name(),
 domain);
+
+    // Add these fields by way of "update"
+    Entity entity =
+        Entity.entity(OBJECT_MAPPER.writeValueAsString(record), 
MediaType.APPLICATION_JSON_TYPE);
+    Response response = new JerseyUriRequestBuilder(
+        "clusters/{}/instances/{}/configs?command=update&doSanityCheck=true")
+        .format(CLUSTER_NAME, INSTANCE_NAME).post(this, entity);
+    // Check that the fields have been added
+    Assert.assertEquals(response.getStatus(), 200);
+    // Check the cluster config is updated
+    Assert.assertEquals(
+        _configAccessor.getInstanceConfig(CLUSTER_NAME, 
instanceName).getDomainAsString(), domain);
+
+    // set domain to an invalid value
+    record.getSimpleFields()
+        .put(InstanceConfig.InstanceConfigProperty.DOMAIN.name(), 
"InvalidDomainValue");
+    entity =
+        Entity.entity(OBJECT_MAPPER.writeValueAsString(record), 
MediaType.APPLICATION_JSON_TYPE);
+    // Updating using an invalid domain value should return a non-OK response
+    new JerseyUriRequestBuilder(
+        "clusters/{}/instances/{}/configs?command=update&doSanityCheck=true")
+        
.expectedReturnStatusCode(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode())
+        .format(CLUSTER_NAME, INSTANCE_NAME).post(this, entity);

Review comment:
       TFTR.
   Result is validated at line 511. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to