diff --git a/core/src/main/java/org/jclouds/cache/internal/BackoffExponentiallyAndRetryOnThrowableCacheLoader.java b/core/src/main/java/org/jclouds/cache/internal/BackoffExponentiallyAndRetryOnThrowableCacheLoader.java index 967a046143..abdecf8c94 100644 --- a/core/src/main/java/org/jclouds/cache/internal/BackoffExponentiallyAndRetryOnThrowableCacheLoader.java +++ b/core/src/main/java/org/jclouds/cache/internal/BackoffExponentiallyAndRetryOnThrowableCacheLoader.java @@ -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 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; + } } }); } diff --git a/core/src/test/java/org/jclouds/cache/internal/BackoffExponentiallyAndRetryOnThrowableCacheLoaderTest.java b/core/src/test/java/org/jclouds/cache/internal/BackoffExponentiallyAndRetryOnThrowableCacheLoaderTest.java index 0b0517aef2..01c7628989 100644 --- a/core/src/test/java/org/jclouds/cache/internal/BackoffExponentiallyAndRetryOnThrowableCacheLoaderTest.java +++ b/core/src/test/java/org/jclouds/cache/internal/BackoffExponentiallyAndRetryOnThrowableCacheLoaderTest.java @@ -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); } -} \ No newline at end of file + + @Test + void testThrowsTimeoutException() throws Exception { + int attempts = 3; + BackoffExponentiallyAndRetryOnThrowableCacheLoader backoff = new BackoffExponentiallyAndRetryOnThrowableCacheLoader( + 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); + } +}