mirror of https://github.com/apache/jclouds.git
Merge pull request #689 from andrewgaul/propagate-timeout-exception
Propagate TimeoutException when possible
This commit is contained in:
commit
4e32001b84
core/src
main/java/org/jclouds/cache/internal
test/java/org/jclouds/cache/internal
|
@ -23,8 +23,10 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.jclouds.cache.ForwardingCacheLoader;
|
||||
import org.jclouds.util.Throwables2;
|
||||
|
||||
import com.google.common.annotations.Beta;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
|
@ -93,7 +95,16 @@ public class BackoffExponentiallyAndRetryOnThrowableCacheLoader<K, V> extends Fo
|
|||
|
||||
@Override
|
||||
public V call() throws Exception {
|
||||
return BackoffExponentiallyAndRetryOnThrowableCacheLoader.super.load(key);
|
||||
try {
|
||||
return BackoffExponentiallyAndRetryOnThrowableCacheLoader.super.load(key);
|
||||
} catch (Exception e) {
|
||||
TimeoutException te = Throwables2.getFirstThrowableOfType(e,
|
||||
TimeoutException.class);
|
||||
if (te != null) {
|
||||
throw te;
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -25,6 +25,9 @@ import static org.easymock.EasyMock.verify;
|
|||
import static org.testng.Assert.assertSame;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.jclouds.rest.ResourceNotFoundException;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -73,4 +76,22 @@ public class BackoffExponentiallyAndRetryOnThrowableCacheLoaderTest {
|
|||
}
|
||||
verify(mock);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testThrowsTimeoutException() throws Exception {
|
||||
int attempts = 3;
|
||||
BackoffExponentiallyAndRetryOnThrowableCacheLoader<String, Boolean> backoff = new BackoffExponentiallyAndRetryOnThrowableCacheLoader<String, Boolean>(
|
||||
ResourceNotFoundException.class, 50l, 500l, attempts, mock);
|
||||
|
||||
expect(mock.load("foo")).andThrow(new ExecutionException(new TimeoutException()));
|
||||
|
||||
replay(mock);
|
||||
try {
|
||||
backoff.load("foo");
|
||||
assertTrue(false);
|
||||
} catch (TimeoutException e) {
|
||||
|
||||
}
|
||||
verify(mock);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue