mirror of https://github.com/apache/jclouds.git
unwrap UncheckedExecutionException
This commit is contained in:
parent
f804932623
commit
6a80aa4313
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue