Fix eclipse/checkstyle warnings
[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 class CommonTestUtils {
22     @FunctionalInterface
23     public interface Invoker {
24         ListenableFuture<?> invokeExecutor(ListeningExecutorService executor, CountDownLatch blockingLatch);
25     }
26
27     public static final Invoker SUBMIT_CALLABLE = (executor, blockingLatch) -> executor.submit(() -> {
28         if (blockingLatch != null) {
29             Uninterruptibles.awaitUninterruptibly(blockingLatch);
30         }
31         return null;
32     });
33
34     public static final Invoker SUBMIT_RUNNABLE = (executor, blockingLatch) -> executor.submit(() -> {
35         if (blockingLatch != null) {
36             Uninterruptibles.awaitUninterruptibly(blockingLatch);
37         }
38     });
39
40     public static final Invoker SUBMIT_RUNNABLE_WITH_RESULT = (executor, blockingLatch) -> executor.submit(() -> {
41         if (blockingLatch != null) {
42             Uninterruptibles.awaitUninterruptibly(blockingLatch);
43         }
44     }, "foo");
45 }