Search in sources :

Example 1 with ListeningExecutorService

use of org.apache.beam.vendor.guava.v26_0_jre.com.google.common.util.concurrent.ListeningExecutorService in project beam by apache.

the class UnboundedReadDeduplicatorTest method cachedIdDeduplicatorMultithreaded.

@Test
public void cachedIdDeduplicatorMultithreaded() throws InterruptedException, ExecutionException {
    byte[] id = new byte[] { -1, 2, 4, 22 };
    UnboundedReadDeduplicator dedupper = CachedIdDeduplicator.create();
    final CountDownLatch startSignal = new CountDownLatch(1);
    int numThreads = 50;
    final CountDownLatch readyLatch = new CountDownLatch(numThreads);
    final CountDownLatch finishLine = new CountDownLatch(numThreads);
    ListeningExecutorService executor = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool());
    AtomicInteger successCount = new AtomicInteger();
    AtomicInteger noOutputCount = new AtomicInteger();
    List<ListenableFuture<?>> futures = new ArrayList<>();
    for (int i = 0; i < numThreads; i++) {
        futures.add(executor.submit(new TryOutputIdRunnable(dedupper, id, successCount, noOutputCount, readyLatch, startSignal, finishLine)));
    }
    readyLatch.await();
    startSignal.countDown();
    finishLine.await(10L, TimeUnit.SECONDS);
    Futures.allAsList(futures).get();
    executor.shutdownNow();
    // The first thread to run will succeed, and no others will
    assertThat(successCount.get(), equalTo(1));
    // The threads may not all complete; all of the threads that do not succeed must not output
    assertThat(noOutputCount.get(), lessThan(numThreads));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArrayList(java.util.ArrayList) ListenableFuture(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.util.concurrent.ListenableFuture) ListeningExecutorService(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.util.concurrent.ListeningExecutorService) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 2 with ListeningExecutorService

use of org.apache.beam.vendor.guava.v26_0_jre.com.google.common.util.concurrent.ListeningExecutorService in project beam by apache.

the class JobInvocationTest method setup.

@Before
public void setup() {
    executorService = Executors.newFixedThreadPool(1);
    JobInfo jobInfo = JobInfo.create("jobid", "jobName", "retrievalToken", Struct.getDefaultInstance());
    ListeningExecutorService listeningExecutorService = MoreExecutors.listeningDecorator(executorService);
    Pipeline pipeline = Pipeline.create();
    runner = new ControllablePipelineRunner();
    jobInvocation = new JobInvocation(jobInfo, listeningExecutorService, PipelineTranslation.toProto(pipeline), runner);
}
Also used : JobInfo(org.apache.beam.runners.fnexecution.provisioning.JobInfo) ListeningExecutorService(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.util.concurrent.ListeningExecutorService) Pipeline(org.apache.beam.sdk.Pipeline) Before(org.junit.Before)

Aggregations

ListeningExecutorService (org.apache.beam.vendor.guava.v26_0_jre.com.google.common.util.concurrent.ListeningExecutorService)2 ArrayList (java.util.ArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 JobInfo (org.apache.beam.runners.fnexecution.provisioning.JobInfo)1 Pipeline (org.apache.beam.sdk.Pipeline)1 ListenableFuture (org.apache.beam.vendor.guava.v26_0_jre.com.google.common.util.concurrent.ListenableFuture)1 Before (org.junit.Before)1 Test (org.junit.Test)1