001/*
002 * Copyright (C) 2006 The Guava Authors
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
005 * in compliance with the License. You may obtain a copy of the License at
006 *
007 * http://www.apache.org/licenses/LICENSE-2.0
008 *
009 * Unless required by applicable law or agreed to in writing, software distributed under the License
010 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
011 * or implied. See the License for the specific language governing permissions and limitations under
012 * the License.
013 */
014
015package com.google.common.util.concurrent;
016
017import static com.google.common.base.Preconditions.checkNotNull;
018
019import com.google.common.annotations.Beta;
020import com.google.common.annotations.GwtIncompatible;
021import com.google.errorprone.annotations.CanIgnoreReturnValue;
022import java.util.concurrent.Callable;
023import java.util.concurrent.TimeUnit;
024
025/**
026 * A TimeLimiter implementation which actually does not attempt to limit time at all. This may be
027 * desirable to use in some unit tests. More importantly, attempting to debug a call which is
028 * time-limited would be extremely annoying, so this gives you a time-limiter you can easily swap in
029 * for your real time-limiter while you're debugging.
030 *
031 * @author Kevin Bourrillion
032 * @since 1.0
033 */
034@Beta
035@CanIgnoreReturnValue
036@GwtIncompatible
037public final class FakeTimeLimiter implements TimeLimiter {
038  @Override
039  public <T> T newProxy(
040      T target, Class<T> interfaceType, long timeoutDuration, TimeUnit timeoutUnit) {
041    checkNotNull(target);
042    checkNotNull(interfaceType);
043    checkNotNull(timeoutUnit);
044    return target; // ha ha
045  }
046
047  @Override
048  public <T> T callWithTimeout(
049      Callable<T> callable, long timeoutDuration, TimeUnit timeoutUnit, boolean amInterruptible)
050      throws Exception {
051    checkNotNull(timeoutUnit);
052    return callable.call(); // fooled you
053  }
054}