package com.gregory.testing.run;

import com.google.common.collect.Lists;
import com.gregory.testing.application.Server;
import com.gregory.testing.message.Message;
import com.gregory.testing.result.BatchResult;

import java.util.ArrayList;
import java.util.List;

public final class TestRunner {

    private final TestCase testCase;

    public TestRunner(TestCase testCase) {
        this.testCase = testCase;
    }

    public List<BatchResult> run() throws Exception {
        switch (testCase.strategy()) {
            case CONSTANT_LOAD:
                return runConstantLoad();
            default:
                throw new RuntimeException("Strategy " + testCase.strategy().name() + " is not supported yet!");
        }
    }

    private List<BatchResult> runConstantLoad() throws Exception {
        int batchSize = testCase.initialBatchSize();
        Server server = testCase.server();
        List<Message> messages = testCase.messages();
        List<BatchResult> results = new ArrayList<>();
        int batchId = 0;
        for (List<Message> batchMessages : Lists.partition(messages, batchSize)) {
            BatchTask task = new BatchTask(batchId++, server, batchMessages);
            results.add(task.call());
        }
        return results;
    }

}

@@ -576,24 +576,104 @@
 tantLoad();%0A
+            case INCREMENTAL_LOAD:%0A                return runIncrementalLoad();%0A
             
@@ -1348,10 +1348,736 @@
 %0A    %7D%0A%0A
+    private List%3CBatchResult%3E runIncrementalLoad() throws Exception %7B%0A        int batchSize = testCase.initialBatchSize();%0A        Server server = testCase.server();%0A        List%3CMessage%3E messages = testCase.messages();%0A        List%3CBatchResult%3E results = new ArrayList%3C%3E();%0A        int batchId = 0;%0A        int messageIndex = 0;%0A        while(messageIndex %3C messages.size()) %7B%0A            List%3CMessage%3E batchMessages = messages.subList(messageIndex, Math.min(messages.size(), messageIndex + batchSize));%0A            messageIndex += batchSize;%0A            batchSize++;%0A            BatchTask task = new BatchTask(batchId++, server, batchMessages);%0A            results.add(task.call());%0A        %7D%0A        return results;%0A    %7D%0A%0A
 %7D%0A

Implement incremental load test