@Override public TaskLocation getLocation() { return TaskLocation.create("testHost", 10000, 10000); }
@Override public TaskLocation getLocation() { if (processHolder == null) { return TaskLocation.unknown(); } else { return TaskLocation.create(processHolder.host, processHolder.port, processHolder.tlsPort); } }
@Inject public SingleTaskBackgroundRunner( TaskToolboxFactory toolboxFactory, TaskConfig taskConfig, ServiceEmitter emitter, @Self DruidNode node, ServerConfig serverConfig ) { this.toolboxFactory = Preconditions.checkNotNull(toolboxFactory, "toolboxFactory"); this.taskConfig = taskConfig; this.emitter = Preconditions.checkNotNull(emitter, "emitter"); this.location = TaskLocation.create(node.getHost(), node.getPlaintextPort(), node.getTlsPort()); this.serverConfig = serverConfig; }
@Test public void testSerde() throws IOException { final ObjectMapper mapper = new ObjectMapper(); mapper.registerModule( new SimpleModule() .addDeserializer(DateTime.class, new DateTimeDeserializer()) .addSerializer(DateTime.class, ToStringSerializer.instance) ); final TaskStatusPlus status = new TaskStatusPlus( "testId", "testType", DateTimes.nowUtc(), DateTimes.nowUtc(), TaskState.RUNNING, RunnerTaskState.RUNNING, 1000L, TaskLocation.create("testHost", 1010, -1), "ds_test", null ); final String json = mapper.writeValueAsString(status); Assert.assertEquals(status, mapper.readValue(json, TaskStatusPlus.class)); }
final TaskLocation taskLocation = TaskLocation.create(childHost, childPort, tlsChildPort);
task, TaskStatus.success(task.getId()), TaskLocation.create("worker", 1, 2) ), workerHolder); Assert.assertEquals(task.getId(), Iterables.getOnlyElement(taskRunner.getCompletedTasks()).getTaskId()); listenerNotificationsAccumulator, ImmutableList.of( ImmutableList.of(task.getId(), TaskLocation.create("worker", 1, 2)), ImmutableList.of(task.getId(), TaskStatus.success(task.getId()))
task1, TaskStatus.running(task1.getId()), TaskLocation.create("worker", 1, 2) ), workerHolder); task2, TaskStatus.success(task2.getId()), TaskLocation.create("worker", 3, 4) ), workerHolder); task3, TaskStatus.running(task3.getId()), TaskLocation.create("worker", 5, 6) ), workerHolder); task4, TaskStatus.success(task4.getId()), TaskLocation.create("worker", 7, 8) ), workerHolder); task5, TaskStatus.running(task5.getId()), TaskLocation.create("worker", 9, 10) ), workerHolder); task6, TaskStatus.success(task6.getId()), TaskLocation.create("worker", 11, 12) ), workerHolder);
@Test public void failOnMalformedURLException() throws IOException { try (IndexTaskClient indexTaskClient = buildIndexTaskClient( EasyMock.createNiceMock(HttpClient.class), id -> TaskLocation.create(id, -2, -2) )) { expectedException.expect(MalformedURLException.class); expectedException.expectMessage("Invalid port number :-2"); indexTaskClient.submitRequestWithEmptyContent( "taskId", HttpMethod.GET, "test", null, true ); } }
@Test public void retryOnChannelException() throws IOException { final HttpClient httpClient = EasyMock.createNiceMock(HttpClient.class); EasyMock.expect(httpClient.go(EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.anyObject())) .andReturn(Futures.immediateFailedFuture(new ChannelException("IndexTaskClientTest"))) .times(2); EasyMock.expect(httpClient.go(EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.anyObject())) .andReturn( Futures.immediateFuture( new FullResponseHolder( HttpResponseStatus.OK, new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK), new StringBuilder() ) ) ) .once(); EasyMock.replay(httpClient); try (IndexTaskClient indexTaskClient = buildIndexTaskClient(httpClient, id -> TaskLocation.create(id, 8000, -1))) { final FullResponseHolder response = indexTaskClient.submitRequestWithEmptyContent( "taskId", HttpMethod.GET, "test", null, true ); Assert.assertEquals(HttpResponseStatus.OK, response.getStatus()); } }
task, TaskStatus.running(task.getId()), TaskLocation.create("worker", 1000, 1001) ), workerHolder); Assert.assertEquals(task.getId(), Iterables.getOnlyElement(taskRunner.getRunningTasks()).getTaskId()); task, TaskStatus.running(task.getId()), TaskLocation.create("worker", 1, 2) ), workerHolder); Assert.assertEquals(task.getId(), Iterables.getOnlyElement(taskRunner.getRunningTasks()).getTaskId()); task, TaskStatus.running(task.getId()), TaskLocation.create("worker", 1, 2) ), workerHolder); Assert.assertEquals(task.getId(), Iterables.getOnlyElement(taskRunner.getRunningTasks()).getTaskId()); task, TaskStatus.running(task.getId()), TaskLocation.create("rogue-worker", 1, 2) ), rogueWorkerHolder); Assert.assertEquals(task.getId(), Iterables.getOnlyElement(taskRunner.getRunningTasks()).getTaskId()); task, TaskStatus.failure(task.getId()), TaskLocation.create("rogue-worker", 1, 2) ), rogueWorkerHolder); Assert.assertEquals(task.getId(), Iterables.getOnlyElement(taskRunner.getRunningTasks()).getTaskId());
private static WorkerHolder createWorkerHolder( ObjectMapper smileMapper, HttpClient httpClient, HttpRemoteTaskRunnerConfig config, ScheduledExecutorService workersSyncExec, WorkerHolder.Listener listener, Worker worker, // simulates task announcements received from worker on first sync call for the tasks that are already // running/completed on the worker. List<TaskAnnouncement> preExistingTaskAnnouncements, // defines behavior for what to do when a particular task is assigned Map<Task, List<TaskAnnouncement>> toBeAssignedTasks, // incremented on each runnable completion in workersSyncExec, useful for deterministically watching that some // work completed AtomicInteger ticks, // Updated each time a shutdown(taskId) call is received, useful for asserting that expected shutdowns indeed // happened. Set<String> actualShutdowns ) { return new WorkerHolder(smileMapper, httpClient, config, workersSyncExec, listener, worker) { private final String workerHost = worker.getHost().substring(0, worker.getHost().indexOf(':')); private final int workerPort = Integer.parseInt(worker.getHost().substring(worker.getHost().indexOf(':') + 1)); @Override
task1, TaskStatus.success(task1.getId()), TaskLocation.create("w1", 1, -1) )), new WorkerHistoryItem.TaskUpdate(TaskAnnouncement.create( task2, TaskStatus.running(task2.getId()), TaskLocation.create("w1", 2, -1) )), new WorkerHistoryItem.TaskUpdate(TaskAnnouncement.create( task3, TaskStatus.running(task3.getId()), TaskLocation.create("w1", 2, -1) )) task3, TaskStatus.running(task3.getId()), TaskLocation.create("w1", 3, -1) )) task1, TaskStatus.success(task1.getId()), TaskLocation.create("w1", 1, -1) )), new WorkerHistoryItem.TaskUpdate(TaskAnnouncement.create( task2, TaskStatus.running(task2.getId()), TaskLocation.create("w1", 2, -1) )),
@Override public TaskLocation getLocation() { if (processHolder == null) { return TaskLocation.unknown(); } else { return TaskLocation.create(processHolder.host, processHolder.port, processHolder.tlsPort); } }
@Inject public SingleTaskBackgroundRunner( TaskToolboxFactory toolboxFactory, TaskConfig taskConfig, ServiceEmitter emitter, @Self DruidNode node, ServerConfig serverConfig ) { this.toolboxFactory = Preconditions.checkNotNull(toolboxFactory, "toolboxFactory"); this.taskConfig = taskConfig; this.emitter = Preconditions.checkNotNull(emitter, "emitter"); this.location = TaskLocation.create(node.getHost(), node.getPlaintextPort(), node.getTlsPort()); this.serverConfig = serverConfig; }
final TaskLocation taskLocation = TaskLocation.create(childHost, childPort, tlsChildPort);