-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[controller] Make to_be_stopped_instances in aggregatedHealthStatus A…
…PI optional (#1274) In Helix's aggregated stoppable check, the "to_be_stopped_instances" is optional and will be omitted in case there are no instances that have previously been approved. This commit makes our controller handle this.
- Loading branch information
1 parent
66bfa36
commit 9b6f027
Showing
6 changed files
with
107 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...on/src/test/java/com/linkedin/venice/controllerapi/TestAggregatedHealthStatusRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.linkedin.venice.controllerapi; | ||
|
||
import static org.testng.Assert.assertEquals; | ||
import static org.testng.Assert.assertNotNull; | ||
import static org.testng.Assert.assertTrue; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.exc.ValueInstantiationException; | ||
import com.linkedin.venice.utils.ObjectMapperFactory; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
|
||
public class TestAggregatedHealthStatusRequest { | ||
private static final ObjectMapper OBJECT_MAPPER = ObjectMapperFactory.getInstance(); | ||
|
||
@Test | ||
public void testDeserializationWithAllFields() throws JsonProcessingException { | ||
String json = | ||
"{\"cluster_id\":\"cluster1\",\"instances\":[\"instance1\",\"instance2\"],\"to_be_stopped_instances\":[\"instance3\",\"instance4\"]}"; | ||
AggregatedHealthStatusRequest request = OBJECT_MAPPER.readValue(json, AggregatedHealthStatusRequest.class); | ||
|
||
assertEquals(request.getClusterId(), "cluster1"); | ||
assertEquals(request.getInstances().size(), 2); | ||
assertEquals(request.getInstances().get(0), "instance1"); | ||
assertEquals(request.getInstances().get(1), "instance2"); | ||
assertEquals(request.getToBeStoppedInstances().size(), 2); | ||
assertEquals(request.getToBeStoppedInstances().get(0), "instance3"); | ||
assertEquals(request.getToBeStoppedInstances().get(1), "instance4"); | ||
} | ||
|
||
@Test | ||
public void testDeserializationWithMandatoryFields() throws JsonProcessingException { | ||
String json = "{\"cluster_id\":\"cluster1\",\"instances\":[\"instance1\",\"instance2\"]}"; | ||
AggregatedHealthStatusRequest request = OBJECT_MAPPER.readValue(json, AggregatedHealthStatusRequest.class); | ||
|
||
assertEquals(request.getClusterId(), "cluster1"); | ||
assertEquals(request.getInstances().size(), 2); | ||
assertEquals(request.getInstances().get(0), "instance1"); | ||
assertEquals(request.getInstances().get(1), "instance2"); | ||
assertNotNull(request.getToBeStoppedInstances()); | ||
assertTrue(request.getToBeStoppedInstances().isEmpty()); | ||
} | ||
|
||
@Test | ||
public void testDeserializationWithMissingMandatoryFields() { | ||
String json = "{\"instances\":[\"instance1\",\"instance2\"]}"; | ||
ValueInstantiationException e = Assert.expectThrows( | ||
ValueInstantiationException.class, | ||
() -> OBJECT_MAPPER.readValue(json, AggregatedHealthStatusRequest.class)); | ||
assertTrue(e.getMessage().contains("'cluster_id' is required"), e.getMessage()); | ||
|
||
String json2 = "{\"cluster_id\":\"cluster1\"}"; | ||
ValueInstantiationException e2 = Assert.expectThrows( | ||
ValueInstantiationException.class, | ||
() -> OBJECT_MAPPER.readValue(json2, AggregatedHealthStatusRequest.class)); | ||
assertTrue(e2.getMessage().contains("'instances' is required"), e2.getMessage()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters