unwrap UncheckedExecutionException

This commit is contained in:
Adrian Cole 2013-01-31 11:55:36 -08:00
parent f804932623
commit 6a80aa4313
2 changed files with 18 additions and 0 deletions

View File

@ -35,6 +35,7 @@ import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.ForwardingObject;
import com.google.common.util.concurrent.UncheckedExecutionException;
/**
* This will retry the supplier if it encounters a timeout exception, but not if it encounters an
@ -120,6 +121,8 @@ public class MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<T> ext
public T get() {
try {
return cache.get("FOO").orNull();
} catch (UncheckedExecutionException e) {
throw propagate(e.getCause());
} catch (ExecutionException e) {
throw propagate(e.getCause());
}

View File

@ -30,6 +30,7 @@ import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExc
import org.testng.annotations.Test;
import com.google.common.base.Supplier;
import com.google.common.util.concurrent.UncheckedExecutionException;
/**
*
@ -73,6 +74,20 @@ public class MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplierTest {
}
}
@Test(expectedExceptions = AuthorizationException.class)
public void testLoaderThrowsAuthorizationExceptionAndAlsoSetsExceptionTypeWhenInUncheckedExecutionException() {
AtomicReference<AuthorizationException> authException = newReference();
try {
new SetAndThrowAuthorizationExceptionSupplierBackedLoader<String>(new Supplier<String>() {
public String get() {
throw new UncheckedExecutionException(new AuthorizationException());
}
}, authException).load("KEY");
} finally {
assertEquals(authException.get().getClass(), AuthorizationException.class);
}
}
@Test(expectedExceptions = RuntimeException.class)
public void testLoaderThrowsOriginalExceptionAndAlsoSetsExceptionTypeWhenNestedAndNotAuthorizationException() {
AtomicReference<AuthorizationException> authException = newReference();