Search in sources :

Example 1 with IndexingServiceCondition

use of org.apache.druid.indexing.common.IndexingServiceCondition in project druid by druid-io.

the class RemoteTaskRunnerTest method testWorkerZKReconnect.

@Test
public void testWorkerZKReconnect() throws Exception {
    makeWorker();
    makeRemoteTaskRunner(new TestRemoteTaskRunnerConfig(new Period("PT5M")));
    Future<TaskStatus> future = remoteTaskRunner.run(task);
    Assert.assertTrue(taskAnnounced(task.getId()));
    mockWorkerRunningTask(task);
    Assert.assertTrue(workerRunningTask(task.getId()));
    byte[] bytes = cf.getData().forPath(ANNOUCEMENTS_PATH);
    cf.delete().forPath(ANNOUCEMENTS_PATH);
    // worker task cleanup scheduled
    Assert.assertTrue(TestUtils.conditionValid(new IndexingServiceCondition() {

        @Override
        public boolean isValid() {
            return remoteTaskRunner.getRemovedWorkerCleanups().containsKey(worker.getHost());
        }
    }));
    // Worker got reconnected
    cf.create().forPath(ANNOUCEMENTS_PATH, bytes);
    // worker task cleanup should get cancelled and removed
    Assert.assertTrue(TestUtils.conditionValid(new IndexingServiceCondition() {

        @Override
        public boolean isValid() {
            return !remoteTaskRunner.getRemovedWorkerCleanups().containsKey(worker.getHost());
        }
    }));
    mockWorkerCompleteSuccessfulTask(task);
    TaskStatus status = future.get();
    Assert.assertEquals(status.getStatusCode(), TaskState.SUCCESS);
    Assert.assertEquals(TaskState.SUCCESS, status.getStatusCode());
}
Also used : IndexingServiceCondition(org.apache.druid.indexing.common.IndexingServiceCondition) Period(org.joda.time.Period) TaskStatus(org.apache.druid.indexer.TaskStatus) Test(org.junit.Test)

Example 2 with IndexingServiceCondition

use of org.apache.druid.indexing.common.IndexingServiceCondition in project druid by druid-io.

the class RemoteTaskRunnerTest method testRunSameAvailabilityGroup.

@Test
public void testRunSameAvailabilityGroup() throws Exception {
    doSetup();
    TestRealtimeTask task1 = new TestRealtimeTask("rt1", new TaskResource("rt1", 1), "foo", TaskStatus.running("rt1"), jsonMapper);
    remoteTaskRunner.run(task1);
    Assert.assertTrue(taskAnnounced(task1.getId()));
    mockWorkerRunningTask(task1);
    TestRealtimeTask task2 = new TestRealtimeTask("rt2", new TaskResource("rt1", 1), "foo", TaskStatus.running("rt2"), jsonMapper);
    remoteTaskRunner.run(task2);
    TestRealtimeTask task3 = new TestRealtimeTask("rt3", new TaskResource("rt2", 1), "foo", TaskStatus.running("rt3"), jsonMapper);
    remoteTaskRunner.run(task3);
    Assert.assertTrue(TestUtils.conditionValid(new IndexingServiceCondition() {

        @Override
        public boolean isValid() {
            return remoteTaskRunner.getRunningTasks().size() == 2;
        }
    }));
    Assert.assertTrue(TestUtils.conditionValid(new IndexingServiceCondition() {

        @Override
        public boolean isValid() {
            return remoteTaskRunner.getPendingTasks().size() == 1;
        }
    }));
    Assert.assertTrue(remoteTaskRunner.getPendingTasks().iterator().next().getTaskId().equals("rt2"));
}
Also used : TestRealtimeTask(org.apache.druid.indexing.common.TestRealtimeTask) TaskResource(org.apache.druid.indexing.common.task.TaskResource) IndexingServiceCondition(org.apache.druid.indexing.common.IndexingServiceCondition) Test(org.junit.Test)

Example 3 with IndexingServiceCondition

use of org.apache.druid.indexing.common.IndexingServiceCondition in project druid by druid-io.

the class RemoteTaskRunnerTest method testWorkerRemoved.

@Test
public void testWorkerRemoved() throws Exception {
    doSetup();
    Assert.assertEquals(3, remoteTaskRunner.getTotalTaskSlotCount().get(WorkerConfig.DEFAULT_CATEGORY).longValue());
    Assert.assertEquals(3, remoteTaskRunner.getIdleTaskSlotCount().get(WorkerConfig.DEFAULT_CATEGORY).longValue());
    Future<TaskStatus> future = remoteTaskRunner.run(task);
    Assert.assertTrue(taskAnnounced(task.getId()));
    mockWorkerRunningTask(task);
    Assert.assertTrue(workerRunningTask(task.getId()));
    cf.delete().forPath(ANNOUCEMENTS_PATH);
    TaskStatus status = future.get();
    Assert.assertEquals(TaskState.FAILED, status.getStatusCode());
    Assert.assertNotNull(status.getErrorMsg());
    Assert.assertTrue(status.getErrorMsg().contains("Canceled for worker cleanup"));
    RemoteTaskRunnerConfig config = remoteTaskRunner.getRemoteTaskRunnerConfig();
    Assert.assertTrue(TestUtils.conditionValid(new IndexingServiceCondition() {

        @Override
        public boolean isValid() {
            return remoteTaskRunner.getRemovedWorkerCleanups().isEmpty();
        }
    }, // cleanup task is independently scheduled by event listener. we need to wait some more time.
    config.getTaskCleanupTimeout().toStandardDuration().getMillis() * 2));
    Assert.assertNull(cf.checkExists().forPath(STATUS_PATH));
    Assert.assertFalse(remoteTaskRunner.getTotalTaskSlotCount().containsKey(WorkerConfig.DEFAULT_CATEGORY));
    Assert.assertFalse(remoteTaskRunner.getIdleTaskSlotCount().containsKey(WorkerConfig.DEFAULT_CATEGORY));
}
Also used : IndexingServiceCondition(org.apache.druid.indexing.common.IndexingServiceCondition) TaskStatus(org.apache.druid.indexer.TaskStatus) RemoteTaskRunnerConfig(org.apache.druid.indexing.overlord.config.RemoteTaskRunnerConfig) Test(org.junit.Test)

Example 4 with IndexingServiceCondition

use of org.apache.druid.indexing.common.IndexingServiceCondition in project druid by druid-io.

the class RemoteTaskRunnerTest method testRunWithCapacity.

@Test
public void testRunWithCapacity() throws Exception {
    doSetup();
    TestRealtimeTask task1 = new TestRealtimeTask("rt1", new TaskResource("rt1", 1), "foo", TaskStatus.running("rt1"), jsonMapper);
    remoteTaskRunner.run(task1);
    Assert.assertTrue(taskAnnounced(task1.getId()));
    mockWorkerRunningTask(task1);
    TestRealtimeTask task2 = new TestRealtimeTask("rt2", new TaskResource("rt2", 3), "foo", TaskStatus.running("rt2"), jsonMapper);
    remoteTaskRunner.run(task2);
    TestRealtimeTask task3 = new TestRealtimeTask("rt3", new TaskResource("rt3", 2), "foo", TaskStatus.running("rt3"), jsonMapper);
    remoteTaskRunner.run(task3);
    Assert.assertTrue(taskAnnounced(task3.getId()));
    mockWorkerRunningTask(task3);
    Assert.assertTrue(TestUtils.conditionValid(new IndexingServiceCondition() {

        @Override
        public boolean isValid() {
            return remoteTaskRunner.getRunningTasks().size() == 2;
        }
    }));
    Assert.assertTrue(TestUtils.conditionValid(new IndexingServiceCondition() {

        @Override
        public boolean isValid() {
            return remoteTaskRunner.getPendingTasks().size() == 1;
        }
    }));
    Assert.assertTrue(remoteTaskRunner.getPendingTasks().iterator().next().getTaskId().equals("rt2"));
}
Also used : TestRealtimeTask(org.apache.druid.indexing.common.TestRealtimeTask) TaskResource(org.apache.druid.indexing.common.task.TaskResource) IndexingServiceCondition(org.apache.druid.indexing.common.IndexingServiceCondition) Test(org.junit.Test)

Aggregations

IndexingServiceCondition (org.apache.druid.indexing.common.IndexingServiceCondition)4 Test (org.junit.Test)4 TaskStatus (org.apache.druid.indexer.TaskStatus)2 TestRealtimeTask (org.apache.druid.indexing.common.TestRealtimeTask)2 TaskResource (org.apache.druid.indexing.common.task.TaskResource)2 RemoteTaskRunnerConfig (org.apache.druid.indexing.overlord.config.RemoteTaskRunnerConfig)1 Period (org.joda.time.Period)1