TaskSchedulerServiceHelper { public static void sendPatchToOwner(Service service, ServiceHost host, String taskSchedulerServiceSelfLink, TaskSchedulerService.State state, URI referLink) { Operation.CompletionHandler handler = (Operation op, Throwable failure) -> { if (null != failure) { ServiceUtils.logSevere(service, failure); return; } NodeSelectorService.SelectOwnerResponse rsp = op.getBody(NodeSelectorService.SelectOwnerResponse.class); Operation patch = Operation .createPatch(UriUtils.buildUri(rsp.ownerNodeGroupReference, taskSchedulerServiceSelfLink)) .setBody(state) .setReferer(referLink); host.sendRequest(patch); }; Operation selectOwnerOp = Operation .createPost(null) .setExpiration(ServiceUtils.computeExpirationTime(OWNER_SELECTION_TIMEOUT)) .setCompletion(handler); host.selectOwner(null, taskSchedulerServiceSelfLink, selectOwnerOp); }  static void sendPatchToOwner(Service service, ServiceHost host, String taskSchedulerServiceSelfLink,
                                      TaskSchedulerService.State state, URI referLink); static final long OWNER_SELECTION_TIMEOUT; }
@Test(dataProvider = "hostCount") public void testSendPatchToOwner(int count) throws Throwable { initEnvironment(count); startDummyServices(3, 0); TaskSchedulerServiceHelper.sendPatchToOwner(service, host, selfLink, new TaskSchedulerService.State(), UriUtils.buildUri(host, selfLink)); QueryTask query = QueryTask.create( QueryTaskUtils.buildTaskStatusQuerySpec( TestServiceWithStage.State.class, TaskState.TaskStage.STARTED)) .setDirect(true); QueryTask response = environment.waitForQuery(query, (QueryTask queryTask) -> queryTask.results.documentLinks.size() >= 3); assertThat(response.results.documentLinks.size(), is(3)); }