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.
This commit is contained in:
Gian Merlino 2016-01-06 13:42:42 -05:00
parent c82b680cd4
commit a355bfb7a9
3 changed files with 19 additions and 6 deletions

View File

@ -56,19 +56,25 @@ public abstract class AbstractTask implements Task
protected AbstractTask(String id, String dataSource, Map<String, Object> 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<String, Object> 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<String, Object> context)
protected AbstractTask(
String id,
String groupId,
TaskResource taskResource,
String dataSource,
Map<String, Object> 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;
}

View File

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

View File

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