package org.apache.poi.benchmark.suite;

import com.google.common.base.Preconditions;
import org.apache.commons.exec.CommandLine;
import org.dstadler.commons.exec.BufferingLogOutputStream;
import org.dstadler.commons.exec.ExecutionHelper;
import org.openjdk.jmh.annotations.*;

import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.util.concurrent.TimeUnit;

@BenchmarkMode(Mode.SingleShotTime)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@State(Scope.Thread)
@Fork(value = 0, warmups = 0)
public abstract class BaseBenchmark {
    protected final File srcDir = new File("sources");

    @Setup
    public final void baseSetUp() throws IOException {
        // ensure directories
        if(!srcDir.exists()) {
            Preconditions.checkState(srcDir.mkdir(), "Could not create directory " + srcDir.getAbsolutePath());
        }

        svnCheckout();
    }

    private void svnCheckout() throws IOException {
        // svn checkout/update
        try (OutputStream out = new BufferingLogOutputStream()) {
            CommandLine cmd = new CommandLine("svn");
            if(new File(srcDir, ".svn").exists()) {
                cmd.addArgument("up");
                ExecutionHelper.getCommandResultIntoStream(cmd, srcDir, 0, 60000, out);
            } else {
                cmd.addArgument("co");
                cmd.addArgument("https://svn.apache.org/repos/asf/poi/trunk");
                cmd.addArgument(srcDir.getName());
                ExecutionHelper.getCommandResultIntoStream(cmd, srcDir.getParentFile(), 0, 60000, out);
            }
        }
    }

    protected void clean() throws IOException {
        runAntTarget("clean", 120000);
    }

    protected void compileAll() throws IOException {
        runAntTarget("compile-all", 1200000);
    }

    protected void testMain() throws IOException {
        runAntTarget("test-main", 1200000);
    }

    protected void testScratchpad() throws IOException {
        runAntTarget("test-scratchpad", 1200000);
    }

    protected void testOOXML() throws IOException {
        runAntTarget("test-ooxml", 1200000);
    }

    protected void testOOXMLLite() throws IOException {
        runAntTarget("test-ooxml-lite", 1200000);
    }

    protected void testExcelant() throws IOException {
        runAntTarget("test-excelant", 1200000);
    }

    protected void testIntegration() throws IOException {
        runAntTarget("test-integration", 1200000);
    }

    private void runAntTarget(String target, long timeout) throws IOException {
        try (OutputStream out = new BufferingLogOutputStream()) {
            CommandLine cmd = new CommandLine("ant");
            cmd.addArgument(target);
            ExecutionHelper.getCommandResultIntoStream(cmd, srcDir, 0, timeout, out);
        }
    }
}

@@ -1774,31 +1774,50 @@
 mpile-all%22, 
-1200000
+TimeUnit.HOURS.toMillis(1)
 );%0A    %7D%0A%0A  
@@ -1895,31 +1895,50 @@
 test-main%22, 
-1200000
+TimeUnit.HOURS.toMillis(1)
 );%0A    %7D%0A%0A  
@@ -2032,23 +2032,42 @@
 chpad%22, 
-1200000
+TimeUnit.HOURS.toMillis(1)
 );%0A    %7D
@@ -2155,23 +2155,42 @@
 ooxml%22, 
-1200000
+TimeUnit.HOURS.toMillis(1)
 );%0A    %7D
@@ -2287,23 +2287,42 @@
 -lite%22, 
-1200000
+TimeUnit.HOURS.toMillis(1)
 );%0A    %7D
@@ -2416,23 +2416,42 @@
 elant%22, 
-1200000
+TimeUnit.HOURS.toMillis(1)
 );%0A    %7D
@@ -2555,15 +2555,34 @@
 n%22, 
-1200000
+TimeUnit.HOURS.toMillis(1)
 );%0A 

Increase timeout to a much higher value to see if that made integration tests fail before