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:
Maytas Monsereenusorn 2020-05-19 19:19:22 -10:00 committed by GitHub
parent 82e5b0573e
commit 5b4b5d77a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 1 deletions

View File

@ -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;
}

View File

@ -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
{