Search in sources :

Example 1 with DescriptionBuilder

use of com.github.benmanes.caffeine.testing.DescriptionBuilder in project caffeine by ben-manes.

the class HasRemovalNotifications method matchesSafely.

@Override
protected boolean matchesSafely(Object ignored, Description description) {
    DescriptionBuilder desc = new DescriptionBuilder(description);
    if (context.removalListenerType == Listener.CONSUMING) {
        List<RemovalNotification<Integer, Integer>> notifications = context.consumedNotifications();
        ForkJoinPool.commonPool().awaitQuiescence(10, TimeUnit.SECONDS);
        int size = 0;
        for (RemovalNotification<?, ?> notification : notifications) {
            if (notification.getCause() == cause) {
                checkNotification(notification);
                size++;
            }
        }
        desc.expectThat("notification count", size, is(count));
    }
    return desc.matches();
}
Also used : DescriptionBuilder(com.github.benmanes.caffeine.testing.DescriptionBuilder)

Example 2 with DescriptionBuilder

use of com.github.benmanes.caffeine.testing.DescriptionBuilder in project caffeine by ben-manes.

the class HasStats method matchesSafely.

@Override
protected boolean matchesSafely(CacheContext context, Description description) {
    if (!context.isRecordingStats()) {
        return true;
    }
    CacheStats stats = context.stats();
    desc = new DescriptionBuilder(description);
    ForkJoinPool.commonPool().awaitQuiescence(10, TimeUnit.SECONDS);
    switch(type) {
        case HIT:
            return desc.expectThat(type.name(), stats.hitCount(), is(count)).matches();
        case MISS:
            return desc.expectThat(type.name(), stats.missCount(), is(count)).matches();
        case EVICTION_COUNT:
            return desc.expectThat(type.name(), stats.evictionCount(), is(count)).matches();
        case EVICTION_WEIGHT:
            return desc.expectThat(type.name(), stats.evictionWeight(), is(count)).matches();
        case LOAD_SUCCESS:
            return desc.expectThat(type.name(), stats.loadSuccessCount(), is(count)).matches();
        case LOAD_FAILURE:
            return desc.expectThat(type.name(), stats.loadFailureCount(), is(count)).matches();
        default:
            throw new AssertionError("Unknown stats type");
    }
}
Also used : DescriptionBuilder(com.github.benmanes.caffeine.testing.DescriptionBuilder) CacheStats(com.github.benmanes.caffeine.cache.stats.CacheStats)

Example 3 with DescriptionBuilder

use of com.github.benmanes.caffeine.testing.DescriptionBuilder in project caffeine by ben-manes.

the class IsCacheReserializable method matchesSafely.

@Override
public boolean matchesSafely(T original, Description description) {
    desc = new DescriptionBuilder(description);
    T copy = SerializableTester.reserialize(original);
    if (original instanceof AsyncLoadingCache<?, ?>) {
        @SuppressWarnings("unchecked") AsyncLoadingCache<Object, Object> asyncCache = (AsyncLoadingCache<Object, Object>) original;
        @SuppressWarnings("unchecked") AsyncLoadingCache<Object, Object> asyncCopy = (AsyncLoadingCache<Object, Object>) copy;
        checkAsynchronousCache(asyncCache, asyncCopy, desc);
    } else if (original instanceof Cache<?, ?>) {
        @SuppressWarnings("unchecked") Cache<Object, Object> syncCache = (Cache<Object, Object>) original;
        @SuppressWarnings("unchecked") Cache<Object, Object> syncCopy = (Cache<Object, Object>) copy;
        checkSyncronousCache(syncCache, syncCopy, desc);
    } else {
        throw new UnsupportedOperationException();
    }
    return desc.matches();
}
Also used : DescriptionBuilder(com.github.benmanes.caffeine.testing.DescriptionBuilder)

Example 4 with DescriptionBuilder

use of com.github.benmanes.caffeine.testing.DescriptionBuilder in project caffeine by ben-manes.

the class IsValidBoundedLocalCache method matchesSafely.

@Override
protected boolean matchesSafely(BoundedLocalCache<K, V> cache, Description description) {
    desc = new DescriptionBuilder(description);
    drain(cache);
    checkReadBuffer(cache);
    checkCache(cache, desc);
    checkEvictionDeque(cache, desc);
    if (!desc.matches()) {
        throw new AssertionError(desc.getDescription().toString());
    }
    return true;
}
Also used : DescriptionBuilder(com.github.benmanes.caffeine.testing.DescriptionBuilder)

Example 5 with DescriptionBuilder

use of com.github.benmanes.caffeine.testing.DescriptionBuilder in project caffeine by ben-manes.

the class IsValidLinkedDeque method matchesSafely.

@Override
protected boolean matchesSafely(LinkedDeque<E> deque, Description description) {
    DescriptionBuilder desc = new DescriptionBuilder(description);
    if (deque.isEmpty()) {
        checkEmpty(deque, desc);
    }
    checkIterator(deque, deque.iterator(), desc);
    checkIterator(deque, deque.descendingIterator(), desc);
    return desc.matches();
}
Also used : DescriptionBuilder(com.github.benmanes.caffeine.testing.DescriptionBuilder)

Aggregations

DescriptionBuilder (com.github.benmanes.caffeine.testing.DescriptionBuilder)7 CacheStats (com.github.benmanes.caffeine.cache.stats.CacheStats)1