Coverage Summary for Class: FakeTimeLimiter (com.google.common.util.concurrent)
| Class | Class, % | Method, % | Line, % |
|---|---|---|---|
| FakeTimeLimiter | 0% (0/1) | 0% (0/6) | 0% (0/28) |
1 /* 2 * Copyright (C) 2006 The Guava Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 * in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the License 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 * or implied. See the License for the specific language governing permissions and limitations under 12 * the License. 13 */ 14 15 package com.google.common.util.concurrent; 16 17 import static com.google.common.base.Preconditions.checkNotNull; 18 19 import com.google.common.annotations.Beta; 20 import com.google.common.annotations.GwtIncompatible; 21 import com.google.errorprone.annotations.CanIgnoreReturnValue; 22 import java.util.concurrent.Callable; 23 import java.util.concurrent.ExecutionException; 24 import java.util.concurrent.TimeUnit; 25 import org.checkerframework.checker.nullness.qual.Nullable; 26 27 /** 28 * A TimeLimiter implementation which actually does not attempt to limit time at all. This may be 29 * desirable to use in some unit tests. More importantly, attempting to debug a call which is 30 * time-limited would be extremely annoying, so this gives you a time-limiter you can easily swap in 31 * for your real time-limiter while you're debugging. 32 * 33 * @author Kevin Bourrillion 34 * @author Jens Nyman 35 * @since 1.0 36 */ 37 @Beta 38 @CanIgnoreReturnValue 39 @GwtIncompatible 40 @ElementTypesAreNonnullByDefault 41 public final class FakeTimeLimiter implements TimeLimiter { 42 @Override 43 public <T> T newProxy( 44 T target, Class<T> interfaceType, long timeoutDuration, TimeUnit timeoutUnit) { 45 checkNotNull(target); 46 checkNotNull(interfaceType); 47 checkNotNull(timeoutUnit); 48 return target; // ha ha 49 } 50 51 @Override 52 @ParametricNullness 53 public <T extends @Nullable Object> T callWithTimeout( 54 Callable<T> callable, long timeoutDuration, TimeUnit timeoutUnit) throws ExecutionException { 55 checkNotNull(callable); 56 checkNotNull(timeoutUnit); 57 try { 58 return callable.call(); 59 } catch (RuntimeException e) { 60 throw new UncheckedExecutionException(e); 61 } catch (Exception e) { 62 throw new ExecutionException(e); 63 } catch (Error e) { 64 throw new ExecutionError(e); 65 } catch (Throwable e) { 66 // It's a non-Error, non-Exception Throwable. Such classes are usually intended to extend 67 // Exception, so we'll treat it like an Exception. 68 throw new ExecutionException(e); 69 } 70 } 71 72 @Override 73 @ParametricNullness 74 public <T extends @Nullable Object> T callUninterruptiblyWithTimeout( 75 Callable<T> callable, long timeoutDuration, TimeUnit timeoutUnit) throws ExecutionException { 76 return callWithTimeout(callable, timeoutDuration, timeoutUnit); 77 } 78 79 @Override 80 public void runWithTimeout(Runnable runnable, long timeoutDuration, TimeUnit timeoutUnit) { 81 checkNotNull(runnable); 82 checkNotNull(timeoutUnit); 83 try { 84 runnable.run(); 85 } catch (RuntimeException e) { 86 throw new UncheckedExecutionException(e); 87 } catch (Error e) { 88 throw new ExecutionError(e); 89 } catch (Throwable e) { 90 // It's a non-Error, non-Exception Throwable. Such classes are usually intended to extend 91 // Exception, so we'll treat it like a RuntimeException. 92 throw new UncheckedExecutionException(e); 93 } 94 } 95 96 @Override 97 public void runUninterruptiblyWithTimeout( 98 Runnable runnable, long timeoutDuration, TimeUnit timeoutUnit) { 99 runWithTimeout(runnable, timeoutDuration, timeoutUnit); 100 } 101 }