* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.yangtools.util.concurrent;
import static org.junit.Assert.assertEquals;
import static org.opendaylight.yangtools.util.concurrent.CommonTestUtils.SUBMIT_RUNNABLE;
import static org.opendaylight.yangtools.util.concurrent.CommonTestUtils.SUBMIT_RUNNABLE_WITH_RESULT;
-import com.google.common.base.Supplier;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
+import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
+import java.io.Serial;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
-import javax.annotation.Nonnull;
+import java.util.function.Supplier;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
static final InitialInvoker EXECUTE = Executor::execute;
public static class TestDeadlockException extends Exception {
+ @Serial
private static final long serialVersionUID = 1L;
-
}
private static final Supplier<Exception> DEADLOCK_EXECUTOR_SUPPLIER = TestDeadlockException::new;
ListenableFuture<String> future = executor.submit(() -> "foo");
- assertEquals( "Future result", "foo", future.get( 5, TimeUnit.SECONDS));
+ assertEquals("Future result", "foo", future.get(5, TimeUnit.SECONDS));
// Test submit with Runnable.
- executor.submit(() -> {
- }).get();
+ executor.submit(() -> { }).get();
// Test submit with Runnable and value.
}
@Test
+ @SuppressWarnings("checkstyle:illegalThrows")
public void testNonBlockingSubmitOnExecutorThread() throws Throwable {
executor = newExecutor();
testNonBlockingSubmitOnExecutorThread(EXECUTE, SUBMIT_CALLABLE);
}
+ @SuppressWarnings("checkstyle:illegalThrows")
void testNonBlockingSubmitOnExecutorThread(final InitialInvoker initialInvoker, final Invoker invoker)
throws Throwable {
}
@Override
- public void onFailure(@Nonnull final Throwable t) {
+ @SuppressWarnings("checkstyle:parameterName")
+ public void onFailure(final Throwable t) {
caughtEx.set(t);
futureCompletedLatch.countDown();
}
- });
+ }, MoreExecutors.directExecutor());
initialInvoker.invokeExecutor(executor, task);
}
@Test
- public void testBlockingSubmitOnExecutorThread() throws Exception {
+ public void testBlockingSubmitOnExecutorThread() throws InterruptedException {
executor = newExecutor();
testBlockingSubmitOnExecutorThread(EXECUTE, SUBMIT_CALLABLE);
}
+ @SuppressWarnings("checkstyle:illegalCatch")
void testBlockingSubmitOnExecutorThread(final InitialInvoker initialInvoker, final Invoker invoker)
- throws Exception {
+ throws InterruptedException {
final AtomicReference<Throwable> caughtEx = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
try {
invoker.invokeExecutor(executor, null).get();
- } catch(ExecutionException e) {
+ } catch (ExecutionException e) {
caughtEx.set(e.getCause());
- } catch(Throwable e) {
+ } catch (Throwable e) {
caughtEx.set(e);
} finally {
latch.countDown();
initialInvoker.invokeExecutor(executor, task);
- assertTrue("Task did not complete - executor likely deadlocked", latch.await( 5, TimeUnit.SECONDS));
+ assertTrue("Task did not complete - executor likely deadlocked", latch.await(5, TimeUnit.SECONDS));
assertNotNull("Expected exception thrown", caughtEx.get());
assertEquals("Caught exception type", TestDeadlockException.class, caughtEx.get().getClass());
}