Merge branch 'master' of ../controller
[yangtools.git] / common / util / src / test / java / org / opendaylight / yangtools / util / concurrent / CommonTestUtils.java
1 /*
2  * Copyright (c) 2014 Brocade Communications Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.yangtools.util.concurrent;
10
11 import com.google.common.util.concurrent.ListenableFuture;
12 import com.google.common.util.concurrent.ListeningExecutorService;
13 import com.google.common.util.concurrent.Uninterruptibles;
14 import java.util.concurrent.CountDownLatch;
15
16 /**
17  * Some common test utilities.
18  *
19  * @author Thomas Pantelis
20  */
21 public final class CommonTestUtils {
22     private CommonTestUtils() {
23         throw new UnsupportedOperationException();
24     }
25
26     @FunctionalInterface
27     public interface Invoker {
28         ListenableFuture<?> invokeExecutor(ListeningExecutorService executor, CountDownLatch blockingLatch);
29     }
30
31     public static final Invoker SUBMIT_CALLABLE = (executor, blockingLatch) -> executor.submit(() -> {
32         if (blockingLatch != null) {
33             Uninterruptibles.awaitUninterruptibly(blockingLatch);
34         }
35         return null;
36     });
37
38     public static final Invoker SUBMIT_RUNNABLE = (executor, blockingLatch) -> executor.submit(() -> {
39         if (blockingLatch != null) {
40             Uninterruptibles.awaitUninterruptibly(blockingLatch);
41         }
42     });
43
44     public static final Invoker SUBMIT_RUNNABLE_WITH_RESULT = (executor, blockingLatch) -> executor.submit(() -> {
45         if (blockingLatch != null) {
46             Uninterruptibles.awaitUninterruptibly(blockingLatch);
47         }
48     }, "foo");
49 }