Search in sources :

Example 1 with Loader

use of com.github.benmanes.caffeine.cache.testing.CacheSpec.Loader in project caffeine by ben-manes.

the class LoadingCacheTest method asyncLoad_exception.

@Test
public void asyncLoad_exception() throws Exception {
    Exception e = new Exception();
    CacheLoader<Integer, Integer> loader = key -> {
        throw e;
    };
    try {
        loader.asyncLoad(1, Runnable::run).join();
    } catch (CompletionException ex) {
        assertThat(ex.getCause(), is(sameInstance(e)));
    }
}
Also used : Arrays(java.util.Arrays) CacheContext(com.github.benmanes.caffeine.cache.testing.CacheContext) Iterables(com.google.common.collect.Iterables) Listeners(org.testng.annotations.Listeners) CacheExecutor(com.github.benmanes.caffeine.cache.testing.CacheSpec.CacheExecutor) HasStats.hasLoadFailureCount(com.github.benmanes.caffeine.cache.testing.HasStats.hasLoadFailureCount) Population(com.github.benmanes.caffeine.cache.testing.CacheSpec.Population) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Test(org.testng.annotations.Test) Loader(com.github.benmanes.caffeine.cache.testing.CacheSpec.Loader) CacheSpec(com.github.benmanes.caffeine.cache.testing.CacheSpec) CacheValidationListener(com.github.benmanes.caffeine.cache.testing.CacheValidationListener) ImmutableList(com.google.common.collect.ImmutableList) HasStats.hasLoadSuccessCount(com.github.benmanes.caffeine.cache.testing.HasStats.hasLoadSuccessCount) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Map(java.util.Map) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) CheckNoWriter(com.github.benmanes.caffeine.cache.testing.CheckNoWriter) HasStats.hasHitCount(com.github.benmanes.caffeine.cache.testing.HasStats.hasHitCount) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) HasRemovalNotifications.hasRemovalNotifications(com.github.benmanes.caffeine.cache.testing.HasRemovalNotifications.hasRemovalNotifications) Set(java.util.Set) CompletionException(java.util.concurrent.CompletionException) HasStats.hasMissCount(com.github.benmanes.caffeine.cache.testing.HasStats.hasMissCount) Implementation(com.github.benmanes.caffeine.cache.testing.CacheSpec.Implementation) Ints(com.google.common.primitives.Ints) RemovalNotification(com.github.benmanes.caffeine.cache.testing.RemovalNotification) Matchers.both(org.hamcrest.Matchers.both) ExecutionException(java.util.concurrent.ExecutionException) Listener(com.github.benmanes.caffeine.cache.testing.CacheSpec.Listener) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Compute(com.github.benmanes.caffeine.cache.testing.CacheSpec.Compute) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) Matchers.equalTo(org.hamcrest.Matchers.equalTo) CacheProvider(com.github.benmanes.caffeine.cache.testing.CacheProvider) Matchers.is(org.hamcrest.Matchers.is) Awaits.await(com.github.benmanes.caffeine.testing.Awaits.await) Assert(org.junit.Assert) Collections(java.util.Collections) CompletionException(java.util.concurrent.CompletionException) CompletionException(java.util.concurrent.CompletionException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.testng.annotations.Test)

Example 2 with Loader

use of com.github.benmanes.caffeine.cache.testing.CacheSpec.Loader in project caffeine by ben-manes.

the class LoadingCacheTest method asyncReload_exception.

@Test
public void asyncReload_exception() throws Exception {
    for (Exception e : Arrays.asList(new Exception(), new RuntimeException())) {
        CacheLoader<Integer, Integer> loader = key -> {
            throw e;
        };
        try {
            loader.asyncReload(1, 1, Runnable::run).join();
            Assert.fail();
        } catch (CompletionException ex) {
            assertThat(ex.getCause(), is(sameInstance(e)));
        }
    }
}
Also used : Arrays(java.util.Arrays) CacheContext(com.github.benmanes.caffeine.cache.testing.CacheContext) Iterables(com.google.common.collect.Iterables) Listeners(org.testng.annotations.Listeners) CacheExecutor(com.github.benmanes.caffeine.cache.testing.CacheSpec.CacheExecutor) HasStats.hasLoadFailureCount(com.github.benmanes.caffeine.cache.testing.HasStats.hasLoadFailureCount) Population(com.github.benmanes.caffeine.cache.testing.CacheSpec.Population) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Test(org.testng.annotations.Test) Loader(com.github.benmanes.caffeine.cache.testing.CacheSpec.Loader) CacheSpec(com.github.benmanes.caffeine.cache.testing.CacheSpec) CacheValidationListener(com.github.benmanes.caffeine.cache.testing.CacheValidationListener) ImmutableList(com.google.common.collect.ImmutableList) HasStats.hasLoadSuccessCount(com.github.benmanes.caffeine.cache.testing.HasStats.hasLoadSuccessCount) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Map(java.util.Map) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) CheckNoWriter(com.github.benmanes.caffeine.cache.testing.CheckNoWriter) HasStats.hasHitCount(com.github.benmanes.caffeine.cache.testing.HasStats.hasHitCount) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) HasRemovalNotifications.hasRemovalNotifications(com.github.benmanes.caffeine.cache.testing.HasRemovalNotifications.hasRemovalNotifications) Set(java.util.Set) CompletionException(java.util.concurrent.CompletionException) HasStats.hasMissCount(com.github.benmanes.caffeine.cache.testing.HasStats.hasMissCount) Implementation(com.github.benmanes.caffeine.cache.testing.CacheSpec.Implementation) Ints(com.google.common.primitives.Ints) RemovalNotification(com.github.benmanes.caffeine.cache.testing.RemovalNotification) Matchers.both(org.hamcrest.Matchers.both) ExecutionException(java.util.concurrent.ExecutionException) Listener(com.github.benmanes.caffeine.cache.testing.CacheSpec.Listener) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Compute(com.github.benmanes.caffeine.cache.testing.CacheSpec.Compute) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) Matchers.equalTo(org.hamcrest.Matchers.equalTo) CacheProvider(com.github.benmanes.caffeine.cache.testing.CacheProvider) Matchers.is(org.hamcrest.Matchers.is) Awaits.await(com.github.benmanes.caffeine.testing.Awaits.await) Assert(org.junit.Assert) Collections(java.util.Collections) CompletionException(java.util.concurrent.CompletionException) CompletionException(java.util.concurrent.CompletionException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.testng.annotations.Test)

Aggregations

CacheContext (com.github.benmanes.caffeine.cache.testing.CacheContext)2 CacheProvider (com.github.benmanes.caffeine.cache.testing.CacheProvider)2 CacheSpec (com.github.benmanes.caffeine.cache.testing.CacheSpec)2 CacheExecutor (com.github.benmanes.caffeine.cache.testing.CacheSpec.CacheExecutor)2 Compute (com.github.benmanes.caffeine.cache.testing.CacheSpec.Compute)2 Implementation (com.github.benmanes.caffeine.cache.testing.CacheSpec.Implementation)2 Listener (com.github.benmanes.caffeine.cache.testing.CacheSpec.Listener)2 Loader (com.github.benmanes.caffeine.cache.testing.CacheSpec.Loader)2 Population (com.github.benmanes.caffeine.cache.testing.CacheSpec.Population)2 CacheValidationListener (com.github.benmanes.caffeine.cache.testing.CacheValidationListener)2 CheckNoWriter (com.github.benmanes.caffeine.cache.testing.CheckNoWriter)2 HasRemovalNotifications.hasRemovalNotifications (com.github.benmanes.caffeine.cache.testing.HasRemovalNotifications.hasRemovalNotifications)2 HasStats.hasHitCount (com.github.benmanes.caffeine.cache.testing.HasStats.hasHitCount)2 HasStats.hasLoadFailureCount (com.github.benmanes.caffeine.cache.testing.HasStats.hasLoadFailureCount)2 HasStats.hasLoadSuccessCount (com.github.benmanes.caffeine.cache.testing.HasStats.hasLoadSuccessCount)2 HasStats.hasMissCount (com.github.benmanes.caffeine.cache.testing.HasStats.hasMissCount)2 RemovalNotification (com.github.benmanes.caffeine.cache.testing.RemovalNotification)2 Awaits.await (com.github.benmanes.caffeine.testing.Awaits.await)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2