mirror of https://github.com/apache/druid.git
Fails creation of TaskResource if availabilityGroup is null (#9892)
* Fails creation of TaskResource if availabilityGroup is null * add check for requiredCapacity
This commit is contained in:
parent
82e5b0573e
commit
5b4b5d77a8
|
@ -21,6 +21,7 @@ package org.apache.druid.indexing.common.task;
|
|||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
/**
|
||||
*/
|
||||
|
@ -35,7 +36,8 @@ public class TaskResource
|
|||
@JsonProperty("requiredCapacity") int requiredCapacity
|
||||
)
|
||||
{
|
||||
this.availabilityGroup = availabilityGroup;
|
||||
this.availabilityGroup = Preconditions.checkNotNull(availabilityGroup, "availabilityGroup");
|
||||
Preconditions.checkArgument(requiredCapacity > 0);
|
||||
this.requiredCapacity = requiredCapacity;
|
||||
}
|
||||
|
||||
|
|
|
@ -185,6 +185,48 @@ public class TaskSerdeTest
|
|||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTaskResourceValid() throws Exception
|
||||
{
|
||||
TaskResource actual = jsonMapper.readValue(
|
||||
"{\"availabilityGroup\":\"index_xxx_mmm\", \"requiredCapacity\":1}",
|
||||
TaskResource.class
|
||||
);
|
||||
Assert.assertNotNull(actual);
|
||||
Assert.assertNotNull(actual.getAvailabilityGroup());
|
||||
Assert.assertTrue(actual.getRequiredCapacity() > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTaskResourceWithNullAvailabilityGroupShouldFail() throws Exception
|
||||
{
|
||||
thrown.expectCause(CoreMatchers.isA(NullPointerException.class));
|
||||
jsonMapper.readValue(
|
||||
"{\"availabilityGroup\":null, \"requiredCapacity\":10}",
|
||||
TaskResource.class
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTaskResourceWithZeroRequiredCapacityShouldFail() throws Exception
|
||||
{
|
||||
thrown.expectCause(CoreMatchers.isA(NullPointerException.class));
|
||||
jsonMapper.readValue(
|
||||
"{\"availabilityGroup\":null, \"requiredCapacity\":0}",
|
||||
TaskResource.class
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTaskResourceWithNegativeRequiredCapacityShouldFail() throws Exception
|
||||
{
|
||||
thrown.expectCause(CoreMatchers.isA(NullPointerException.class));
|
||||
jsonMapper.readValue(
|
||||
"{\"availabilityGroup\":null, \"requiredCapacity\":-1}",
|
||||
TaskResource.class
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIndexTaskSerde() throws Exception
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue