From a355bfb7a917af3eeda258694a2c986b2a9e82ae Mon Sep 17 00:00:00 2001 From: Gian Merlino Date: Wed, 6 Jan 2016 13:42:42 -0500 Subject: [PATCH] Fix default TaskResource for RealtimeIndexTasks. It was supposed to be the same as the task id, but it wasn't because "makeTaskId" has a random component. --- .../druid/indexing/common/task/AbstractTask.java | 16 +++++++++++----- .../indexing/common/task/RealtimeIndexTask.java | 2 +- .../common/task/RealtimeIndexTaskTest.java | 7 +++++++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/indexing-service/src/main/java/io/druid/indexing/common/task/AbstractTask.java b/indexing-service/src/main/java/io/druid/indexing/common/task/AbstractTask.java index bb6359ea00c..67bf7227d3e 100644 --- a/indexing-service/src/main/java/io/druid/indexing/common/task/AbstractTask.java +++ b/indexing-service/src/main/java/io/druid/indexing/common/task/AbstractTask.java @@ -56,19 +56,25 @@ public abstract class AbstractTask implements Task protected AbstractTask(String id, String dataSource, Map context) { - this(id, id, new TaskResource(id, 1), dataSource, context); + this(id, null, null, dataSource, context); } protected AbstractTask(String id, String groupId, String dataSource, Map context) { - this(id, groupId, new TaskResource(id, 1), dataSource, context); + this(id, groupId, null, dataSource, context); } - protected AbstractTask(String id, String groupId, TaskResource taskResource, String dataSource, Map context) + protected AbstractTask( + String id, + String groupId, + TaskResource taskResource, + String dataSource, + Map context + ) { this.id = Preconditions.checkNotNull(id, "id"); - this.groupId = Preconditions.checkNotNull(groupId, "groupId"); - this.taskResource = Preconditions.checkNotNull(taskResource, "resource"); + this.groupId = groupId == null ? id : groupId; + this.taskResource = taskResource == null ? new TaskResource(id, 1) : taskResource; this.dataSource = Preconditions.checkNotNull(dataSource, "dataSource"); this.context = context; } diff --git a/indexing-service/src/main/java/io/druid/indexing/common/task/RealtimeIndexTask.java b/indexing-service/src/main/java/io/druid/indexing/common/task/RealtimeIndexTask.java index 192d79685c9..45deeffed41 100644 --- a/indexing-service/src/main/java/io/druid/indexing/common/task/RealtimeIndexTask.java +++ b/indexing-service/src/main/java/io/druid/indexing/common/task/RealtimeIndexTask.java @@ -142,7 +142,7 @@ public class RealtimeIndexTask extends AbstractTask super( id == null ? makeTaskId(fireDepartment) : id, String.format("index_realtime_%s", makeDatasource(fireDepartment)), - taskResource == null ? new TaskResource(makeTaskId(fireDepartment), 1) : taskResource, + taskResource, makeDatasource(fireDepartment), context ); diff --git a/indexing-service/src/test/java/io/druid/indexing/common/task/RealtimeIndexTaskTest.java b/indexing-service/src/test/java/io/druid/indexing/common/task/RealtimeIndexTaskTest.java index 269dd8099da..9cefaa10822 100644 --- a/indexing-service/src/test/java/io/druid/indexing/common/task/RealtimeIndexTaskTest.java +++ b/indexing-service/src/test/java/io/druid/indexing/common/task/RealtimeIndexTaskTest.java @@ -274,6 +274,13 @@ public class RealtimeIndexTaskTest ); } + @Test(timeout = 60_000L) + public void testDefaultResource() throws Exception + { + final RealtimeIndexTask task = makeRealtimeTask(null); + Assert.assertEquals(task.getId(), task.getTaskResource().getAvailabilityGroup()); + } + @Test(timeout = 60_000L) public void testBasics() throws Exception {