// Path: job/src/main/java/com/palominolabs/benchpress/job/task/TaskFactory.java
// @NotThreadSafe
// public interface TaskFactory {
// 
//     /**
//      * @param jobId                      job id
//      * @param sliceId                    the slice of the overall job that these tasks are part of
//      * @param workerId                   the worker that these tasks are running in
//      * @param progressClient             client the workers can use to hand any notable data back to the controller
//      * @return runnables
//      * @throws IOException if task creation fails
//      */
//     @Nonnull
//     Collection<Runnable> getRunnables(@Nonnull UUID jobId, int sliceId, @Nonnull UUID workerId,
//             @Nonnull ScopedProgressClient progressClient) throws
//             IOException;
// 
//     // TODO actually call this somewhere
//     void shutdown();
// }
// 
// Path: task-reporting/src/main/java/com/palominolabs/benchpress/task/reporting/ScopedProgressClient.java
// public class ScopedProgressClient {
// 
//     private final UUID jobId;
// 
//     private final int sliceId;
// 
//     private final String jobFinishedUrl;
//     private final String jobProgressUrl;
//     private final TaskProgressClient client;
// 
//     public ScopedProgressClient(UUID jobId, int sliceId, String jobFinishedUrl, String jobProgressUrl, TaskProgressClient client) {
//         this.jobId = jobId;
//         this.sliceId = sliceId;
//         this.jobFinishedUrl = jobFinishedUrl;
//         this.jobProgressUrl = jobProgressUrl;
//         this.client = client;
//     }
// 
//     public void reportFinished(Duration duration) {
//         client.reportFinished(jobId, sliceId, duration, jobFinishedUrl);
//     }
// 
//     public void reportProgress(JsonNode data) {
//         client.reportProgress(jobId, sliceId, data, jobProgressUrl);
//     }
// }


import com.fasterxml.jackson.databind.node.TextNode;
import com.ning.http.client.AsyncCompletionHandler;
import com.ning.http.client.AsyncHttpClient;
import com.ning.http.client.Response;
import com.palominolabs.benchpress.job.task.TaskFactory;
import com.palominolabs.benchpress.task.reporting.ScopedProgressClient;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import javax.annotation.Nonnull;
import static com.google.common.collect.Lists.newArrayList;
package com.palominolabs.benchpress.task.simplehttp;



final class SimpleHttpTaskFactory implements TaskFactory {
    private final String url;

    SimpleHttpTaskFactory(String url) {
        this.url = url;
    }

    @Nonnull
    @Override
    public Collection<Runnable> getRunnables(@Nonnull UUID jobId, int sliceId, @Nonnull UUID workerId,
            @Nonnull ScopedProgressClient progressClient) throws IOException {
        List<Runnable> runnables = newArrayList();

        runnables.add(() -> {
            AsyncHttpClient client = new AsyncHttpClient();
            try {
                client.prepareGet(url).execute(new AsyncCompletionHandler<Object>() {
                    @Override
                    public Object onCompleted(Response response) throws Exception {
                        progressClient.reportProgress(new TextNode(response.getResponseBody()));
                        return null;
                    }
                }).get();
            } catch (InterruptedException | ExecutionException | IOException e) {
                throw new RuntimeException(e);
            }
        });
        return runnables;
    }

    @Override
// Path: job/src/main/java/com/palominolabs/benchpress/job/task/TaskFactory.java
// @NotThreadSafe
// public interface TaskFactory {
// 
//     /**
//      * @param jobId                      job id
//      * @param sliceId                    the slice of the overall job that these tasks are part of
//      * @param workerId                   the worker that these tasks are running in
//      * @param progressClient             client the workers can use to hand any notable data back to the controller
//      * @return runnables
//      * @throws IOException if task creation fails
//      */
//     @Nonnull
//     Collection<Runnable> getRunnables(@Nonnull UUID jobId, int sliceId, @Nonnull UUID workerId,
//             @Nonnull ScopedProgressClient progressClient) throws
//             IOException;
// 
//     // TODO actually call this somewhere
//     void shutdown();
// }
// 
// Path: task-reporting/src/main/java/com/palominolabs/benchpress/task/reporting/ScopedProgressClient.java
// public class ScopedProgressClient {
// 
//     private final UUID jobId;
// 
//     private final int sliceId;
// 
//     private final String jobFinishedUrl;
//     private final String jobProgressUrl;
//     private final TaskProgressClient client;
// 
//     public ScopedProgressClient(UUID jobId, int sliceId, String jobFinishedUrl, String jobProgressUrl, TaskProgressClient client) {
//         this.jobId = jobId;
//         this.sliceId = sliceId;
//         this.jobFinishedUrl = jobFinishedUrl;
//         this.jobProgressUrl = jobProgressUrl;
//         this.client = client;
//     }
// 
//     public void reportFinished(Duration duration) {
//         client.reportFinished(jobId, sliceId, duration, jobFinishedUrl);
//     }
// 
//     public void reportProgress(JsonNode data) {
//         client.reportProgress(jobId, sliceId, data, jobProgressUrl);
//     }
// }


// Path: integration-test/src/test/java/com/palominolabs/benchpress/task/simplehttp/SimpleHttpTaskFactory.java
import com.fasterxml.jackson.databind.node.TextNode;
import com.ning.http.client.AsyncCompletionHandler;
import com.ning.http.client.AsyncHttpClient;
import com.ning.http.client.Response;
import com.palominolabs.benchpress.job.task.TaskFactory;
import com.palominolabs.benchpress.task.reporting.ScopedProgressClient;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import javax.annotation.Nonnull;
import static com.google.common.collect.Lists.newArrayList;

package com.palominolabs.benchpress.task.simplehttp;



final class SimpleHttpTaskFactory implements TaskFactory {
    private final String url;

    SimpleHttpTaskFactory(String url) {
        this.url = url;
    }

    @Nonnull
    @Override
    public Collection<Runnable> getRunnables(@Nonnull UUID jobId, int sliceId, @Nonnull UUID workerId,
            @Nonnull ScopedProgressClient progressClient) throws IOException {
        List<Runnable> runnables = newArrayList();

        runnables.add(() -> {
            AsyncHttpClient client = new AsyncHttpClient();
            try {
                client.prepareGet(url).execute(new AsyncCompletionHandler<Object>() {
                    @Override
                    public Object onCompleted(Response response) throws Exception {
                        progressClient.reportProgress(new TextNode(response.getResponseBody()));
                        return null;
                    }
                }).get();
            } catch (InterruptedException | ExecutionException | IOException e) {
                throw new RuntimeException(e);
            }
        });
        return runnables;
    }

    @Override
    public void shutdown() {