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));
}
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);
}
Aggregations