Search in sources :

Example 86 with UncheckedExecutionException

use of com.google.common.util.concurrent.UncheckedExecutionException in project guava by google.

the class CacheLoadingTest method testBulkLoadUncheckedException.

public void testBulkLoadUncheckedException() throws ExecutionException {
    Exception e = new RuntimeException();
    CacheLoader<Object, Object> loader = exceptionLoader(e);
    LoadingCache<Object, Object> cache = CacheBuilder.newBuilder().recordStats().build(bulkLoader(loader));
    CacheStats stats = cache.stats();
    assertEquals(0, stats.missCount());
    assertEquals(0, stats.loadSuccessCount());
    assertEquals(0, stats.loadExceptionCount());
    assertEquals(0, stats.hitCount());
    try {
        cache.getAll(asList(new Object()));
        fail();
    } catch (UncheckedExecutionException expected) {
        assertThat(expected).hasCauseThat().isSameInstanceAs(e);
    }
    stats = cache.stats();
    assertEquals(1, stats.missCount());
    assertEquals(0, stats.loadSuccessCount());
    assertEquals(1, stats.loadExceptionCount());
    assertEquals(0, stats.hitCount());
}
Also used : UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) IOException(java.io.IOException) InvalidCacheLoadException(com.google.common.cache.CacheLoader.InvalidCacheLoadException) ExecutionException(java.util.concurrent.ExecutionException)

Example 87 with UncheckedExecutionException

use of com.google.common.util.concurrent.UncheckedExecutionException in project guava by google.

the class CacheLoadingTest method testReloadAfterFailure.

public void testReloadAfterFailure() throws ExecutionException {
    final AtomicInteger count = new AtomicInteger();
    final Exception e = new IllegalStateException("exception to trigger failure on first load()");
    CacheLoader<Integer, String> failOnceFunction = new CacheLoader<Integer, String>() {

        @Override
        public String load(Integer key) throws Exception {
            if (count.getAndIncrement() == 0) {
                throw e;
            }
            return key.toString();
        }
    };
    CountingRemovalListener<Integer, String> removalListener = countingRemovalListener();
    LoadingCache<Integer, String> cache = CacheBuilder.newBuilder().removalListener(removalListener).build(failOnceFunction);
    try {
        cache.getUnchecked(1);
        fail();
    } catch (UncheckedExecutionException ue) {
        assertThat(ue).hasCauseThat().isSameInstanceAs(e);
    }
    assertEquals("1", cache.getUnchecked(1));
    assertEquals(0, removalListener.getCount());
    count.set(0);
    cache.refresh(2);
    checkLoggedCause(e);
    assertEquals("2", cache.getUnchecked(2));
    assertEquals(0, removalListener.getCount());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) IOException(java.io.IOException) InvalidCacheLoadException(com.google.common.cache.CacheLoader.InvalidCacheLoadException) ExecutionException(java.util.concurrent.ExecutionException)

Example 88 with UncheckedExecutionException

use of com.google.common.util.concurrent.UncheckedExecutionException in project guava by hceylan.

the class CacheLoadingTest method testBulkLoadUncheckedException.

public void testBulkLoadUncheckedException() throws ExecutionException {
    Exception e = new RuntimeException();
    CacheLoader<Object, Object> loader = exceptionLoader(e);
    LoadingCache<Object, Object> cache = CacheBuilder.newBuilder().build(bulkLoader(loader));
    CacheStats stats = cache.stats();
    assertEquals(0, stats.missCount());
    assertEquals(0, stats.loadSuccessCount());
    assertEquals(0, stats.loadExceptionCount());
    assertEquals(0, stats.hitCount());
    try {
        cache.getAll(asList(new Object()));
        fail();
    } catch (UncheckedExecutionException expected) {
        assertSame(e, expected.getCause());
    }
    stats = cache.stats();
    assertEquals(1, stats.missCount());
    assertEquals(0, stats.loadSuccessCount());
    assertEquals(1, stats.loadExceptionCount());
    assertEquals(0, stats.hitCount());
}
Also used : UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) IOException(java.io.IOException) InvalidCacheLoadException(com.google.common.cache.CacheLoader.InvalidCacheLoadException) ExecutionException(java.util.concurrent.ExecutionException)

Example 89 with UncheckedExecutionException

use of com.google.common.util.concurrent.UncheckedExecutionException in project guava by hceylan.

the class CacheLoadingTest method testLoadUncheckedException.

public void testLoadUncheckedException() throws ExecutionException {
    Exception e = new RuntimeException();
    CacheLoader<Object, Object> loader = exceptionLoader(e);
    LoadingCache<Object, Object> cache = CacheBuilder.newBuilder().build(loader);
    CacheStats stats = cache.stats();
    assertEquals(0, stats.missCount());
    assertEquals(0, stats.loadSuccessCount());
    assertEquals(0, stats.loadExceptionCount());
    assertEquals(0, stats.hitCount());
    try {
        cache.get(new Object());
        fail();
    } catch (UncheckedExecutionException expected) {
        assertSame(e, expected.getCause());
    }
    stats = cache.stats();
    assertEquals(1, stats.missCount());
    assertEquals(0, stats.loadSuccessCount());
    assertEquals(1, stats.loadExceptionCount());
    assertEquals(0, stats.hitCount());
    try {
        cache.getUnchecked(new Object());
        fail();
    } catch (UncheckedExecutionException expected) {
        assertSame(e, expected.getCause());
    }
    stats = cache.stats();
    assertEquals(2, stats.missCount());
    assertEquals(0, stats.loadSuccessCount());
    assertEquals(2, stats.loadExceptionCount());
    assertEquals(0, stats.hitCount());
    cache.refresh(new Object());
    checkLoggedCause(e);
    stats = cache.stats();
    assertEquals(2, stats.missCount());
    assertEquals(0, stats.loadSuccessCount());
    assertEquals(3, stats.loadExceptionCount());
    assertEquals(0, stats.hitCount());
    Exception callableException = new RuntimeException();
    try {
        cache.get(new Object(), throwing(callableException));
        fail();
    } catch (UncheckedExecutionException expected) {
        assertSame(callableException, expected.getCause());
    }
    stats = cache.stats();
    assertEquals(3, stats.missCount());
    assertEquals(0, stats.loadSuccessCount());
    assertEquals(4, stats.loadExceptionCount());
    assertEquals(0, stats.hitCount());
    try {
        cache.getAll(asList(new Object()));
        fail();
    } catch (UncheckedExecutionException expected) {
        assertSame(e, expected.getCause());
    }
    stats = cache.stats();
    assertEquals(4, stats.missCount());
    assertEquals(0, stats.loadSuccessCount());
    assertEquals(5, stats.loadExceptionCount());
    assertEquals(0, stats.hitCount());
}
Also used : UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) IOException(java.io.IOException) InvalidCacheLoadException(com.google.common.cache.CacheLoader.InvalidCacheLoadException) ExecutionException(java.util.concurrent.ExecutionException)

Example 90 with UncheckedExecutionException

use of com.google.common.util.concurrent.UncheckedExecutionException in project Essentials by EssentialsX.

the class UserMap method getUser.

public User getUser(final String name) {
    try {
        final String sanitizedName = StringUtil.safeString(name);
        if (names.containsKey(sanitizedName)) {
            final UUID uuid = names.get(sanitizedName);
            return getUser(uuid);
        }
        final File userFile = getUserFileFromString(sanitizedName);
        if (userFile.exists()) {
            ess.getLogger().info("Importing user " + name + " to usermap.");
            User user = new User(new OfflinePlayer(sanitizedName, ess.getServer()), ess);
            trackUUID(user.getBase().getUniqueId(), user.getName(), true);
            return user;
        }
        return null;
    } catch (UncheckedExecutionException ex) {
        return null;
    }
}
Also used : UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) File(java.io.File)

Aggregations

UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)101 ExecutionException (java.util.concurrent.ExecutionException)60 IOException (java.io.IOException)31 InvalidCacheLoadException (com.google.common.cache.CacheLoader.InvalidCacheLoadException)22 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)10 Test (org.junit.Test)9 Map (java.util.Map)8 ArrayList (java.util.ArrayList)7 File (java.io.File)6 TimeoutException (java.util.concurrent.TimeoutException)6 Stopwatch (com.google.common.base.Stopwatch)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 HashMap (java.util.HashMap)5 List (java.util.List)5 NoSuchElementException (java.util.NoSuchElementException)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 InputStream (java.io.InputStream)4 Callable (java.util.concurrent.Callable)4 SirixIOException (org.sirix.exception.SirixIOException)4 TypeSignature (com.facebook.presto.common.type.TypeSignature)3