// Path: mug/src/main/java/com/google/mu/util/concurrent/Parallelizer.java
// static <T> Stream<Runnable> forAll(Stream<? extends T> inputs, Consumer<? super T> consumer) {
//   requireNonNull(consumer);
//   return inputs.map(input -> () -> consumer.accept(input));
// }
// 
// Path: mug/src/main/java/com/google/mu/util/concurrent/Parallelizer.java
// static class UncheckedExecutionException extends RuntimeException {
//   UncheckedExecutionException(Throwable cause) {
//     super(cause);
//   }
//   private static final long serialVersionUID = 1L;
// }


import static com.google.common.truth.Truth.assertThat;
import static com.google.mu.util.concurrent.Parallelizer.forAll;
import static java.util.Arrays.asList;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeFalse;
import static org.junit.Assume.assumeTrue;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.Verifier;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import com.google.common.truth.IterableSubject;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.mu.util.concurrent.Parallelizer.UncheckedExecutionException;
        UncheckedExecutionException.class,
        () -> parallelize(Stream.of(() -> raise(exception))));
    assertThat(caught.getCause()).isSameAs(exception);
  }

  private void translateToString(int i) {
    translated.put(i, Integer.toString(i));
  }

  private static <K> Map<K, String> mapToString(Collection<K> keys) {
    return keys.stream().collect(Collectors.toMap(k -> k, Object::toString));
  }

  /** Keeps track of active threads and makes sure it doesn't exceed {@link #maxInFlight}. */
  private void runTask(Runnable task) {
    try {
      try {
        assertThat(activeThreads.incrementAndGet()).isAtMost(maxInFlight);
      } catch (Throwable e) {
        thrown.add(e);
        return;
      }
      task.run();
    } finally {
      activeThreads.decrementAndGet();
    }
  }

  private <T> void parallelize(Stream<? extends T> inputs, Consumer<? super T> consumer)
      throws InterruptedException, TimeoutException {
// Path: mug/src/main/java/com/google/mu/util/concurrent/Parallelizer.java
// static <T> Stream<Runnable> forAll(Stream<? extends T> inputs, Consumer<? super T> consumer) {
//   requireNonNull(consumer);
//   return inputs.map(input -> () -> consumer.accept(input));
// }
// 
// Path: mug/src/main/java/com/google/mu/util/concurrent/Parallelizer.java
// static class UncheckedExecutionException extends RuntimeException {
//   UncheckedExecutionException(Throwable cause) {
//     super(cause);
//   }
//   private static final long serialVersionUID = 1L;
// }


// Path: mug/src/test/java/com/google/mu/util/concurrent/ParallelizerTest.java
import static com.google.common.truth.Truth.assertThat;
import static com.google.mu.util.concurrent.Parallelizer.forAll;
import static java.util.Arrays.asList;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeFalse;
import static org.junit.Assume.assumeTrue;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.Verifier;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import com.google.common.truth.IterableSubject;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.mu.util.concurrent.Parallelizer.UncheckedExecutionException;

        UncheckedExecutionException.class,
        () -> parallelize(Stream.of(() -> raise(exception))));
    assertThat(caught.getCause()).isSameAs(exception);
  }

  private void translateToString(int i) {
    translated.put(i, Integer.toString(i));
  }

  private static <K> Map<K, String> mapToString(Collection<K> keys) {
    return keys.stream().collect(Collectors.toMap(k -> k, Object::toString));
  }

  /** Keeps track of active threads and makes sure it doesn't exceed {@link #maxInFlight}. */
  private void runTask(Runnable task) {
    try {
      try {
        assertThat(activeThreads.incrementAndGet()).isAtMost(maxInFlight);
      } catch (Throwable e) {
        thrown.add(e);
        return;
      }
      task.run();
    } finally {
      activeThreads.decrementAndGet();
    }
  }

  private <T> void parallelize(Stream<? extends T> inputs, Consumer<? super T> consumer)
      throws InterruptedException, TimeoutException {
    parallelize(forAll(inputs, consumer));