Migrate common/util to JUnit5
[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 package org.opendaylight.yangtools.util.concurrent;
9
10 import com.google.common.util.concurrent.ListenableFuture;
11 import com.google.common.util.concurrent.ListeningExecutorService;
12 import com.google.common.util.concurrent.Uninterruptibles;
13 import java.util.concurrent.CountDownLatch;
14
15 /**
16  * Some common test utilities.
17  *
18  * @author Thomas Pantelis
19  */
20 final class CommonTestUtils {
21     private CommonTestUtils() {
22         throw new UnsupportedOperationException();
23     }
24
25     @FunctionalInterface
26     public interface Invoker {
27         ListenableFuture<?> invokeExecutor(ListeningExecutorService executor, CountDownLatch blockingLatch);
28     }
29
30     public static final Invoker SUBMIT_CALLABLE = (executor, blockingLatch) -> executor.submit(() -> {
31         if (blockingLatch != null) {
32             Uninterruptibles.awaitUninterruptibly(blockingLatch);
33         }
34         return null;
35     });
36
37     public static final Invoker SUBMIT_RUNNABLE = (executor, blockingLatch) -> executor.submit(() -> {
38         if (blockingLatch != null) {
39             Uninterruptibles.awaitUninterruptibly(blockingLatch);
40         }
41     });
42
43     public static final Invoker SUBMIT_RUNNABLE_WITH_RESULT = (executor, blockingLatch) -> executor.submit(() -> {
44         if (blockingLatch != null) {
45             Uninterruptibles.awaitUninterruptibly(blockingLatch);
46         }
47     }, "foo");
48 }