/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.pdfbox;

import org.junit.runners.Parameterized;
import org.junit.runners.model.RunnerScheduler;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * Runs Parameterized JUnit tests in parallel.
 *
 * @see {http://goo.gl/lkigES}
 */
public class ParallelParameterized extends Parameterized
{
    static final long TIMEOUT_SECS = 30;

    private static class FixedThreadPoolScheduler implements RunnerScheduler
    {
        private ExecutorService executorService;

        FixedThreadPoolScheduler()
        {
            int cores = Runtime.getRuntime().availableProcessors();

            // workaround Open JDK 6 bug which causes CMMException: Invalid profile data
            System.out.println("JDK: " + System.getProperty("java.runtime.name"));
            if (System.getProperty("java.runtime.name").equals("OpenJDK Runtime Environment") &&
                System.getProperty("java.specification.version").equals("1.6"))
            {
                cores = 1;
            }

            executorService = Executors.newFixedThreadPool(cores);
        }

        @Override public void finished()
        {
            executorService.shutdown();
            try
            {
                executorService.awaitTermination(TIMEOUT_SECS, TimeUnit.SECONDS);
            }
            catch (InterruptedException exc)
            {
                throw new RuntimeException(exc);
            }
        }

        @Override public void schedule(Runnable childStatement)
        {
            executorService.submit(childStatement);
        }
    }

    public ParallelParameterized(Class c) throws Throwable
    {
        super(c);
        setScheduler(new FixedThreadPoolScheduler());
    }
}

@@ -1493,81 +1493,104 @@
  // 
-workaround Open JDK 6 bug which causes CMMException: Invalid profile data
+for debugging%0A            System.out.println(%22JDK: %22 + System.getProperty(%22java.runtime.name%22));
 %0A   
@@ -1610,35 +1610,39 @@
 em.out.println(%22
-JDK
+Version
 : %22 + System.get
@@ -1656,32 +1656,131 @@
 y(%22java.
-runtime.name%22));
+specification.version%22));%0A%0A            // workaround Open JDK 6 bug which causes CMMException: Invalid profile data
 %0A       

use only one thread on OpenJDK 6